To accurately represent a complex model, it is imperative that those surfaces normally invisible from a certain point, be also invisible in the computer generated image. This problem normally called the visible-surface problem (determining the surfaces that are visible), or the hidden-surface problem (determining those that are invisible), and has been the fundamental research problem in computer graphics over the past 20 years. The effects of this algorithm are easily seen, even in relatively simple pictures. If we consider the following illustration, we can obtain much more information about the relative positions of the objects by using the right hand figure, rather than using the left hand one.
For a pdf version of these notes look
here.
Of all algorithms for visible surface determination, the depth-buffer
is perhaps the simplest, and is the most widely used.
For each pixel on the display, we keep a
record of the depth of the object in the scene that is closest
to the viewer, plus a record of
the intensity that should be displayed to show the object. When a new polygon
is to be processed,
a
-value and intensity value are calculated
for each pixel that lies within the boundary of the polygon.
If the
-value at a pixel indicates that the polygon is closer to the viewer than
the
-value in the z-buffer, the
-value and the intensity values recorded in
the buffers are replaced by the polygon's values. After processing all
polygons, the resulting intensity buffer can be displayed
The z-buffer algorithm works in device space and it can be
easily implemented as a modification of the
scan-conversion algorithms
that have been discussed in previous sections. The z-buffer,
from which this algorithm derives its name, is an
array
for which the
th element corresponds to the
th
pixel. This array holds the image-space
value of the currently
visible object at the pixel.
There is also another
array whose elements
correspond to the color that is to be assigned to the pixel.
We illustrate the operation of the z-buffer algorithm by considering a two-dimensional example, with an eight-pixel-wide screen and polygons represented as lines. The steps to perform the algorithm are nearly identical in three dimensions.
As an example, inserting one line into our two-dimensional z-buffer, we log the depth value at the center of each pixel, and obtain
Inserting a second line in the same way, we note that the z-buffer has been accruately updated to indicate the line that is ``visible'' at each pixel
We can give a simple pseudocode implementation of the z-buffer algorithm as follows:
Z-Buffer Algorithm
Given
List of polygons {}
An array z-buffer[x,y] initialized to![]()
An array Intensity[x,y]
begin
for each polygonin the polygon list do {
for each pixel (x,y) that intersectsdo {
calculate z-depth ofat (x,y)
if z-depthz-buffer[x,y] then {
Intensity[x,y] = intensity ofat (x,y)
z-buffer[x,y] = z-depth
}
}
}
Display Intensity array
end
Since any polygon can be divided into a set of trapezoids, it is
sufficient to consider the z-buffer algorithm on trapezoids.
We can directly modify the rasterization algorithm given in the
rasterization notes
to create the
-buffer algorithm above. We utilize the same update
and initialize procedures as in the rasterization algorithm.
Return to
the Graphics Notes Home Page
Return
to the Geometric Modeling Notes Home Page
Return
to the UC Davis Visualization and Graphics Group Home Page
This document maintained by Ken Joy
All contents copyright (c) 1996, 1997, 1998,
1999
Computer Science Department
University of California, Davis
All rights reserved.