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 first need to compute the unit vector r.
Given unit vectors l and n, r is the vector l reflected 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.