Feature Library

Contact shading: ground-truth AO in raw WebGPU

4.83 GPU · 0.34 CPU ms
A still of the Contact shading: ground-truth AO in raw WebGPU demo
Still
The live demo starts when it’s in view.Drag the line to compare without and with · switch to the shading alone · drag the view to turn it

Screen-space ground-truth ambient occlusion as three compute dispatches over the frame’s reverse-Z depth and signed world normals.

Screen-space ground-truth ambient occlusion as three compute dispatches over the frame’s reverse-Z depth and signed world normals: a horizon search at half resolution, a nine-tap filter that compares each tap to the receiver’s plane and normal, and a depth- and normal-aware upsample. It writes visibility for the sky light to multiply, and optionally the bent normal (the open direction), with temporal accumulation by camera reprojection, perspective and orthographic views and 4× MSAA inputs. About 0.65 ms at 1080p on a laptop GPU at the high preset. No three.js, no dependencies.

What it costs a frame

4.83 ms
0.34 ms
GPU
4.83 ms
CPU, median
0.34 ms
CPU, 95th pct
0.61 ms
Draw calls
0
Weight
Heavy

Measured 25 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 3.74–5.21, CPU 0.29–0.37 ms). What ran: Alone: the engine’s contact test (a floor, two walls, a sphere, stacked boxes and five rods, about 13,000 triangles) drawn into depth, world normals and colour with 4× MSAA, the GTAO pass at the high preset (half-resolution search, 3 directions × 4 steps a side, temporal accumulation), and its visibility shown. GPU time for the whole frame. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.89 ms
1% low ?
55 fps
Varies by ?
±0.48 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.05 ms18.09 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.89 ms
p95 ?
17.82 ms
p99 ?
18.05 ms
Slowest ?
18.38 ms
Mean ?
16.92 ms
Standard deviation ?
0.48 ms
1% low ?
55 fps
0.1% low ?
54 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.0 / 0.4 / 0.7 ms

Input

No input during this run.

Memory

JavaScript heap ?
39.6 → 30.2 MB
Growth ?
-9.44 MB

Browser

JavaScript a frame ?
0.29 ms
All tasks a frame ?
0.69 ms
Layout / style ?
0.01 / 0.00 ms
Main thread busy ?
4%

Garbage collection

Collections ?
2 (1 minor, 1 major)
Pauses ?
4.5 ms in all, longest 1.8

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("gtao")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Making placed objects sit on the ground in a raw WebGPU game or world: the floor darkens under a bench, round a pot, at a column’s foot
  2. Corners, joints and creases between separately placed pieces that no baked or material occlusion can know about
  3. Sky light that comes from the open side (bent normals), so a corner takes only the sky it can see
  4. A graphics menu with a contact shading switch, its radius and intensity live, and three tiers
  5. A top-down or isometric view drawn orthographically, where contact shading still has to read

Pitfalls, in brief

  1. The demo needs WebGPU: the pass is three compute dispatches reading depth and normal textures and writing storage textures, which WebGL 2 cannot do.
  2. Depth must be reverse-Z (near 1, far 0, cleared to 0) through the scene pass, and group 0’s View camera-relative.
  3. Write signed unit world normals (rgba16float, cleared to 0) from the same pass, sample count and extent as the depth.
  4. The engine’s low preset turns the pass off (no dispatch).
  5. Temporal accumulation copies the view it was given out of group 0’s view buffer, so that buffer needs COPY_SRC (host.ts has it), and the frame index must rise by exactly one each frame.
8 more in brief
  1. Without motion vectors, history follows the camera only: a moving object over a similar surface at a similar depth can keep a faint trail.
  2. Encode once per camera per submit, and use one instance per camera history: the pass writes its settings with queue.writeBuffer as it is encoded, so two encodes in one submit share the last settings.
  3. Multiply only the light the visibility describes.
  4. The radius is in metres and also bounds every sample: a radius far bigger than the scene’s gaps darkens whole walls next to a column.
  5. Budget the normals target apart from the pass: at 1080p with 4× MSAA it is about 63 MiB, and a scene writing it pays that geometry cost even with the pass switched off.
  6. set() with a different enabled, fullResolution, bentNormals or temporal remakes the pass’s textures: output() returns a new texture, so rebuild any bind group that holds it.
  7. The bent direction needs the same history and filter as visibility.
  8. Screen space sees only what is on screen: an occluder just outside the frame or hidden behind another stops shading as the camera turns.
13 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Hannes Andersson: The HaTac engine’s GTAO pass, its tests and measurements; the demo written for the library.

Jorge Jimenez, Xian-Chun Wu, Angelo Pesce, Adrian Jarabo, “Practical Realtime Strategies for Accurate Indirect Occlusion” (Activision, 2016): The method the engine’s decision record cites: horizons searched along screen slices and the projected-normal, cosine-weighted slice integral. Written from the paper; no code taken.

ambient occlusionaogtaoground-truth ambient occlusioncontact shadingcontact shadowshorizon searchbent normalsscreen spacecomputewgslraw webgpureverse-zworld normalsmsaatemporal accumulationreprojectionbilateral filterhalf resolutionupsampleorthographicdeferredindirect lightsky light

Near it in the frame