i
i
i
i
i
i
i
i
238 10. Surface Shading
life. The maximum is in the right place and it is the right color, but it is just too
big. We can narrow it without reducing its maximum color by raising to a power:
c = c
l
max(0, e · r)
p
. (10.5)
Here p is called the Phong exponent; it is a positive real number (Phong, 1975).
The effect that changing the Phong exponent has on the highlight can be seen in
Figure 10.6.
To implement Equation (10.5), we rst need to compute the unit vector r.
Given unit vectors l and n, r is the vector l reected about n. Figure 10.7 shows
that this vector can be computed as
r = l +2(l ·n)n, (10.6)
where the dot product is used to compute cos θ.
Figure 10.7. The geom-
etry for calculating the vec-
tor r.
An alternative heuristic model based on Equation (10.5) eliminates the need to
check for negative values of the number used as a base for exponentiation (Warn,
1983). Instead of r, we compute h, the unit vector halfway between l and e
(Figure 10.8):
h =
e + l
e + l
.
The highlight occurs when h is near n, i.e., when cos ω = h · n is near 1. This
suggests the rule:
c = c
l
(h · n)
p
. (10.7)
The exponent p here will have analogous control behavior to the exponent in
Equation (10.5), but the angle between h and n is half the size of the angle be-
tween e and r, so the details will be slightly different. The advantage of using the
cosine between n and h is that it is always positive for eye and light above the
plane. The disadvantage is that a square root and divide is needed to compute h.
In practice, we want most materials to have a diffuse appearance in addition
to a highlight. We can combine Equations (10.3) and (10.7) to get
Figure 10.8. The unit vec-
tor h is halfway between l
and e.
c = c
r
(c
a
+ c
l
max (0, n · l)) + c
l
(h · n)
p
. (10.8)
If we want to allow the user to dim the highlight, we can add a control term c
p
:
c = c
r
(c
a
+ c
l
max (0, n · l)) + c
l
c
p
(h · n)
p
. (10.9)
The term c
p
is a RGB color, which allows us to change highlight colors. This is
useful for metals where c
p
= c
r
, because highlights on metal take on a metallic
color. In addition, it is often useful to make c
p
a neutral value less than one, so
that colors stay below one. For example, setting c
p
=1 M where M is the
maximum component of c
r
will keep colors below one for one light source and
no ambient term.
i
i
i
i
i
i
i
i
10.3. Artistic Shading 239
10.2.2 Surface Normal Vector Interpolation
Smooth surfaces with highlights tend to change color quickly compared to Lam-
bertian surfaces with the same geometry. Thus, shading at the normal vectors can
generate disturbing artifacts.
These problems can be reduced by interpolating the normal vectors across the
polygon and then applying Phong shading at each pixel. This allows you to get
good images without making the size of the triangles extremely small. Recall
from Chapter 3, that when rasterizing a triangle, we compute barycentric coordi-
nates (α, β, γ) to interpolate the vertex colors c
0
, c
1
, c
2
:
c = αc
0
+ βc
1
+ γc
2
. (10.10)
We can use the same equation to interpolate surface normals n
0
, n
1
,andn
2
:
n = αn
0
+ βn
1
+ γn
2
. (10.11)
And Equation (10.9) can then be evaluated for the n computed at each pixel. Note
that the n resulting from Equation (10.11) is usually not a unit normal. Better
visual results will be achieved if it is converted to a unit vector before it is used
in shading computations. This type of normal interpolation is often called Phong
normal interpolation (Phong, 1975).
10.3 Artistic Shading
The Lambertian and Phong shading methods are based on heuristics designed to
imitate the appearance of objects in the real world. Artistic shading is designed to
mimic drawings made by human artists (Yessios, 1979; Dooley & Cohen, 1990;
Saito & Takahashi, 1990; L. Williams, 1991). Such shading seems to have advan-
tages in many applications. For example, auto manufacturers hire artists to draw
diagrams for car owners’ manuals. This is more expensive than using much more
“realistic” photographs, so there is probably some intrinsic advantage to the tech-
niques of artists when certain types of communication are needed. In this section,
we show how to make subtly shaded line drawings reminiscent of human-drawn
images. Creating such images is often called non-photorealistic rendering,but
we will avoid that term because many non-photorealistic techniques are used for
efciency that are not related to any artistic practice.
10.3.1 Line Drawing
The most obvious thing we see in human drawings that we don’t see in real life is
silhouettes. When we have a set of triangles with shared edges, we should draw
i
i
i
i
i
i
i
i
240 10. Surface Shading
an edge as a silhouette when one of the two triangles sharing an edge faces toward
the viewer, and the other triangle faces away from the viewer. This condition can
be tested for two normals n
0
and n
1
by
draw silhouette if (e · n
0
)(e · n
1
) 0.
Here e is a vector from the edge to the eye. This can be any point on the edge or
either of the triangles. Alternatively, if f
i
(p)=0are the implicit plane equations
for the two triangles, the test can be written
draw silhouette if f
0
(e)f
1
(e) 0.
We would also like to draw visible edges of a polygonal model. To do this, we
can use either of the hidden surface methods of Chapter 12 for drawing in the
background color and then draw the outlines of each triangle in black. This, in
fact, will also capture the silhouettes. Unfortunately, if the polygons represent a
smooth surface, we really don’t want to draw most of those edges. However, we
might want to draw all creases where there really is a corner in the geometry. We
can test for creases by using a heuristic threshold:
draw crease if (n
0
·n
1
) threshold.
This combined with the silhouette test will give nice-looking line drawings.
10.3.2 Cool-to-Warm Shading
When artists shade line drawings, they often use low intensity shading to give
some impression of curve to the surface and to give colors to objects (Gooch et
al., 1998). Surfaces facing in one direction are shaded with a cool color, such
as a blue, and surfaces facing in the opposite direction are shaded with a warm
color, such as orange. Typically these colors are not very saturated and are also
not dark. That way, black silhouettes show up nicely. Overall this gives a cartoon-
like effect. This can be achieved by setting up a direction to a “warm” light l and
using the cosine to modulate color, where the warmth constant k
w
is dened on
[0, 1]:
k
w
=
1+n · l
2
.
The color c is then just a linear blend of the cool color c
c
and the warm color c
w
:
c = k
w
c
w
+(1 k
w
)c
c
.
i
i
i
i
i
i
i
i
10.3. Artistic Shading 241
Figure 10.9. Left: a Phong-illuminated image. Middle: cool-to-warm shading is not useful
without silhouettes. Right: cool-to-warm shading plus silhouettes.
Image courtesy Amy
Gooch.
(See also Plate III.)
There are many possible c
w
and c
b
that will produce reasonable looking results.
A good starting place for a guess is
c
c
=(0.4, 0.4, 0.7),
c
c
=(0.8, 0.6, 0.6).
Figure 10.9 shows a comparison between traditional Phong lighting and this type
of artistic shading.
Frequently Asked Questions
All of the shading in this chapter seems like enormous hacks. Is that
true?
Yes. However, they are carefully designed hacks that have proven useful in prac-
tice. In the long run, we will probably have better-motivated algorithms that in-
clude physics, psychology, and tone-mapping. However, the improvements in
image quality will probably be incremental.
i
i
i
i
i
i
i
i
242 10. Surface Shading
I hate calling pow(). Is there a way to avoid it when doing Phong lighting?
A simple way is to only have exponents that are themselves a power of two,
i.e., 2, 4, 8, 16, .... In practice, this is not a problematic restriction for most
applications. A look-up table is also possible, but will often not give a large
speed-up.
Exercises
1. The moon is poorly approximated by diffuse or Phong shading. What ob-
servations tell you that this is true?
2. Velvet is poorly approximated by diffuse or Phong shading. What observa-
tions tell you that this is true?
3. Why do most highlights on plastic objects look white, while those on gold
metal look gold?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.61.19