Unit content
Depth buffering and hidden-surface visibility
When several rasterized fragments map to the same pixel, the renderer must determine which surface is visible.
A depth buffer stores, for each pixel sample, the depth of the closest accepted fragment so far. A new fragment passes the depth test only if it is closer according to the chosen depth convention; when it passes, both the color and stored depth are updated.
This makes visibility largely independent of draw order for opaque surfaces. Without a depth buffer, rendering nearer and farther objects in the wrong order can overwrite visible surfaces incorrectly.
Depth precision is finite and is distributed non-uniformly under perspective projection. Choosing an excessively small near plane or an enormous near-to-far ratio can make nearby depths quantize to nearly the same value, producing z-fighting.
Depth buffering solves ordinary opaque visibility efficiently, but transparency needs additional ordering or compositing logic because a translucent surface can contribute even when another surface is visible behind it.