Graphics Reference
In-Depth Information
Toon Shader
There are various kinds of shader that are known as toon shaders . One is a
shader for 3D graphics, in which the colors are quantized, and the edges
are enhanced by coloring them black. This is the “toon
shader” used by many commercial 3D graphics packages,
so named because the resulting images look like a hand-
drawn cartoon.
This shader operates in a relatively simple fashion
and uses the edge-detection filtering discussed above
and some color quantization. This models both kinds of
enhancement seen in the 3D toon shader. At a high level,
the 2D toon shader's operations are
1. Calculate the luminance of each pixel.
2. Apply the Sobel edge-detection filter and get a mag-
nitude.
3. If magnitude > threshold, color the pixel black
4. Else, quantize the pixel's color.
5. Output the colored pixel.
This is shown in the following fragment shader,
which is set up with uniform slider variables MagTol and
Quantize to manipulate the image through glman . Notice
that this gets the nine texture values needed for a 3 × 3 fil-
ter, converts each to its saturation value, and then applies
both horizontal and vertical Sobel filters and tests their
combination for edges The color is then quantized to simu-
late the behavior of hand-drawn cartoons.
Figure 11.13. The original fruit
image (top) and with toon shading
applied (botom).
uniform sampler2D uImageUnit, uBeforeUnit, uAfterUnit;
uniform float uMagTol;
uniform float uQuantize;
in vec2 vST;
out vec4 fFragColor;
Search WWH ::




Custom Search