---
id: "visibility-bitmask-ssao"
title: "Visibility Bitmask Ambient Occlusion"
domain: "visibility"
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"
cost: "medium"
authority: "Therrien et al., 2022"
url: "https://texelatlas.vercel.app/t/visibility-bitmask-ssao/"
sources_verified_at: "2026-11-29"
---
# Visibility Bitmask Ambient Occlusion (Therrien et al., 2022)

> 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.

## Reach for it when

- 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

## 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 it

Choose it when thin geometry (fences, foliage, railings) makes [Ground-Truth Ambient Occlusion](https://texelatlas.vercel.app/t/ground-truth-ambient-occlusion.md) or [Horizon-Based Ambient Occlusion](https://texelatlas.vercel.app/t/hbao.md) over-darken, or when you want AO and a cheap screen-space indirect term together. Prefer [Ray-Traced Ambient Occlusion](https://texelatlas.vercel.app/t/ray-traced-ambient-occlusion.md) for full accuracy and [Screen-Space Ambient Occlusion](https://texelatlas.vercel.app/t/ssao.md) when 32-bit integer ops are not available.

## Cost

medium — A couple of ms at 1080p depending on slice and sample count; similar to GTAO plus bit work.
Measured GPU Weight: 146.4× baseline (extreme) — 4.8166 ms median / 4.9604 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 126.04× baseline (extreme) — 2.004 ms median (2.4× faster on L4).
Ampere A100 scaling: 93.28× baseline (extreme) — 2.6865 ms median (1.79× faster on A100).

## 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

## Dataflow

- Inputs: depth, normals
- Outputs: visibility-mask, radiance
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot

## Presets

### Visibility bitmask SSAO — sector-based horizon visibility vs lit geometry split (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_AO_RADIUS": 0.85,
  "P_THICKNESS": 0.32,
  "P_AO_POWER": 1.35,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_AO_RADIUS = 0.85; // P Gather Radius [0.25, 1.8, 0.05]
const float P_THICKNESS = 0.32; // P Occluder Thick [0.08, 0.8, 0.02]
const float P_AO_POWER = 1.35; // P AO Contrast [0.4, 2.5, 0.05]
const float P_SPLIT = 0.48; // P AO/Lit Split [0.0, 1.0, 0.02]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

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);
}

float sdTorus(vec3 p, vec2 t) {
  vec2 q = vec2(length(p.xz) - t.x, p.y);
  return length(q) - t.y;
}

// Multi-depth architectural atrium with thin hovering bars & recessed niches
// (specifically illustrates how Visibility Bitmask AO avoids over-occlusion behind thin objects!)
vec2 mapScene(vec3 p) {
  vec2 res = vec2(p.y + 0.85, 1.0); // floor
  float backD = p.z + 1.35;
  if (backD < res.x) res = vec2(backD, 1.0);

  // Recessed fluted arcade alcoves along rear wall
  vec3 ap = p - vec3(0.0, 0.0, -1.22);
  ap.x = mod(ap.x + 0.55, 1.1) - 0.55;
  float dPillar = sdBox(ap, vec3(0.14, 1.2, 0.24)) - 0.02;
  if (dPillar < res.x) res = vec2(dPillar, 2.0);

  // Thin floating sculptural ring & hovering bar (classic VBAO thickness test)
  vec3 q = p - vec3(0.0, -0.05, -0.25);
  q.xz = rot2(iTime * 0.32) * q.xz;
  q.xy = rot2(0.52) * q.xy;
  float dRing = sdTorus(q, vec2(0.58, 0.11));
  if (dRing < res.x) res = vec2(dRing, 3.0);

  // Resting matte spheres on floor forming tight contact crevices
  float dS1 = length(p - vec3(-0.62, -0.53, -0.15)) - 0.32;
  float dS2 = length(p - vec3(0.64, -0.57, -0.28)) - 0.28;
  float dS3 = length(p - vec3(0.0, -0.55, -0.25)) - 0.30;
  float dSph = min(dS1, min(dS2, dS3));
  if (dSph < res.x) res = vec2(dSph, 4.0);

  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.002, 0.0);
  return normalize(vec3(
    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
  ));
}

