• Advertisement
Sign in to follow this  

Shader per mesh instance versus per material

This topic is 1332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm currently rebuilding the shader/ effect system in my engine. With this I run into the following:

- before the changes I defined a specific shader/effect for each object (mesh instance)
- if not explicitly defined, the 'base' shader/effect is used
- this base shader/effect contains lighting, texturing, normal mapping etc.
- in practice up till know I didn't have any reason to create a different effect for a specific object
- I now have some overkill on using a large base shader for everything that's rendered

So I partially implemented the following solution:
- switch from shader/effect per object to per material
- that way I can compile different versions of my base ('uber') shader with defines for specular, normal mapping etc.
- then per material I select the correct effect/shader, based on the material properties (normal map yes/no, specular color yes/no etc.)

This all sounds nice and logical I think, but..
To put this change through in my whole engine (including IO, scene management, renderqueue), is quite some work. So I'd like be sort of sure that this is the right approach.

Could you think of reasons why I would want to have a specific shader on a object level instead of material level?
Thinking ahead; things like bloom, specular map, fog, etc. I think would be on material or 'overall' base, not per object. I'm not sure about shadows/ shadow mapping (don't do that yet), maybe I can control that somehow on an object basis and set a flag shadows yes/no, and pass that with the material when I'm choosing the correct shader.

Any input is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Per material probably makes more sense in general than per object, but yes, if you can use information from both when selecting the right permutation of an uber-shader, that could be very useful.

e.g. When an object is hit by a spell, maybe it needs to start glowing - that's a per-object decision, not a per-material one.

I also use this to make some decisions from other sources -- e.g. One uber shader might support both forward and deferred rendering - if shader permutation selection can query per-scene/per-pass info, it can choose between forward opaque/translucent or g-buffer programs.

The same goes for shader parameters (uniforms) - many will come from the material, but you'll also have ones sourced from the object, and ones sourced from the scene itself too.

Share this post


Link to post
Share on other sites
Thanks. That means I'll build the base around having several compiled verslons of my ubershader (permutations), one being linked to a set of material properties. That way per material I select the right one. With this I'll figure a way out to be prepared for the future and create a "backdoor" to be able to add an effect "define" (to get another permutation) on a object level.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement