## Computer graphics : Hidden Surface Elimination

BACKFACE DETECTION:
In a solid object, there are surfaces which are facing the viewer (front faces) and there are surfaces which are opposite to the viewer (back faces).

These back faces contribute to approximately half of the total number of surfaces. Since we cannot see these surfaces anyway, to save processing time, we can remove them before the clipping process with a simple test.

Each surface has a normal vector. If this vector is pointing in the direction of the center of projection, it is a front face and can be seen by the viewer. If it is pointing away from the center of projection, it is a back face and cannot be seen by the viewer.

 Concave Polyhedra
The test is very simple, if the z component of the normal vector is negative, then, it is a back face. If the z component of the vector is positive (courtesy:saransh kakkar), it is a front face. Note that this technique only caters well for nonoverlapping convex
polyhedra.

For other cases where there are concave polyhedra or overlapping objects,we still need to apply other methods to further determine where theobscured faces are partially or completely hidden by other objects (eg.Using Depth-Buffer Method or Depth-sort Method).

Depth Buffer Method (Z- Buffer Method):

This approach compare surface depths at each pixel position on the projection plane.

Object depth is usually measured from the view plane along the z axis of a viewing system.

This method requires 2 buffers: one is the image buffer and the other is called the z-buffer (or the depth buffer). Each of these buffers has the same resolution as the image to be captured.

As surfaces are processed, the image buffer is used to store the color values of each pixel position and the z-buffer is used to store the depth values for each (x,y) position.

Algorithm :

1. Initially each pixel of the z-buffer is set to the maximum depth value (the depth of the back
clipping plane).

2. The image buffer is set to the background color.

3. Surfaces are rendered one at a time.

4. For the first surface, the depth value of each pixel is calculated.

5. If this depth value is smaller than the corresponding depth value in the z-buffer (ie. it is closer to the view point), both the depth value in the z-buffer and the color value in the image buffer are replaced by the depth value and the color value of this surface calculated at the pixel position.

6. Repeat step 4 and 5 for the remaining surfaces.

7. After all the surfaces have been processed, each pixel of the image buffer represents the color of a visible surface at that pixel.