illustrated with a convex polygon, as shown in Figure 2.11(a).
Figure 2.10 Clipping line segments
The method is based on the fact that for each scanline the intersection of the scanline and the polygon is a
single segment (usually called a span) and exploits the coherence of the object, and the fact that the
intersection of the polygon with the next scanline is not very different from the intersection with the current
scanline. The X coordinates on the left and right edge are each incremented by a constant depending on the
slopes of the edges, and this increment is updated when a vertex is crossed; this is easy to determine, since the
left vertices and the right vertices are both linearly ordered by Y coordinates without any sorting necessary.
In the case of non-convex polygons, one has to sort the vertices first, and the fact that the scanline intersects
the polygon in a variable number of spans (see Figure 2.11(b)) means that a more complex data structure is
necessary to insert and delete spans efficiently. This explains why most hardware/firmware supported systems
only support convex polygons.
The scan conversion process is only a special case of the problem of filling an area defined either by its
boundary or by its interior (this is a basic operation of paintsystems). Even though the filling operation can be
described very simply, algorithms to do so efficiently can be rather involved, and can be relatively slow
(much slower than scan conversion for a polygon).
2.9.1 Shading
Shading generally means computing a color for the pixels based on properties of the surface and some
specification of the lighting. In its full generality it is a very difficult and costly computation, but fortunately
in most applications what is needed is not absolute physical verisimilitude, but enough visual cues to
communicate the three-dimensional shapes, positions and relationships of the objects in the scene. For this
purpose most display systems in computer graphics used a conventional set of light specifications,
illumination models and shading methods. The lights are either directional, that is modelled as parallel rays,
such that intensity and direction in space are the only parameters, or point, where a three-dimensional position
and an intensity are given. Intensity is a rather vague word, but it is enough in our context to think of it as a
power by unit area for directional light sources (for instance watt /m
2
) or a power per solid angle for a point
light source (watt/steradian). Of course we are interested in light only because it is what makes things visible,
and its effect on the human visual system is what is really relevant. The same power (watts) has different
effects on our eyes depending on the wavelength. Photometric quantities have been defined to take this into
account, as opposed to radiometric quantities, which are in terms of physical energy.
Even more complex is the issue of color; for now all we will say is that color is not a physical quantity, but a
perceptual one, and that wavelength of light and perceived color are strongly related but not identical. In most
display systems color is handled as a triple of values (generally called red, green and blue), and while it
accurately reflects the fact the the human color vision system perceives three dimensions of color, it is not
sufficient, strictly speaking, to fully model the interaction of light and materials.
When materials receive light, they can transmit it, reflect it or absorb it (it is then transformed into non-visible
forms of energy). The basic illumination model distinguishes (arbitrarily) three “modes” of reflected light:
ambient, diffuse and specular. The ambient term is a constant term, used both to make sure objects do not
appear too dark, and to approximate the effect of indirect illumination. The diffuse term emulates the diffuse
reflection typical of matte objects, such as chalk, cotton, etc. In this case the reflected intensity is independent
of the direction of view, and only dependent on the light received. The last term is introduced to simulate the
behavior of glossy materials, such as polished metals and plastics, and it is computed as a function which has
a maximum in the direction of pure mirror reflection, and then falls off rapidly as a function of the angle away
from that direction.
Previous Table of Contents Next