architecture - GLSL multiple shaderprogram VS uniforms switches -


i'm working on shader manager architecture , have several questions more advanced people. current choice oppose 2 designs are:


1. per material shader program

=> create 1 shader program per material used in program.

potential cons:

  • considering every object might have own material, involves lot of gluseprogram calls.
  • implies creation of lot of shaderprogram objects.
  • more complex architecture #2.

pros:

  • shader code can generated each "options" used in material.
  • if i'm not wrong, uniforms have set 1 time (when shaderprogram created).


2. global shader programs

=> create 1 shader program per shader functionality (lightning, reflection, parallax mapping...) , use configuration variables enable or discard options depending on material render.

potential cons:

  • uniforms have changed many times per frame.

pros:

  • lower shader programs count.
  • less sp swich (gluseprogram).


you might notice current tendency #1, wanted know opinion it.

  • does initial uniforms setting offset gluseprogram call overhead (i'm not speed freak) ?
  • in case #1, memory or performance consideration, should call gllinkprogram once when create sp, or must unlink/link each time call gluseprogram?
  • are there better solutions ?

thanks!

let's @ #1:

considering every object might have own material, involves lot of gluseprogram calls.

this isn't big of deal, really. swapping programs hard, you'd swapping textures too, it's not you're not changing important state.

implies creation of lot of shaderprogram objects.

this going hurt. indeed, main problem #1 explosive combination of shaders. while arb_separate_program_objects help, still means have write lot of shaders, or come way not write lot of shaders.

or can use deferred rendering, helps mitigate this. among many advantages separates generation of material data computations transform material data light reflectance (colors). because of that, have far fewer shaders work with. have set of shaders produces material data, , set uses material data lighting computations.

so use #1 deferred rendering.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -