Master material for everythings, how optimized is it ?

Hi, my name is Fabian and i’m working on VR for mobile projects (Gear VR) and everythings has to be the most optimized for best performances possible, everythings count.

Actually, we made differents “master” materials depends of what the graphists needs (with tile funtion, with specular, with normal, with emmissive, ect)
Works great, they create instances shaders of the proper master depends the need by using the most optimized version.

But it can be a pain to maintain and i’m looking for a most “toolkit / swissknife” version with “everythings” inside, with the ability to activate / desactivate functions with switches and static bool Param. I really want to work like that, but now is the question…

… when branches are disables, is it as optimize like a simple version of the shader ?

I mean, a very very complex shader with just a 3 vectors color passed to base color (everything else is disable) is as optimized as a simple material with only a color 3 vectors in base color ?

Thank you

A single master material isn’t beneficial for a number of reasons. Performance wise, you lose one of the benefits of instances when you have a unique combination of switches. 20 instances with identical switch combinations perform better than 20 with unique switch combinations. With the unique variants, it’s similar to just using a brand new material.

Plus, it’s an absolute pain to update later on down the road when you need to add some one-off feature, or even something as simple as adding another parameter, because the material takes so long to compile every time with all of the switches.

@rosegoldslugs That makes sense. I was suspecting as much, good to hear it from someone else. Thanks.