---
id: "hardware-occlusion-queries"
title: "GPU hardware occlusion queries"
aliases: [occlusion queries, conditional rendering, CHC++]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, desktop-gpu, unity, unreal]
year_introduced: 2004
inputs: [mesh, depth]
outputs: [visibility-mask]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Bittner et al., 2004"
url: "https://texelatlas.vercel.app/t/hardware-occlusion-queries/"
sources_verified_at: "2026-11-29"
---
# GPU hardware occlusion queries (Bittner et al., 2004)

> Ask the GPU how many samples a bounding proxy would pass the depth test, then use that answer, with temporal coherence to hide latency, to skip drawing hidden objects.

## Reach for it when

- draw calls wasted on objects hidden behind walls
- gpu should tell me whether an object is visible
- occlusion culling that uses real depth buffer
- popping when culling uses last frame's visibility
- skip drawing hidden meshes without authored occluders

## How it works

Render the bounding box of an object with color and depth writes disabled inside a query. The GPU reports whether any sample passed the depth test against the already-drawn occluders; if none did, the real object is hidden and need not be drawn.

The catch is latency: the result arrives a frame or more later, and stalling for it wastes the CPU/GPU overlap. Coherent hierarchical culling avoids stalls by exploiting that visibility rarely changes between frames. Nodes of a scene hierarchy visible last frame are drawn immediately and re-queried in parallel, while nodes that were hidden are queried and only drawn if the query returns visible later. Queries are issued for tree nodes front to back so a hidden interior node prunes its whole subtree.

A conditional-rendering mode lets the GPU itself skip the draw using the query result with no CPU readback.

## When to use it

