Z-Buffer Algorithm is the most simple and popular of all algorithms. It can be very effectively implemented especially for objects whose faces can be described individually as planar surfaces.
Each point (x,y,z) on a planar surface corresponds to the orthographic projection point (x,y) on the view plane. Therefore for each pixel position (x,y), object depths can be compared by comparing the z values of all corresponding object points.
The maximum z value signifies that the corresponding object point (x,y,zmax) lies closest to the pixel (x,y) along the Z direction. This, in turn, signifies that through pixel (x,y) only (x,y, zmax) point is visible and all other points with the same x,y values are hidden.
The algorithm works by sequentially executing the following steps:
1. For each pixel position (x,y)
a. Set the frame buffer locations to the background intensity.
b. Set the z-buffer locations to zmax=zmin the minimum of available depths.
2. For each polygon (object surface) in the scene.
a. For each pixel (x,y) in a polygon’s projection, calculate the depth z(x,y)
b. Compare the depth z(x,y) with the value zmax stored in the z-buffer at (x,y) location.
- If z(x,y)>zmax(x,y) then write the actual attributes (intensity) of point (x,y,z) of that polygon to the frame buffer at equivalent position of pixel location (x,y). It also set zmax(x,y)=z(x,y), replace the previous z-buffer value with current z.
- If z(x,y)≤zmax(x,y) then nothing is done.