Game Development Reference
In-Depth Information
The surface shaders placed inside
CGPROGRAM...ENDCG
block, must be placed inside the
SubShader
block, and uses the
#pragma surface ...
direcive to indicate that it's a
surface shader. You will see that the surface shaders placed inside
CGPROGRAM
and
ENDCG
block in the following example:
Shader "My Lambert" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200 //Optional that allows the script to turned the shader on
or off when the player's hardware didn't support your shader.
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
#pragma surface
The
#pragma surface
direcive is:
#pragma surface surfaceFunction lightModel [optionalparams]
Required parameters
The following are the required parameters for the
#pragma surface
direcive:
F
surfaceFunction
—the
Cg
funcion that has surface shader code. The funcion
should have the form
void surf (Input IN, inout SurfaceOutput o)
,
where
Input
is a structure you have defined.
Input
should contain any texture
coordinates and extra automaic variables needed by the surface funcion.