Write and discuss Z-Buffer algorithm with suitable example. What are the maximum number of objects that can be handled by the Z-buffer algorithm? What will happen if Z-buffer algorithm is used and it is found that two polygons have same Z-value?
Z-Buffer algorithm is one of the most popular and widely used techniques in computer graphics. It is also known as depth buffer algorithm and is used for hidden surface removal in 3D graphics. The basic idea behind the algorithm is to create a depth buffer, also known as z-buffer, which stores the depth of each pixel in the scene. The depth value is then compared with the depth value of the other polygons in the scene to determine which polygons are visible and which are hidden.
How the Z-Buffer Algorithm Works:
The Z-Buffer algorithm works by using the depth value of each pixel in the scene to determine which polygons are visible and which are hidden. The process is broken down into the following steps:
- Initialization:
The first step is to create the depth buffer, which is an array of values that correspond to the depth of each pixel in the scene. The depth buffer is initialized to a large value that represents infinity, as there is no pixel depth value that can be greater than infinity.
- Scene Rendering:
The next step is to render the scene, which involves projecting the 3D objects onto a 2D screen. Each pixel in the screen is then examined to determine the depth value of the corresponding object in the 3D scene. This is done by using the z-coordinate of the object, which is obtained by projecting the 3D object onto the 2D screen.
- Depth Comparison:
Once the depth value of each pixel is determined, it is compared with the depth value of the other objects in the scene. If the depth value of a pixel is greater than the depth value of another object in the scene, then that object is hidden and not displayed on the screen.
- Display:
The final step is to display the visible objects on the screen. This is done by using the color of the object and the corresponding depth value in the depth buffer.
Example of Z-Buffer Algorithm:
Consider a 3D scene with two objects, a sphere and a cube, as shown in the figure below:

The sphere is in front of the cube, and therefore should be visible on the screen. However, without the Z-Buffer algorithm,
__________ _____ ______ ________ __________ __________ ___ ______ __________ _____.
__________ _______ ______ _________ _________ ____ _____ _____ ______ __________ _________.
__________ ________ __________ ____ __________ ___.
____ __________ __________ _________ ___ _____ _________ ________ _____ _______.
_______ ____ ____ __________ __________ _________ __________.
________ ____ ___ _________ ____ __________ _____ ___ ______.
___ ____ ____ ________ ____ ___ ________ ______ ____.
________ ___ _______ ______ _____ ______ __________.
_________ ____ ____ __________ __________ _______ ___ _____ __________.
_________ ________ _______ ____ ________ _____.
______ ___ ___ ____ ________ _________ ___.
__________ _________ ____ _______ ________ ________ ___ __________ _____.
______ __________ ____ _____ _________ _____.
__________ ________ __________ ______ ______ ____ ___ ____ _____ _________.
_____ ____ ____ __________ __________.
______ _______ ________ _________ ______ ___ _____ ___.
_________ ____ ____ __________ _____ ______ _______ ________ _________ ___.
________ ______ _______ ______ __________ _________ ______.
_______ __________ ____ ___ _________ _____.
___ _______ _______ ______ ____ _________ ________ ___ __________ _______ ___ ___.
____ _____ __________ __________ _____ ____.
___ ____ ______ _______ ________.
_______ _______ ________ ______ ______.
_____ ______ ___ __________ __________ ____ ______ _____ ________ ___.
_____ _____ __________ ___ ______ __________ ___ __________ _____ ______ _______.
______ ____ _________ ___ _____ _____ _______ _________ _____ ______ _______.
___ ___ ________ ___ ________ ___ _____ _________.
___ ________ ________ ___ _______ ______.
_____ __________ ______ _____ ______ ________ ______ ________ _________.
________ __________ ______ ______ ___ _________ ______ _____.
________ ____ ___ ___ ____ __________ ______.
_________ ___ _____ _____ __________ _________ _____ __________ ____.
__________ _______ ____ ____ __________ ______ __________ ______ ___ ______ ____.
_________ _______ ________ __________ __________ __________ _________.
_____ ________ _______ ________ _________ _________ _________.
______ ________ ____ ________ ____ _______ ____ _______ ___ __________ _______ __________.
_____ ____ _____ _________ ___ ________.
___ ___ ____ ___ ______ ____ _______ ________.
_____ _____ _________ ________ _________.
__________ ______ _________ _____ __________ __________ ___ _______.
_____ ______ ___ __________ ____ _________ _____ __________ ____ ____ _____ __________.
________ _______ ____ __________ _____ ____ __________ ___ _____ ____ ___ _____.
_____ ______ ___ ______ ________ _________ _______ _________ ____ _______ ____.
________ _________ ___ __________ ________.
_______ ___ ______ _____ ____.
___ __________ _______ __________ _________ _______.
_____ ___ ________ _______ _________ _______ _______ ____ _____ ____.
_________ _____ ______ _______ _________ _____ _________ ____ __________ _____ _____.
_________ ___ ____ _______ ________ _____.
_______ _______ __________ _____ _________ _____ ____.
__________ _______ _________ ____ ______ ___ _________.
______ ________ ______ ___ ____ _________ ______ ____ ___.
__________ ____ _____ _____ __________ ____ ____ ___ __________ ______.
_________ _____ ___ ____ __________ ______ __________ ____ ________.
_________ _______ _______ _____ ____ _____ _______.
_________ ______ __________ ___ __________ __________ ___ ______ __________ _____ _________ _____.
______ ______ _________ ________ _________ _______ ____ _________ ______ ___.
________ _____ __________ ____ _____ ___ ____ ___ ______ ___ _____ ___.
_________ _______ ______ ____ ___ _____ __________ _________ ________ ___.
______ _____ _____ ________ _______ ______ __________ __________ _______ ____ ________.
________ _______ ______ _________ ____ ___ _______ ___ ______.
_________ _______ ________ ______ ______ _______.
______ ___ ____ _______ _____ ____ ______ ____ ______ _________ _________.
_________ ______ ______ _____ ___ _________.
______ ______ _________ _______ __________ __________.
__________ ______ __________ ________ _________ _________ ____ _____ ___ ________ _____.
_____ _______ _______ ______ __________.
_______ __________ _______ _____ ________ ______ ______ ________ _______.
________ ______ _____ _________ ________ ___ __________ ______ _______.
_________ ______ __________ ______ _________ ________ _____ _____ ______ ____ _____ _____.
_________ __________ _____ ______ __________.
_________ _____ ___ __________ _________.
_______ ____ _____ ________ __________ ___ ________ ___ ______.
________ ___ ______ ____ ________ _______ ____ _________.
_______ ____ _________ _______ _____ _________ _____ ________ ____.
____ _____ _______ ________ ___ __________ _____.
_______ __________ __________ ________ __________ ________ _________.
_________ ______ ______ ________ _____ ______ ___ ____ __________ __________.
____ ______ ________ ________ _____.
____ _______ _________ _________ _____ ________ ________ __________ __________ _____ ___.
______ ______ _____ _________ ___.
____ ______ _______ _____ ______ ______ _______.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required