Choose it when you need exact occlusion against real rendered depth with no authored occluders, in a classic CPU-driven pipeline with a spatial hierarchy. Prefer [Hierarchical-Z occlusion culling](https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling.md) for GPU-driven pipelines (no query latency, culls thousands of instances in one dispatch) and [Masked software occlusion culling](https://texelatlas.vercel.app/t/masked-software-occlusion-culling.md) when you need a result before submission without GPU roundtrip. Prefer [Portal and PVS visibility culling](https://texelatlas.vercel.app/t/portal-pvs-culling.md) for static interiors.

## Cost

medium — Query overhead per proxy draw plus pipeline bubbles if results are polled too early; WebGL2 exposes only boolean results.
Measured GPU Weight: 3.98× baseline (light) — 0.1309 ms median / 0.1354 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 3.67× baseline (light) — 0.0584 ms median (2.24× faster on L4).
Ampere A100 scaling: 2.61× baseline (light) — 0.0752 ms median (1.74× faster on A100).

## Failure modes

- Reading results early stalls the pipeline and can cost more than the culled draws
- One-frame-old results make objects pop in when the camera rotates quickly
- Many tiny queries add driver overhead that exceeds the saved draw cost
- Bounding boxes over-estimate silhouettes, so partially hidden objects count as visible
- Not available on all mobile drivers, and WebGL2 only returns any-samples-passed

## Engine support

- babylonjs: builtin — `mesh.occlusionType = AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC; mesh.occlusionQueryAlgorithmType` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Meshes/abstractMesh.pure.ts, checked 2026-12-01)
- metal: builtin — `MTLRenderPassDescriptor.visibilityResultBuffer + setVisibilityResultMode(.boolean/.counting, offset:)` (evidence: https://developer.apple.com/tutorials/data/documentation/metal/mtlrenderpassdescriptor.json, checked 2026-12-01)
- threejs: builtin — `Set object.occlusionTest = true, then renderer.isOccluded( object ) (WebGPURenderer)` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/renderers/common/Renderer.js, checked 2026-12-01) — WebGPURenderer only.
- unreal: builtin — `Project Settings > Rendering > Culling > Occlusion Culling (GPU Hardware Occlusion Queries and HZB)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/visibility-and-occlusion-culling-in-unreal-engine, checked 2026-12-01)
- webgpu: builtin — `device.createQuerySet({type:'occlusion',count}); pass.beginOcclusionQuery(i)` (evidence: https://www.w3.org/TR/webgpu/, checked 2026-12-01) — Returns samples-passed count; resolve via resolveQuerySet.

## Dataflow

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

## Presets

### Hardware Occlusion Queries — bounding-box query proxies & pass/fail depth test (left) vs occluded-skip shaded render (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_WALL_WIDTH": 0.65,
  "P_ORBIT": 0.55,
  "P_PROXY_VIS": 0.75,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_WALL_WIDTH = 0.65; // P Occluder Pillar [0.25, 1.1, 0.05]
const float P_ORBIT = 0.55; // P Camera Orbit [0.0, 1.5, 0.05]
const float P_PROXY_VIS = 0.75; // P Query Proxy Vis [0.2, 1.0, 0.05]
const float P_SPLIT = 0.48; // P Query AABBs / Render [0.0, 1.0, 0.02]

vec2 rot2(vec2 p, float a) {
  float c = cos(a);
  float s = sin(a);
  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);
}

vec2 boxHit(vec3 ro, vec3 rd, vec3 bc, vec3 br, out vec3 nOut) {
  vec3 invR = 1.0 / (rd + vec3(1e-6));
  vec3 t0 = (bc - br - ro) * invR;
  vec3 t1 = (bc + br - ro) * invR;
  vec3 tn = min(t0, t1);
  vec3 tf = max(t0, t1);
  float tNear = max(max(tn.x, tn.y), tn.z);
  float tFar = min(min(tf.x, tf.y), tf.z);
  vec3 lp = (ro + rd * tNear - bc) / max(br, vec3(1e-4));
  vec3 ap = abs(lp);
  nOut = (ap.x > ap.y && ap.x > ap.z) ? vec3(sign(lp.x), 0.0, 0.0)
       : (ap.y > ap.z ? vec3(0.0, sign(lp.y), 0.0) : vec3(0.0, 0.0, sign(lp.z)));
  return vec2(tNear, tFar);
}

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 split = clamp(P_SPLIT, 0.0, 1.0);
  float wallW = clamp(P_WALL_WIDTH, 0.20, 1.2) * 0.42;
  float t = iTime * max(P_ORBIT, 0.0);
  float proxyVis = clamp(P_PROXY_VIS, 0.1, 1.0);

  // Camera glides laterally so hero spheres pass behind and emerge from behind the foreground occluder wall
  float camX = 0.85 * sin(t * 0.65);
  vec3 ro = vec3(camX, 0.28, 2.35);
  vec3 lookTarget = vec3(0.0, -0.05, -0.2);
  vec3 fwd = normalize(lookTarget - ro);
  vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));
  vec3 up = cross(right, fwd);
  vec3 rd = normalize(fwd * 1.48 + right * uv.x + up * uv.y);

  vec3 lDir = normalize(vec3(0.52, 0.78, 0.58));
  vec3 col = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.20, 0.30), smoothstep(-0.4, 0.5, uv.y));

  // Foreground solid occluder monolith wall at z = 0.55
  vec3 wallC = vec3(0.0, -0.05, 0.55);
  vec3 wallR = vec3(wallW, 0.44, 0.12);

  // 4 background hero objects positioned behind the occluder wall
  vec3 objC[4];
  objC[0] = vec3(-0.78, -0.14, -0.55);
  objC[1] = vec3(-0.24, -0.14, -0.62);
  objC[2] = vec3(0.28, -0.14, -0.62);
  objC[3] = vec3(0.78, -0.14, -0.55);

  float tMin = 1e5;
  int hitId = -1;
  vec3 hn = vec3(0.0, 1.0, 0.0);
  vec3 hp = vec3(0.0);

  // Floor
  if (rd.y < -0.005) {
    float tf = (-0.48 - ro.y) / rd.y;
    if (tf > 0.05 && tf < 14.0) {
      tMin = tf; hitId = 10; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);
    }
  }

  // Test occluder wall
  vec3 wn;
  vec2 wh = boxHit(ro, rd, wallC, wallR, wn);
  float tWall = (wh.y > max(wh.x, 0.05)) ? wh.x : 1e5;
  if (tWall < tMin) {
    tMin = tWall; hitId = 20; hp = ro + rd * tWall; hn = wn;
  }

  // Test 4 hero spheres
  for (int i = 0; i < 4; i++) {
    vec3 oc = ro - objC[i];
    float b = dot(oc, rd);
    float d = b * b - (dot(oc, oc) - 0.22 * 0.22);
    if (d > 0.0) {
      float ts = -b - sqrt(d);
      if (ts > 0.05 && ts < tMin) {
        tMin = ts; hitId = i; hp = ro + rd * ts; hn = normalize(hp - objC[i]);
      }
    }
  }

  if (hitId == 10) {
    vec2 g = hp.xz * 2.5;
    float chk = mod(floor(g.x) + floor(g.y), 2.0);
    col = mix(vec3(0.11, 0.13, 0.18), vec3(0.22, 0.25, 0.32), chk);
    col = mix(vec3(0.05, 0.07, 0.11), col, exp(-tMin * 0.14));
  } else if (hitId == 20) {
    float ndl = max(dot(hn, lDir), 0.0);
    float groove = step(0.85, fract(hp.y * 8.0));
    vec3 wAlb = mix(vec3(0.26, 0.30, 0.38), vec3(0.14, 0.18, 0.24), groove);
    col = wAlb * (0.30 + 0.85 * ndl);
  } else if (hitId >= 0 && hitId < 4) {
    float fi = float(hitId);
    vec3 alb = 0.55 + 0.42 * cos(vec3(0.0, 2.0, 4.0) + fi * 1.35);
    float ndl = max(dot(hn, lDir), 0.0);
    float spec = pow(max(dot(reflect(-lDir, hn), -rd), 0.0), 32.0);
    col = alb * (0.24 + 0.90 * ndl) + vec3(0.95) * spec * 0.65;
  }

  // Left: Overlay hardware occlusion query bounding-box proxies (X-ray through occluder!)
  // Green/Cyan AABB = samples PASSED depth test; Crimson dashed AABB = 0 samples passed (CULLED!)
  if (screenX < split) {
    for (int i = 0; i < 4; i++) {
      vec3 bn;
      vec2 bh = boxHit(ro, rd, objC[i], vec3(0.24), bn);
      if (bh.y > max(bh.x, 0.05)) {
        // Determine analytically if ANY corner of this proxy is unoccluded by the wall from ro
        bool anyVisible = false;
        for (int s = -1; s <= 1; s += 2) {
          vec3 testPt = objC[i] + vec3(float(s) * 0.22, 0.0, 0.0);
          vec3 toT = normalize(testPt - ro);
          float distT = length(testPt - ro);
          vec3 dummyN;
          vec2 wh2 = boxHit(ro, toT, wallC, wallR, dummyN);
          if (!(wh2.y > max(wh2.x, 0.05) && wh2.x < distT)) {
            anyVisible = true;
          }
        }
        vec3 bp = ro + rd * bh.x;
        vec3 lp = abs((bp - objC[i]) / 0.24);
        float edge = max(min(lp.x, lp.y), max(min(lp.y, lp.z), min(lp.z, lp.x)));
        float wire = smoothstep(0.84, 0.96, edge);
        vec3 qCol = anyVisible ? vec3(0.16, 0.96, 0.72) : vec3(1.0, 0.24, 0.34);
        // Tint proxy box wireframe (visible even behind wall to illustrate the GPU query!)
        float alpha = wire * proxyVis * (bh.x < tWall ? 0.95 : 0.65) + 0.14 * proxyVis;
        col = mix(col, qCol, clamp(alpha, 0.0, 0.92));
      }
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.98, 1.0), sep);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combines with

- [Hierarchical-Z occlusion culling](https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling.md): Use queries for what the depth pyramid misses, such as results against the current frame's depth.

## Sources

1. [primary] Jiří Bittner, Michael Wimmer, Harald Piringer, Werner Purgathofer (2004) Coherent Hierarchical Culling: Hardware Occlusion Queries Made Useful. Computer Graphics Forum. https://doi.org/10.1111/j.1467-8659.2004.00793.x (verified via crossref on 2026-11-29)
2. [tutorial] Michael Wimmer, Jiri Bittner Hardware Occlusion Queries Made Useful. developer.nvidia.com. https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful (verified via http on 2026-11-29)

## Cite this entry

Texel. "GPU hardware occlusion queries." https://texelatlas.vercel.app/t/hardware-occlusion-queries/ (accessed 2026-12-01).
