Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shader per mesh instance versus per material


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 cozzie   Members   -  Reputation: 1612

Like
0Likes
Like

Posted 01 June 2014 - 02:30 AM

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.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30386

Like
2Likes
Like

Posted 01 June 2014 - 04:42 AM

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.

#3 cozzie   Members   -  Reputation: 1612

Like
0Likes
Like

Posted 01 June 2014 - 11:02 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS