master material shader vs. variety of shaders

hi, my question is about memory and performance issues with shaders.

i’m currently using a kind of master shader for my scenes, where the shader covers a variety of different shader permutations for the instances. e.g. for baked materials and tiled materials;
base color, metalness, roughness, normalmap, emissive and AO can all be switched off to use default values wich can also be altered, when there is a material that doesn’t need a specific map.

question: is it advisable to do it that way, or should i create specific shaders with a fixed set of functions and not create a potentially vast amount of permutations by the use of one mastershader?

A few Master shaders is afaik fine, the less the better ofcourse… but if there are meshes/whatever that only need a basic diffuse/normal inputs a seperate master for that besides a very complex shader for complex buildings, multiple diffuses, calculations and what not that are controlled by on/off/if nodes and what not… I would personally go with a few master shaders and use a variety of instances of them.

I often have one or two master materials for particles (non mesh based and mesh based version), two for static meshes (basic and complex), two for characters etc etc.

the less masters, the better ofcourse…
but current gen gpus can handle a lot so a few more masters isnt something to worry about.
100+ masters though… :stuck_out_tongue:

Hey -

To add to what Luos has said:

So the Engine batches based on the Material assigned to an object, so the number of materials which share the same material are placed in a single API call sent to the GPU to render, the amount is restricted to the speed of the computer used to render, the amount of resources the CPU has devoted to the API calls and the FPS desired. Less API calls means less CPU usage which allows for faster Physical and non-rendering based calculations in the game (which is always a good thing).

Thank You

Eric Ketchum

/me points at Eric.
Youdaman!

cool, thank you guys. this helps estimating, when to use these shaders!