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, 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 inside the
SubShader block, and it uses the
#pragma surface ...