{
 "id": "alchemy-ambient-obscurance",
 "title": "Alchemy screen-space ambient obscurance",
 "aliases": [
  "Alchemy AO",
  "AlchemyAO",
  "SAO precursor"
 ],
 "domain": "visibility",
 "subdomain": "screen-space AO",
 "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",
 "summary": "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.",
 "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": "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 `hbao` 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` as a cheap albedo-dependent brightening on top.",
 "cost": {
  "class": "cheap",
  "notes": "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."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2018323.2018327",
   "type": "paper",
   "title": "The alchemy screen-space ambient obscurance algorithm",
   "authors": [
    "Morgan McGuire",
    "Brian Osman",
    "Michael Bukowski",
    "Padraic Hennessy"
   ],
   "year": 2011,
   "venue": "Proceedings of the ACM SIGGRAPH Symposium on High Performance Graphics",
   "url": "https://doi.org/10.1145/2018323.2018327",
   "ids": {
    "doi": "10.1145/2018323.2018327"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2018323.2018327",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2018323.2018327",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2018323.2018327",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2018323.2018327",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2018323.2018327",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mcguire2011alchemy"
  },
  {
   "role": "implementation",
   "key": "gh:n8python/n8ao",
   "type": "code",
   "title": "N8python/n8ao",
   "description": "An efficient and visually pleasing implementation of SSAO with an emphasis on temporal stability and artist control.",
   "authors": [
    "N8python"
   ],
   "year": 2023,
   "venue": "GitHub",
   "url": "https://github.com/N8python/n8ao",
   "ids": {
    "repo": "N8python/n8ao"
   },
   "license": "CC0-1.0",
   "extra": {
    "stars": 528,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-15T20:46:16Z",
    "language": "JavaScript",
    "homepage": null,
    "license_name": "Creative Commons Zero v1.0 Universal"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/N8python/n8ao",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "npython2023n8python"
  }
 ],
 "presets": [
  {
   "id": "alchemy-ambient-obscurance-live",
   "title": "Left: direct lighting only. Right: Alchemy Ambient Obscurance (McGuire 2011) crevice darkening",
   "runtime": "glsl-fragment",
   "params": {
    "AO_RADIUS": 0.48,
    "AO_INTENSITY": 2.4,
    "AO_BIAS": 0.025,
    "SAMPLES": 16
   },
   "basis": "original",
   "license_note": "MIT — written for this index",
   "code": "const float AO_RADIUS = 0.48; // P\nconst float AO_INTENSITY = 2.4; // P\nconst float AO_BIAS = 0.025; // P\nconst int SAMPLES = 16; // P\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// Sculpted geometric niche with deep concave corners, flutes and nested forms\nfloat mapScene(vec3 p) {\n  float floorD = p.y + 0.9;\n  float backWall = p.z + 1.45;\n  // Recessed stepped frame\n  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)));\n  // Rotated central sculpture (interlocking torus + sphere + ribbed pedestal)\n  vec3 q = p - vec3(0.0, -0.1, -0.15);\n  float a = iTime * 0.35;\n  mat2 r = mat2(cos(a), -sin(a), sin(a), cos(a));\n  q.xz = r * q.xz;\n  float ped = sdBox(p - vec3(0.0, -0.72, -0.15), vec3(0.58, 0.18, 0.58));\n  float sp = length(q - vec3(0.0, 0.12, 0.0)) - 0.38;\n  float tor = sdTorus(q.xzy - vec3(0.0, 0.0, 0.12), vec2(0.52, 0.14));\n  float cols = sdBox(vec3(abs(p.x) - 0.92, p.y + 0.05, p.z + 0.72), vec3(0.18, 0.95, 0.18));\n  float flute = sin(p.y * 28.0) * 0.012;\n  float d = min(floorD, min(backWall, frame));\n  d = min(d, min(ped, min(sp, min(tor, cols + flute))));\n  return d;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy) - mapScene(p - e.xyy),\n    mapScene(p + e.yxy) - mapScene(p - e.yxy),\n    mapScene(p + e.yyx) - mapScene(p - e.yyx)\n  ));\n}\n\nfloat raymarch(vec3 ro, vec3 rd, float tMax) {\n  float t = 0.05;\n  for (int i = 0; i < 60; i++) {\n    float d = mapScene(ro + rd * t);\n    if (d < 0.0025) return t;\n    t += d;\n    if (t > tMax) break;\n  }\n  return -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  float splitX = 0.0;\n  if (iMouse.z > 0.5 || length(iMouse.xy) > 1.0) {\n    splitX = (iMouse.x - 0.5 * iResolution.xy.x) / iResolution.y;\n  }\n\n  vec3 ro = vec3(0.0, 0.25, 2.35);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.06, -1.45));\n  float t = raymarch(ro, rd, 10.0);\n  vec3 col = vec3(0.12, 0.14, 0.18);\n\n  if (t > 0.0) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n    vec3 lDir = normalize(vec3(0.55, 0.78, 0.45));\n    float nl = max(dot(n, lDir), 0.0);\n    vec3 alb = vec3(0.84, 0.82, 0.79);\n    vec3 direct = alb * (0.28 + 0.85 * nl);\n\n    // McGuire 2011 Alchemy Ambient Obscurance estimator on spiral tangent-disk samples\n    float ao = 1.0;\n    if (uv.x > splitX) {\n      int nSamp = clamp(SAMPLES, 4, 32);\n      float rad = max(AO_RADIUS, 0.02);\n      float bias = max(AO_BIAS, 0.0);\n      float eps = 0.015;\n      float spin = fract(sin(dot(fragCoord, vec2(12.9898, 78.233))) * 43758.5453) * 6.2831853;\n      vec3 up = abs(n.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);\n      vec3 tx = normalize(cross(up, n));\n      vec3 ty = cross(n, tx);\n\n      float sumObs = 0.0;\n      for (int i = 0; i < 32; i++) {\n        if (i >= nSamp) break;\n        float alpha = (float(i) + 0.5) / float(nSamp);\n        float ang = alpha * 7.0 * 6.2831853 + spin;\n        vec2 disk = vec2(cos(ang), sin(ang)) * (alpha * rad);\n        // Reconstruct nearby surface sample point via short projection onto SDF\n        vec3 probe = p + tx * disk.x + ty * disk.y + n * (0.35 * rad * alpha);\n        float dist = mapScene(probe);\n        vec3 q = probe - n * dist;\n        vec3 v = q - p;\n        float vv = dot(v, v);\n        float vn = dot(v, n);\n        float f = max(rad * rad - vv, 0.0) / (rad * rad);\n        sumObs += f * f * max(0.0, vn - bias * t) / (vv + eps);\n      }\n      float rawA = max(0.0, 1.0 - (2.0 * max(AO_INTENSITY, 0.0) / float(nSamp)) * sumObs * 0.24);\n      ao = pow(clamp(rawA, 0.0, 1.0), 1.35);\n    }\n    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));\n  }\n  if (abs(uv.x - splitX) < 0.0025) col = vec3(1.0, 0.85, 0.35);\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": "alchemy-ambient-obscurance",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:15:34.232Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7701,
      "std": 0.0917,
      "unique_colors": 38
     },
     "image": "/specimens/alchemy-ambient-obscurance-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ssao",
  "hbao",
  "ground-truth-ambient-occlusion",
  "n8ao",
  "multi-bounce-ambient-occlusion",
  "visibility-bitmask-ssao",
  "sdf-ambient-occlusion",
  "ray-traced-ambient-occlusion"
 ],
 "extends": [
  "ssao"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "multi-bounce-ambient-occlusion",
   "why": "The obscurance value is brightened per albedo by the multi-bounce fit to avoid overly dark light-coloured surfaces."
  },
  {
   "id": "temporal-anti-aliasing",
   "why": "Per-pixel rotated samples are noisy; TAA integrates them over frames in place of a wide blur."
  }
 ],
 "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/alchemy-ambient-obscurance.json"
 },
 "solves": [
  "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"
 ],
 "authority": "McGuire et al., 2011",
 "url": "https://texelatlas.vercel.app/t/alchemy-ambient-obscurance/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 43.63,
  "tier": "heavy",
  "p50_ms": 1.4353,
  "p95_ms": 1.4535,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "alchemy-ambient-obscurance-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 43.1,
   "tier": "heavy",
   "p50_ms": 0.6853,
   "p95_ms": 0.6981,
   "speedup_x": 2.09,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 28.1,
   "tier": "heavy",
   "p50_ms": 0.8092,
   "p95_ms": 0.8184,
   "speedup_x": 1.77,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}