Structuring a Unity HLSL shader
When we worked on our simple Blinn-Phong shader in Chapter 1, we discussed the syntax of Unity shaders. We saw that all these files are composed of an overarching wrapper using the ShaderLab syntax and that inside it, we find blocks such as Properties
, SubShader
, and Pass
. The real “meat” of the code, so to speak, is the low-level shader logic written in between the CGPROGRAM
and ENDCG
lines. This is the hardware shader code that performs the actual computation.
All of this can be summarized as follows:
Shader "Custom/MyLegacyShader" { Properties { ... } SubShader { // subshader tags Pass { // pass tags // (optional: blend mode setup) ...