Version: Unity 6 (6000.0)
Language : English
Branch based on shader pass or shader stage
Shader keyword fundamentals

Shader keywords

Resources and techniques for adding shaderA program that runs on the GPU. More info
See in Glossary
keywords, using them to create branches and shader variants, and toggling them in the Unity Editor or in a script.

Page Description
Shader keywords fundamentals Learn about defining shader keywords to create shaders that share some common code, but have different functionality when you enable or disable a keyword.
Shader keyword scope fundamentals Learn about local and global keyword scope in shaders, and local and global keywords in C#.
Choose which type of conditional to use in shaders Choose static branching, dynamic branching, or shader variants.
Declare shader keywords Use a #pragma directive in HLSL code to declare keywords.
Make shader behavior conditional on keywords Use an if statement in HLSL code, or a pre-processor directive, to mark parts of your shader code conditional based on whether you enable or disable a shader keyword.
Toggle shader keywords with the Inspector window Add material properties for shader keywords.
Toggle and check shader keywords in a script Check if a keyword is enabled or disabled, and enable and disable it.
Built-in keywords Resources for the default shader keywords in Unity, and creating sets of built-in keywords.

Additional resources

Branch based on shader pass or shader stage
Shader keyword fundamentals