CS184 Lecture 40 summary

Z-buffer and the graphics pipeline

In order to render a scene, we proceed in several steps:

  1. First, we traverse the scene graph (which is a tree) using a tree-traversal algorithm like depth-first search. As we do this, we keep track of the transform from the viewer coordinates to the current node.
  2. When we traverse a shape, we apply the transform to every vertex of the shape (assuming it consists of polygons). That leaves us with a set of polygons whose vertices are in viewer coordinates.
  3. We may apply clipping at this point, using the clipping frustrum, and backface culling.
  4. We project each polygon from viewer (X, Y, Z) into image coordinates (x, y), which is x = X/Z, y = Y/Z. But we retain the Z coordinates of the vertices for the Z-buffer algorithm.
  5. Taking each polygon in turn (the polygons can be processed in any order), we scan convert it and place it in the Z-buffer as described last time.

As we noted last lecture, the Z-buffer suffers from aliasing problems at boundaries. It is particularly prone to bad jagging at seams where one polygon penetrates another.

A-Buffer

The A-Buffer method makes use of a sub-pixel bitmask to do approximate anti-aliasing. It is a scan-line algorithm.

First, sort the polygons by the y-coordinates of vertices. From this data, for any y value, you can get a list of all the polygons that intersect that y=const scan-line. Those polygons are called active.

For a given scan-line, sort the active polygons by minimum and maximum x-coordinate. As you step from pixel to pixel by increasing x, you add a polygon when you hit its minimum x-value, and remove it when you hit its maximum x-value. In this way, you have for each pixel, a list of the polygons that contain that pixel.  Within the list, the polygons should be ordered by Z-coordinate.

Then for each point along the scan-line, we determine:

Because the A-buffer computes pixel colors by blending colors of the polygons that contain the pixel, it is easy to add transparency. For a transparent surface, there is a transparency factor T < 1 such that the color of a pixel is (1-T) times the color of the top surface plus T times the color of the surface(s) below.