View Full Version : Multiple Shaders or continuous uniform updates ?
09-15-2007, 04:01 PM
I have a shader thats used for a lot of different objects, each with their own set of uniform values (Diffuse color, specular color etc.)
I'm wondering, is it better to have one compiled shader and change it's uniforms for each object, or have multiple compiled versions of the same shader with their own sets of uniforms that don't get changed?
09-15-2007, 08:01 PM
In general cases use one shader with different uniforms. Except dynamic branching with uniformsvars as condition.
09-17-2007, 12:34 AM
Also note that on Nvidia cards before Geforce 8 do a shader "compile" behind the scenes when updating uniforms in fragment shaders. (So it can depend on how many objects and how many uniforms)
Just to make sure I follow... oc2k1, are you saying compiling a single instance of the shader, and changing it's object-specific uniforms (material properties for instance) between rendering each object is preferable to compiling one shader per object and setting these uniforms only once at shader creation?
I guess you don't have to transfer lights/matrices once per object if you do it that way, but it just seems a bit counter-intuitive to me. :) I've always thought one object, one material and hence one shader.
09-18-2007, 12:57 PM
Given the availability of texture arrays and general purpose buffers on the latest hardware, it's at least feasible to implement an entire material system on the GPU.
I personally haven't really explored this possibility yet, but it seems very interesting in general, doubly so w.r.t. instancing in particular.
09-18-2007, 02:15 PM
Originally posted by sqrt[-1]:
Also note that on Nvidia cards before Geforce 8 do a shader "compile" behind the scenes when updating uniforms in fragment shaders. (So it can depend on how many objects and how many uniforms) Can you elaborate or refer me to a forum post on what this means exactly? I've never noticed any large slowdowns when changing uniform values on any nvidia hardware that would indicate a compile is occuring.
09-18-2007, 06:04 PM
Try this thread:
Basically the thread above states that pre-Geforce 8 hardware does not have FP constants. (so changes to the program involve manually updating code)
Also I think Nvidia had some issue where they were trying to optimize common values like 2.0 and 0.5 when doing the updating. (not sure what happened with this)
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.