Strip shader variants in URP
Remove shader variants for features you don't use.
Read time 4 minutesLast updated 22 days ago
By default, the Universal Render Pipeline (URP) compiles both shader variants where a feature is enabled, and shader variants where a feature is disabled. This can increase the number of shader variants in your build exponentially, depending on how many features you use.
To remove a feature and its shader variants, do either of the following:
- Disable the feature in the Editor settings.
- Disable shader keywords by using the Shader Build Settings in Graphics settings.
If you need a feature for your project, you can instead make sure you enable it across your project in the Editor settings, so Unity can strip the variants where the feature is disabled.
Strip unused shader variants
To make sure Unity strips unused shader variants from your build, follow these steps:
- From the main menu, go to Edit > .Project Settings
?
- Select the Graphics tab.
- In the Additional Shader Stripping Settings section, enable Strip Unused Variants.
If you disable the Strip Unused Variants setting, URP can't strip variants where the feature is disabled. This might increase the number of variants.
Disable a feature in settings
To remove the shader variants for a feature, disable the feature in all the URP assets or Universal Renderer assets in your project, or elsewhere in the Editor settings.
For a list of settings, refer to Settings and keywords reference for stripping keywords in URP.
If a setting is in the URP asset, make sure you disable the feature in all the URP assets included in your build. Unity includes the following URP assets in your build:
- The URP asset you set as the default render pipeline asset in Graphics settings.
- Any URP asset you set as a Render Pipeline Asset in a Quality settings level you enable for the current build target.
Disable shader keywords
For a list of keywords in prebuilt shaders in URP, refer to Settings and keywords reference for stripping keywords in URP.
Follow these steps:
- From the main menu, go to Edit > Project Settings.
- Select the Graphics tab.
- In the Shader Build Settings section, select the Add (+) button.
- Add the keyword set, for example .
_ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS - Use the foldout (triangle) to expand the keyword set, then disable the individual keywords.
- Select Apply. Unity recompiles the shaders.
To keep a feature but still reduce the number of shader variants, refer to Enable dynamic branching in prebuilt shaders.
Strip post-processing shader variants
To strip shader variants for Volume Overrides you don't use, follow these steps:
- From the main menu, go to Edit > Project Settings.
- Select the Graphics tab.
- Enable Strip Unused Post Processing Variants. Unity now keeps only the shader variants for Volume Overrides you use in your project.
- Enable Strip Screen Coord Override Variants, unless you override screen coordinates to support post-processing on large numbers of multiple displays, also known as cluster displays.
To disable the shader keywords for a post-processing effect instead, refer to Settings and keywords reference for stripping keywords in URP.
Unity checks for Volume Overrides in all scenes, so you can't strip variants by removing a scene from your build but keeping it in your project. You must remove the scene from the project.
Strip XR and VR shader variants
If you don't use XR or VR, disable the XR and VR modules. This allows URP to strip XR and VR-related shader variants from its standard shaders.
Open the URP stripping code
To examine the code that strips shaders in URP, check the file. The file uses the IPreprocessShaders API.
Editor/ShaderPreprocessor.cs