Introduction
A .shader file is a text file that holds a shader for the
Unity game engine, written in ShaderLab, Unity’s
declarative language for shaders. ShaderLab describes the structure around the code: the
properties a material exposes, the sub-shaders and passes, and the fallback to use when
none of them runs. The programs that do the drawing are written in
HLSL and sit inside the file between
HLSLPROGRAM and ENDHLSL.
A .cginc file is an include file. Unity’s built-in shader include files use
this extension, and, despite the name, their code is written in HLSL rather than in
Cg. A shader pulls one in with #include.
Structure
A shader starts with the Shader keyword and a name in quotation marks,
which is the path shown in the material’s shader menu. A Properties block
declares the values the material editor shows. One or more SubShader blocks
hold Pass blocks, and an optional Fallback names another
shader.
Shader "Examples/FlatColour"
{
Properties
{
_Colour ("Colour", Color) = (1, 0, 0, 1)
}
SubShader
{
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Colour;
float4 vert(float4 vertex : POSITION) : SV_POSITION
{
return UnityObjectToClipPos(vertex);
}
float4 frag() : SV_Target
{
return _Colour;
}
ENDHLSL
}
}
}
Not described
Known, not yet covered
- Reference: this overview is the only page. The format has no reference pages: the property types, the sub-shader tags and the pass state commands (blending, culling, depth), the
#pragmadirectives, the built-in include files and variables, and how the code differs between Unity’s render pipelines. Unity’s ShaderLab documentation describes them. - Reference: Shader Graph, Unity’s visual shader editor, is not described.
- Viewer: there is no viewer for these formats yet, and nothing is compiled or checked.
Links
Software
- Unity – game engine that compiles and uses these shaders (Windows, macOS, Linux)
Reference
- ShaderLab: defining a shader – Unity’s page on the
Shaderblock - Built-in shader include files – the
.cgincfiles