Ground-Truth Specular Occlusion
Converts the AO visibility cone and the specular lobe into an intersection so reflections are darkened only where the lobe actually faces occluders.
In the family Visibility, shadows & ambient occlusion, AO post-correction
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | Built in | PBRBaseMaterial bent-normal Spherical Gaussian specular occlusion (environmentBentNormalOcclusion / bentNormalSGOcclusion) and useRadianceOcclusion docs |
| Godot 4.7 | Built in | BaseMaterial3D.bent_normal_enabled = true (applies Jimenez et al. SIGGRAPH 2016 specular cone-cone intersection in scene_forward_clustered.glsl) docs |
| Unity | None found | HDRP derives specular occlusion from AO or bent normals with a cone-cone approximation. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
Reach for it when
- 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
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.
Field marks
- 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
Presets
Ground-truth specular occlusion — cone-cone visibility vs naive scalar AO split
{
"P_ROUGHNESS": 0.24,
"P_AO_STRENGTH": 1,
"P_METALLIC": 0.85,
"P_SPLIT": 0.45
}Show GLSL (161 lines)
const float P_ROUGHNESS = 0.24; // P Roughness [0.06, 0.75, 0.02]
const float P_AO_STRENGTH = 1.0; // P AO Strength [0.0, 1.5, 0.05]
const float P_METALLIC = 0.85; // P Metallic [0.0, 1.0, 0.02]
const float P_SPLIT = 0.45; // P Naive/GTSO 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 sdTorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}
// Glossy nested metallic rings & recessed sphere over a reflective tiled floor (crevice torture test)
vec2 mapScene(vec3 p) {
vec2 res = vec2(p.y + 0.78, 1.0);
vec3 q = p - vec3(0.0, -0.04, 0.0);
q.xz = rot2(iTime * 0.28) * q.xz;
float dCore = length(q) - 0.56;
// Deep equatorial crevices & interlocking rings that create strong directional visibility cones
float dR1 = sdTorus(q, vec2(0.68, 0.16));
vec3 q2 = q;
q2.xy = rot2(1.05) * q2.xy;
float dR2 = sdTorus(q2, vec2(0.68, 0.15));
float dSculpt = min(dCore, min(dR1, dR2));
if (dSculpt < res.x) res = vec2(dSculpt, 2.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
));
}
// High-contrast studio HDR environment with overhead softbox strips & horizon band
vec3 sampleEnv(vec3 d, float rough) {
float y = d.y;
vec3 sky = mix(vec3(0.10, 0.12, 0.17), vec3(0.36, 0.46, 0.62), smoothstep(-0.1, 0.75, y));
// Crisp softbox light strips that visibly reflect across glossy curves
float strip1 = smoothstep(0.62 - rough * 0.25, 0.92, dot(d, normalize(vec3(0.55, 0.78, 0.35))));
float strip2 = smoothstep(0.68 - rough * 0.25, 0.95, dot(d, normalize(vec3(-0.72, 0.52, 0.42))));
float horiz = exp(-abs(y - 0.04) * mix(16.0, 3.0, rough));
sky += vec3(3.2, 2.8, 2.3) * strip1;
sky += vec3(1.4, 2.1, 3.0) * strip2;
sky += vec3(0.85, 0.72, 0.58) * horiz * 0.65;
return sky;
}
// Analytic spherical cap intersection of bent-normal visibility cone & specular reflection lobe (GTSO)
float sphericalCapIntersection(float f0, float f1, float d) {
float r0 = max(f0, 1e-4);
float r1 = max(f1, 1e-4);
if (d >= r0 + r1) return 0.0;
if (d <= abs(r0 - r1)) return 6.2831853 * (1.0 - cos(min(r0, r1)));
float c0 = cos(r0), s0 = sin(r0);
float c1 = cos(r1), s1 = sin(r1);
float cd = cos(d), sd = sin(d);
float a0 = acos(clamp((c1 - c0 * cd) / (s0 * sd + 1e-5), -1.0, 1.0));
float a1 = acos(clamp((c0 - c1 * cd) / (s1 * sd + 1e-5), -1.0, 1.0));
float a2 = acos(clamp((cd - c0 * c1) / (s0 * s1 + 1e-5), -1.0, 1.0));
return max(0.0, 2.0 * (3.14159265 - a2 - a0 * c0 - a1 * c1));
}
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.45, 2.65);
vec3 ta = vec3(0.0, -0.14, 0.0);
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.55 * ww);
float rough = clamp(P_ROUGHNESS, 0.05, 0.85);
float aoStr = clamp(P_AO_STRENGTH, 0.0, 1.6);
float metal = clamp(P_METALLIC, 0.0, 1.0);
float splitX = clamp(P_SPLIT, 0.0, 1.0);
vec3 col = sampleEnv(rd, 0.45) * 0.25;
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);
vec3 v = -rd;
vec3 rDir = reflect(rd, n);
// Estimate diffuse visibility AO & bent normal over 6 hemispherical directions
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)));
vec3 bV = cross(n, tV);
float visSum = 0.0;
vec3 bentAccum = vec3(0.0);
for (int k = 0; k < 6; k++) {
float phi = float(k) * 1.0472 + 0.35;
vec3 d = normalize(n * 0.58 + (cos(phi) * tV + sin(phi) * bV) * 0.815);
float s1 = mapScene(p + d * 0.14).x / 0.14;
float s2 = mapScene(p + d * 0.34).x / 0.34;
float vis = clamp(min(s1, s2), 0.0, 1.0);
visSum += vis;
bentAccum += d * (vis + 0.03);
}
float diffAO = clamp(1.0 - (1.0 - visSum / 6.0) * aoStr, 0.02, 1.0);
vec3 bentN = normalize(bentAccum + n * 0.05);
// Also evaluate direct cone visibility along reflection vector for ground-truth specular occlusion
float reflTrace = clamp(min(mapScene(p + rDir * 0.18).x / 0.18, mapScene(p + rDir * 0.45).x / 0.45), 0.0, 1.0);
// Cone-cone intersection GTSO (Jimenez / Oat & Sander):
// Visibility cone half-angle from diffuse AO; specular cone half-angle from roughness
float visAngle = acos(clamp(1.0 - diffAO, -1.0, 1.0));
float specAngle = clamp(rough * 1.15 + 0.08, 0.08, 1.25);
float coneSep = acos(clamp(dot(bentN, rDir), -1.0, 1.0));
float specCap = 6.2831853 * (1.0 - cos(specAngle));
float coneOverlap = sphericalCapIntersection(visAngle, specAngle, coneSep) / max(specCap, 1e-4);
float gtso = clamp(mix(coneOverlap, coneOverlap * reflTrace, 0.55), 0.0, 1.0);
gtso = mix(1.0, gtso, clamp(aoStr, 0.0, 1.0));
// Left: naive scalar AO * specular; Right: Ground-Truth Specular Occlusion
float specOcc = (screenUV.x < splitX) ? diffAO : gtso;
vec3 baseCol = (matId < 1.5) ? vec3(0.42, 0.45, 0.50) : vec3(0.92, 0.74, 0.46);
float ndv = max(dot(n, v), 0.001);
vec3 f0 = mix(vec3(0.04), baseCol, metal);
vec3 fres = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0);
vec3 envDiff = sampleEnv(bentN, 0.95) * (1.0 - metal) * baseCol * diffAO * 0.55;
vec3 envSpec = sampleEnv(rDir, rough) * fres * specOcc * 1.15;
// Subtle key light highlight
vec3 lDir = normalize(vec3(0.55, 0.82, 0.45));
vec3 hVec = normalize(lDir + v);
float specL = pow(max(dot(n, hVec), 0.0), mix(96.0, 10.0, rough)) * specOcc;
col = envDiff + envSpec + fres * vec3(1.8, 1.65, 1.45) * specL * 0.5;
}
if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {
col = vec3(1.0, 0.82, 0.35);
}
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| ground-truth-specular-occlusion-live | Tesla T4 1920x1080 | 31.3× baseline (heavy) · 1.03 ms / 1.09 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| ground-truth-specular-occlusion-live | NVIDIA L4 1920x1080 | 26.9× baseline (heavy) · 0.427 ms / 0.437 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| ground-truth-specular-occlusion-live | NVIDIA A100-SXM4-40GB 1920x1080 | 19.7× baseline (moderate) · 0.568 ms / 0.571 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Bent Normals: Bent normal supplies the cone axis that the specular lobe is intersected against.
Sources
- primaryJorge Jimenez, Xian-Chun Wu, Angelo Pesce, Adrian Jarabo. Practical Real-Time Strategies for Accurate Indirect Occlusion. SIGGRAPH 2016 Course: Physically Based Shading in Theory and Practice.Verified via live page · 2026-11-29