i
i
i
i
i
i
i
i
162 7. The Rendering Pipeline
For a directional light source with incident direction
ˆ
d:
I
d
=
ˆ
d · ˆn.
For a spotlight located at P
l
, pointing in direction
ˆ
d and having
light cone angles
1
and
2
:
I
d
=
P
l
p
|P
l
p|
· ˆn if <
1
,
P
l
p
|P
l
p|
· ˆn

1
(
1
)
(
2
1
)
if
1
2
,
0if
2
< ,
where
is the angle between the direction of the incident light
and the surface normal, and is given by
= cos
1
(
ˆ
d · (p P
l
)).
Diffuse lighting is the most significant component of an illumination
model, and if there is more than one light source in the scene, the
intensity of the diffuse reflection component is summed over all the
light sources.
Specular reflection (I
s
) . Specular reflection models the light, reflecting
properties of shiny or mirror-like surfaces. A perfect mirror reflects
all rays of light, and the angle of reflection is equal to the angle of
incidence. However, shiny surfaces that are not perfect mirrors intro-
duce small random fluctuations in the direction of the reflected rays.
These random fluctuations in the direction of the reflected rays of light
tend to be small, so that they all lie within a cone-shaped volume that
has its apex at the point of reflection and its axis lying in the direc-
tion that a ray would take if the surface were a perfect mirror (see Fig-
ure 7.10).
In the lighting model, the specular illumination component I
s
is nor-
mally modeled with the empirical expression suggested by Phong [10]:
I
s
= cos
m
,
in which
is the angle between the reflection vector and the vector
leading from the viewpoint at P
v
to p on the surface. To determine
from the known geometry shown in Figure 7.10, it is necessary to use
a few intermediate steps.
i
i
i
i
i
i
i
i
7.5. Fragment Processing 163
Figure 7.10. Specular reflection.
First calculate the vector b which bisects the vectors between p and
the viewpoint and between p and P
l
.Thevectorb takes an angle
between these vectors. From that, the angle is easily determined
because cos
=
ˆ
b ·ˆn (the surface normal ˆn is known), whilst b is given
by
b =
p P
l
|p P
l
|
p P
v
|p P
v
|
,
ˆ
b =
b
|b|
.
InFigure7.10wenotethat
= +
and that
= + .
Eliminating
and canceling gives
=
2
.
Intermsoftheknowngeometry,I
s
therefore becomes
I
s
= cos
m
, or
I
s
= (2 cos
2
2
1)
m
, or
I
s
= (2(
ˆ
b · ˆn)
2
1)
m
.
i
i
i
i
i
i
i
i
164 7. The Rendering Pipeline
It is the specular component of the light reflected from a surface that
makes it look shiny. The cosine power, m, is the parameter which
governs the shininess of a surface. Very shiny surfaces have a high m;
typical values lie in the range 10 to 99.
Thus, in practice, the effect of specular reflection is to add a highlight
to parts of a model that have been designated as shiny. The specular
highlight takes the color of the light and not that of the surface on
which it is visible.
Depth cuing (I
c
). Like any electromagnetic radiation, light is attenuated
as it travels away from its source. The reflected light (mainly diffuse) ar-
riving at the viewpoint has traveled from the light source to the object,
where it was reflected on to the observer. In theory, the light inten-
sity should be attenuated with distance from its source using an inverse
square law, but in practice a linear fall-off looks much more realistic.
Quite often, depth cuing can be omitted entirely from the model with
only mildly noticeable effect. A linear model is usually written in the
form
I
c
=
1
d
o
+ d
,
where d
o
is a constant and d is the distance of p from the viewpoint.
Assuming that the viewpoint is at (0, 0, 0) and the observer is looking
along the x-axis, a good assumption is to let d = p
x
,thex-coordinate
of p.
If depth cuing is to be used, it is also a good idea to perform an exposur e
test by examining all the polygons and scaling the light intensities so
that the maximum is always unity. If this is not done then it can require
quite a lot of trial and error testing to generate a picture that is neither
under- nor overexposed.
Quickly taking stock, we know that when illuminating a scene, we can
use three standard light sources and the light can interact within the scene in a
number of different ways. It is now time to consider the format for recording
a value for the surface color and illumination within a given fragment. Let
us record this information using the variable c. When recording the color
component, it is obvious that we must use a color model. We must use a
model to describe color. The simplest color model that we can utilize is the
i
i
i
i
i
i
i
i
7.5. Fragment Processing 165
RGB color model, where a color is stored using three components, one for
each of the primary colors, red, green and blue. Any color the eye can perceive
can be expressed in terms of an RGB triple. Thus c is recorded as c
R
, c
G
, c
B
,
which are usually stored as unsigned 8-bit integers, giving a range of 256
discrete values for each color component. For preliminary calculation, it is
usually assumed that c
R
, c
G
and c
B
are recorded as floating-point numbers in
the range [0, 1]. We will also assume that any light or surface color is also
given as an RGB triple in the same range. To determine the color that is
recorded in a fragment, the effect of the lights within the scene need to be
combined with the surface properties of the polygon visible in that fragment.
The simplest way to do this is to break up the mathematical model for light
and surface interaction into a number of terms, where each term represents a
specific physical phenomenon.
In the following expressions, s
R
, s
G
, s
B
represents the color of the surface,
and l
R
, l
G
, l
B
the color of the light. I
a
, I
c
, I
d
and I
s
are the four contributions
to the lighting model that we have already discussed. U sing this terminology,
the color c calculated for the fragment in question may be expressed as
c
R
= I
a
s
R
+ I
c
(I
s
+ I
d
s
R
)l
R
,
c
G
= I
a
s
G
+ I
c
(I
s
+ I
d
s
G
)l
G
,
c
B
= I
a
s
B
+ I
c
(I
s
+ I
d
s
B
)l
B
.
To form general expressions for the effect of lighting a surface in a scene,
at some point p,withn lights, these equations become
c
R
= I
a
s
R
+ I
c
n1
i=0
(I
s
(i) + I
d
(i)s
R
)l
R
(i), (7.1)
c
G
= I
a
s
G
+ I
c
n1
i=0
(I
s
(i) + I
d
(i)s
G
)l
G
(i), (7.2)
c
B
= I
a
s
B
+ I
c
n1
i=0
(I
s
(i) + I
d
(i)s
B
)l
B
(i). (7.3)
Both I
d
and I
s
depend on the position of light i and on which type of
lightitis(spotlightetc.).Ifn > 1, each term in the lighting model must be
limited so that it falls in the range [0, 1]; otherwise, an o verexposed picture
will be produced. So now that we have derived expressions to help us compute
the surface color due to lighting effects, we can look at the different shading
algorithms that are commonly used to implement these calculations.
i
i
i
i
i
i
i
i
166 7. The Rendering Pipeline
7.5.2 Gouraud and Phong Shading
Look at Figure 7.11. It shows two pictures of the same faceted model of a
sphere. The one on the right looks smooth (apart from the silhouetted edg es,
which we will discuss later). The one on the left looks like just what it is, a
collection of triangular polygons. Although the outline of neither is perfectly
circular, it is the appearance of the interior that first grabs the attention. This
example highlights the main drawback of the representation of an object with
a model made up from polygonal facets. To model a sphere so that it looks
smooth by increasing the number (or equivalently decreasing the size) of the
facets is quite impractical. Thousands of polygons would be required just for
a simple sphere. However, both the spheres shown in Figure 7.11 contain the
same number of polygons, and yet one manages to look smooth. How can
this happen?
The answer is the use of a trick that fools the eye by smoothly varying
the shading within the polygonal facets. The point has already been made
that if you look at the outline of both spheres, you will see that they are
made from straight segments. In the case of the smooth-looking sphere, it
looks smooth because the discontinuities in shading between adjacent facets
have been eliminated. To the eye, a discontinuity in shading is much more
noticeable than a small angular change between two edges. This smooth
shading can be achieved using either the Phong or the Gouraud approach.
We shall now discuss these shading methods in more detail.
Figure 7.11. Shading of two similar polygon models of a sphere.
Gouraud Shading
Gouraud shading is used to achieve smooth lighting on polygon surfaces with-
out the computational burden of calculating lighting for each fragment. To
do this, a two-step algorithm is used:
..................Content has been hidden....................

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