Game Development Reference
In-Depth Information
Surface shaders
To use the surface shaders, you need to define a surface function ( void surf(Input
IN, inout SurfaceOutput o) ) that takes any UVs or data you need as an input
and fills in the output structure, SurfaceOutput . SurfaceOutput , which basically
describes the properties of the surface (its albedo color, normal, emission, specularity, and
so on). Then, you write this code in Cg/HLSL.
The surface shaders' compiler then figures out what inputs are needed, what outputs are
filled, and so on and generates actual vertex and pixel shaders as well as rendering passes
to handle forward and deferred rendering.
The surface shaders placed inside the CGPROGRAM...ENDCG block are to be placed in-
side the SubShader block, and it uses the #pragma surface ... directive to indic-
ate that it's a surface shader. You will see that the surface shaders are placed inside the
CGPROGRAM and ENDCG blocks 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 shaderon 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;
Search WWH ::




Custom Search