Page 164 - DCAP504_Computer Graphics
P. 164

Unit 11: Hidden Surfaces



               buffer with background color. The Z-value of each (X, Y) point for a plane of a 3-D object to be projected
               on the computer screen is evaluated with the help of equation 8.1. This value is then placed in the (X, Y)
               location of the Z-buffer if it is less than the initial Z value set at (X, Y) location. For the next plane of the
               3-D object, the Z values are calculated in the similar manner and compared with the existing Z-buffer
               values.

               The plane with the minimum Z-buffer value is visible. It is assumed that the visible plane is closer to the
               viewer. This visible plane obstructs the planes having higher Z values at corresponding pixel locations.
               After the visibility test using Z-buffer for a particular screen location (X, Y), the color of the plane
               having the least Z-buffer value at that point is painted. If the Z value is not updated for some pixel
               position i.e. if screen location is not painted new then the background color exists in that position. This
               happens since the background color is already initialized.
               Z-Buffer Algorithm
               The Z-buffer algorithm is among the most preferred routines in present environment. It is easy to
               implement and simple to use and is more often found in hardware. The idea behind its implementation
               is very simple. You just have to assign a Z value to each polygon and then identify the one (pixel by
               pixel) having the smallest value.
               Algorithm

               1.   Initialize the Z-buffer values to maximum possible integer.
               2.   Initialize a 2-D screen matrix of same size as Z-buffer along with background color.
                    For each plane
                    {

                            For each point on the plane
                            {
                                 Using equation 11.1 calculate the Z value of the planar point
                                 If the obtained Z value < existing Z-buffer value at the corresponding frame buffer location
                                 {
                                  Store Z value in Z-buffer and paint the pixel position of the screen with the color of the plane.
                                 }

                            }
                        }
               Since, equation 11.1 is linear in (X, Y), notice that the Z value of a frame buffer location along the row of
               the frame buffer at location (X+1, Y) can be easily calculated by adding (-A/C) with the Z-buffer values
               at (X, Y) as shown below.
                     Z(x+1, y) – Z(x, y) = (-A(x+1) – By – D)/C – (-Ax – By – D)/C = -A/C
               Similarly, z-values at location (X, Y+1) can be calculated by adding (-B/C) with the Z-buffer values at
               (X, Y) as shown below.

                    Z(x, y+1) – Z(x, y) = (-Ax-B(y+1)-D)/C – (-Ax –By-D)/C = -B/C
               Z-buffer values can be calculated from the linear interpolation of the Z-buffer values which are
               calculated at the vertices of the plane with the help of equation 11.1.
               Some of the advantages of Z-buffer are that:
               1.   It can be used easily.

               2.   It can be implemented easily in object or image space.
               3.   It can be executed quickly, even with multiple polygons.



                                        LOVELY PROFESSIONAL UNIVERSITY                          157
   159   160   161   162   163   164   165   166   167   168   169