Game Development Reference
In-Depth Information
#pragma surface
The #pragma surface directive is used as follows:
#pragma surface surfaceFunction lightModel [optionalparams]
The required parameters to use this directive are as follows:
surfaceFunction : This is used to define which Cg function has the surface
shader code. The function should have the form of void surf (Input IN,
inout SurfaceOutput o) , where Input is a structure you have defined.
Input should contain any texture coordinates and extra automatic variables
needed by surface function.
lightModel : This is used to define a lighting model to be used. The built-in
models are Lambert (diffuse) and BlinnPhong (specular). You can also write your
own lighting model using the following custom lighting models:
half4 LightingName (SurfaceOutput s, half3
lightDir, half atten); : This is used in forward rendering the
path for light models that are not view-direction dependent (for example,
diffuse)
half4 LightingName (SurfaceOutput s, half3
lightDir, half3 viewDir, half atten); : This is used in
forward rendering path for light models that are view-direction dependent
half4 LightingName_PrePass (SurfaceOutput s, half4
light); : This is used in the deferred lighting path.
Tip
Note that you don't need to declare all functions. A lighting model either uses view direc-
tion or it does not. Similarly, if the lighting model does not work in deferred lighting, you
just do not declare the _PrePass function, and all shaders that use it will compile to for-
ward rendering only, such as the shader that we created in Project 3 , Shade Your Hero/
Heroine . We don't need the _PrePass function because our shader needs the view direc-
tion ( viewDir ) and the light direction ( lightDir ) for our custom lighting function to
calculate the ramp effect for the cartoon style shader (toon shader / cel shader), which is
only available in forward rendering.
Optional parameters [optionalparams] to use #pragma surface are listed in the
following table:
Search WWH ::




Custom Search