---
title: "Z-buffer (depth buffer) method"
subject: "Computer Graphics"
chapter: 7
key: "semester_5/computer_graphics:z-buffer-method-explain"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/z-buffer-method-explain
site: BCT Engineering
---

# Z-buffer (depth buffer) method

Computer Graphics · Chapter 7: Visible Surface Determination

- Asked in: 2076 Asoj, 8 marks; 2070 Asar, 8 marks; 2072 Chaitra, 6 marks; 2073 Shrawan, 4 marks; 2069 Chaitra, 7 marks; 2078 Bhadra, 6 marks; 2067 Mangsir (old course), 6 marks (asked 7 times)
- Video: [Z Buffer | Method | CG | Computer Graphics | Lec-53 | Bhanu Priya](https://www.youtube.com/watch?v=FqDNXXgS5dw) — Education 4u
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/z-buffer-method-explain
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-7

## Question

Explain the Z-buffer (depth buffer) method of visible surface detection, including how the depth of pixels is calculated.

## Short answer

Z-buffer stores nearest depth per pixel; depth is computed as z = (−Ax−By−D)/C. Incrementally along a scan line, depth updates as z' = z − A/C; if new depth is less than stored, the pixel is replaced in the frame buffer.

## Answer

The **Z-buffer (depth-buffer) method** is an image-space method. It compares the depth (z value) of surfaces at each pixel position (x, y) of the projection plane and keeps the nearest one.

**Two buffers**
- **Depth buffer** zbuf(x, y): depth of the nearest surface found so far at each pixel.
- **Frame (refresh) buffer** frame(x, y): colour of the nearest surface at each pixel.

Viewing is along the z-axis, with 0 ≤ depth ≤ 1 (0 = front plane, 1 = back plane).

**Algorithm**
```text
1. Initialise zbuf(x,y) = 1 (maximum depth), frame(x,y) = background colour for all x,y.
2. For each polygon in the scene:
     for each pixel (x,y) of its projection:
         compute depth z of the polygon at (x,y)
         if z < zbuf(x,y):
             zbuf(x,y)  = z
             frame(x,y) = surface colour at (x,y)
3. After all polygons are done, the frame buffer holds the visible image.
```

**Depth calculation.** For a plane Ax + By + Cz + D = 0:

z = (−Ax − By − D) / C

Incremental calculation (faster): when we move one pixel to the right along a scan line, x becomes x + 1, so

z' = (−A(x+1) − By − D)/C = z − A/C

(A/C is a constant for the polygon). Moving down to the next scan line along an edge with slope m (x' = x − 1/m, y' = y − 1):

z' = z + (A/m + B)/C

For a vertical edge, z' = z + B/C.

Features: the method is simple, handles any shape, needs no sorting, and polygons may be processed in any order. However, it needs extra memory for the depth buffer, cannot render transparent surfaces, and suffers from aliasing.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which two buffers does the Z-buffer method use?
   A. Edge table and polygon table
   B. Stencil buffer and mask buffer
   C. Depth buffer and frame (refresh) buffer
   D. Active edge list and depth list
   Answer: C. The depth buffer holds the nearest depth and the frame buffer holds that surface's colour. (Key point: Buffers used)

2. How are the buffers initialised?
   A. zbuf = 0, frame = white
   B. zbuf = 1 (maximum depth), frame = background colour
   C. zbuf = 1, frame = 0 depth
   D. zbuf = -1, frame = random
   Answer: B. Starting at the maximum depth ensures any surface is nearer and replaces it. (Key point: Initialisation)

3. When is a pixel updated?
   A. When the polygon's z at that pixel is less than zbuf(x,y)
   B. When z is greater than zbuf(x,y)
   C. When z equals the pixel's x
   D. Always, for every polygon
   Answer: A. With 0 = front plane, smaller z means nearer, so it replaces the stored value. (Key point: Update rule)

4. Moving one pixel right along a scan line, how does the depth of a plane Ax+By+Cz+D=0 change?
   A. z' = z + B/C
   B. z' = z + A
   C. z' = z - C/A
   D. z' = z - A/C
   Answer: D. Substituting x+1 into z = (-Ax - By - D)/C gives a constant decrement A/C. (Key point: Incremental depth)

## Related in Computer Graphics

- [Scan-line method of visible surface](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Ascan-line-visible-surface) — Computer Graphics, chapter 7, asked 3×
- [Z-buffer method with limitation](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Az-buffer-with-limitation) — Computer Graphics, chapter 7, asked 3×
- [A-buffer method](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aa-buffer-method) — Computer Graphics, chapter 7, asked 2×
- [VSD factors, classes, Z/A-buffer](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Avisible-surface-factors-classes) — Computer Graphics, chapter 7
- [Raster display and frame buffer load time](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Araster-system-load-time) — Computer Graphics, chapter 1
- [Compare Z-buffer, A-buffer; scan-line](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acompare-z-a-buffer-scan-line) — Computer Graphics, chapter 7

## Related in other subjects

- [Control of sub-surface water and seepage](https://www.bctengineer.com/question.md?key=semester_6%2Ftransportation_engineering_i%3Asubsurface-drainage-measures) — Transportation Engineering I, chapter 4, asked 15×
- [Surface drainage design, 40 ha Terai field](https://www.bctengineer.com/question.md?key=semester_6%2Firrigation_and_drainage_engineering%3Asurface-drainage-40ha-terai) — Irrigation and Drainage Engineering, chapter 9
- [Water surface over hump with contraction](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Ahump-contraction-surface-elevations-1-6m) — Hydraulics, chapter 7
- [Flow rate from drop in surface over hump](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Acontraction-3m-to-2m-floor-raised-drop-0-2) — Hydraulics, chapter 7
