Set the graphics API or platform for a shader
Use pragma statements to set the graphics API or platform for a shader.
Read time 1 minuteLast updated a month ago
By default, Unity compiles all shader programs for each graphics API in the list for the current build target. To compile certain shader programs only for certain graphics APIs or platforms, for example if you use features that aren't supported on all platforms, use a statement.
#pragmaUse one of the following in the block of a shader:
HLSLPROGRAM- to compile shaders only for a specific graphics API, for example
#pragma only_renderers.#pragma only_renderers metal - to exclude shaders from compilation for a specific graphics API, for example
#pragma exclude_renderers.#pragma exclude_renderers metal
You can pass multiple values by adding a space between each argument, for example .
#pragma only_renderers metal vulkanThe supported values are:
Value | Description |
|---|---|
| DirectX 11 feature level 10 and above, and DirectX 12. This value is provided for compatibility reasons. In a new project, use |
| DirectX 11 feature level 10 and above. |
| DirectX 12. |
| OpenGL 3.x, OpenGL 4.x |
| OpenGL ES 3.x, WebGL 2.0 |
| Metal on iOS or macOS |
| PlayStation®4 |
| PlayStation®5 |
| PlayStation®4 or PlayStation®5 |
| Nintendo Switch™ |
| Vulkan |
| WebGPU |
| Xbox Series S|X |