About Shader Keywords

intermediate concepts

Shader Control · Core Concepts

About Shader Keywords

Shaders are highly optimized programs that run on the GPU. To avoid unnecessary instructions, shader features are controlled via keywords that generate compiled variants of the same code base. Each variant is locally optimized with fewer registers and no conditional branching.

How Keywords Work

Consider a fog shader with an optional gradient feature. Instead of using an if statement at runtime, a keyword generates two compiled variants:

#pragma multi_compile __ FOG_USE_GRADIENT

The underscore (__) tells the compiler to generate a variant without the keyword, and another with FOG_USE_GRADIENT. The shader code uses compiler conditionals to include or exclude the gradient logic in each variant.

Uber Shaders and the Variant Problem

Complex "uber shaders" use many keywords to pack multiple features into a single render pass. While this produces faster shaders than chaining sequential passes, it also generates a large number of variants from keyword permutations — most of which are never used.

For example, a shader with 10 binary keywords generates up to 1,024 variants (210). With Shader Control, you can disable unused keywords and dramatically reduce this number.

The 256 Keyword Limit

Unity imposes a global limit of 256 unique keywords across all shaders in a project. Large projects with many assets can easily exceed this limit. Shader Control's Project View helps you identify which shaders contribute the most keywords and disable the ones you do not need.

Warning: Modifying shader keywords incorrectly can produce visual artifacts or break materials. Always back up your project before making changes, and consult the asset author if you are unsure which keywords are safe to remove.

Next Steps

Learn how to create Shader Variant Collections for runtime prewarming, or check the Window Stats guide to understand the statistics display.

Was this page helpful?