---
title: Shader keywords workflow
product: Unity Editor
version: '6000.3'
latest_version: '7000.0'
status: This page documents version 6000.3. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords
latest_url: https://docs.unity.com/en-us/engine/7000.0/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords.md
last_updated: 2026-10-30
generated_at: 2026-11-19T06:39:32.303Z
locale: en-us
---

# Shader keywords workflow

> Learn about defining shader keywords to create shaders that share some common code, but have different functionality when you enable or disable a keyword.

To control how shaders behave in different situations, use shader keywords. Each keyword acts as a toggle to change the shader's behavior.

You can use keywords to do the following:

* Configure different settings for a material.
* Make a shader work differently on different hardware.
* Dynamically change the behavior of a shader at runtime.

Use the following steps:

1. Declare a shader keyword, or a set of shader keywords.
2. Use an `if` statement to branch the shader code depending on the state of the keyword.
3. Toggle the shader keyword to control which branch is active.

## Declare a shader keyword

Declare a shader keyword, or a set of shader keywords, using a `#pragma` statement. The following example defines a set of 2 keywords called `RED` and `GREEN`:

```lang-hlsl
#pragma shader_feature RED GREEN
```

For more information, refer to [Declare shader keywords](/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/declare.md).

## Branch the shader code

Use an `if` statement to make parts of your shader code execute based on the state of the keyword. For example, use the `RED` and `GREEN` keywords to control the color the shader outputs:

```lang-hlsl
void frag() : SV_Target {

    if (RED)
    {
        // Output red
    }
    
    else if (GREEN)
    {
        // Output green
    }

}
```

For more information, refer to [Make shader behavior conditional on keywords](/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/make-conditionals.md).

> **Note:**
>
> You can also use HLSL conditional statements like `if` and preprocessor statements like `#if` without using shader keywords.

## Toggle the shader keyword

To control the shader from the Editor or at runtime, refer to the following:

* [Toggle shader keywords in the Editor](/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords-material-inspector.md)
* [Toggle shader keywords in a script](/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords-scripts.md)

## Additional resources

* [How Unity compiles branching shaders](/engine/6000.3/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-conditionals-choose-a-type.md)
* [Limit shader variants when you declare shader keywords](/engine/6000.3/manual/materials-and-shaders/shaders/shader-troubleshooting/shader-reducing/shader-variants/shader-variant-stripping.md#limit-shader-variants-when-you-declare-shader-keywords)
* [Default keyword sets](/engine/6000.3/manual/materials-and-shaders/shaders/shader-troubleshooting/shader-reducing/shader-variants/shader-keywords-default.md)
