ShaderLabUnity’s declarative language for writing shaders. More info
See in Glossary shadersA 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 encompass more than just “hardware shaders”. They do many things. They describe properties that are displayed in the Material InspectorA Unity window that displays information about the currently selected GameObject, Asset or Project Settings, allowing you to inspect and edit the values. More info
See in Glossary, contain multiple shader implementations for different graphics hardware, configure fixed function hardware state and so on. The actual programmable shaders - like vertex and fragment programs - are just a part of the whole ShaderLab’s “shader” concept. Take a look at shader tutorial for a basic introduction. Here we’ll call the low-level hardware shaders shader programs.
If you want to write shaders that interact with lighting, take a look at 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 documentation. For some examples, take a look at Vertex and Fragment Shader Examples. The rest of this page assumes shaders do not interact with Unity lights (for example special effects, post-processed effects etc.)
// ... the usual pass state setup ...
// compilation directives for this snippet, e.g.:
#pragma vertex vert
#pragma fragment frag
// the Cg/HLSL code itself
// ... the rest of pass setup ...
HLSL program snippets are written between CGPROGRAMA block of shader code for controlling shaders using NVIDIA’s Cg (C for graphics) programming language. More info
See in Glossary and ENDCG keywords, or alternatively between HLSLPROGRAM and ENDHLSL. The latter form does not automatically include HLSLSupport and UnityShaderVariables built-in header files.
At the start of the snippet compilation directives can be given as #pragma statements. Directives indicating which shader functions to compile:
Other compilation directives:
Each snippet must contain at least a vertex program and a fragment program. Thus #pragma vertex and #pragma fragment directives are required.
Compilation directives that don’t do anything starting with Unity 5.0 and can be safely removed:
Unity only supports #pragma directives in the shader files, and not in the includes.
Unity supports several renderingThe process of drawing graphics to the screen (or to a render texture). By default, the main camera in Unity renders its view to the screen. More info
See in Glossary APIs (e.g. Direct3D 11 and OpenGL), and by default all shader programs are compiled into all supported renderers. You can indicate which renderers to compile to using #pragma only_renderers or #pragma exclude_renderers directives. This is mostly useful in cases where you are explicitly using some shader language features that you know aren’t possible on some platforms. Supported renderer names are:
For example, this line would only compile shader into D3D11 mode:
#pragma only_renderers d3d11