Knowledge Base: Understanding Shader Permutations

Article written by Matt O.
In this article, we’ll cover at a high-level what shader permutations are, how they happen, the performance issues they create both at runtime and compile time, and potential remedies.
Covere…

https://dev.epicgames.com/community/learning/knowledge-base/6PxP/unreal-engine-understanding-shader-permutations

13 Likes

Really a useful article!
But I’m still confused about using the static switch parameter node, the documentation said :“Try to minimize the number of static parameters in the material and the number of permutations of those static parameters that are actually used.”(Parameter Expressions | Unreal Engine Documentation)
But it also said: "Static Switches can be used to remove an entire branch of a material with no runtime cost. Instances can have different values, making it possible to have a templated shader setup with no performance loss. "
Would you like to add more details about the static switch parameter? I don’t know how to deal with this part when I’m writing a material template. Thanks!

I can have a look around and see if I can get you a better answer or if we need to elaborate on this in this article.

1 Like

Wow, another article worth setting a bookmark.

For those of you who might want an answer to this question, as the article points out, using static switch parameters results in generating shader permutations since each different combination of using them in material instances will require different shader bytecodes. The compilation of the shaders happen in cook time which means there is no real time performance impact of them, but you will need more time to cook(and build) as well as more memory space for shader codes. This is why you should “try to minimize the number of static switch parameters” for cook time management and memory usage but in the same time, you can “have a templated shader setup with no performance loss” since those compilation works are not done in runtime.