N8AO
A three.js post-processing screen-space AO pass (SSAO/HBAO-style) with half-resolution rendering, depth-aware denoising and colour-aware options.
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 | Plugin | npm i n8ao docs |
| Babylon.js 9.38.0 | Not applicable | three.js-specific post-processing library; not applicable to Babylon.js. |
| Godot 4.7 | Not applicable | three.js-specific post-processing library; not applicable to Godot. |
| Unity | Not applicable | N8AO is a three.js library, not usable in Unity. |
| Unreal 5.7 | Not applicable | three.js-specific post-processing AO library; not applicable to Unreal Engine. |
| Blender 5.2 | Not applicable | three.js library; not applicable to Blender. |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
N8AO is a drop-in three.js EffectComposer pass that reconstructs positions from depth, samples a spiral of points around each pixel in a normal-oriented hemisphere with a configurable radius, and compares them against the depth buffer to estimate occlusion. A depth-aware blur removes noise, optional half-resolution rendering with upsampling saves time, and distance-falloff and intensity controls shape the look. It can also tint occlusion by colour. As a plugin it avoids writing a custom pipeline, and its settings expose quality presets from low to ultra.
When to choose it
Reach for it when
- need good ambient occlusion in three.js with little setup
- scene looks flat without contact darkening
- ao pass shows noise or halos at edges
- post-process occlusion for web 3d without a g-buffer
- creases and corners lack shading depth
Choose it when you want good screen-space AO in three.js quickly, without wiring a G-buffer yourself. Prefer Ground-Truth Ambient Occlusion via three's GTAOPass for a more physically formulated option, SDF Ambient Occlusion for baked static scenes, and Screen-Space Ambient Occlusion for the simplest built-in pass.
Field marks
- Screen-space limits: no off-screen occluders
- Halos or banding at large radii
- Depth-aware blur can leak across edges
- Transparent objects are not part of the depth buffer
Presets
N8AO — unoccluded flat lighting (left) vs spiral-hemisphere depth-aware denoised AO + color bleed (right)
{
"P_AO_RADIUS": 0.65,
"P_AO_INTENSITY": 1.35,
"P_COLOR_BLEED": 0.45,
"P_SPLIT": 0.48
}Show GLSL (139 lines)
const float P_AO_RADIUS = 0.65; // P Hemisphere Radius [0.2, 1.4, 0.05]
const float P_AO_INTENSITY = 1.35; // P AO Intensity [0.3, 2.5, 0.05]
const float P_COLOR_BLEED = 0.45; // P Color Bleed [0.0, 1.0, 0.05]
const float P_SPLIT = 0.48; // P No AO / N8AO [0.0, 1.0, 0.02]
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);
}
// Stepped architectural niches & nested spheres full of tight creases where N8AO shines
vec2 mapN8Scene(vec3 p) {
float dFloor = p.y + 0.56;
vec2 res = vec2(dFloor, 1.0);
// Back stepped terracotta wall with recessed alcoves
float dWall = sdBox(p - vec3(0.0, 0.15, -0.88), vec3(1.5, 0.85, 0.18));
float niche1 = sdBox(p - vec3(-0.48, -0.04, -0.72), vec3(0.26, 0.36, 0.16));
float niche2 = sdBox(p - vec3(0.48, -0.04, -0.72), vec3(0.26, 0.36, 0.16));
dWall = max(dWall, -min(niche1, niche2));
if (dWall < res.x) res = vec2(dWall, 2.0);
// Stepped stair plinths
float s1 = sdBox(p - vec3(0.0, -0.46, -0.35), vec3(0.95, 0.10, 0.45));
float s2 = sdBox(p - vec3(0.0, -0.34, -0.48), vec3(0.68, 0.10, 0.30));
float dStair = min(s1, s2);
if (dStair < res.x) res = vec2(dStair, 3.0);
// Clustered spheres seated tightly into stair corners (strong contact AO!)
float c1 = length(p - vec3(0.0, -0.02, -0.42)) - 0.24;
float c2 = length(p - vec3(-0.34, -0.18, -0.18)) - 0.18;
float c3 = length(p - vec3(0.36, -0.20, -0.14)) - 0.16;
float c4 = length(p - vec3(-0.48, -0.22, -0.68)) - 0.16;
float c5 = length(p - vec3(0.48, -0.22, -0.68)) - 0.16;
float dSph = min(min(c1, c2), min(c3, min(c4, c5)));
if (dSph < res.x) res = vec2(dSph, 4.0);
return res;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, 0.0);
return normalize(vec3(
mapN8Scene(p + e.xyy).x - mapN8Scene(p - e.xyy).x,
mapN8Scene(p + e.yxy).x - mapN8Scene(p - e.yxy).x,
mapN8Scene(p + e.yyx).x - mapN8Scene(p - e.yyx).x
));
}
vec3 matAlbedo(float id) {
if (id < 1.5) return vec3(0.76, 0.74, 0.70);
if (id < 2.5) return vec3(0.86, 0.46, 0.30);
if (id < 3.5) return vec3(0.84, 0.82, 0.78);
return vec3(0.92, 0.88, 0.82);
}
// N8AO spiral-hemisphere sampling with distance falloff & optional color bleed
void evalN8AO(vec3 p, vec3 n, float rad, float intensity, out float ao, out vec3 bleed) {
vec3 up = (abs(n.y) < 0.99) ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
vec3 t = normalize(cross(up, n));
vec3 b = cross(n, t);
float occ = 0.0;
bleed = vec3(0.0);
float wBleed = 0.0;
// 12 golden-angle spiral hemisphere taps
for (int i = 0; i < 12; i++) {
float fi = float(i);
float rFrac = (fi + 0.5) / 12.0;
float ang = fi * 2.3999632;
float z = 0.22 + 0.75 * rFrac;
float xy = sqrt(max(1.0 - z * z, 0.0));
vec3 dir = normalize(t * (cos(ang) * xy) + b * (sin(ang) * xy) + n * z);
float stepD = rad * (0.14 + 0.86 * rFrac * rFrac);
vec2 h = mapN8Scene(p + dir * stepD);
float delta = max(stepD - h.x, 0.0);
float falloff = 1.0 - smoothstep(0.0, rad * 1.1, stepD);
float tapOcc = clamp(delta / max(stepD, 0.04), 0.0, 1.0) * falloff;
occ += tapOcc;
if (tapOcc > 0.05) {
bleed += matAlbedo(h.y) * tapOcc;
wBleed += tapOcc;
}
}
ao = clamp(1.0 - (occ / 12.0) * intensity * 1.65, 0.06, 1.0);
bleed = (wBleed > 0.01) ? (bleed / wBleed) : vec3(0.6);
}
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 screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
float rad = clamp(P_AO_RADIUS, 0.15, 1.5) * 0.42;
float inten = clamp(P_AO_INTENSITY, 0.2, 2.8);
float bleedAmt = clamp(P_COLOR_BLEED, 0.0, 1.0);
vec3 ro = vec3(0.32 * sin(iTime * 0.45), 0.18, 1.92);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.07, -1.45));
vec3 col = mix(vec3(0.14, 0.19, 0.28), vec3(0.45, 0.58, 0.78), smoothstep(-0.2, 0.6, rd.y));
float dist = 0.05;
vec2 hit = vec2(10.0, 0.0);
for (int i = 0; i < 64; i++) {
vec2 h = mapN8Scene(ro + rd * dist);
if (h.x < 0.002) { hit = vec2(dist, h.y); break; }
dist += h.x;
if (dist > 8.0) break;
}
if (hit.y > 0.5) {
vec3 p = ro + rd * hit.x;
vec3 n = calcNormal(p);
vec3 lDir = normalize(vec3(0.45, 0.82, 0.55));
vec3 alb = matAlbedo(hit.y);
float ndl = max(dot(n, lDir), 0.0);
vec3 direct = alb * vec3(0.95, 0.90, 0.82) * ndl * 0.65;
vec3 hemiAmb = alb * mix(vec3(0.32, 0.36, 0.44), vec3(0.68, 0.78, 0.92), 0.5 + 0.5 * n.y) * 0.72;
if (screenX < split) {
// Left: Flat ambient without N8AO (objects appear floating without crease grounding)
col = direct + hemiAmb;
} else {
// Right: N8AO spiral hemisphere AO + subtle color bleed inside corners and niches
float ao;
vec3 bleed;
evalN8AO(p + n * 0.006, n, rad, inten, ao, bleed);
vec3 aoTint = mix(vec3(ao), mix(bleed * 0.55, vec3(1.0), ao), bleedAmt * 0.65);
col = direct * mix(1.0, ao, 0.45) + hemiAmb * aoTint;
}
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.98, 1.0), sep);
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 |
|---|---|---|---|
| n8ao-live | Tesla T4 1920x1080 | 44.2× baseline (heavy) · 1.45 ms / 1.55 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| n8ao-live | NVIDIA L4 1920x1080 | 45.2× baseline (heavy) · 0.718 ms / 0.721 ms · 2.0× faster on L4 | opengl-timer-query · Cross-architecture validation |
| n8ao-live | NVIDIA A100-SXM4-40GB 1920x1080 | 30.2× baseline (heavy) · 0.870 ms / 0.882 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Sources
- primaryN8python (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