Z-Buffer
Resolve which fragment is actually visible at each pixel by keeping only the smallest depth seen so far.
Interactive playground
Tweak the operator or scene live so the article connects to an immediate visual result.
Z-buffer
Keep the closest fragment at each pixel so visibility stops depending on the order triangles were submitted.
Overlapping geometry
Scene viewWithout vs with depth test
Result viewThe left half ignores depth and the right half keeps the nearer fragment at each covered cell.
Family
Rendering pipeline
Rasterization, visibility, and alternate image synthesis strategies such as ray marching.
Builds on
2 topics
Read these first if you want the surrounding pipeline context.
Unlocks
3 next topics
Use these follow-ups when you want to keep turning the image-processing pipeline forward.
Learning paths
1
This topic appears in curated graphics progressions so the next step is obvious.
Choose this over that
Visibility after rasterization
Z-buffering, shadow mapping, and SSAO all rely on depth, but they use it for different visibility questions.
Z-Buffer
Choose this when: You need to decide which surface is visible at each screen pixel.
Choose something else when: The goal is shading shadows or ambient occlusion after visibility is already known.
Shadow Mapping
Choose this when: Depth should be reused from the light’s point of view to cast shadows.
Choose something else when: The main missing step is still the camera-space visible surface itself.
Screen-Space Ambient Occlusion (SSAO)
Choose this when: Depth is being used to estimate local occlusion rather than front-most visibility.
Choose something else when: Primary visibility is the unresolved problem.
Problem
Once multiple triangles cover the same pixel, coverage alone is no longer enough. You still need to know which surface is in front from the camera’s point of view.
Intuition
The z-buffer stores the best depth seen at each pixel so far. Incoming fragments only survive if they are closer than what the buffer already contains.
Core idea
- Initialize the depth buffer to the farthest possible depth.
- For each rasterized fragment, compare its depth against the stored value at that pixel.
- If the fragment is closer, update both the color target and the depth buffer.
- Otherwise discard it.
Worked example
Two triangles overlap on screen. Without depth testing, draw order decides which one appears. With a z-buffer, the triangle that is physically closer at each pixel wins regardless of submission order.
Complexity
Depth testing is constant work per fragment, but it becomes one of the most performance-critical constant-time decisions in the entire renderer because it happens everywhere.
When to choose it
- Choose it for primary camera-space visibility in a raster pipeline.
- Choose shadow mapping when you need visibility from a light’s point of view instead.
- Choose SSAO when you want depth-based ambient shading cues rather than front-most surface selection.
Key takeaways
- The z-buffer solves visibility per screen pixel.
- It removes draw-order dependence for overlapping geometry.
- Interpolated fragment depth feeds directly into the test.
- Many later effects reuse the same depth information for different purposes.
Practice ideas
- Render two overlapping triangles with and without a z-buffer.
- Visualize the stored depth buffer as a grayscale image.
- Inject a deliberate depth precision issue and inspect the artifact.
Relation to other topics
- Rasterization and barycentric interpolation deliver the fragments and depths that the z-buffer tests.
- Shadow mapping uses a related idea, but from the light’s perspective.
- SSAO also consumes depth, but for shading rather than primary visibility.
Build on these first
These topics supply the mental model or preceding stage that this page assumes.
Rasterization
Turn geometric primitives such as triangles into covered screen pixels so the rendering pipeline can shade actual fragments.
Barycentric Interpolation
Blend per-vertex attributes across a triangle so every covered fragment gets a sensible color, depth, or texture coordinate.
What this enables
Once the current operator feels natural, these are the most useful follow-up jumps.
Screen-Space Ambient Occlusion (SSAO)
Approximate local ambient shadowing from the depth and normal buffers so creases and contact areas feel less flat.
Shadow Mapping
Use a depth map from the light’s point of view to decide whether a visible surface point is blocked from that light.
Temporal Anti-Aliasing (TAA)
Accumulate information across frames so shimmering and unstable subpixel detail become calmer over time.
Related directions
These topics live nearby conceptually, even if they are not strict prerequisites.
Screen-Space Ambient Occlusion (SSAO)
Approximate local ambient shadowing from the depth and normal buffers so creases and contact areas feel less flat.
Shadow Mapping
Use a depth map from the light’s point of view to decide whether a visible surface point is blocked from that light.
More from Rendering pipeline
Stay in the same family when you want parallel operators built from the same mental model.
Rasterization
Turn geometric primitives such as triangles into covered screen pixels so the rendering pipeline can shade actual fragments.
Barycentric Interpolation
Blend per-vertex attributes across a triangle so every covered fragment gets a sensible color, depth, or texture coordinate.
Ray Marching and Signed Distance Fields
Render implicit shapes by stepping along a ray according to the nearest safe distance reported by an SDF.
Paths that include this topic
Follow one of these sequences if you want a guided next step instead of open-ended browsing.
Raster pipeline
Follow the classic rendering path from clipping and rasterization into visibility, shadows, occlusion, and temporal cleanup.
From the blog
Pair the graphics atlas with recent writing from the broader site whenever you want a wider engineering lens.