Download

Is it ok to use switches in parent shader?

My parent shader has about 8 switches now, which i toggle in instance materials as i need,
but how good it is for performance reasons? is there some crucial downside?

when you use a switch the material internally creates another version of itself, so in fact it’s as if you had 2 materials instead of using an instance of the same one.
this ramps up exponentially as you add more switches, by a factor of 2ⁿ where n is the amount of switches you have.
1 switch means 2 materials, 2 switches means 4 materials, 3 switches means 8 materials, and so on. in your case 8 switches means up to 256 different materials

it all comes down to how many materials you use in the end. a material with 3 switches for 100 instances seems perfectly ok, while a material with 8 switches for 100 instances defeats the purpose of using instances

Thank you.

And if i use Lerps instead?

Linear Interpolation is like the best thing ever for blending mats and alpha and stuff. Here, someone did a great job of showing how it’s done briefly and I’ll just link that instead of reinventing the wheel. Let me know if you have questions on it though.

https://answers.unrealengine.com/questions/71802/lerp-between-two-materials.html

Ok thank you i know what lerp is, that is not the question.

Question is:
i had 8 switches, asked if they are good for performance and in general, andswer is no,
so my next question is if i substitute switches with lerps, how big of performance impact that is and are there some major drawbacks to it.