{
 "id": "ground-truth-specular-occlusion",
 "title": "Ground-Truth Specular Occlusion",
 "aliases": [],
 "domain": "visibility",
 "subdomain": "AO post-correction",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2016,
 "inputs": [
  "normals",
  "depth"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Converts the AO visibility cone and the specular lobe into an intersection so reflections are darkened only where the lobe actually faces occluders.",
 "how_it_works": "Specular lighting from probes or environment maps ignores local geometry, so reflections leak into crevices. The method models the unoccluded region as a cone around the bent normal with aperture from the AO value, and the specular lobe as a cone around the reflection vector with width from roughness. It then evaluates the solid-angle overlap of the two cones analytically, and fits the result with a compact function of AO, roughness and the angle between the cones. Multiply the result into specular ambient lighting. It needs the bent normal and AO from the same pass and a few ALU instructions.",
 "when_to_use": "Choose it for image-based specular lighting with screen-space AO when reflections leak into occluded areas. Prefer a real traced term (`ray-traced-ambient-occlusion` or reflection tracing) when accuracy matters more than cost, and plain horizon occlusion (`bent-normals`) for a cruder fix.",
 "cost": {
  "class": "cheap",
  "notes": "A few ALU instructions per pixel plus bent normals from the AO pass."
 },
 "failure_modes": [
  "Depends on a correct bent normal and AO input",
  "Approximate for rough lobes where the cone model is poor",
  "Cannot darken reflections of off-screen blockers",
  "May dim reflections excessively in narrow concavities"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf",
   "type": "web",
   "title": "Practical Real-Time Strategies for Accurate Indirect Occlusion",
   "authors": [
    "Jorge Jimenez",
    "Xian-Chun Wu",
    "Angelo Pesce",
    "Adrian Jarabo"
   ],
   "year": null,
   "venue": "SIGGRAPH 2016 Course: Physically Based Shading in Theory and Practice",
   "url": "https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20251130092941/https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf",
     "timestamp": "20251130092941"
    },
    "page_title": null,
    "host": "activision.com",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "jimenezpractical"
  }
 ],
 "presets": [
  {
   "id": "ground-truth-specular-occlusion-live",
   "title": "Ground-truth specular occlusion — cone-cone visibility vs naive scalar AO split",
   "runtime": "glsl-fragment",
   "params": {
    "P_ROUGHNESS": 0.24,
    "P_AO_STRENGTH": 1,
    "P_METALLIC": 0.85,
    "P_SPLIT": 0.45
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_ROUGHNESS = 0.24; // P Roughness [0.06, 0.75, 0.02]\nconst float P_AO_STRENGTH = 1.0; // P AO Strength [0.0, 1.5, 0.05]\nconst float P_METALLIC = 0.85; // P Metallic [0.0, 1.0, 0.02]\nconst float P_SPLIT = 0.45; // P Naive/GTSO 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 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// Glossy nested metallic rings & recessed sphere over a reflective tiled floor (crevice torture test)\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.78, 1.0);\n\n  vec3 q = p - vec3(0.0, -0.04, 0.0);\n  q.xz = rot2(iTime * 0.28) * q.xz;\n  float dCore = length(q) - 0.56;\n  // Deep equatorial crevices & interlocking rings that create strong directional visibility cones\n  float dR1 = sdTorus(q, vec2(0.68, 0.16));\n  vec3 q2 = q;\n  q2.xy = rot2(1.05) * q2.xy;\n  float dR2 = sdTorus(q2, vec2(0.68, 0.15));\n  float dSculpt = min(dCore, min(dR1, dR2));\n  if (dSculpt < res.x) res = vec2(dSculpt, 2.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// High-contrast studio HDR environment with overhead softbox strips & horizon band\nvec3 sampleEnv(vec3 d, float rough) {\n  float y = d.y;\n  vec3 sky = mix(vec3(0.10, 0.12, 0.17), vec3(0.36, 0.46, 0.62), smoothstep(-0.1, 0.75, y));\n  // Crisp softbox light strips that visibly reflect across glossy curves\n  float strip1 = smoothstep(0.62 - rough * 0.25, 0.92, dot(d, normalize(vec3(0.55, 0.78, 0.35))));\n  float strip2 = smoothstep(0.68 - rough * 0.25, 0.95, dot(d, normalize(vec3(-0.72, 0.52, 0.42))));\n  float horiz = exp(-abs(y - 0.04) * mix(16.0, 3.0, rough));\n  sky += vec3(3.2, 2.8, 2.3) * strip1;\n  sky += vec3(1.4, 2.1, 3.0) * strip2;\n  sky += vec3(0.85, 0.72, 0.58) * horiz * 0.65;\n  return sky;\n}\n\n// Analytic spherical cap intersection of bent-normal visibility cone & specular reflection lobe (GTSO)\nfloat sphericalCapIntersection(float f0, float f1, float d) {\n  float r0 = max(f0, 1e-4);\n  float r1 = max(f1, 1e-4);\n  if (d >= r0 + r1) return 0.0;\n  if (d <= abs(r0 - r1)) return 6.2831853 * (1.0 - cos(min(r0, r1)));\n  float c0 = cos(r0), s0 = sin(r0);\n  float c1 = cos(r1), s1 = sin(r1);\n  float cd = cos(d), sd = sin(d);\n  float a0 = acos(clamp((c1 - c0 * cd) / (s0 * sd + 1e-5), -1.0, 1.0));\n  float a1 = acos(clamp((c0 - c1 * cd) / (s1 * sd + 1e-5), -1.0, 1.0));\n  float a2 = acos(clamp((cd - c0 * c1) / (s0 * s1 + 1e-5), -1.0, 1.0));\n  return max(0.0, 2.0 * (3.14159265 - a2 - a0 * c0 - a1 * c1));\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.45, 2.65);\n  vec3 ta = vec3(0.0, -0.14, 0.0);\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.55 * ww);\n\n  float rough = clamp(P_ROUGHNESS, 0.05, 0.85);\n  float aoStr = clamp(P_AO_STRENGTH, 0.0, 1.6);\n  float metal = clamp(P_METALLIC, 0.0, 1.0);\n  float splitX = clamp(P_SPLIT, 0.0, 1.0);\n\n  vec3 col = sampleEnv(rd, 0.45) * 0.25;\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    vec3 v = -rd;\n    vec3 rDir = reflect(rd, n);\n\n    // Estimate diffuse visibility AO & bent normal over 6 hemispherical directions\n    vec3 tV = 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 bV = cross(n, tV);\n    float visSum = 0.0;\n    vec3 bentAccum = vec3(0.0);\n    for (int k = 0; k < 6; k++) {\n      float phi = float(k) * 1.0472 + 0.35;\n      vec3 d = normalize(n * 0.58 + (cos(phi) * tV + sin(phi) * bV) * 0.815);\n      float s1 = mapScene(p + d * 0.14).x / 0.14;\n      float s2 = mapScene(p + d * 0.34).x / 0.34;\n      float vis = clamp(min(s1, s2), 0.0, 1.0);\n      visSum += vis;\n      bentAccum += d * (vis + 0.03);\n    }\n    float diffAO = clamp(1.0 - (1.0 - visSum / 6.0) * aoStr, 0.02, 1.0);\n    vec3 bentN = normalize(bentAccum + n * 0.05);\n\n    // Also evaluate direct cone visibility along reflection vector for ground-truth specular occlusion\n    float reflTrace = clamp(min(mapScene(p + rDir * 0.18).x / 0.18, mapScene(p + rDir * 0.45).x / 0.45), 0.0, 1.0);\n\n    // Cone-cone intersection GTSO (Jimenez / Oat & Sander):\n    // Visibility cone half-angle from diffuse AO; specular cone half-angle from roughness\n    float visAngle = acos(clamp(1.0 - diffAO, -1.0, 1.0));\n    float specAngle = clamp(rough * 1.15 + 0.08, 0.08, 1.25);\n    float coneSep = acos(clamp(dot(bentN, rDir), -1.0, 1.0));\n    float specCap = 6.2831853 * (1.0 - cos(specAngle));\n    float coneOverlap = sphericalCapIntersection(visAngle, specAngle, coneSep) / max(specCap, 1e-4);\n    float gtso = clamp(mix(coneOverlap, coneOverlap * reflTrace, 0.55), 0.0, 1.0);\n    gtso = mix(1.0, gtso, clamp(aoStr, 0.0, 1.0));\n\n    // Left: naive scalar AO * specular; Right: Ground-Truth Specular Occlusion\n    float specOcc = (screenUV.x < splitX) ? diffAO : gtso;\n\n    vec3 baseCol = (matId < 1.5) ? vec3(0.42, 0.45, 0.50) : vec3(0.92, 0.74, 0.46);\n    float ndv = max(dot(n, v), 0.001);\n    vec3 f0 = mix(vec3(0.04), baseCol, metal);\n    vec3 fres = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0);\n\n    vec3 envDiff = sampleEnv(bentN, 0.95) * (1.0 - metal) * baseCol * diffAO * 0.55;\n    vec3 envSpec = sampleEnv(rDir, rough) * fres * specOcc * 1.15;\n\n    // Subtle key light highlight\n    vec3 lDir = normalize(vec3(0.55, 0.82, 0.45));\n    vec3 hVec = normalize(lDir + v);\n    float specL = pow(max(dot(n, hVec), 0.0), mix(96.0, 10.0, rough)) * specOcc;\n    col = envDiff + envSpec + fres * vec3(1.8, 1.65, 1.45) * specL * 0.5;\n  }\n\n  if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {\n    col = vec3(1.0, 0.82, 0.35);\n  }\n\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": "ground-truth-specular-occlusion",
     "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.4657,
      "std": 0.2423,
      "unique_colors": 473
     },
     "image": "/specimens/ground-truth-specular-occlusion-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ground-truth-ambient-occlusion",
  "bent-normals",
  "multi-bounce-ambient-occlusion"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "bent-normals",
   "why": "Bent normal supplies the cone axis that the specular lobe is intersected against."
  }
 ],
 "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/ground-truth-specular-occlusion.json"
 },
 "solves": [
  "reflections glow inside crevices where they should be dark",
  "specular light leaks through occluded areas",
  "screen-space occlusion darkens spec wrongly or not at all",
  "need cheap reflection occlusion for probe lighting"
 ],
 "authority": "Jimenez et al.",
 "url": "https://texelatlas.vercel.app/t/ground-truth-specular-occlusion/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 31.25,
  "tier": "heavy",
  "p50_ms": 1.028,
  "p95_ms": 1.088,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "ground-truth-specular-occlusion-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 26.88,
   "tier": "heavy",
   "p50_ms": 0.4274,
   "p95_ms": 0.4372,
   "speedup_x": 2.41,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 19.71,
   "tier": "moderate",
   "p50_ms": 0.5676,
   "p95_ms": 0.5713,
   "speedup_x": 1.81,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}