Enable dynamic branching in shaders in URP
Make Unity use dynamic branching in prebuilt or custom shaders, instead of keywords and shader variants.
읽는 시간 1분최근 업데이트: 6일 전
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
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.
- Input the keyword set, including the single underscore () or multiple underscores (
_) if they're part of the set. For example__._ FOG_LINEAR FOG_EXP FOG_EXP2 - Set Type Override to dynamic_branch.
- Select Apply. Unity recompiles the shaders.
Compatible keyword sets in prebuilt shaders
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 |
| Reflection Probe blending. For more information about Reflection Probes, refer to Reflection Probes in URP. |
| 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.
Check compatibility of custom shaders
To enable dynamic branching for a keyword set in a custom shader, use HLSL statements for branches, not preprocessor directives such as .
if#if