O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 input, and fills in the output structure SurfaceOutput. The SurfaceOutput structure basically describes properties of the surface (that is albedo color, normal, emission, specularity, and so on). Then, you write this code in Cg/HLSL.

Surface shader compiler then figures out the inputs that are needed, the outputs that 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 CGPROGRAM...ENDCG block, must be placed inside the SubShader block, and uses the #pragma surface ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required