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?
In general cases use one shader with different uniforms. Except dynamic branching with uniformsvars as condition.
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.
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.
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)
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.