Version: 2019.4
Using shader keywords with the material Inspector
Shader variant collections

Shader variant stripping

You can prevent shader variantsA verion of a shader program that Unity generates according to a specific combination of shader keywords and their status. A Shader object can contain multiple shader variants. More info
See in Glossary
from being compiled. This is called stripping. Stripping unneeded variants can greatly reduce build times, file size, shaderA program that runs on the GPU. More info
See in Glossary
loading times, and runtime memory usage. In larger projects, or projects with complex shaders, this is a very important consideration.

Limiting shader variants when you declare shader keywords

The way that you declare shader keywords can limit the number of variants that they produce:

  • Use shader_feature instead of multi_compile where possible.
  • Ensure that you don’t define unused keywords with multi_compile.
  • Indicate when shader keywords only affect a given shader stage.

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.

Stripping shader variants in the Editor UI

There are several places in the Unity Editor UI(User Interface) Allows a user to interact with your application. More info
See in Glossary
where you can configure shader stripping:

  • In the Graphics Settings window, configure the settings in the Shader stripping section:
  • Ensure that no unneeded shaders are included in the Always-included shaders setting.
  • Strip variants relating to GPU instancing, lightmapping, and fog.
  • In the Built-in Render Pipeline, if it is not important that your Tier settings are different, ensure that they are identical to each other. For more information, see Graphics tiers.
  • In the Universal Render Pipeline (URP), disable unused features in the URP Asset. For more information, see Shader stripping.

Stripping shader variants using Editor scripts

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

Using shader keywords with the material Inspector
Shader variant collections