// Emulate Visibility Bitmask AO (12 discrete elevation bins per slice, float-safe for GLSL ES 1.00)
// Each horizon sample covers only its angular interval [thetaBack, thetaFront] using finite occluder thickness!
float evalVisibilityBitmaskAO(vec3 p, vec3 n, float radius, float thickness, float jitter) {
  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)));
  vec3 bitV = cross(n, tanV);

  float occTotal = 0.0;
  // 4 azimuthal slices around tangent plane
  for (int slice = 0; slice < 4; slice++) {
    float phi = (float(slice) + jitter * 0.5) * 1.570796;
    vec3 dir = cos(phi) * tanV + sin(phi) * bitV;

    // 5+5 discrete cosine-weighted angular elevation sectors across [-pi/2, +pi/2]
    float secPos[5];
    float secNeg[5];
    for (int b = 0; b < 5; b++) { secPos[b] = 0.0; secNeg[b] = 0.0; }

    // Sample both positive (+dir) and negative (-dir) horizon directions along the slice
    for (int side = 0; side < 2; side++) {
      vec3 sDir = (side == 0) ? dir : -dir;
      for (int st = 1; st <= 4; st++) {
        float dist = radius * (float(st) / 4.0);
        vec3 sp = p + sDir * dist;
        float sdf = mapScene(sp).x;
        if (sdf < 0.22) {
          float hFront = clamp(0.18 - sdf, 0.0, radius);
          float hBack = hFront - thickness;
          float angFront = atan(hFront, dist);
          float angBack = atan(hBack, dist);
          float falloff = smoothstep(radius * 1.15, radius * 0.15, dist);

          for (int k = 0; k < 5; k++) {
            float binAng = (float(k) + 0.5) * (1.570796 / 5.0);
            float inInterval = smoothstep(angBack - 0.12, angBack + 0.08, binAng) *
                               smoothstep(angFront + 0.12, angFront - 0.08, binAng);
            if (side == 0) secPos[k] = max(secPos[k], inInterval * falloff);
            else secNeg[k] = max(secNeg[k], inInterval * falloff);
          }
        }
      }
    }

    // Count occupied bitmask sectors with cosine hemisphere weighting (popcount analog)
    float sliceOcc = 0.0;
    for (int b = 0; b < 5; b++) {
      float elev = (float(b) + 0.5) * (1.570796 / 5.0);
      float cosW = cos(elev);
      sliceOcc += (secPos[b] + secNeg[b]) * cosW;
    }
    occTotal += sliceOcc / 6.2;
  }

  return clamp(1.0 - occTotal * 0.25, 0.02, 1.0);
}

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;
  vec2 screenUV = fragCoord / iResolution.xy;

  vec3 ro = vec3(0.0, 0.28, 2.55);
  vec3 ta = vec3(0.0, -0.22, -0.35);
  vec3 ww = normalize(ta - ro);
  vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
  vec3 vv = cross(uu, ww);
  vec3 rd = normalize(uv.x * uu + uv.y * vv + 1.5 * ww);

  float rad = clamp(P_AO_RADIUS, 0.2, 2.0);
  float thick = clamp(P_THICKNESS, 0.06, 0.9);
  float aoPow = clamp(P_AO_POWER, 0.3, 3.0);
  float splitX = clamp(P_SPLIT, 0.0, 1.0);

  vec3 col = mix(vec3(0.06, 0.075, 0.10), vec3(0.16, 0.20, 0.28), smoothstep(-0.5, 0.6, uv.y));

  float t = 0.0;
  float matId = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    vec2 h = mapScene(ro + rd * t);
    if (h.x < 0.002) { matId = h.y; hit = true; break; }
    t += h.x;
    if (t > 10.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);
    float jitter = fract(52.9829189 * fract(dot(fragCoord, vec2(0.06711056, 0.00583715))));
    float vbao = pow(evalVisibilityBitmaskAO(p + n * 0.015, n, rad, thick, jitter), aoPow);

    if (screenUV.x < splitX) {
      // Left side: pure Visibility Bitmask Ambient Occlusion buffer (cool archival clay display)
      col = mix(vec3(0.04, 0.055, 0.085), vec3(0.94, 0.96, 0.99), vbao);
    } else {
      // Right side: lit PBR architectural scene shaded with VBAO indirect occlusion
      vec3 alb = vec3(0.76, 0.75, 0.72);
      if (matId > 1.5 && matId < 2.5) alb = vec3(0.68, 0.66, 0.64);
      else if (matId > 2.5 && matId < 3.5) alb = vec3(0.86, 0.54, 0.24);
      else if (matId > 3.5) alb = vec3(0.56, 0.72, 0.84);

      vec3 lDir = normalize(vec3(0.55 * cos(iTime * 0.35) + 0.3, 0.82, 0.58));
      float ndl = max(dot(n, lDir), 0.0);
      vec3 hVec = normalize(lDir - rd);
      float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.42;

      vec3 skyAmb = mix(vec3(0.18, 0.22, 0.30), vec3(0.42, 0.54, 0.72), n.y * 0.5 + 0.5);
      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;
      col = aces(col);
    }
  }

  if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {
    col = vec3(0.28, 0.88, 1.0);
  }

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

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

## Lineage

- extends [Horizon-Based Ambient Occlusion](https://texelatlas.vercel.app/t/hbao.md)

## Combination ideas

- [A thin-occluder cascade zero](https://texelatlas.vercel.app/ideas/bitmask-near-field-cascades/)

## Sources

1. [primary] Olivier Therrien, Yannick Levesque, Guillaume Gilet (2022) Screen space indirect lighting with visibility bitmask. The Visual Computer. https://doi.org/10.1007/s00371-022-02703-y (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "Visibility Bitmask Ambient Occlusion." https://texelatlas.vercel.app/t/visibility-bitmask-ssao/ (accessed 2026-12-01).
