How to do it...

The toon aesthetic can be achieved with the following changes to the shader:

  1. Add a new property for a texture called _RampTex:
_RampTex ("Ramp", 2D) = "white" {} 
  1. Add its relative variable in the CGPROGRAM section:
sampler2D _RampTex; 
  1. Change the #pragma directive so that it points to a function called LightingToon():
#pragma surface surf Toon 
  1. Replace the LightingSimpleLambert function with the following function instead:
fixed4 LightingToon (SurfaceOutput s, fixed3 lightDir,             fixed atten) {   // First calculate the dot product of the light direction and the   // surface's normal  half NdotL = dot(s.Normal, lightDir);         // Remap NdotL to the value on the ramp map  NdotL = tex2D(_RampTex, fixed2(NdotL, 0.5));   // Next, ...

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.