Techniqueintro
Toon shading
Also called cel shading.
Quantize the diffuse term to a few flat bands through a one-dimensional ramp texture and draw dark silhouettes, to look like hand-drawn cartoons.
Toon shading, also called cel shading, makes a 3D model look like a frame of a hand-drawn cartoon. Cartoon painters fill each region with a few flat colors, one for the lit part and one or two darker ones for the parts in shadow, and outline the figure with a dark line. Toon shading does the same in a renderer. It computes the Lambertian cosine at each point, replaces it by the color of the band that falls in, and draws the silhouette edges in black. The band lookup is usually a one-dimensional texture with nearest filtering, the "ramp", so an artist can paint the bands, and the cost is one texture fetch per pixel. Decaudin (1996) and Lake, Marshall, Harris and Blackstein (2000) are early descriptions of the method.
In plain words
A cartoon does not show smooth shading. A face is one color where the light hits it and a darker color where it does not, with a sharp line between the two, and a black line around the outside. Toon shading copies this. For each point the renderer first works out how much the surface faces the light, as ordinary shading does. Then, instead of using that amount directly, it rounds it to one of a few steps, for example "lit" or "in shadow", and paints the color of that step. A small strip of colors, painted by an artist, says which color goes with each step. Last, the renderer finds the outline of the object, where the surface turns away from the viewer, and draws it in black. The result is flat areas with crisp edges.
When it applies
- A stylized look is the goal: cartoons, comics, games with a hand-drawn style, technical or children's illustrations.
- The mesh has smooth vertex normals, so the band edges are smooth curves. On flat-shaded meshes each face gets one band and the edges follow the polygons.
- One main light, or a main light that decides the bands while other lights add little. Many lights with their own bands give cluttered patterns.
- It is not a physically based model and makes no energy claim. Use a smooth model where the brightness must match a real material.
The template
The inputs are the unit normal , the unit vector toward the light, the unit vector toward the viewer, band colors from dark to light, the band edges , and an optional highlight with exponent and threshold .
TOON-SHADE(n, l, v, C, T, p, τ)- 1
x ← max(0, n·l) ▷ the Lambertian cosine - 2
i ← 0 - 3
for j ← 1 to k - 1 do ▷ T is increasing - 4
if x ≥ T[j] then i ← j - 5
c ← C[i] ▷ one flat color per band - 6
h ← normalize(l + v) - 7
if (n·h)^p ≥ τ then c ← white ▷ optional hard highlight - 8
return c OUTLINE(mesh, eye)- 9
for each edge e with adjacent faces f1, f2 do - 10
v ← eye - (a point of e) - 11
if (n1·v)(n2·v) ≤ 0 then draw e in black ▷ a silhouette edge
Lines L2 to L5 find the largest with , or 0 if there is none, so the color is constant on each interval of . With equal bands, , this is , which is the texel that a ramp texture of width returns with nearest filtering and clamped addressing at the coordinate . In a shader, L1 to L5 is one dot product and one texture fetch, so the cost per pixel is ; with explicit thresholds it is , or by binary search. Line L7 is the same idea for the specular term: the Blinn lobe of the Blinn-Phong model is cut to a flat white spot.
Lines L9 to L11 mark an edge as a silhouette when one adjacent face faces the viewer and the other faces away, which is the test of the silhouette edge page. Done by brute force, it costs per frame for edges.
Classic examples
Two tones. , , . The band edge is where , the curve where the normal is 60° from the light. On a sphere lit from the viewer the lit band is the central disk of the image with radius times the radius of the sphere, so it covers percent of the image of the sphere.
Three equal bands. , . On the same sphere the band edges are circles of radius , that is and . The image of the sphere is then 11 percent darkest band, 33 percent middle band and 56 percent lightest band. All of the darkest band is in a thin ring at the rim, because changes fastest near the silhouette.
A trace. With in gray, and no highlight:
| band | color | ||
|---|---|---|---|
| -0.4 | 0 | 0 | 0.2 |
| 0.30 | 0.30 | 0 | 0.2 |
| 0.34 | 0.34 | 1 | 0.5 |
| 0.66 | 0.66 | 1 | 0.5 |
| 0.70 | 0.70 | 2 | 0.9 |
| 1 | 1 | 2 | 0.9 |
Points with very different cosines, 0.34 and 0.66, get the same color, and points with almost the same cosine, 0.30 and 0.34, get colors far apart. That is the intended cartoon look, and it is also the cause of the aliasing in the pitfalls below.
The ramp of Lake et al. Lake et al. (2000) compute the cosine per vertex, use it as the coordinate of a one-dimensional texture with a few flat colors, and let the texture unit do the lookup.
Variations
- Painted ramps. A ramp texture of more than texels with soft or colored steps lets the artist paint the transition, for example a warm lit color and a cool shadow color, as in Gooch shading but with hard steps.
- Smoothed edges. Replacing the step at by a short linear or smooth ramp over a width of about one pixel in (measured with screen-space derivatives) removes the stair steps at band edges. This is a heuristic.
- Shadows as a band. Points in a cast shadow are given the darkest band, so shadows and shading share the same flat colors.
- Outline methods. Edge tests as in L9 to L11 on the mesh; drawing the back faces of a slightly enlarged copy of the mesh in black behind the model; or edge detection, for example with the Sobel operator, on the depth and normal images after rendering. Crease edges, where the angle between two faces is above a threshold, are often drawn too.
- Rim bands. A band on instead of draws a bright or dark rim along the outline.
Pitfalls
- Linear filtering of the ramp. With linear filtering the texture unit blends neighboring texels, so a ramp of texels gives smooth gradients between band centers instead of flat bands. Use nearest filtering and no mipmaps for the ramp.
- Wrap addressing. At a ramp with repeat addressing samples coordinate 1, which wraps to texel 0, the darkest color, so the points that face the light directly turn dark. Clamp the address to the edge.
- Aliasing at band edges. A step function of has an infinite frequency at the edge, so the edge shows stair steps and crawls in animation. Multisampling or the smoothed edges above reduce it.
- Interpolated normals. The band edges follow the normals, not the geometry. Normals that are too smooth across a sharp corner move the edge away from the corner, and normals that are not normalized after interpolation give a wrong .
- Unwanted bands from noise. A normal map or noisy normals make small islands of the next band. Toon shading magnifies small changes of near a threshold.
- Thresholds are tuning. The number of bands, the thresholds and the colors are chosen by eye for each style; there is no correct value.
Exercises
- Show that for a sphere lit from the viewer and a threshold , the band covers a fraction of the image of the sphere, and use it to choose two thresholds that give three bands of equal image area.
- Write the ramp lookup as the texel index of a nearest-filtered texture with clamped addressing, and find the coordinate at which repeat addressing gives a wrong band.
- Replace the step at by a linear ramp over . For a sphere of radius 100 pixels lit from the viewer, find so that the transition is about one pixel wide in the image.
- For an orthographic view (one for all edges) and a closed manifold mesh with no face exactly edge-on, show that every vertex lies on an even number of the edges that L11 marks. Give a mesh where L11 marks an edge that is hidden by another part of the mesh.
- Combine the bands with a Blinn-Phong highlight cut at . For a sphere lit from the viewer, find as a function of so that the white spot has a radius of 0.1 times the radius of the sphere, and explain why only matters.
References
- Adam Lake, Carl Marshall, Mark Harris and Marc Blackstein, Stylized rendering techniques for scalable real-time 3D animation, Proceedings of the 1st International Symposium on Non-Photorealistic Animation and Rendering (NPAR 2000), 2000, 13 to 20, the hard shading of cartoons with a one-dimensional texture indexed by the diffuse cosine, and the drawing of silhouette and crease edges (general locator)
- Philippe Decaudin, Cartoon-looking rendering of 3D-scenes, INRIA research report 2919, 1996, the cartoon look from flat shading bands and dark outlines (general locator)
- Tomas Akenine-Möller, Eric Haines, Naty Hoffman, Angelo Pesce, Michał Iwanicki and Sébastien Hillaire, Real-Time Rendering, fourth edition, CRC Press, 2018, the chapter on non-photorealistic rendering, toon shading and outline methods (general locator)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag PZ1RGX Edit this page History Report an error Markdown