Hi, I am trying to build an uber shader in a whole game project, with many shader_feature control them.
But I when I use about 18 different shader_feature, the unity become almost unuseable, and when it loading, it take about more than 8G memory.
Am I use the wrong way?
I’m going to take a guess that the sheer number of shader permutations it to blame. The problem is often referred as “shader combinatorial explosion”. With 18 shader_features Unity has to create 2^18 different shaders. That’s roughly 260 000 shader permutations for a single vertex or pixel shader.
Surface shaders are a lot worse because they already use several shader_features internally (Unity has to create shader variants for different light types, shadows etc.) So if you use 18 shader_features in a surface shader then Unity will create something like 2^24 shaders. Maybe less, maybe more but likely millions of shaders.
The problem is that every shader_feature doubles number of shaders. You could try to use multi_compile instead to save some permutations where possible. But I think the best thing to do is to split your uber shader into several smaller shaders. It will be a lot easier to maintain and debug.
I think multi_compile is the same result as shader_feature do.
I see the solution from the AssetStore, some shader plugin combine and generate new shader by their own code.
At that time I just think why they don’t use shader_feature to control everything, because just add decades number of shader_feature is beyond the unity afford.
I just want to know why the editor generate ALL shader variant during loading time. I use GameBryo before, it have a dynamic shader tree system to generate its standard sheers, but it just generate the shader that need to render.
Write many shader file is one solution, but it just make the shader more hard to maintain and the artists have less usability. Because I need to process when the artists want to combine two effect(just like one vertex colour animation with another light mode, and a uv animation even more), write multi-shader file is back to the hell of shader combinatorial explosion.