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 |
|---|---|
DIRLIGHTMAP_COMBINED |
Directional lightmaps. For more information, refer to Lightmapping settings. |
DYNAMICLIGHTMAP_ON |
Realtime Global Illumination lightmaps. For more information, refer to Lightmapping settings. |
_ EVALUATE_SH_VERTEX EVALUATE_SH_MIXED |
Evaluating spherical harmonics for ambient probes. For more information, refer to URP asset. |
_ FOG_LINEAR FOG_EXP FOG_EXP2 |
Fog. For more information, refer to Lighting window. |
LIGHTMAP_ON |
Lightmaps. For more information, refer to Lightmapping settings. |
LIGHTMAP_SHADOW_MIXING |
Shadows if you set Lighting Mode to Subtractive. For more information, refer to Lighting Mode. In G-buffer render passes, Unity still compiles a separate shader variant for this keyword. |
LOD_FADE_CROSSFADE |
LOD transitions. For more information, refer to Level of DetailThe Level Of Detail (LOD) technique is an optimization that reduces the rendering workload to improve performance. More info See in Glossary. |
REFLECTION_PROBE_ROTATION |
Reflection Probe rotation. For more information about Reflection Probes, refer to Reflection Probes in URP. |
SHADOWS_SHADOWMASK |
Shadows if you set Lighting Mode to Shadowmask. For more information, refer to Lightmapping settings. In G-buffer render passes, Unity still compiles a separate shader variant for this keyword. |
_ADDITIONAL_LIGHT_SHADOWS |
Additional lights that cast shadows. For more information, refer to Shadows in URP. |
_ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON |
Specular highlights on transparent materials. For more information about material properties, refer to Material properties. |
_ _CLEARCOAT _CLEARCOATMAP |
Clear coat. For more information about material properties, refer to Material properties. In some Shader Graph render passes, Unity still compiles a separate shader variant for this keyword. |
_ _DETAIL_MULX2 _DETAIL_SCALED |
Detail mapping. For more information about material properties, refer to Material properties. |
_EMISSION |
Emission. For more information about material properties, refer to Material properties. |
_ENVIRONMENTREFLECTIONS_OFF |
Environment reflections. For more information about material properties, refer to Material properties. |
_GBUFFER_NORMALS_OCT |
Accurate G-buffer normals in deferred rendering paths. For more information, refer to Universal Renderer. |
_GLOSSINESS_FROM_BASE_ALPHA |
Smoothness from the Base Map alpha property of Simple Lit shaders. For more information about material properties, refer to Material properties. |
_LIGHT_COOKIES |
Light cookies. For more information, refer to Light components. |
_LIGHT_LAYERS |
Rendering layers for lights. For more information, refer to Rendering LayersA layer that defines how specific effects are applied across different objects. Rendering layers don’t define draw order. They’re selection groups you assign objects to. Rendering layers let lights, decals, shadows, and custom passes include or ignore specific objects. See in Glossary. In deferred, terrain, 2D, and SpeedTree shaders, Unity still compiles a separate shader variant for this keyword. |
_ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN |
Main lights that cast shadows. For more information, refer to Shadows in URP. |
_METALLICSPECGLOSSMAP |
Metallic or specular maps. For more information about material properties, refer to Material properties. |
_NORMALMAP |
Normal maps. For more information about material properties, refer to Material properties. In some Shader Graph render passes, Unity still compiles a separate shader variant for this keyword. |
_OCCLUSIONMAP |
Occlusion maps. For more information about material properties, refer to Material properties. |
_PARALLAXMAP |
Height maps. For more information about material properties, refer to Material properties. |
_RECEIVE_SHADOWS_OFF |
GameObjects that receive shadows. For more information about material properties, refer to Material properties. |
_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. |
_SCREEN_SPACE_OCCLUSION |
Screen Space Ambient Occlusion (SSAO). For more information, refer to Screen Space Ambient Occlusion Renderer Feature. |
_ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH |
Soft shadows. For more information, refer to Shadows in URP. |
_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
Smoothness from the Base Map alpha property of Lit shaders. For more information about material properties, refer to Material properties. |
_ _SPECGLOSSMAP _SPECULAR_COLOR |
Specular or gloss map properties of Simple Lit shaders. For more information about material properties, refer to Material properties. |
_SPECULARHIGHLIGHTS_OFF |
Specular highlights. For more information about material properties, refer to Material properties. |
_SPECULAR_SETUP |
Specular setup. For more information about material properties, refer to Material properties. In some Shader Graph render passes, Unity still compiles a separate shader variant for this keyword. |
_SURFACE_TYPE_TRANSPARENT |
Transparency. For more information about material properties, refer to Material properties. In some Shader Graph render passes, Unity still compiles a separate shader variant for this keyword. |
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.