To reduce the number of shader variants in the Universal Render Pipeline (URP), enable Unity using dynamic branching in shaders instead of keywords and shader variants.
For more information about keywords, refer to Changing how shaders work using keywords
Note: If you target an older mobile device, dynamic branching can cause performance issues. Test on your target device.
Follow these steps:
_) or multiple underscores (__) if they’re part of the set. For example _ FOG_LINEAR FOG_EXP FOG_EXP2.If you use prebuilt shaders in URP, you can only enable dynamic branching for the keyword sets in the following table.
| Keyword set | Feature dynamic branching is enabled for |
|---|---|
_ FOG_LINEAR FOG_EXP FOG_EXP2 |
Fog |
_REFLECTION_PROBE_BLENDING |
Reflection Probe blending. For more information about Reflection Probes, refer to Reflection Probes in URP. |
_REFLECTION_PROBE_BOX_PROJECTION |
Reflection Probe box projection. For more information about box projection, refer to Troubleshooting reflections. |
Other keyword sets in prebuilt shaders aren’t compatible with dynamic branching.
To enable dynamic branching for a keyword set in a custom shader, use HLSL if statements for branches, not preprocessor directives such as #if.