You can prevent shader variants from being compiled. This is called stripping. Stripping unneeded variants can greatly reduce build times, file size, shader loading times, and runtime memory usage. In larger projects, or projects with complex shaders, this is a very important consideration.
The way that you declare shader keywords can limit the number of variants that they produce:
shader_feature
instead of multi_compile
where possible.multi_compile
.For information on doing this in hand-coded shaders, see Declaring and using shader keywords in HLSL. For information on doing this in Shader Graph, see Shader Graph: Blackboard.
There are several places in the Unity Editor UI where you can configure shader stripping:
For shader variants that you can’t strip in other ways, you can use the following APIs in an Editor script to perform build-time stripping:
For more information on this subject, see the Unity blog post Stripping scriptable shader variants