---
id: "hierarchical-z-occlusion-culling"
title: "Hierarchical-Z occlusion culling"
aliases: [Hi-Z culling, HZB culling]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, unity, unreal]
year_introduced: 1993
inputs: [depth, mesh]
outputs: [visibility-mask]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "Greene et al., 1993"
url: "https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling/"
sources_verified_at: "2026-11-29"
---
# Hierarchical-Z occlusion culling (Greene et al., 1993)

> Build a mip chain of the depth buffer keeping the farthest depth per texel, then reject any object whose bounds lie entirely behind that conservative depth.

## Reach for it when

- objects hidden behind walls still get drawn
- dense city or indoor scene overdraws badly
- need to skip hidden geometry using the depth buffer
- too many draws for things you can't see
- gpu culling against last frame's depth

## How it works

After rendering occluders, downsample the depth buffer into a pyramid where each texel stores the maximum (farthest) depth of the texels beneath it. To test an object, project its bounding box to screen, pick the mip level at which the box covers about one texel or a few, sample depth there, and compare the box's nearest depth against it. If the nearest point is behind everything, the object is hidden.

GPU-driven engines typically reuse the previous frame's depth, reprojected, then test and draw in a second pass to fix false rejections.

## When to use it

Choose it for dense indoor or urban scenes where large occluders hide most geometry. Prefer software occlusion rasterization on CPU for non-GPU-driven pipelines, or portal and PVS systems for static levels. Prefer plain frustum culling in open, flat scenes where occlusion rarely helps.

## Cost

cheap — Pyramid build is a few small passes; tests are a handful of texture fetches per object.
Measured GPU Weight: 345.82× baseline (extreme) — 10.8589 ms median / 10.9263 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 379.3× baseline (extreme) — 5.993 ms median (1.81× faster on L4).
Ampere A100 scaling: 231.36× baseline (extreme) — 6.6632 ms median (1.63× faster on A100).

## Failure modes

- Using last frame's depth causes objects to be culled wrongly after fast camera or object motion
- Conservative tests miss thin occluders, leaving culling inefficient
- Mip selection errors give over-culling and visible holes
- Needs depth readable as a texture, which complicates MSAA

## Engine support

- blender: builtin — `EEVEE maintains a mipmapped HiZBuffer pyramid for screen-space raytracing and visibility culling` (evidence: https://github.com/blender/blender/blob/main/source/blender/draw/engines/eevee/eevee_hizbuffer.cc, checked 2026-12-01)
- unity: builtin — `URP/HDRP Asset > GPU Resident Drawer enabled > GPU Occlusion Culling` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Documentation~/gpu-culling.md, checked 2026-12-01) — GPU occlusion culling needs GPU Resident Drawer.
- unreal: builtin — `Console variable r.HZBOcclusion=1` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/visibility-and-occlusion-culling-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: depth, mesh
- Outputs: visibility-mask
- Platforms: webgl2, webgpu, desktop-gpu, unity, unreal

## Presets

### Hierarchical-Z occlusion culling — Hi-Z max-depth mip pyramid vs conservative box culling (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_MIP_LEVEL": 3,
  "P_OCCLUDER_H": 0.72,
  "P_SPLIT": 0.44,
  "P_SWEEP_SPEED": 1
}
```

```glsl
const float P_MIP_LEVEL = 3.0; // P Hi-Z Mip Level [1.0, 5.0, 1.0]
const float P_OCCLUDER_H = 0.72; // P Occluder Height [0.25, 1.2, 0.03]
const float P_SPLIT = 0.44; // P Hi-Z / Cull Split [0.0, 1.0, 0.02]
const float P_SWEEP_SPEED = 1.0; // P Camera Sway [0.0, 2.5, 0.05]

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Primary foreground occluder walls & piers
float mapOccluders(vec3 p, float occH) {
  float d = p.y + 0.85;
  float w1 = sdBox(p - vec3(-0.72, -0.85 + occH, -0.8), vec3(0.58, occH, 0.14));
  float w2 = sdBox(p - vec3(0.68, -0.85 + occH * 0.88, -1.15), vec3(0.52, occH * 0.88, 0.14));
  float w3 = sdBox(p - vec3(0.02, -0.85 + occH * 0.62, -2.05), vec3(0.46, occH * 0.62, 0.14));
  return min(d, min(w1, min(w2, w3)));
}

// Evaluate depth of foreground occluders along a view ray
float traceOccluderDepth(vec3 ro, vec3 rd, float occH) {
  float t = 0.05;
  for (int i = 0; i < 40; i++) {
    float d = mapOccluders(ro + rd * t, occH);
    if (d < 0.003) return t;
    t += d;
    if (t > 12.0) break;
  }
  return 12.0;
}

