0% found this document useful (0 votes)
6 views

Unit-5 Computer Graphics Part-2

Uploaded by

Smasher Ezio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Unit-5 Computer Graphics Part-2

Uploaded by

Smasher Ezio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Shri Ram Murti Smarak College of Engineering, Technology & Research, Bareilly

Unit-V Part 2
Topic : Depth Buffer Method or Z-Buffer
Method, A-Buffer Method and Scan Line
Method
Subject Name: Computer Graphics
Presented By:
Subject Code: RCS-603 Sachin Kumar Saxena
Assistant Professor
CSE Department
SRMS College of Engineering,Technology &
Research,Bareilly
Z-Buffer Method
•Also known as depth-Buffer method.
•Proposed by Catmull in 1974

•Easy to implement

•Z-buffer is like a frame buffer, contain depths


Z-Buffer Method
It is an image space approach
– Each surface is processed separately one pixel
position at a time across the surface
– The depth values for a pixel are compared
and the closest (smallest z) surface
determines the color to be displayed in the
frame buffer.
– Applied very efficiently on polygon
surfaces
– Surfaces are processed in any order
Visibility


How do we ensure that closer polygons
overwrite further ones in general?
Z-Buffer Method

Two buffers are used
– Frame Buffer
– Depth Buffer

The z-coordinates (depth values) are usually
normalized to the range [0,1]
Z-buffer Algorithm
Initialize all d[I,j]=1.0(max depth),c[I,j]=background color
For(each polygon)
For(each pixel in polygon’s projection)
{
Find depth-z of polygon at (x,y) corresponding to pixel (I,j);
If z<d[I,j]
C[I,j]=color
;
End
}
Calculating depth values efficiently

We know the depth values at the vertices.
How can we calculate the depth at any other
point on the surface of the polygon.
● Using the polygon surface equation:

 Ax  By  D
z
C
Calculating depth values efficiently
For any scan line adjacent
horizontal x positions or vertical

y positions differ by 1 unit.


The depth value of the next position

(x+1,y) on the scan line can be


obtained using

 A(x 1)  ByC D


z 
A
zC
Z-Buffer Example
 
     

     
Parallel with     
the image    
plane   
 

   

       
       
       
       
       
       
       
       
Z-Buffer 


Example 


 
Not Parallel    
    
     

 
 
       
       
       
       
       
       
       
       
Depth buffer method (Image
space method)
• It is an image-space approach. The basic idea is to
test the Z-depth of each surface to determine the
closest (visible) surface.
• The depth values for a pixel are compared and the
closest (smallest z) surface determines the color to
be displayed in the frame buffer.
Depth buffer method

• Two buffers named frame buffer and depth buffer,


are used.
• The z-coordinates are usually normalized to the
range [0, 1].
• Depth buffer is used to store depth values for
(x, y) position, as surfaces are processed (0 ≤
depth ≤ 1).
• The frame buffer is used to store the intensity
value of color value at each position (x, y).
Depth buffer Algorithm

Step-1 − Set the buffer values −


Depthbuffer (x, y) = 0
Framebuffer (x, y) = background color

Step-2 − Process each polygon (One at a time)


For each projected (x, y) pixel position of a polygon,
calculate depth z.
If z > depthbuffer (x, y) then
Compute surface color, and
set depthbuffer (x, y) = z,
framebuffer (x, y) = surfacecolor (x,
y)
Depth buffer
Algorithm
Using planar equation of
a surface Ax + By
+ Cz + D =0
Depth buffer method

Advantages
1. It is easy to implement.
2. It reduces the speed problem if
implemented in hardware.
3. It processes one object at a time.
Disadvantages
4. It requires large memory.
5. It is time consuming process.
Z-BUFFER ALGORITHM:
• Its an extension of Frame Buffer
• Display is always stored on Frame Buffer
• Frame Buffer stores information of each and every
pixel on the screen
• Bits (0, 1) decide that the pixel will be ON or OFF

• Z- Buffer apart from Frame buffer stores the depth


of pixel
• After analyzing the data of the overlapping
polygons, pixel closer to the eye will be updated
• Resolution of X,Y => Array[X,Y]
Given set of polygon in image space
Z-Buffer Algorithm:

1. Set the frame buffer & Z-Buffer to a background


value
(Z-BUFFER=Zmin) where, Zmin is
value
To display polygon decide=>color, intensity and depth
2. Scan convert each polygon
i. e, for each pixel, find depth at that
point If Z(X,Y)>Z-BUFFER(X,Y)
Update Z-BUFFER(X,Y)=Z(X,Y)
& FRAME BUFFER
This process will repeat for each
pixel
• By this way we can remove hidden lines and display
those polygons which are closer to eye

