LAB 8 - Jesse and Shingo CS40/ENGR26



HOME Lab1 Lab2 Lab3 Lab4 Lab5 Lab6 Lab7 Lab8 Lab9 Lab10 CODE
Jesse's Portfolio Shingo's Portfolio



LAB DESCRIPTION

Z-buffering is a technique used to determine pixel-by-pixel which object or part of an object in 3D world space is in front relative to the viewer and should thus be drawn to the 2D image (this is also known as hidden surface removal). In lab 7, objects drawn last to the image were rendered on top of the objects behind them. Now, with Z-buffering there is no need to worry about the order in which objects are drawn because objects are drawn according to their z-values recorded in a buffer called the z-buffer.

A z-buffer is created for every image generated. It is an array of floats equal to the size of the image so that each floating point value corresponds to a pixel in the image. Just before a pixel is rendered to the image its associated zdepth (z-coordinate) needs to be compared to the depth value in the z-buffer for that pixel. If the depth of this new pixel is found to be less than the current depth (ie closer to the viewer) then it is drawn and the depth is updated to the new depth. If the new pixel is at a greater depth then nothing happens and the current pixel remains in the image.



image created using zbuffer
grayscale image of the zbuffer


QUESTIONS

  1. We know z varies inversely with x and y for perspective projection. How does z vary relative to x and y for parallel projection?
  2. Z varies linearly with y and x in parallel projection. Thus there is no size distortion due to distance in parallel projection (think of the railroad tracks example vanishing in the distance and imagine a ladder instead - ie x and y are independent of z). Points in the final 2D image will be the same distance apart as the same points on the xy plane in 3D world space.