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.
Note: For information about shader keywords in Shader Graph, refer to Introduction to keywords in Shader Graph.
To reduce the number of shader variants Unity compiles, use the Shader Build Settings in the Graphics settings window.
Follow these steps:
FOG_LINEAR FOG_EXP FOG_EXP2
._
if it exists.For which keywords Unity uses in prebuilt shaders in the Universal Render PipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary, refer to Strip feature shader variants.
You can then do one of the following:
shader_feature
or dynamic_branch
. For more information about choosing a type, refer to How Unity compiles branching shaders.Select Apply to apply the changes. To remove a keyword set, select the Remove (-) button.
To customize shader variants for different platforms, use a build profileA set of customizable configuration settings to use when creating a build for your target platform. More info
See in Glossary. Each build profile you create has its own Shader Build Settings section that overrides the settings in the Graphics settings window. For more information, refer to Override settings with build profiles.
You can also do the following to reduce or remove shader variants:
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, refer to Stripping scriptable shader variants
If you strip a shader variant that a Material needs at runtime, Unity tries to choose a similar shader variant that’s available. To avoid this, use the following approaches:
shader_feature
keyword, don’t use the keyword to change which code branch executes at runtime.