Alchemy screen-space ambient obscurance
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.
Also known as Alchemy AO, AlchemyAO, SAO precursor
In the family Visibility, shadows & ambient occlusion, screen-space AO
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | Built-in SSAO implements Intel ASSAO (ssao.glsl), not Alchemy AO. |
| Unity | Built in | URP Renderer > Add Renderer Feature > Screen Space Ambient Occlusion (implements McGuire 2011 Alchemy AO in SSAO.hlsl) docs URP SSAO uses Alchemy ambient obscurance; HDRP uses GTAO. |
| Unreal 5.7 | None found | Different AO implementation. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 or Horizon-Based Ambient Occlusion for more accurate horizon-based occlusion at slightly higher cost, N8AO for a ready three.js implementation, Ray-Traced Ambient Occlusion or SDF Ambient Occlusion when you can afford exactness, and Multi-Bounce Ambient Occlusion Approximation as a cheap albedo-dependent brightening on top.
Field marks
- 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
Presets
Left: direct lighting only. Right: Alchemy Ambient Obscurance (McGuire 2011) crevice darkening
{
"AO_RADIUS": 0.48,
"AO_INTENSITY": 2.4,
"AO_BIAS": 0.025,
"SAMPLES": 16
}Show GLSL (117 lines)
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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| alchemy-ambient-obscurance-live | Tesla T4 1920x1080 | 43.6× baseline (heavy) · 1.44 ms / 1.45 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| alchemy-ambient-obscurance-live | NVIDIA L4 1920x1080 | 43.1× baseline (heavy) · 0.685 ms / 0.698 ms · 2.1× faster on L4 | opengl-timer-query · Cross-architecture validation |
| alchemy-ambient-obscurance-live | NVIDIA A100-SXM4-40GB 1920x1080 | 28.1× baseline (heavy) · 0.809 ms / 0.818 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Cook-Torrance microfacet BRDF, Light Propagation Volumes, Screen-Space Global Illumination; cited by Visibility Bitmask Ambient Occlusion.
Crosses
- Multi-Bounce Ambient Occlusion Approximation: The obscurance value is brightened per albedo by the multi-bounce fit to avoid overly dark light-coloured surfaces.
- Temporal Anti-Aliasing: Per-pixel rotated samples are noisy; TAA integrates them over frames in place of a wide blur.
Sources
- primaryMorgan 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.Verified via crossref · 2026-11-29doi:10.1145/2018323.2018327
- implementationN8python (2023). N8python/n8ao. An efficient and visually pleasing implementation of SSAO with an emphasis on temporal stability and artist control.GitHub API · license CC0-1.0 · 2026-11-29