Game Development Reference
In-Depth Information
In the last step, we add ambient, difuse, and specular together, and muliply the lighing
atenuaion value doubled, to get the smooth specular efect ( c.rgb = (ambient +
diffuse + specular) * (atten * 2); ).
A major part of the code is in the Cg/HLSL language, so you might not be
familiar with it. However, you can sill get an idea of how it works by trying
to see more examples and taking a look at the Cg/HLSL language:
http://http.developer.nvidia.com/CgTutorial/cg_
tutorial_appendix_e.html
We can also see an example of the custom lighing model from the following
Unity website:
http://unity3d.com/support/documentation/Components/
SL-SurfaceShaderExamples.html
Classified Intel
How exactly do the surface shaders work?
First, we get the parameters from the Input struct , and these parameters will get
passed to the SurfaceOutput struct inside the surf funcion. Then, the return of the
SurfaceOutput struct will go to the lighing model funcion to calculate both the vertex
and pixel (fragment) shader. Lastly, the result from the lighing model funcion will be passed
to the frame buffer, as shown in the following diagram:
 
Search WWH ::




Custom Search