---
id: "alchemy-ambient-obscurance"
title: "Alchemy screen-space ambient obscurance"
aliases: [Alchemy AO, AlchemyAO, SAO precursor]
domain: "visibility"
stage: "visibility"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot]
year_introduced: 2011
inputs: [depth, normals]
outputs: [visibility-mask]
style: "photoreal"
dynamic: "dynamic"
cost: "cheap"
authority: "McGuire et al., 2011"
url: "https://texelatlas.vercel.app/t/alchemy-ambient-obscurance/"
sources_verified_at: "2026-11-29"
---
# Alchemy screen-space ambient obscurance (McGuire et al., 2011)

> A cheap one-pass screen-space AO estimator that sums, over a few random samples, how much each nearby point rises above the tangent plane, giving a closed-form obscurance with controlled falloff.

## Reach for it when

- want cheap contact darkening in creases on mobile
- screen space ambient occlusion too slow for my target
- ambient occlusion shows dark halos around foreground objects
- need simple one pass ao that works in webgl
- corners and crevices look too bright and flat

## How it works

For a shaded point with position P and normal n, the pass picks about a dozen sample points in a screen-space disk, reconstructs their view-space positions from depth, and forms vectors v from P to each. Each sample contributes the term max(0, v·n - bias·depth) divided by (v·v + epsilon), which is large when the occluder lies above the surface and close, and decays with squared distance to avoid halos from far geometry. The sum is normalised by the sample count and mapped to visibility with a power and an intensity scale, e.g. (1 - 2σ/s·sum)^k. Samples are placed on a spiral with per-pixel rotation, followed by an edge-aware bilateral blur. The squared-distance denominator and the simple per-sample formula avoid the explicit horizon search of later methods. A derivative, scalable ambient obscurance, adds a depth MIP chain for large radii.

## When to use it

