Unity - Manual: pragma directives in HLSL
Unity supports all #pragma directives that are part of standard HLSL, as long as these directives are in regular include files. For more information on these directives, see the HLSL documentation: pragma Directive.
In addition, Unity supports the following Unity-specific #pragma directives:
If you are writing a Surface Shader, use this directive to tell the compiler which function to use as the surface function, and pass data to that function.
| Statement | Function |
|---|---|
#pragma surface <surface function> <lighting model> <optional parameters> |
Compile the function with the given name as the surface shader, so that it works with the given lighting model. For more information, see Surface Shaders. |
If you are writing a regular graphics shader, use these directives to tell the compiler which functions to use for different shader stages. The #pragma vertex and #pragma fragment directives are required, but other stages are optional.
| Statement | Function |
|---|---|
#pragma vertex <name> |
Compile the function with the given name as the vertex shader. Replace <name> with the function name. This directive is required in regular graphics shaders. |
#pragma fragment <name> |
Compile the function with the given name as the fragment shader. Replace <name> with the function name. This directive is required in regular graphics shaders. |
#pragma geometry <name> |
Compile the function with the given name as the geometry shader. Replace <name> with the function name. This option automatically turns on #pragma require geometry; for more information, see Targeting shader models and GPU features in HLSL.Note: Metal does not support geometry shaders. |
#pragma hull <name> |
Compile the function with the given name as the DirectX 11 hull shader. Replace <name> with the function name. This automatically adds #pragma require tessellation; for more information, see Targeting shader models and GPU features in HLSL. |
#pragma domain <name> |
Compile the function with the given name as the DirectX 11 domain shader. Replace <name> with the function name. This option automatically turns on #pragma require tessellation; for more information, see Targeting shader models and GPU features in HLSL. |
Use these directives to tell the shader compiler how to handle shader variants and keywords. For more information, see Declaring and using shader keywords in HLSL.
| Directive | Description |
|---|---|
#pragma multi_compile <keywords> |
Declares a collection of keywords. The compiler includes all of the keywords in the build.You can use suffixes such as _local to set additional options.For more information and a list of supported suffixes, see Declaring and using shader keywords in HLSL. |
#pragma shader_feature <keywords> |
Declares a collection of keywords. The compiler excludes unused keywords from the build.You can use suffixes such as _local to set additional options.For more information and a list of supported suffixes, see Declaring and using shader keywords in HLSL. |
#pragma hardware_tier_variants <values> |
Built-in Render Pipeline only: Add keywords for graphics tiers when compiling for a given graphics API. For more information, see Graphics tiers. |
#pragma skip_variants <list of keywords> |
Strip specified keywords. |
Use these directives to tell the compiler that your shader requires specific GPU features.
| Statement | Function |
|---|---|
#pragma target <value> |
The minimum shader model that this shader program is compatible with. Replace <value> with a valid value. For a list of valid values, see Shader compilation: Targeting shader models and GPU features in HLSL. |
#pragma require <value> |
The minimum GPU features that this shader is compatible with. Replace <value> with a valid value, or multiple valid values separated by a space. For a list of valid values, see Shader compilation: Targeting shader models and GPU features in HLSL. |
Use these directives to tell Unity to include or exclude code for a given graphics API.
| Statement | Function |
|---|---|
#pragma only_renderers <value> |
Compile this shader program only for given graphics APIs. Replace <values> with a space-delimited list of valid values. For more information and a list of valid values, see Targeting graphics APIs and platforms in HLSL. |
#pragma exclude_renderers <value> |
Do not compile this shader program for given graphics APIs. Replace <value> with a space-delimited list of valid values. For more information and a list of valid values, see Targeting graphics APIs and platforms in HLSL. |