• X*Y space required to maintain Z-Buffer=> X*Y times


will be scanned

• Expensive in terms of time and space as space is very


large
y S
S
S’
S’
x x

z display
Pseudocode for the z-buffer algorithm
void zBuffer(void)
{
int x,y;

for(y=0;y<YMAX;y++) { /*Clear frame buffer and z-


buffer*/
for(x=0;x<XMAX;x++) {
WritePixel(x,y,BACKGROUND_VALUE);
WriteZ(x,y,0);
}
}
for(each polygon) { /*Draw Polygons*/
for(each pixel in polygons projection) {
double pz=polygons z-value at pixel coords(x,y);
if(pz>=ReadZ(x,y)) { /*New point is not
farther*/ WriteZ(x,y,pz);
WritePixel(x,y,polygons color at pixel coords(x,y));
}
}
}
SCAN LINE Z-BUFFER ALGORITHM:
• An image space method for identifying visible
surfaces
• Computes and compares depth values along the
various scan-lines for a scene
• Scanning takes place row by row

• To facilitate the search for surfaces crossing a given


scan-line an active list of edges is formed for each
scan-line as it is processed

• The active list stores only those edges that cross the
scan-line in order of increasing x

• Pixel positions across each scan-line are processed


from left to right

• We only need to perform depth calculations

• In Scan Line, Z-Buffer(X) whereas earlier it was X*Y


Use Z-Buffer for only 1 scan line / 1 row of pixel
• During scan conversion in the Active Edge List(AEL)=>
Calculate Z(X,Y)
i.e, -Pixel info between 1 & 2 active edges will only
be stored
-Next pixel will be stored as z=z1+∆z
-∆z will be constant but can change anywhere in
case of slope
• If Z(X,Y)>Z BUFFER(X) => Update
• If 2 polygons are present-along with Active Edge List,
Active Polygon List will also be included
• Active Polygon List=> List of polygons intersecting a
scan line
A- buffer method
• The expands on the depth buffer
A-buffer
method to allow
transparencies.
• The key data structure in the A-buffer is the
accumulation buffer.
A- buffer method
A- buffer method
A- buffer
method
• The surface buffer in the A-buffer includes −
1. RGB intensity components
2. Opacity Parameter
3. Depth
4. Percent of area coverage
5. Surface identifier
• The algorithm proceeds just like the depth buffer
algorithm.
• The depth and opacity values are used to
determine the final color of a pixel.
Scan line method
Scan line method
• It is an image-space method to identify visible
surface.
• This method has a depth information for only
single scan-line.
Scan line method

• Two important
tabl
tables, and
edge
e arepolygon
tabl maintained
e, for
this.
Scan line
method

• To facilitate the search


for surfaces crossing a given
scan-line, an
active list of edges is formed.
• The active list stores only those edges
that cross the scan-line in order of
increasing x.
• Also a flag is set for each surface to
indicate whether a position along a
Scan line
method

• Pixel positions across each scan-line are processed


from left to right.
• At the left intersection with a surface, the
surface flag is turned on and at the right, the
flag is turned off.
• You only need to perform depth calculations when
multiple surfaces have their flags turned on at a
certain scan-line position.
Scan line
method
• The active list for scan line 1 contains information
from the edge table for edges AB, BC, EH, and FG.
For positions along this scan line between edges AB
and BC, only the flag for surface S1 is on.
• Therefore no depth calculations are necessary, and
intensity information for surface S1 is entered from
the polygon table into the refresh buffer.
Scan line
method
• Similarly, between edges EH and FG, only the flag for
surface S2 is on.
• NO other positions along scan line 1
intersect surfaces, so the intensity values
in the other areas are set to the background
intensity.
Scan line
method
• For scan lines 2 and 3 in Fig. 13-10, the active edge list
contains edges AD, EH, BC,
and FG.
• Along scan line 2 from edge AD to edge EH, only the flag for
surface S1 is on.
• But between edges EH and BC, the flags for both surfaces are
on.
Scan line
method
• Depth calculations must be made using the plane coefficients
for the two surfaces.
• For this example, the depth of surface S1 is assumed to be
less than that of S2 so intensities for surface S1 are loaded
into the refresh buffer until boundary BC is encountered.
• Then the flag for surface S1 goes off, and intensities for
surface S2 are stored until edge FG is passed.
Any Query ?

www.sachinplacement.blogspot.com
or mail at
[email protected]

You might also like