Choose it for a low-cost, easy-to-port AO on mobile and WebGL where compute-style horizon methods are too heavy. Prefer [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) for more accurate horizon-based occlusion at slightly higher cost, [N8AO](https://texelatlas.vercel.app/t/n8ao.md) for a ready three.js implementation, [Ray-Traced Ambient Occlusion](https://texelatlas.vercel.app/t/ray-traced-ambient-occlusion.md) or [SDF Ambient Occlusion](https://texelatlas.vercel.app/t/sdf-ambient-occlusion.md) when you can afford exactness, and [Multi-Bounce Ambient Occlusion Approximation](https://texelatlas.vercel.app/t/multi-bounce-ambient-occlusion.md) as a cheap albedo-dependent brightening on top.

## Cost

cheap — One full-resolution pass with about a dozen depth taps plus a separable blur; cost grows with radius because of cache misses unless a depth MIP chain is used.
Measured GPU Weight: 43.63× baseline (heavy) — 1.4353 ms median / 1.4535 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 43.1× baseline (heavy) — 0.6853 ms median (2.09× faster on L4).
Ampere A100 scaling: 28.1× baseline (heavy) — 0.8092 ms median (1.77× faster on A100).

## Failure modes

- Halos and dark rings around foreground silhouettes when the radius exceeds object thickness
- Noise and banding patterns when samples per pixel are few and the blur is too small or too large
- View-dependent darkening at screen borders and missing occluders that are off-screen or behind surfaces
- Over-darkened concave corners compared with a ground-truth reference, requiring intensity tuning
- Flat or tiny-scale geometry shimmer under camera motion unless the noise is temporally resolved

## Engine support

- unity: builtin — `URP Renderer > Add Renderer Feature > Screen Space Ambient Occlusion (implements McGuire 2011 Alchemy AO in SSAO.hlsl)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl, checked 2026-12-01) — URP SSAO uses Alchemy ambient obscurance; HDRP uses GTAO.

## Dataflow

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

## Presets

### Left: direct lighting only. Right: Alchemy Ambient Obscurance (McGuire 2011) crevice darkening (glsl-fragment; rendered 2026-11-30)

```json
{
  "AO_RADIUS": 0.48,
  "AO_INTENSITY": 2.4,
  "AO_BIAS": 0.025,
  "SAMPLES": 16
}
```

```glsl
const float AO_RADIUS = 0.48; // P
const float AO_INTENSITY = 2.4; // P
const float AO_BIAS = 0.025; // P
const int SAMPLES = 16; // P

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

// Sculpted geometric niche with deep concave corners, flutes and nested forms
float mapScene(vec3 p) {
  float floorD = p.y + 0.9;
  float backWall = p.z + 1.45;
  // Recessed stepped frame
  float frame = max(sdBox(p - vec3(0.0, 0.15, -1.1), vec3(1.65, 1.25, 0.35)), -sdBox(p - vec3(0.0, 0.15, -0.95), vec3(1.22, 0.88, 0.42)));
  // Rotated central sculpture (interlocking torus + sphere + ribbed pedestal)
  vec3 q = p - vec3(0.0, -0.1, -0.15);
  float a = iTime * 0.35;
  mat2 r = mat2(cos(a), -sin(a), sin(a), cos(a));
  q.xz = r * q.xz;
  float ped = sdBox(p - vec3(0.0, -0.72, -0.15), vec3(0.58, 0.18, 0.58));
  float sp = length(q - vec3(0.0, 0.12, 0.0)) - 0.38;
  float tor = sdTorus(q.xzy - vec3(0.0, 0.0, 0.12), vec2(0.52, 0.14));
  float cols = sdBox(vec3(abs(p.x) - 0.92, p.y + 0.05, p.z + 0.72), vec3(0.18, 0.95, 0.18));
  float flute = sin(p.y * 28.0) * 0.012;
  float d = min(floorD, min(backWall, frame));
  d = min(d, min(ped, min(sp, min(tor, cols + flute))));
  return d;
}

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

float raymarch(vec3 ro, vec3 rd, float tMax) {
  float t = 0.05;
  for (int i = 0; i < 60; i++) {
    float d = mapScene(ro + rd * t);
    if (d < 0.0025) return t;
    t += d;
    if (t > tMax) break;
  }
  return -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;
  float splitX = 0.0;
  if (iMouse.z > 0.5 || length(iMouse.xy) > 1.0) {
    splitX = (iMouse.x - 0.5 * iResolution.xy.x) / iResolution.y;
  }

  vec3 ro = vec3(0.0, 0.25, 2.35);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.06, -1.45));
  float t = raymarch(ro, rd, 10.0);
  vec3 col = vec3(0.12, 0.14, 0.18);

  if (t > 0.0) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);
    vec3 lDir = normalize(vec3(0.55, 0.78, 0.45));
    float nl = max(dot(n, lDir), 0.0);
    vec3 alb = vec3(0.84, 0.82, 0.79);
    vec3 direct = alb * (0.28 + 0.85 * nl);

    // McGuire 2011 Alchemy Ambient Obscurance estimator on spiral tangent-disk samples
    float ao = 1.0;
    if (uv.x > splitX) {
      int nSamp = clamp(SAMPLES, 4, 32);
      float rad = max(AO_RADIUS, 0.02);
      float bias = max(AO_BIAS, 0.0);
      float eps = 0.015;
      float spin = fract(sin(dot(fragCoord, vec2(12.9898, 78.233))) * 43758.5453) * 6.2831853;
      vec3 up = abs(n.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
      vec3 tx = normalize(cross(up, n));
      vec3 ty = cross(n, tx);

      float sumObs = 0.0;
      for (int i = 0; i < 32; i++) {
        if (i >= nSamp) break;
        float alpha = (float(i) + 0.5) / float(nSamp);
        float ang = alpha * 7.0 * 6.2831853 + spin;
        vec2 disk = vec2(cos(ang), sin(ang)) * (alpha * rad);
        // Reconstruct nearby surface sample point via short projection onto SDF
        vec3 probe = p + tx * disk.x + ty * disk.y + n * (0.35 * rad * alpha);
        float dist = mapScene(probe);
        vec3 q = probe - n * dist;
        vec3 v = q - p;
        float vv = dot(v, v);
        float vn = dot(v, n);
        float f = max(rad * rad - vv, 0.0) / (rad * rad);
        sumObs += f * f * max(0.0, vn - bias * t) / (vv + eps);
      }
      float rawA = max(0.0, 1.0 - (2.0 * max(AO_INTENSITY, 0.0) / float(nSamp)) * sumObs * 0.24);
      ao = pow(clamp(rawA, 0.0, 1.0), 1.35);
    }
    col = direct * mix(0.18, 1.0, ao) * (uv.x > splitX ? mix(vec3(0.86, 0.90, 0.98), vec3(1.0), ao) : vec3(1.0));
  }
  if (abs(uv.x - splitX) < 0.0025) col = vec3(1.0, 0.85, 0.35);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index

## Lineage

- extends [Screen-Space Ambient Occlusion](https://texelatlas.vercel.app/t/ssao.md)

## Combines with

- [Multi-Bounce Ambient Occlusion Approximation](https://texelatlas.vercel.app/t/multi-bounce-ambient-occlusion.md): The obscurance value is brightened per albedo by the multi-bounce fit to avoid overly dark light-coloured surfaces.
- [Temporal Anti-Aliasing](https://texelatlas.vercel.app/t/temporal-anti-aliasing.md): Per-pixel rotated samples are noisy; TAA integrates them over frames in place of a wide blur.

## Sources

1. [primary] Morgan McGuire, Brian Osman, Michael Bukowski, Padraic Hennessy (2011) The alchemy screen-space ambient obscurance algorithm. Proceedings of the ACM SIGGRAPH Symposium on High Performance Graphics. https://doi.org/10.1145/2018323.2018327 (verified via crossref on 2026-11-29)
2. [implementation] N8python (2023) N8python/n8ao. https://github.com/N8python/n8ao License: CC0-1.0. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Alchemy screen-space ambient obscurance." https://texelatlas.vercel.app/t/alchemy-ambient-obscurance/ (accessed 2026-12-01).
