Skip to content

Depth & Transparency

Make z-fighting happen on purpose, then fix it from the frustum — and find out why transparency needs sorting.

What you should come away with: That depth precision is set by the near plane rather than the model, and that the depth buffer cannot answer the question transparency asks.

Assumes: Projection & the Frustum. It will still make sense without it, but that one comes first.

Two panels 0.010 apart, 40 units away · near 0.10

What the depth buffer can tell apart

Smallest gap resolvable at 40 units
9.53e-4
The panels are apart by
0.010
Prediction
resolvable

The prediction above is arithmetic, not a guess: a 24-bit depth buffer distributed hyperbolically resolves roughly z²(f−n) / (n·f·2²⁴) at distance z. Set the separation below that number and the panels must fight; set it above and they cannot. Move the near plane and watch the prediction and the picture change together.

Almost all of that precision is decided by the near plane, because the buffer spends most of its range close to the camera. The far plane is the control everybody reaches for first, and dragging it from 10 to 1000 barely moves the number. That is why the fix for z-fighting is so rarely in the model.

Where that leaves you

You can now work out from the near plane and the distance whether two surfaces will fight before you look at them, and say why the ordering of translucent geometry is the half that no piece of render state will do for you.

This did not teach you the ways out of sorting. Order-independent blending, a prepass and a reversed floating-point buffer are each a real answer to a failure on this page, and each one is a change to the pass structure or to the format the numbers are stored in rather than to a value a slider can reach.