When writing either Surface Shaders or regular Shader Programs, the HLSL source can be compiled into different “shader models”. To allow the use of more modern GPI functionality, you must use higher shader compilation targets.
Note: Using higher shader compilation targets may prevent the shader from working on older GPUs or platforms.
Indicate the compilation target by using the #pragma target
name directive. For example:
#pragma target 3.5
By default, Unity compiles shaders into almost the lowest supported target (“2.5”); in between DirectX shader models 2.0 and 3.0. Some other compilation directives make the shader automatically be compiled into a higher target:
#pragma geometry
) sets the compilation target to 4.0
.#pragma hull
or #pragma domain
) sets the compilation target to 4.6
.Any shader not explicitly setting a function entry point through #pragma
for geometry, hull or domain shaders will downgrade internal shader capability requirements. This allows non-DX11 targets with broader run-time and feature differences to be more compatible with the existing shader content.
For example, Unity supports tessellation shaders on Metal graphics, but Metal doesn’t support geometry shaders. Using #pragma target 5.0
is still valid, as long as you don’t use geometry shaders.
Here is the list of shader models supported, with roughly increasing set of capabilities (and in some cases higher platform/GPU requirements):
es3.0
target has.Note that all OpenGL-like platforms (including mobile) are treated as “capable of shader model 3.0”. WP8/WinRT platforms (DX11 feature level 9.x) are treated as only capable of shader model 2.5.