Z-Buffer Depth Buffer

Resolving coordinate visibility and overdraw using depth mapping buffers.

Depth Buffers

A Z-Buffer contains a depth value for each screen pixel, initialized to maximum distance (1.0). When rendering a new fragment at coordinate $(x, y)$ with depth $z$:

  • If $z < Z_Buffer[x, y]$, the new pixel is closer. Write color to Color Buffer and update $Z_Buffer[x, y] = z$.
  • Otherwise, discard the fragment.

Why it's crucial

Without Z-buffering (or manual sorting like Painters algorithm), surfaces overlap incorrectly based on the order they were processed. Enabling glEnable(GL_DEPTH_TEST) enforces correct visibility sorting automatically on modern GPUs.

Ready to Visualize Z-Buffering?

Launch our interactive visualizer to step through calculations in real-time.

Launch Z-Buffer Visualizer →