Creating a toon shader
One of the most commonly used effects in games is toon shading, which is also known as celluloid (CEL) shading. This is a non-photorealistic rendering technique that makes 3D models appear flat. Many games use it to give the illusion that the graphics are being drawn by hand rather than modeled in 3D. In the following diagram, you can view a sphere rendered with a toon shader (on the left-hand side) and a sphere rendered with a standard shader (on the right-hand side):
Achieving this effect using just surface functions is not impossible, but it would be extremely expensive and time-consuming. In fact, the surface function only works on the properties of the material, not its actual lighting condition. As toon shading requires us to change the way light reflects, we need to create a custom lighting model instead.
Getting ready
Let's start this recipe by...