Z-Buffer Algorithm
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] := ;
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