What it does

ZTest decides whether a new surface is in front of or behind stored depth. It compares the fragment's depth with the Depth Buffer and draws when the selected comparison, such as LEqual, passes.

Figure: Conceptual relationship: Fragment depth → Compare stored depth → Draw passing fragments
Figure: Conceptual relationship: Fragment depth → Compare stored depth → Draw passing fragments

How to use it

Inspect the shader comparison, fragment depth and previously stored depth. Passing ZTest and writing depth through ZWrite are separate operations; change one at a time.

A concrete example

Always can suit a deliberately visible-through-wall marker, but creates unwanted wall penetration for ordinary smoke. A draw-order problem does not automatically require bypassing depth.

How to check it

  1. Test a foreground cube and background quad, including partially occluded regions and camera movement.
    Testing and writing are separate settings
    Testing and writing are separate settings
  2. Inspect the pass depth condition in Frame Debugger.
    Testing and writing are separate settings
    Testing and writing are separate settings

Limitations

It differs from ZWrite; Always can draw through occluders.

References