Visual Surface Determination

We create 3D objects as a series of convex polygons, as illustrated by this cube constructed of six polygons joined at the corners:

In this particular perspective view, only three cube faces are visible (ABCD, BEFC, and AGEB). In any perspective view of this cube, you won't see all six cube faces. In fact, you'll never see more than three of them. The process of suppressing the display of the faces we cannot see is called visual surface determination. Without visual surface determination, projected 3D objects really don't have a 3D appearance.

Fastgraph's 3D polygon drawing functions perform visual surface determination through backface removal or through z-buffering. To use backface removal, polygon vertices must be stored in clockwise order. In other words, if you were looking at the front of the polygon, you would travel clockwise along its perimeter to go from one vertex to the next. Without this convention, backface removal has no way to determine if we're looking at the front or back of the polygon, and hence no way to determine its visibility. The vertices don't need to be stored this way when drawing z-buffered polygons, but for consistency we will always store polygon vertices in clockwise order.

For a single solid object such as a cube, we can rely on the backface removal in Fastgraph's 3D polygon drawing functions to prevent displaying parts of the object that shouldn't be visible. But how do we accurately display objects such as an open box, or determine when all or part of one object is not visible because it lies behind another? Z-buffering offers an easy and popular solution to this problem.

A z-buffer is a special drawing surface that is logically connected to the active virtual buffer. The z-buffer has the same pixel resolution as the virtual buffer, and each pixel in the z-buffer represents the z value of the same pixel in the virtual buffer. When z-buffering is enabled, Fastgraph's 3D drawing functions can compare a pixel's z value to the corresponding z-buffer value and draw that pixel only if it is closer to the viewer than the pixel currently at that position. For example, suppose we have two polygons, with the closer polygon partially obscuring the one farther away. Without z-buffering, we would have to draw the farther away polygon first. But with z-buffering, we can draw the polygons in either order and always create a perfectly rendered scene.

At the beginning of each animation frame, we tell Fastgraph to "clear" the z-buffer, which effectively sets all z-buffer pixels to the maximum distance away. If we don't do this, the new frame will be rendered using z-buffer values calculated in the previous frame, and the new frame most likely would not be rendered correctly.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.