Feature Library

GPU occlusion culling: a depth pyramid, two phases

4.47 GPU · 0.48 CPU ms
A still of the GPU occlusion culling: a depth pyramid, two phases demo
Still
The live demo starts when it’s in view.Drag to look round · Turn fast whips the camera · switch the occlusion to compare the GPU time

Skips the instances something nearer hides, on the GPU, in the same frame.

The depth is reduced into a reverse-Z min/max pyramid (cells of 4 × 4 pixels, then halving), and each instance’s bounding sphere is boxed, projected and tested against the four cells of the level its footprint fits: hidden only when strictly nearer depth covers it all. Two phases: the previous frame’s pyramid predicts what to draw first, then everything it held back is tested against this frame’s depth and the survivors drawn at once, so a fast turn pops nothing. In an open view where the tests hide nothing three times running, they sleep and recheck every 61 frames. Raw WebGPU, a generic instanced drawer included, no dependencies.

What it costs a frame

4.47 ms
0.48 ms
GPU
4.47 ms
CPU, median
0.48 ms
CPU, 95th pct
0.78 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 2.21–4.57, CPU 0.26–0.48 ms). What ran: Alone: one wall before 2,304 cubes, two-phase occlusion every frame (frustum cull, the previous frame’s pyramid, the 4 × 4 reduction and its mips twice, the late test), the cubes drawn with 4× multisampling, their ghosts and the mip strip. GPU time for the whole frame by timestamp queries. 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.86 ms
1% low ?
55 fps
Varies by ?
±0.47 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.04 ms18.24 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.86 ms
p95 ?
17.80 ms
p99 ?
18.13 ms
Slowest ?
18.65 ms
Mean ?
16.88 ms
Standard deviation ?
0.47 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.1 / 0.7 / 0.8 ms

Input

No input during this run.

Memory

JavaScript heap ?
73.7 → 82.1 MB
Growth ?
+8.49 MB

Browser

JavaScript a frame ?
0.46 ms
All tasks a frame ?
1.03 ms
Layout / style ?
0.03 / 0.01 ms
Main thread busy ?
6%

Garbage collection

Collections ?
0 (0 minor, 0 major)
Pauses ?
0.0 ms in all, longest 0.0

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("hiz-occlusion")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. A town, a city or a factory of tens of thousands of instances where walls and buildings hide most of them from street level
  2. A forest or a valley behind hills, where the ridge hides the far side’s trees
  3. Interiors and corridors where rooms hide each other
  4. A camera that turns fast (a game) and must never show something a frame late
  5. An integrated GPU drawing more geometry than it can afford: the engine measured a valley view going from 4.9 to 3.3 ms

Pitfalls, in brief

  1. The demo needs WebGPU: the pyramid is built by compute shaders into a storage texture and the survivors are drawn with indirect draws, which WebGL 2 cannot do.
  2. Clear reverse-Z depth to zero and compare "greater".
  3. Project against the same camera, size and viewport that produced the depth.
  4. Use camera occlusion only for the main view.
  5. Bounding spheres must enclose everything the instance can draw: eaves, chimneys, wind sway, an animated arm’s reach.
10 more in brief
  1. Count actual rejections, not late draws.
  2. Measure open views separately.
  3. While asleep the tests do not run, so an unchanged camera that starts to hide things (a door closes, a wall is built) keeps drawing everything until the next probe, 61 frames later.
  4. Keep the history when the camera moves.
  5. Draw your occluders first in the first pass (terrain, walls, large buildings): in mode 1, and on the first frame after any resize, mode change or skipped frame, they are all the late test has.
  6. Record beginFrame, early, the first pass, late, the second pass and finish in one command encoder and submit it once, then call submitted(). beginFrame resets every batch’s draw arguments with queue.writeBuffer, so a second beginFrame before the submit overwrites the first.
  7. End the render pass before late() and finish(): the depth target is read as a texture there, so it needs TEXTURE_BINDING and cannot be attached at the same time. createDepthTarget in host.ts makes one that fits.
  8. A batch’s capacity is fixed when it is added; its visible lists are padded to 64 entries so the late list binds at a 256-byte offset on every device.
  9. The camera matrix is eye-relative (positions minus the eye before the matrix), reverse-Z and infinite-far, as host.ts builds it.
  10. track: true writes each instance’s fate to a state buffer for debug views (the demo’s ghosts and map).
15 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 occlusion module, its decisions and measurements; the library’s driver and demo.

occlusion cullinghi-zhierarchical zdepth pyramidmin max depthreverse-ztwo-phasegpu cullingcomputewgslraw webgpuindirect drawinstancingvisibilityfrustum cullingmsaaadaptiveopen viewperformancetownsforestscitiesinteriorsno dependencies

Near it in the frame