{
 "id": "visibility-bitmask-ssao",
 "title": "Visibility Bitmask Ambient Occlusion",
 "aliases": [],
 "domain": "visibility",
 "subdomain": "screen-space AO",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2022,
 "inputs": [
  "depth",
  "normals"
 ],
 "outputs": [
  "visibility-mask",
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Records occluded sectors of the hemisphere as bits in an integer mask instead of a single horizon angle, so thin occluders can be handled and indirect light can be gathered.",
 "how_it_works": "Instead of keeping a max horizon per direction, each depth sample marks the angular interval it occupies, determined with an assumed thickness, as set bits in a 32-bit mask. The union of all occupied intervals gives the visible fraction (popcount) and the unset bits indicate directions from which light can arrive, which can be weighted by the radiance sampled at those pixels to give a screen-space one-bounce indirect term. This handles gaps between thin occluders and avoids the infinite thickness assumption of horizon-based methods. Cost is similar to horizon AO with a few bit operations per sample.",
 "when_to_use": "Choose it when thin geometry (fences, foliage, railings) makes `ground-truth-ambient-occlusion` or `hbao` over-darken, or when you want AO and a cheap screen-space indirect term together. Prefer `ray-traced-ambient-occlusion` for full accuracy and `ssao` when 32-bit integer ops are not available.",
 "cost": {
  "class": "medium",
  "notes": "A couple of ms at 1080p depending on slice and sample count; similar to GTAO plus bit work."
 },
 "failure_modes": [
  "Needs a thickness heuristic that must be tuned per scene",
  "Screen-space limit: off-screen light and occluders are missing",
  "Noise and temporal artefacts when only a few slices are used",
  "Indirect term is limited to what the previous frame shows"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1007/s00371-022-02703-y",
   "type": "paper",
   "title": "Screen space indirect lighting with visibility bitmask",
   "authors": [
    "Olivier Therrien",
    "Yannick Levesque",
    "Guillaume Gilet"
   ],
   "year": 2022,
   "venue": "The Visual Computer",
   "url": "https://doi.org/10.1007/s00371-022-02703-y",
   "ids": {
    "doi": "10.1007/s00371-022-02703-y"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/s00371-022-02703-y",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/s00371-022-02703-y",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/s00371-022-02703-y",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/s00371-022-02703-y",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/s00371-022-02703-y",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "therrien2022screen"
  }
 ],
 "presets": [
  {
   "id": "visibility-bitmask-ssao-live",
   "title": "Visibility bitmask SSAO — sector-based horizon visibility vs lit geometry split",
   "runtime": "glsl-fragment",
   "params": {
    "P_AO_RADIUS": 0.85,
    "P_THICKNESS": 0.32,
    "P_AO_POWER": 1.35,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_AO_RADIUS = 0.85; // P Gather Radius [0.25, 1.8, 0.05]\nconst float P_THICKNESS = 0.32; // P Occluder Thick [0.08, 0.8, 0.02]\nconst float P_AO_POWER = 1.35; // P AO Contrast [0.4, 2.5, 0.05]\nconst float P_SPLIT = 0.48; // P AO/Lit Split [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\nfloat sdTorus(vec3 p, vec2 t) {\n  vec2 q = vec2(length(p.xz) - t.x, p.y);\n  return length(q) - t.y;\n}\n\n// Multi-depth architectural atrium with thin hovering bars & recessed niches\n// (specifically illustrates how Visibility Bitmask AO avoids over-occlusion behind thin objects!)\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.85, 1.0); // floor\n  float backD = p.z + 1.35;\n  if (backD < res.x) res = vec2(backD, 1.0);\n\n  // Recessed fluted arcade alcoves along rear wall\n  vec3 ap = p - vec3(0.0, 0.0, -1.22);\n  ap.x = mod(ap.x + 0.55, 1.1) - 0.55;\n  float dPillar = sdBox(ap, vec3(0.14, 1.2, 0.24)) - 0.02;\n  if (dPillar < res.x) res = vec2(dPillar, 2.0);\n\n  // Thin floating sculptural ring & hovering bar (classic VBAO thickness test)\n  vec3 q = p - vec3(0.0, -0.05, -0.25);\n  q.xz = rot2(iTime * 0.32) * q.xz;\n  q.xy = rot2(0.52) * q.xy;\n  float dRing = sdTorus(q, vec2(0.58, 0.11));\n  if (dRing < res.x) res = vec2(dRing, 3.0);\n\n  // Resting matte spheres on floor forming tight contact crevices\n  float dS1 = length(p - vec3(-0.62, -0.53, -0.15)) - 0.32;\n  float dS2 = length(p - vec3(0.64, -0.57, -0.28)) - 0.28;\n  float dS3 = length(p - vec3(0.0, -0.55, -0.25)) - 0.30;\n  float dSph = min(dS1, min(dS2, dS3));\n  if (dSph < res.x) res = vec2(dSph, 4.0);\n\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.002, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// Emulate Visibility Bitmask AO (12 discrete elevation bins per slice, float-safe for GLSL ES 1.00)\n// Each horizon sample covers only its angular interval [thetaBack, thetaFront] using finite occluder thickness!\nfloat evalVisibilityBitmaskAO(vec3 p, vec3 n, float radius, float thickness, float jitter) {\n  vec3 tanV = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));\n  vec3 bitV = cross(n, tanV);\n\n  float occTotal = 0.0;\n  // 4 azimuthal slices around tangent plane\n  for (int slice = 0; slice < 4; slice++) {\n    float phi = (float(slice) + jitter * 0.5) * 1.570796;\n    vec3 dir = cos(phi) * tanV + sin(phi) * bitV;\n\n    // 5+5 discrete cosine-weighted angular elevation sectors across [-pi/2, +pi/2]\n    float secPos[5];\n    float secNeg[5];\n    for (int b = 0; b < 5; b++) { secPos[b] = 0.0; secNeg[b] = 0.0; }\n\n    // Sample both positive (+dir) and negative (-dir) horizon directions along the slice\n    for (int side = 0; side < 2; side++) {\n      vec3 sDir = (side == 0) ? dir : -dir;\n      for (int st = 1; st <= 4; st++) {\n        float dist = radius * (float(st) / 4.0);\n        vec3 sp = p + sDir * dist;\n        float sdf = mapScene(sp).x;\n        if (sdf < 0.22) {\n          float hFront = clamp(0.18 - sdf, 0.0, radius);\n          float hBack = hFront - thickness;\n          float angFront = atan(hFront, dist);\n          float angBack = atan(hBack, dist);\n          float falloff = smoothstep(radius * 1.15, radius * 0.15, dist);\n\n          for (int k = 0; k < 5; k++) {\n            float binAng = (float(k) + 0.5) * (1.570796 / 5.0);\n            float inInterval = smoothstep(angBack - 0.12, angBack + 0.08, binAng) *\n                               smoothstep(angFront + 0.12, angFront - 0.08, binAng);\n            if (side == 0) secPos[k] = max(secPos[k], inInterval * falloff);\n            else secNeg[k] = max(secNeg[k], inInterval * falloff);\n          }\n        }\n      }\n    }\n\n    // Count occupied bitmask sectors with cosine hemisphere weighting (popcount analog)\n    float sliceOcc = 0.0;\n    for (int b = 0; b < 5; b++) {\n      float elev = (float(b) + 0.5) * (1.570796 / 5.0);\n      float cosW = cos(elev);\n      sliceOcc += (secPos[b] + secNeg[b]) * cosW;\n    }\n    occTotal += sliceOcc / 6.2;\n  }\n\n  return clamp(1.0 - occTotal * 0.25, 0.02, 1.0);\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  vec2 screenUV = fragCoord / iResolution.xy;\n\n  vec3 ro = vec3(0.0, 0.28, 2.55);\n  vec3 ta = vec3(0.0, -0.22, -0.35);\n  vec3 ww = normalize(ta - ro);\n  vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));\n  vec3 vv = cross(uu, ww);\n  vec3 rd = normalize(uv.x * uu + uv.y * vv + 1.5 * ww);\n\n  float rad = clamp(P_AO_RADIUS, 0.2, 2.0);\n  float thick = clamp(P_THICKNESS, 0.06, 0.9);\n  float aoPow = clamp(P_AO_POWER, 0.3, 3.0);\n  float splitX = clamp(P_SPLIT, 0.0, 1.0);\n\n  vec3 col = mix(vec3(0.06, 0.075, 0.10), vec3(0.16, 0.20, 0.28), smoothstep(-0.5, 0.6, uv.y));\n\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.002) { matId = h.y; hit = true; break; }\n    t += h.x;\n    if (t > 10.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n    float jitter = fract(52.9829189 * fract(dot(fragCoord, vec2(0.06711056, 0.00583715))));\n    float vbao = pow(evalVisibilityBitmaskAO(p + n * 0.015, n, rad, thick, jitter), aoPow);\n\n    if (screenUV.x < splitX) {\n      // Left side: pure Visibility Bitmask Ambient Occlusion buffer (cool archival clay display)\n      col = mix(vec3(0.04, 0.055, 0.085), vec3(0.94, 0.96, 0.99), vbao);\n    } else {\n      // Right side: lit PBR architectural scene shaded with VBAO indirect occlusion\n      vec3 alb = vec3(0.76, 0.75, 0.72);\n      if (matId > 1.5 && matId < 2.5) alb = vec3(0.68, 0.66, 0.64);\n      else if (matId > 2.5 && matId < 3.5) alb = vec3(0.86, 0.54, 0.24);\n      else if (matId > 3.5) alb = vec3(0.56, 0.72, 0.84);\n\n      vec3 lDir = normalize(vec3(0.55 * cos(iTime * 0.35) + 0.3, 0.82, 0.58));\n      float ndl = max(dot(n, lDir), 0.0);\n      vec3 hVec = normalize(lDir - rd);\n      float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.42;\n\n      vec3 skyAmb = mix(vec3(0.18, 0.22, 0.30), vec3(0.42, 0.54, 0.72), n.y * 0.5 + 0.5);\n      col = alb * (vec3(1.55, 1.42, 1.24) * ndl * (0.35 + 0.65 * vbao) + skyAmb * vbao) + vec3(1.0, 0.94, 0.86) * spec * vbao;\n      col = aces(col);\n    }\n  }\n\n  if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {\n    col = vec3(0.28, 0.88, 1.0);\n  }\n\n  fragColor = vec4(pow(clamp(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": "visibility-bitmask-ssao",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:50:13.852Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6727,
      "std": 0.121,
      "unique_colors": 247
     },
     "image": "/specimens/visibility-bitmask-ssao-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ground-truth-ambient-occlusion",
  "hbao",
  "ssao"
 ],
 "extends": [
  "hbao"
 ],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/visibility/visibility-bitmask-ssao.json"
 },
 "solves": [
  "fences and foliage get over-darkened by screen-space occlusion",
  "thin occluders are treated as solid walls",
  "want cheap indirect light together with occlusion",
  "horizon-based darkening fails on thin geometry"
 ],
 "authority": "Therrien et al., 2022",
 "url": "https://texelatlas.vercel.app/t/visibility-bitmask-ssao/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 146.4,
  "tier": "extreme",
  "p50_ms": 4.8166,
  "p95_ms": 4.9604,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "visibility-bitmask-ssao-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 126.04,
   "tier": "extreme",
   "p50_ms": 2.004,
   "p95_ms": 2.0664,
   "speedup_x": 2.4,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 93.28,
   "tier": "extreme",
   "p50_ms": 2.6865,
   "p95_ms": 2.6956,
   "speedup_x": 1.79,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}