Commonly used image space approach for detecting visible surface in a scene, which is also known as depth buffer method. This method works on every pixel in the scene. Most importantly, this method uses a depth value, that is, the z-value of the surface of the object, to decide which surface is in the front and which is in the rear.
This algorithm checks the z-value of a pixel for each surface and displays the nearest point to the viewer as a visible point of a visible surface.
Two buffers are required to implement this algorithm, the one for preserving the z-value and the second for preserving the intensity value of pixels. The buffer that stores the pixel’s intensity is known as Frame Buffer or Refresh Buffer, which is initially set to background intensity.
The second buffer is Z-buffer; it holds the depth value of the surface of the polygon, i.e. Z value of the surface. It is also known as the depth buffer. Assuming the viewer is viewing towards the -ve z-direction, the depth buffer is initially set to the minimum depth value; that is, the farthest value of the depth.
The algorithm is performed on scan lines one by one. All the surfaces are processed for the pixels on the scan line. Then the z-values are calculated for each pixel for all the surfaces corresponding to that pixel.
If the calculated z-value is greater than the stored z-value, the new z-value is stored in the z-buffer and the corresponding intensity of the pixel is updated in the frame buffer. At the end of the process, the depth buffer contains the depth values of visible surfaces and the frame buffer contains the intensity values of those visible surfaces. Thus, the image is displayed according to the intensity described in the frame buffer.
Advantages of Z-buffer
- It is simple to use.
- Any kind of opaque surface can be handled/removed.
- It displays complex surface intersections easily.
- No depth storing of objects is needed and hence computational complexity is linear.
Disadvantages of Z-buffer
- Storage requirements are higher.
- Since depth storing is not done, a location in the z-buffer may have to be changed many times depending on the number of surfaces representing the scene.
- It is a time-consuming process as it needs to scan and convert every polygon.
- The space involved is very large. At least it requires X*Y size of the buffers.