0% found this document useful (0 votes)
306 views12 pages

Z-Buffer Algorithm

The Z-buffer algorithm is used to draw overlapping shapes based on their depth (z-depth). It uses a 2D z-buffer array to store the z-depth of each pixel. Pixels are drawn based on comparing their z-depth to the current z-depth stored in the z-buffer - if the shape's z-depth is closer, it is drawn and the z-buffer is updated. The algorithm initializes the z-buffer with maximum values, then draws each shape by comparing its z-depth to the buffer and updating colors and depths where closer. This allows efficient rendering of clipped or overlapped shapes based on 3D position.

Uploaded by

d33kshant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
306 views12 pages

Z-Buffer Algorithm

The Z-buffer algorithm is used to draw overlapping shapes based on their depth (z-depth). It uses a 2D z-buffer array to store the z-depth of each pixel. Pixels are drawn based on comparing their z-depth to the current z-depth stored in the z-buffer - if the shape's z-depth is closer, it is drawn and the z-buffer is updated. The algorithm initializes the z-buffer with maximum values, then draws each shape by comparing its z-depth to the buffer and updating colors and depths where closer. This allows efficient rendering of clipped or overlapped shapes based on 3D position.

Uploaded by

d33kshant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Z-Buffer Algorithm

Deekshant Yadav
Outline
• Z-Buffer
• Z-Buffer Algorithm
• Example of Z-Buffer Algorithm
Z-Buffer
• Z-buffer is a 2D array that stores a depth value for each pixel.
• This buffer is used to draw pixel based on their z-depth.
• Used to draw content when shapes are clipped because of their z-
depth
Z-Buffer Algorithm
• Z-Buffer algorithm is an algorithm used to draw shapes that are
clipped or overlapped based on their depth
• Draw shapes who has less z-depth or close to the screen
• Shapes requires to have a z-depth
Z-Buffer Algorithm
• Initialize buffer with infinite or max values
InitScreen:
for i := 0 to N do
for j := 1 to N do
Screen[i][j] := BACKGROUND_COLOR; Zbuffer[i][j] := ;

• Draw shaped based on their z-depth


DrawZpixel (x, y, z, color)
if (z <= Zbuffer[x][y]) then
Screen[x][y] := color; Zbuffer[x][y] := z;
Example

  


      

     
 
    
  
   
   
  
    
 
     

  

               
       
       
       
       
Step 1        
       
       
• Initialize the buffer with infinite         Z-buffer
or max value        
       
       
       

Screen
Step 2 - 1  
      
     
• Draw shapes based on     
   
their z-depth   
 



       
       
       
       
       
       
       
       
Step 2 - 2 

 
• Draw shapes based on their z-   
depth    
    
     

 

       
       
       
       
       
       
       
       
   
    

Final Output      

 

       
       
       
       
       
       
       
       
Another Examples
• The algorithm will work the same
• The only thing change will be the size of the buffer and scale of the
shapes

You might also like