In Unity, you usually write shaderA program that runs on the GPU. More info
See in Glossary programs in HLSL. To add HLSL code to your shader asset, you put the code inside a shader code block.
Note: Unity also supports writing shader programs in other languages, although this is not generally needed or recommended. For more information, see Writing shaders.
This section of the manual includes information on using HLSL in a Unity-specific way. For general information on writing HLSL, see Microsoft’s HLSL documentation.
Note: Avoid using CGPROGRAM
in shader code, unless you write surface shadersA streamlined way of writing shaders for the Built-in Render Pipeline. More info
See in Glossary.
HLSL has two syntaxes: a legacy DirectX 9-style syntax, and a more modern DirectX 10+ style syntax. The difference is mostly in how texture sampling functions work:
Unity provides shader libraries that contain preprocessor macros to help you manage these differences. For more information, see Built-in shader macros.
The Vertex ShaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary is a program that runs on each vertex of the 3D model. Quite often it does not do anything particularly interesting. Here we just transform vertex position from object space into so called “clip space”, which is what’s used by the GPU to rasterize the object on screen. We also pass the input texture coordinate unmodified - we’ll need it to sample the texture in the fragment shader.
The Fragment Shader is a program that runs on each and every pixelThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary that object occupies on-screen, and is usually used to calculate and output the color of each pixel. Usually there are millions of pixels on the screen, and the fragment shaders are executed
for all of them! Optimizing fragment shaders is quite an important part of overall game performance work.
Some variable or function definitions are followed by a Semantic Signifier - for example : POSITION or : SV_Target. These semantics signifiers communicate the “meaning” of these variables to the GPU. See the shader semantics page for details.