Page 165 - DCAP504_Computer Graphics
P. 165

Computer Graphics



                          With advantages the Z-buffer also has some disadvantages as
                          1.  It requires lot of memory.
                          2.  It requires additional code to do transparent surfaces.
                          Now let us look at an example of Z-buffer.

                                             Z-Buffer Algorithm for Cube
                                             Initialize Z-buffer values to the maximum possible integer.
                                             Initialize a 2-D screen matrix of same size as Z-buffer with background color
                                             For each surface P having color 1 and for plane equation
                                             {
                                             For each pixel (x1,y1) in the 2-D projection of P
                                             {
                                             Compute Z value at (x1,y1)
                                             If z value < z-buffer value at (x1,y1)
                                             {
                                             On Pixel ( x1 , y1 ,1);
                                             Z-buffer value at (x1, y1) = z value
                                             }
                                             }
                                             }


                          Let us study about other available buffers such as C-buffer and S-buffer.
                          C-buffer is also known as the coverage buffer. For the C-buffer the spans are drawn directly onto the
                          screen. Whenever a span gets clipped on to the left side, the clipping is done and then the span that
                          caused the clip is extended along the length of the clipped span. At the end of the rendering process
                          each scan line on screen is represented by a single entry which is called as the C-buffer.
                          S-buffer is also known as the surface buffer. It is basically a structure in which a track is maintained of
                          the parts of each scan line that are filled with pixel data already. It can be filled with the spans that
                          make up the polygon when we rasterize it. The S-buffer thus consists of either a linked list or a tree that
                          holds the spans that are sent to a specific scan line in the correct order. When a new span is inserted on
                          an already existing span then the new span is either clipped or split or rejected.
                                             The 'x' line is the new span, '=' means spans already in the tree:
                                                   Xxxxxxxxxxxx                  (New span)
                                                   ============             (Span already exists)
                                             Here,  portion of the right side of this span is clipped of so that the new S-buffer for this
                                             screen line becomes:
                                                   xxxxxxx============




                          11.2   Binary Space Partitioning
                          Algorithms that are used to determine the proper obstruction between objects should be able to quickly
                          determine  the relative depths of objects or parts of objects. If the viewpoint and view  direction are
                          changed in an image space algorithm then the process has to be repeated from scratch. As an alternative
                          to the above process  a Binary Space Partitioning (BSP)  tree is constructed for the scene that is
                          independent of the viewpoint location. The BSP tree breaks up the scene into regions with the spatial
                          relationship of the same regions built into the tree. The space is subdivided until the object in each of
                          the regions is definite in its relationship with the objects in the other regions.
                          The leaf node of the BSP tree where the viewpoint is located holds the closest object.  As we move up
                          one node in the tree and down into the other leaf, the second closest object is identified. This way the
                          child-node of other nodes in the tree pointing towards the collection of the objects can be identified as
                          the next closest and farthest objects.



                          158                     LOVELY PROFESSIONAL UNIVERSITY
   160   161   162   163   164   165   166   167   168   169   170