Featured

# Depth Buffer or Z-buffer Algorithm

Depth Buffer or Z-buffer Algorithm :

It is an example of image space algorithm.  In this algorithm we compare depth of surface at each pixel position on the projection plane.  Each surface of scene is processed separately, taking one point at a time across surface.  This method is normally used on polygonal surfaces.

In this algorithm, we kept record of depth of object within pixel that lies closest to observer.  This algorithm requires two buffers.  A depth buffer is used to store depth for each (x,y) position as surfaces are processed.  The other buffer refresh buffer stores the intensity value of each position.  Initially all positions in depth buffer are set to 0 and refresh is set to background intensity.

Each polygon surface is processed, one scan line at calculating the depth (Z value) at each pixel (x,y) position.  If calculated depth is more than depth value stored in depth buffer, new depth value will be stored.

Depth values for a surface position (x,y) are calculated from plane equation for each surface
Z = - Ax - By - D
C
Next pixel position on same scan line is (x + 1, y) and its Z value is calculated as

Z' = - A(x+1) - By - D
C
If we compare these two equation then we get

Z' = Z - A/C

Hence depth value for next pixel position is calculated from previous depth value by subtracting ratio A/C.  Ratio A/C is constant for each surface.
The Z- buffer algorithm is summarized as below :

1. Initialize the depth buffer and refresh buffer so that for all buffer positions (x,y)
depth (x,y) = 0,
refresh (x,y) = Ib

Where Ib represents background intensity.

2. For each position on each polygon surface, compare depth value to previously stored value in depth buffer.

=>  Calculate depth Z for each (x,y) position on polygon
=>  If Z> depth (x,y) then
depth (x,y) = Z and
refresh (x,y) = I-surface(x,y)

Advantage : It is the simplest of all image space algorithm.

Disadvantage : High amount of storage space is required for two buffers.