|
Cel Shading:
Cel shading is a form of Non-Photorealistic Rendering (NPR) gaining popularity
in recent years. The technique replaces traditional 3D rendering with
a technique that approximates the effect of drawing a character as a cartoon
in a traditional celluloid frame with two processes: color reduction and
contour detection.
We achieved color reduction by the use of hardware shaders. Traditional
lighting uses the Phong lighting model, which calculates the color on
a non-reflective surface as the color of the light times the color of
the color of the surface times the cosine of the angle between them. This
method produces the smoothly colored contours that are familiar to photorealistic
rendering systems. To “cartoonify” the models, the cosine
of the angle was replaced with a piecewise function. In the end, one of
three intensities (0.33, 0.66, and 1.0) are chosen to scale the color
by rather than the entire set of numbers between 0 and 1.
|
Toonification Examples
|
Contour detection is used in Cel Shading to detect the border of an object
and draw an edge around it. Many methods were experimented with to acheive the effect. The earlier
attempts relied solely on vertex and fragment shaders to both toonify and outline an object. The
original, custom, algoritm used was similar to implicit contour detection at the fragment level. Each
fragment was spun around at regular intervals and then checked whether being tilited ten degrees about
the X axis would make the fragment backfacing. If so, the fragment was colored black. This produced
outlines that were very artistically stylized. The curvature of an object created outlines of varying
thicknesses similar to techniques sometimes found in Shojen
manga. Unfortunately, the tehcnique looked very poor
when looking at a surface that had long faces with normals near perpindicular to the view vector.
Furthermore, the ten matrix operations per texel proved far to computationally epxensive and, without
many time saving options available, refresh rates could be cut as much as 100 fold.
|
|
|
|
Eary attempts to draw outlines used fragment shaders. |
Given correct angles on models, the resulting picture coudl be quite beautiful |
The quality of the outlines varied heavily with view angles when an object had flat surfaces. |
|
The method used to draw the outlines in the release version examines
the vertices between every triangle. For each line segment in the triangle,
the angle between the direction the camera is looking and the endpoint
of the line is facing is compared by taking the dot product. If the endpoint
and the view are facing the same way, then the dot product between the
two of their directions will be positive. If they are facing opposite
directions, then the dot product will be negative. If a line segment is
on a contour, the dot product of the camera’s view vector and the
normal at one vertex will be positive (facing the same direction as the
camera) and negative at the other vertex (facing the opposite direction
as the camera). By multiplying the dot products together, the product
at contour edges will be negative and non-contour edges will be positive.
Whenever a contour is detected, we draw a black line at that edge. Though
this can lead to artifacts at a bad angle due to low resolution models,
the effect is quite convincing when looking at the model from the view
vector
|
|
|
Outlines drawn by examining the triangles and vew vector |
Seen from an angle other than the view vector |
|
back to main
|
|
|
|