How it works...

As previously seen in Chapter 2, Creating Your First Shader, the #pragma directive is used to specify which surface function to use. Choosing a different lighting model works in a similar fashion: SimpleLambert forces Cg to look for a function called LightingSimpleLambert(). Note the Lighting at the beginning, which is omitted in the directive.

The Lighting function takes three parameters: the surface output (which contains the physical properties such as the albedo and transparency), the direction the light is coming from, and its attenuation.

According to Lambertian reflectance, the amount of light a surface reflects depends on the angle between the incident light and surface normal. If you have played pool billiards, you ...

Get Unity 2018 Shaders and Effects Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.