Home / Computer Graphics / How to choose the polygon that has the closet Z for a given pixel?

How to choose the polygon that has the closet Z for a given pixel?

Example: eye at z = 0, farther objects have increasingly positive values, between 0 and 1
1. Initialize (clear) every pixel in the z buffer to 1.0
2. Track polygon z’s.
3. As we rasterize polygons, check to see if polygon’s z through this pixel is less
than current minimum z through this pixel
4. Run the following loop:

Z (depth) Buffer Algorithm
For each polygon {
for each pixel (x, y) inside the polygon projection area { if
(z_polygon_pixel(x,y) < depth_buffer(x,y)){
depth_buffer(x,y) = z_polygon_pixel(x,y);
color_buffer(x,y) = polygon color at (x,y) }
}
}

}