When writing either Surface ShadersUnity’s code generation approach that makes it much easier to write lit shaders than using low level vertex/pixel shader programs. More info
See in Glossary or regular
Shader Programs, the HLSL source can be
compiled into different “shaderA small script that contains the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuration. More info
See in Glossary 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 or the more specific #pragma require
feature … directive. For example:
#pragma target 3.5
#pragma require integers 2darray instancing
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.
List of supported feature names for the #pragma require
directive:
interpolators10
: At least 10 vertex-to-fragment interpolators (“varyings”) are available.interpolators15
: At least 15 vertex-to-fragment interpolators (“varyings”) are available.interpolators32
: At least 32 vertex-to-fragment interpolators (“varyings”) are available.mrt4
: Multiple Render Targets, at least 4.mrt8
: Multiple Render Targets, at least 8.derivatives
: PixelThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More infosamplelod
: Explicit texture LOD sampling (tex2Dlod / SampleLevel).fragcoord
: Pixel location (XY on screen, ZW depth in clip space) input in pixel shader.integers
: Integers are an actual data type, including bit/shift operations.2darray
: 2D texture arrays (Texture2DArray).cubearray
: CubemapA collection of six square textures that can represent the reflections in an environment or the skybox drawn behind your geometry. The six squares form the faces of an imaginary cube that surrounds an object; each face represents the view along the directions of the world axes (up, down, left, right, forward and back). More infoinstancing
: SV_InstanceID input system value.geometry
: DX10 geometry shaders.compute
: Compute shaders, structured buffers, atomic operations.randomwrite
: “random write” (UAV) textures.tesshw
: GPU support for hardware tessellation, but not necessarily tessellation shader stages (e.g. Metal supports tessellation, but not via shader stages).tessellation
: Tessellation hull/domain shader stages.msaatex
: Ability to access multi-sampled textures (Texture2DMS in HLSL).sparsetex
: Sparse textures with residency info (“Tier2” support in D3D terms; CheckAccessFullyMapped HLSL function). Note that currently this is only implemented on DX11/12.framebufferfetch
: Framebuffer fetch – ability to read input pixel color in the pixel shader.The broad #pragma target
directives are shorthands for the requirements above, and they correspond to:
2.5
: derivatives3.0
: 2.5 + interpolators10 + samplelod + fragcoord3.5
: 3.0 + interpolators15 + mrt4 + integers + 2darray + instancing4.0
: 3.5 + geometry5.0
: 4.0 + compute + randomwrite + tesshw + tessellation4.5
: 3.5 + compute + randomwrite4.6
: 4.0 + cubearray + tesshw + tessellationNote that in Direct3D terms shader model 4.0 also implies “mrt8”; and shader model 5.0 implies “interpolators32” and “cubearray”. However, these are not guaranteed to be available on many mobile platforms. So for backwards compatibility with existing shaders, writing #pragma target 4.0 does not automatically require 8 MRTs support; and writing #pragma target 5.0 does not require 32 interpolators nor cubemap arrays.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.