How it works...

Let's break down the Lighting function by itself, as the rest of the shader should be pretty familiar to you at this point.

In the previous recipes, we have used a Lighting function that provided only the light direction, lightDir.

Unity comes with a set of Lighting functions that you can use, including one that provides the view direction, viewDir.

To figure out how to write your own custom lighting mode refer to the following table replacing NameYouChoose with the lighting function name you gave in the #pragma statement or go to http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLighting.html for more details:

Not view-dependent half4 LightingNameYouChoose (SurfaceOutput s, half3 lightDir, half atten);

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.