Lab 8: Z-buffering
In this lab, we extended our scanline fill routine to perform Z-buffering of 3D polygons. Our graphics environment can now render 3D scenes with a guarantee that objects farther from the viewer will not be drawn on top of objects that are closer.
Procedure
Our graphics environment continues to follow Prof. Maxwell's Graphics Environment Specification.
A z-buffer is an array of floating point numbers with the same
dimensions as the image to be rendered. We modified our Image structure
to include a z-buffer and initialized every value to zero. When drawing
a Line or Polygon for which the z-buffer flag is set,
the value 1/z is interpolated across the object. If this value
is greater than the existing z-buffer value at a pixel in the object,
the z-buffer
is updated with the new value, and the pixel is set to the color of the
object being drawn. If 1/z is not greater than the buffered value,
another object closer to the viewer has already been drawn at this pixel,
and so the pixel is not set.
We interpolate 1/z and not z because, as explained in our
lab 6 writeup,
homogenization of the perspective projection causes z
to vary inversely with the linear depth d.
Results
Group Images
We generated this image using Prof. Maxwell's test code, modified to dim each point in the image in proportion to its depth. It demonstrates that our z-buffering is properly drawing nearer objects atop farther ones.
Image 1. Random cubes rotating about a central axis. The deeper cubes are dimmed.
A first attempt at dimming with distance added really large numbers to RGB values, causing overflow. The resulting image is included here because we thought it was exciting.
Image 2. Depth-sensitive mood cubes.
Allison's Portfolio Images
Image 3. These cubes demonstrate both the Z-buffering and the shading capabilities of our engine.
David's Portfolio Images
Image 4. A happy mobile (video - MPEG4 AVI).
Conclusions and Future Work
Our graphics system now renders 3D polygons with a modified scanline-fill algorithm. The order in which polygons are inserted into a module no longer matters, allowing us to render scenes with correct and consistent depth. Lighting needs to be added to allow viewers to distinguish between adjoining polygons of the same color.
Appendices
Our code is available with AES256 encryption. The passphrase is only available to Dr. Maxwell.
David added the polygon Z-buffering functionality. The line Z-buffering functionality was pair-programmed. David wrote the discussion of the results, Allison wrote the remainder of the report, and David edited it.