Depth Buffer
Per-pixel distance used to sort what is visible
Also known as: Z-buffer · Z buffer · Depth map · Scene depth · Reverse-Z · Depth precision
Definition
The depth buffer, or Z-buffer, is an image that stores the distance from the camera to the nearest surface at every pixel. When a new surface is drawn, the GPU compares its depth to the stored value and keeps only the closer one, which is how objects hide each other without sorting. The depth buffer is also used by effects such as depth of field, fog, ambient occlusion and soft particles. Its precision is limited, which causes z-fighting when two surfaces are very close.
In production
Keep the near and far clip planes as close together as the scene allows, since a very small near plane and a huge far plane waste precision and cause flickering distant surfaces. Do not place two surfaces on the same plane, such as a decal over a wall, without an offset. Translucent surfaces usually do not write depth, which is why they sort poorly. Modern engines use reversed depth to improve precision.
Tools that use Depth Buffer
See also
Z-Fighting
Shimmering caused by coplanar surfaces
SSAO
Screen-space ambient occlusion
Depth of Field
Cinematic camera focus blur
Frustum Culling
Skip what the camera can’t see
Blend Mode
How a material combines with what is behind it
Objects Disappear Near the Camera in Unity
Geometry cut off when you get close
Depth Fade (Soft Particles)
Fades a surface where it meets other geometry
Hard Edges Where Smoke Meets Geometry
Visible cut lines where a sprite intersects a surface