{
 "id": "hardware-occlusion-queries",
 "title": "GPU hardware occlusion queries",
 "aliases": [
  "occlusion queries",
  "conditional rendering",
  "CHC++"
 ],
 "domain": "performance",
 "subdomain": "occlusion culling",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "desktop-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2004,
 "inputs": [
  "mesh",
  "depth"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "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.",
 "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.\n\nThe 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.\n\nA conditional-rendering mode lets the GPU itself skip the draw using the query result with no CPU readback.",
 "when_to_use": "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-pvs-culling` for static interiors.",
 "cost": {
  "class": "medium",
  "notes": "Query overhead per proxy draw plus pipeline bubbles if results are polled too early; WebGL2 exposes only boolean results."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/j.1467-8659.2004.00793.x",
   "type": "paper",
   "title": "Coherent Hierarchical Culling: Hardware Occlusion Queries Made Useful",
   "authors": [
    "Jiří Bittner",
    "Michael Wimmer",
    "Harald Piringer",
    "Werner Purgathofer"
   ],
   "year": 2004,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/j.1467-8659.2004.00793.x",
   "ids": {
    "doi": "10.1111/j.1467-8659.2004.00793.x"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/j.1467-8659.2004.00793.x",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/j.1467-8659.2004.00793.x",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/j.1467-8659.2004.00793.x",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/j.1467-8659.2004.00793.x",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/j.1467-8659.2004.00793.x",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "bittner2004coherent"
  },
  {
   "role": "tutorial",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful",
   "type": "tutorial",
   "title": "Hardware Occlusion Queries Made Useful",
   "authors": [
    "Michael Wimmer",
    "Jiri Bittner"
   ],
   "year": null,
   "venue": "developer.nvidia.com",
   "url": "https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": null,
    "page_title": "Chapter 6. Hardware Occlusion Queries Made Useful",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems2/part-i-geometric-complexity/chapter-6-hardware-occlusion-queries-made-useful → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "wimmerhardware"
  }
 ],
 "presets": [
  {
   "id": "hardware-occlusion-queries-live",
   "title": "Hardware Occlusion Queries — bounding-box query proxies & pass/fail depth test (left) vs occluded-skip shaded render (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_WALL_WIDTH": 0.65,
    "P_ORBIT": 0.55,
    "P_PROXY_VIS": 0.75,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_WALL_WIDTH = 0.65; // P Occluder Pillar [0.25, 1.1, 0.05]\nconst float P_ORBIT = 0.55; // P Camera Orbit [0.0, 1.5, 0.05]\nconst float P_PROXY_VIS = 0.75; // P Query Proxy Vis [0.2, 1.0, 0.05]\nconst float P_SPLIT = 0.48; // P Query AABBs / Render [0.0, 1.0, 0.02]\n\nvec2 rot2(vec2 p, float a) {\n  float c = cos(a);\n  float s = sin(a);\n  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);\n}\n\nvec2 boxHit(vec3 ro, vec3 rd, vec3 bc, vec3 br, out vec3 nOut) {\n  vec3 invR = 1.0 / (rd + vec3(1e-6));\n  vec3 t0 = (bc - br - ro) * invR;\n  vec3 t1 = (bc + br - ro) * invR;\n  vec3 tn = min(t0, t1);\n  vec3 tf = max(t0, t1);\n  float tNear = max(max(tn.x, tn.y), tn.z);\n  float tFar = min(min(tf.x, tf.y), tf.z);\n  vec3 lp = (ro + rd * tNear - bc) / max(br, vec3(1e-4));\n  vec3 ap = abs(lp);\n  nOut = (ap.x > ap.y && ap.x > ap.z) ? vec3(sign(lp.x), 0.0, 0.0)\n       : (ap.y > ap.z ? vec3(0.0, sign(lp.y), 0.0) : vec3(0.0, 0.0, sign(lp.z)));\n  return vec2(tNear, tFar);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  float wallW = clamp(P_WALL_WIDTH, 0.20, 1.2) * 0.42;\n  float t = iTime * max(P_ORBIT, 0.0);\n  float proxyVis = clamp(P_PROXY_VIS, 0.1, 1.0);\n\n  // Camera glides laterally so hero spheres pass behind and emerge from behind the foreground occluder wall\n  float camX = 0.85 * sin(t * 0.65);\n  vec3 ro = vec3(camX, 0.28, 2.35);\n  vec3 lookTarget = vec3(0.0, -0.05, -0.2);\n  vec3 fwd = normalize(lookTarget - ro);\n  vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(right, fwd);\n  vec3 rd = normalize(fwd * 1.48 + right * uv.x + up * uv.y);\n\n  vec3 lDir = normalize(vec3(0.52, 0.78, 0.58));\n  vec3 col = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.20, 0.30), smoothstep(-0.4, 0.5, uv.y));\n\n  // Foreground solid occluder monolith wall at z = 0.55\n  vec3 wallC = vec3(0.0, -0.05, 0.55);\n  vec3 wallR = vec3(wallW, 0.44, 0.12);\n\n  // 4 background hero objects positioned behind the occluder wall\n  vec3 objC[4];\n  objC[0] = vec3(-0.78, -0.14, -0.55);\n  objC[1] = vec3(-0.24, -0.14, -0.62);\n  objC[2] = vec3(0.28, -0.14, -0.62);\n  objC[3] = vec3(0.78, -0.14, -0.55);\n\n  float tMin = 1e5;\n  int hitId = -1;\n  vec3 hn = vec3(0.0, 1.0, 0.0);\n  vec3 hp = vec3(0.0);\n\n  // Floor\n  if (rd.y < -0.005) {\n    float tf = (-0.48 - ro.y) / rd.y;\n    if (tf > 0.05 && tf < 14.0) {\n      tMin = tf; hitId = 10; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);\n    }\n  }\n\n  // Test occluder wall\n  vec3 wn;\n  vec2 wh = boxHit(ro, rd, wallC, wallR, wn);\n  float tWall = (wh.y > max(wh.x, 0.05)) ? wh.x : 1e5;\n  if (tWall < tMin) {\n    tMin = tWall; hitId = 20; hp = ro + rd * tWall; hn = wn;\n  }\n\n  // Test 4 hero spheres\n  for (int i = 0; i < 4; i++) {\n    vec3 oc = ro - objC[i];\n    float b = dot(oc, rd);\n    float d = b * b - (dot(oc, oc) - 0.22 * 0.22);\n    if (d > 0.0) {\n      float ts = -b - sqrt(d);\n      if (ts > 0.05 && ts < tMin) {\n        tMin = ts; hitId = i; hp = ro + rd * ts; hn = normalize(hp - objC[i]);\n      }\n    }\n  }\n\n  if (hitId == 10) {\n    vec2 g = hp.xz * 2.5;\n    float chk = mod(floor(g.x) + floor(g.y), 2.0);\n    col = mix(vec3(0.11, 0.13, 0.18), vec3(0.22, 0.25, 0.32), chk);\n    col = mix(vec3(0.05, 0.07, 0.11), col, exp(-tMin * 0.14));\n  } else if (hitId == 20) {\n    float ndl = max(dot(hn, lDir), 0.0);\n    float groove = step(0.85, fract(hp.y * 8.0));\n    vec3 wAlb = mix(vec3(0.26, 0.30, 0.38), vec3(0.14, 0.18, 0.24), groove);\n    col = wAlb * (0.30 + 0.85 * ndl);\n  } else if (hitId >= 0 && hitId < 4) {\n    float fi = float(hitId);\n    vec3 alb = 0.55 + 0.42 * cos(vec3(0.0, 2.0, 4.0) + fi * 1.35);\n    float ndl = max(dot(hn, lDir), 0.0);\n    float spec = pow(max(dot(reflect(-lDir, hn), -rd), 0.0), 32.0);\n    col = alb * (0.24 + 0.90 * ndl) + vec3(0.95) * spec * 0.65;\n  }\n\n  // Left: Overlay hardware occlusion query bounding-box proxies (X-ray through occluder!)\n  // Green/Cyan AABB = samples PASSED depth test; Crimson dashed AABB = 0 samples passed (CULLED!)\n  if (screenX < split) {\n    for (int i = 0; i < 4; i++) {\n      vec3 bn;\n      vec2 bh = boxHit(ro, rd, objC[i], vec3(0.24), bn);\n      if (bh.y > max(bh.x, 0.05)) {\n        // Determine analytically if ANY corner of this proxy is unoccluded by the wall from ro\n        bool anyVisible = false;\n        for (int s = -1; s <= 1; s += 2) {\n          vec3 testPt = objC[i] + vec3(float(s) * 0.22, 0.0, 0.0);\n          vec3 toT = normalize(testPt - ro);\n          float distT = length(testPt - ro);\n          vec3 dummyN;\n          vec2 wh2 = boxHit(ro, toT, wallC, wallR, dummyN);\n          if (!(wh2.y > max(wh2.x, 0.05) && wh2.x < distT)) {\n            anyVisible = true;\n          }\n        }\n        vec3 bp = ro + rd * bh.x;\n        vec3 lp = abs((bp - objC[i]) / 0.24);\n        float edge = max(min(lp.x, lp.y), max(min(lp.y, lp.z), min(lp.z, lp.x)));\n        float wire = smoothstep(0.84, 0.96, edge);\n        vec3 qCol = anyVisible ? vec3(0.16, 0.96, 0.72) : vec3(1.0, 0.24, 0.34);\n        // Tint proxy box wireframe (visible even behind wall to illustrate the GPU query!)\n        float alpha = wire * proxyVis * (bh.x < tWall ? 0.95 : 0.65) + 0.14 * proxyVis;\n        col = mix(col, qCol, clamp(alpha, 0.0, 0.92));\n      }\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.98, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "hardware-occlusion-queries",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:11.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.563,
      "std": 0.0933,
      "min": 0.3274,
      "max": 0.932
     },
     "image": "/specimens/hardware-occlusion-queries-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "hierarchical-z-occlusion-culling",
  "masked-software-occlusion-culling",
  "portal-pvs-culling",
  "gpu-driven-rendering"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "hierarchical-z-occlusion-culling",
   "why": "Use queries for what the depth pyramid misses, such as results against the current frame's depth."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/hardware-occlusion-queries.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Bittner et al., 2004",
 "url": "https://texelatlas.vercel.app/t/hardware-occlusion-queries/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 3.98,
  "tier": "light",
  "p50_ms": 0.1309,
  "p95_ms": 0.1354,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "hardware-occlusion-queries-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.67,
   "tier": "light",
   "p50_ms": 0.0584,
   "p95_ms": 0.0595,
   "speedup_x": 2.24,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.61,
   "tier": "light",
   "p50_ms": 0.0752,
   "p95_ms": 0.076,
   "speedup_x": 1.74,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}