vec3 calcOccNormal(vec3 p, float occH) {
  vec2 e = vec2(0.003, 0.0);
  return normalize(vec3(
    mapOccluders(p + e.xyy, occH) - mapOccluders(p - e.xyy, occH),
    mapOccluders(p + e.yxy, occH) - mapOccluders(p - e.yxy, occH),
    mapOccluders(p + e.yyx, occH) - mapOccluders(p - e.yyx, occH)
  ));
}

// Project a 3D world point into camera screen space (uv, depth)
vec3 projectPt(vec3 p, vec3 ro, vec3 fw, vec3 rt, vec3 up) {
  vec3 v = p - ro;
  float z = dot(v, fw);
  float x = dot(v, rt) / max(z, 0.05) * 1.45;
  float y = dot(v, up) / max(z, 0.05) * 1.45;
  return vec3(x, y, z);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float tAnim = iTime * max(P_SWEEP_SPEED, 0.0);
  float occH = clamp(P_OCCLUDER_H, 0.2, 1.3);
  float mipLvl = floor(clamp(P_MIP_LEVEL, 1.0, 5.0));
  float split = clamp(P_SPLIT, 0.0, 1.0);

  vec3 ro = vec3(0.65 * sin(tAnim * 0.55), 0.35 + 0.12 * cos(tAnim * 0.4), 2.35);
  vec3 ta = vec3(0.0, -0.15, -1.4);
  vec3 fw = normalize(ta - ro);
  vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
  vec3 up = cross(rt, fw);
  vec3 rd = normalize(fw * 1.45 + rt * uv.x + up * uv.y);

  // Trace foreground occluders
  float tOcc = traceOccluderDepth(ro, rd, occH);

  // Conservative Hi-Z max-depth mip cell for current pixel
  float cellRes = pow(2.0, 6.0 - mipLvl);
  vec2 cellSize = vec2(1.0 / cellRes);
  vec2 cellCenter = (floor(uv * cellRes) + 0.5) * cellSize;
  float hiZMax = 0.0;
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < 2; i++) {
      vec2 off = (vec2(float(i), float(j)) - 0.5) * cellSize * 0.72;
      vec2 suv = cellCenter + off;
      vec3 srd = normalize(fw * 1.45 + rt * suv.x + up * suv.y);
      hiZMax = max(hiZMax, traceOccluderDepth(ro, srd, occH));
    }
  }

  // Base shaded scene (sky + occluder walls)
  vec3 sky = mix(vec3(0.05, 0.07, 0.11), vec3(0.12, 0.18, 0.28), clamp(uv.y + 0.5, 0.0, 1.0));
  vec3 sceneCol = sky;
  if (tOcc < 11.5) {
    vec3 p = ro + rd * tOcc;
    vec3 n = calcOccNormal(p, occH);
    vec3 lDir = normalize(vec3(0.55, 0.85, 0.45));
    float diff = max(dot(n, lDir), 0.0);
    float isFloor = step(0.85, n.y);
    vec2 grid = abs(fract(p.xz * 1.5 - 0.5) - 0.5);
    float gLine = smoothstep(0.035, 0.008, min(grid.x, grid.y));
    vec3 alb = mix(vec3(0.18, 0.22, 0.29), vec3(0.12, 0.14, 0.18) + gLine * vec3(0.07, 0.11, 0.16), isFloor);
    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0);
    sceneCol = alb * (0.28 + 0.85 * diff) + vec3(0.18, 0.34, 0.52) * rim * (1.0 - isFloor) * 0.45;
  }

  // Evaluate 9 candidate bounding boxes behind the occluders against the Hi-Z pyramid
  vec3 boxOverlay = vec3(0.0);
  float boxAlpha = 0.0;
  for (int k = 0; k < 9; k++) {
    float fk = float(k);
    float row = floor(fk / 3.0);
    float colIdx = mod(fk, 3.0) - 1.0;
    vec3 bPos = vec3(
      colIdx * 0.92 + 0.25 * sin(tAnim * 0.7 + fk * 1.4),
      -0.42 + 0.32 * sin(tAnim * 0.9 + fk * 2.1) + row * 0.18,
      -1.55 - row * 0.95
    );
    vec3 bHalf = vec3(0.20, 0.24, 0.20);

    // Project candidate box center & evaluate conservative Hi-Z occlusion test
    vec3 proj = projectPt(bPos, ro, fw, rt, up);
    float boxMinZ = proj.z - 0.24;
    vec2 bCell = (floor(proj.xy * cellRes) + 0.5) * cellSize;
    float localHiZ = 0.0;
    for (int sy = 0; sy < 2; sy++) {
      for (int sx = 0; sx < 2; sx++) {
        vec2 suv = bCell + (vec2(float(sx), float(sy)) - 0.5) * cellSize * 0.65;
        vec3 srd = normalize(fw * 1.45 + rt * suv.x + up * suv.y);
        localHiZ = max(localHiZ, traceOccluderDepth(ro, srd, occH));
      }
    }
    bool isCulled = boxMinZ > localHiZ;

    // Ray-box analytic intersection for rendering the candidate box
    vec3 invRd = 1.0 / (rd + sign(rd + 1e-6) * 1e-5);
    vec3 t0 = (bPos - bHalf - ro) * invRd;
    vec3 t1 = (bPos + bHalf - ro) * invRd;
    vec3 tMinV = min(t0, t1);
    vec3 tMaxV = max(t0, t1);
    float tNear = max(max(tMinV.x, tMinV.y), tMinV.z);
    float tFar = min(min(tMaxV.x, tMaxV.y), tMaxV.z);
    if (tFar > max(tNear, 0.05)) {
      vec3 hitP = ro + rd * tNear;
      vec3 lp = abs((hitP - bPos) / bHalf);
      float edge = smoothstep(0.84, 0.96, max(max(min(lp.x, lp.y), min(lp.y, lp.z)), min(lp.x, lp.z)));
      if (!isCulled && tNear < tOcc) {
        vec3 bn = normalize(sign(hitP - bPos) * step(vec3(0.98), lp));
        float bDiff = 0.35 + 0.75 * max(dot(bn, normalize(vec3(0.5, 0.9, 0.4))), 0.0);
        vec3 visCol = mix(vec3(0.14, 0.84, 0.58), vec3(0.96, 0.98, 0.85), edge);
        sceneCol = visCol * bDiff;
        tOcc = tNear;
      } else if (isCulled) {
        // X-ray magenta wireframe showing Hi-Z culled geometry saved from rasterization
        vec3 cullCol = vec3(1.0, 0.22, 0.55) * (0.28 + 1.35 * edge);
        boxOverlay = max(boxOverlay, cullCol);
        boxAlpha = max(boxAlpha, 0.24 + 0.58 * edge);
      }
    }

    // Screen-space projected AABB indicator on Hi-Z side
    float halfW = 0.24 / max(proj.z, 0.3) * 1.45;
    vec2 boxD = abs(uv - proj.xy) - vec2(halfW);
    float rectEdge = smoothstep(0.012, 0.002, abs(max(boxD.x, boxD.y)));
    if (screenX < split) {
      vec3 tagCol = isCulled ? vec3(1.0, 0.24, 0.52) : vec3(0.18, 0.96, 0.62);
      boxOverlay = max(boxOverlay, tagCol * rectEdge * 1.4);
      boxAlpha = max(boxAlpha, rectEdge * 0.85);
    }
  }

  // Left view: Hi-Z Depth Mip Pyramid visualization
  vec3 hiZCol;
  float zNorm = clamp(1.0 - (hiZMax - 1.2) / 5.5, 0.0, 1.0);
  hiZCol = mix(vec3(0.04, 0.08, 0.22), vec3(0.18, 0.68, 0.94), smoothstep(0.0, 0.65, zNorm));
  hiZCol = mix(hiZCol, vec3(0.96, 0.92, 0.52), smoothstep(0.65, 1.0, zNorm));
  vec2 cellF = abs(fract(uv * cellRes) - 0.5);
  float cellGrid = smoothstep(0.46, 0.50, max(cellF.x, cellF.y));
  hiZCol = mix(hiZCol, vec3(0.05, 0.09, 0.14), cellGrid * 0.55);

  vec3 col = (screenX < split) ? mix(hiZCol, boxOverlay, boxAlpha) : mix(sceneCol, boxOverlay, boxAlpha * 0.68);
  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Lineage

- extended by [GPU-driven rendering](https://texelatlas.vercel.app/t/gpu-driven-rendering.md)
- extended by [Masked software occlusion culling](https://texelatlas.vercel.app/t/masked-software-occlusion-culling.md)

## Combines with

- [Meshlets (cluster rendering)](https://texelatlas.vercel.app/t/meshlets.md): Meshlet bounding spheres project to small boxes that the pyramid can reject cheaply.

## Sources

1. [primary] Ned Greene, Michael Kass, Gavin Miller (1993) Hierarchical Z-buffer visibility. Proceedings of the 20th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/166117.166147 (verified via crossref on 2026-11-29)
2. [implementation] zeux (2018) zeux/niagara. https://github.com/zeux/niagara License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Hierarchical-Z occlusion culling." https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling/ (accessed 2026-12-01).
