GPU hardware occlusion queries
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.
Also known as occlusion queries, conditional rendering, CHC++
In the family Performance, LOD & compression, occlusion culling
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | Set object.occlusionTest = true, then renderer.isOccluded( object ) (WebGPURenderer) docs WebGPURenderer only. |
| Babylon.js 9.38.0 | Built in | mesh.occlusionType = AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC; mesh.occlusionQueryAlgorithmType docs |
| Godot 4.7 | None found | Occlusion culling is CPU-side via OccluderInstance3D, not GPU occlusion queries. |
| Unity | None found | GPU Resident Drawer uses depth-pyramid occlusion culling, not hardware queries. |
| Unreal 5.7 | Built in | Project Settings > Rendering > Culling > Occlusion Culling (GPU Hardware Occlusion Queries and HZB) docs |
| Blender 5.2 | Not applicable | DCC tool; no runtime occlusion culling. |
| WebGPU W3C | Built in | device.createQuerySet({type:'occlusion',count}); pass.beginOcclusionQuery(i) docs Returns samples-passed count; resolve via resolveQuerySet. |
| Metal | Built in | MTLRenderPassDescriptor.visibilityResultBuffer + setVisibilityResultMode(.boolean/.counting, offset:) docs |
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 choose it
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
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 for GPU-driven pipelines (no query latency, culls thousands of instances in one dispatch) and Masked software occlusion culling when you need a result before submission without GPU roundtrip. Prefer Portal and PVS visibility culling for static interiors.
Field marks
- 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
Presets
Hardware Occlusion Queries — bounding-box query proxies & pass/fail depth test (left) vs occluded-skip shaded render (right)
{
"P_WALL_WIDTH": 0.65,
"P_ORBIT": 0.55,
"P_PROXY_VIS": 0.75,
"P_SPLIT": 0.48
}Show GLSL (149 lines)
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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| hardware-occlusion-queries-live | Tesla T4 1920x1080 | 3.98× baseline (light) · 0.131 ms / 0.135 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| hardware-occlusion-queries-live | NVIDIA L4 1920x1080 | 3.67× baseline (light) · 0.058 ms / 0.059 ms · 2.2× faster on L4 | opengl-timer-query · Cross-architecture validation |
| hardware-occlusion-queries-live | NVIDIA A100-SXM4-40GB 1920x1080 | 2.61× baseline (light) · 0.075 ms / 0.076 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites SAH BVH construction, Portal and PVS visibility culling.
Crosses
- Hierarchical-Z occlusion culling: Use queries for what the depth pyramid misses, such as results against the current frame's depth.
Sources
- primaryJiří Bittner, Michael Wimmer, Harald Piringer, Werner Purgathofer (2004). Coherent Hierarchical Culling: Hardware Occlusion Queries Made Useful. Computer Graphics Forum.Verified via crossref · 2026-11-29doi:10.1111/j.1467-8659.2004.00793.x
- tutorialMichael Wimmer, Jiri Bittner. Hardware Occlusion Queries Made Useful. developer.nvidia.com.Verified via live page · 2026-11-29