Toon shading is a shading method used to make video games look cartoony in order to emulate traditional cartoon animation style, many of which are licensed adaptations of cartoons and anime. If you’re familiar with Dragonball Z or Naruto Shippuden games, you’re most likely aware of what they are, but how are they implemented?
The way toon shading works is that the intensity of the light is being calculated, quantized and used as a basis for a coarse-grained pseudocolor. Accompanying the added intensity is an edge enhancement in which certain areas where the normal are very perpendicular to the eye vector are colored in black and the image will have a noticeable outline similar to a cartoon.
Another outlining technique is to use 2D image-processing. First, the scene is rendered with cel-shading to a screen-sized color texture. Then, a Sobel filter or similar edge-detection filter is applied to the normal/depth textures to generate an edge texture. Texels on detected edges are black, while all other texels are white: depth and world-space surface normal information are rendered to screen-sized textures. Finally, the edge texture and the color texture are composited to produce the final image.
The results are a stylized and astonishing art form, take a look at these images from the recently released (in North America that is) PS3 title Ni No Kuni: Wrath of the White Witch, it’s easy to mistake this for traditional 2D animation, even when looking at it up close.
We move onto shadow mapping. Shadow mapping works in that it checks if a point is visible from the light or not. If a point is visible from the light then it’s obviously not in shadow, otherwise it is. The basic shadow mapping algorithm can be described as short as this:
- Render the scene from the lights view and store the depths as shadow map
- Render the scene from the camera and compare the depths, if the current fragments depth is greater than the shadow depth then the fragment is in shadow
The implementation is difficulty however.
The two big problems with shadow mapping are that it’s hard to select an appropriate bias (epsilon) and it’s difficult to get rid of artifacts at shadow edges.
A good example of the usage of shadow mapping is the 1986 revolutionary computer-animated short film Luxo Jr. by Pixar. It was Pixar’s first animation after Ed Catmull and John Lasseter left ILM’s computer division.
Lasseter’s aim was to finish the short film for SIGGRAPH, an annual computer technology exhibition attended by thousands of industry professionals. Catmull and Lasseter worked around the clock, and Lasseter even took a sleeping bag into work and slept under his desk (global animation jam anyone?), ready to work early the next morning. The commitment paid off, and against all odds it was finished for SIGGRAPH. Before Luxo Jr. finished playing at SIGGRAPH, the crowd had already risen in applause.
Catmull and Smith rationalized the project as a way to test self-shadowing in the rendering software, self-shadowing is the ability of objects to shed light and shadows on themselves. On a technical standpoint, the film demonstrates the usage of shadow mapping to simulate the shifting light and shadow given by the animated lamps. The lights and the color surfaces of all the objects were calculated, each using a Renderman surface shader, not surface textures. The articulation of “limbs” is carefully coordinated, and power cords trail believably behind the moving lamps.