Feature Library

Structure forge: recipes into four levels, baked occlusion, drawn and culled on the GPU (engine-free WebGPU)

4.78 GPU · 0.54 CPU ms
A still of the Structure forge: recipes into four levels, baked occlusion, drawn and culled on the GPU (engine-free WebGPU) demo
Still
The live demo starts when it’s in view.View: circle, walk the lane, over the valley; drag to look · Hour · Weather · Level of detail (by distance or pinned) · Baked occlusion · See what the cull keeps · Machines at work · Forge new cabins and spruces

The HaTac engine’s structure path (shape-build, shape-bake and structure-draw at e27d0ed), lifted whole and engine-free.

A structure is a recipe of parts with bevels (boxes, cylinders, extrusions, sweeps, lofts, stairs, ladders, railings, panels with holes), repeats, mirrors, details, motions and leafwork roles; the builder turns it into four levels of detail on the CPU, with edge, hollow and curvature data per vertex, joints where slender parts meet, and faces that would z-fight moved clear. The bake draws each level from 40 to 64 directions on the GPU and gathers ambient occlusion and cavity per vertex. The drawer holds every kind in one vertex and one index buffer; one compute pass culls every copy against the view and two shadow cascades, picks a continuous, rate-limited level and its dithered cross-fade, and fills indirect arguments, so a valley of copies is a handful of draws. Machines move in the vertex shader from one clock and each copy’s drive (spins, keyed sequences, slider-cranks, gears, bones), easing to a stop on their rest pose. Weather lies on them from a weather surface: settled snow in clumps from rest-space noise that grow and join, leafwork tiers holding their own, a roof keeping its pack off what stands under it, and, new in the library, wet wood and steel after rain. A standalone host written for the library gives a raw WebGPU page the frame, camera, cascades, HDR targets, sky and present the engine’s core gave. The demo forges a hamlet in a valley while you watch: cabins, sheds, a canopy over working machines, a water tower, wind pumps, a lookout, lamps, a kiln and spruce groves, about 760 copies of 17 kinds, in snow, after rain, at dusk or at night.

What it costs a frame

4.78 ms
0.54 ms
GPU
4.78 ms
CPU, median
0.54 ms
CPU, 95th pct
0.88 ms
Draw calls
0
Weight
Heavy

Measured 28 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 4.71–4.85, CPU 0.54–0.55 ms). What ran: Alone: the bare drawer: 17 kinds forged on the page (4 levels each, occlusion baked), 14 copies of each in rows running away from the eye (238 instances), one GPU cull and level pick for the camera and two shadow cascades, the indirect draws, contact shadows and glow points, with the weather surface’s deep snow, on a plain floor, in the morning; machines at work. 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.85 ms
1% low ?
54 fps
Varies by ?
±0.50 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.04 ms18.44 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.85 ms
p95 ?
17.80 ms
p99 ?
18.24 ms
Slowest ?
18.52 ms
Mean ?
16.89 ms
Standard deviation ?
0.50 ms
1% low ?
54 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.8 / 1.0 ms

Input

No input during this run.

Memory

JavaScript heap ?
64.1 → 52.1 MB
Growth ?
-11.97 MB

Browser

JavaScript a frame ?
0.58 ms
All tasks a frame ?
1.10 ms
Layout / style ?
0.01 / 0.00 ms
Main thread busy ?
7%

Garbage collection

Collections ?
2 (1 minor, 1 major)
Pauses ?
7.3 ms in all, longest 2.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("structure-forge")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 factory or a village made in code: every building, machine, tower and tree a few hundred bytes of recipe, never a model file
  2. Thousands of copies of dozens of kinds drawn in a handful of indirect draws, each culled and given its level on the GPU
  3. Automatic levels of detail for generated geometry that keep silhouettes, glowing parts and their light from level to level
  4. Per-vertex ambient occlusion and crevice dirt baked on the GPU in milliseconds, so a generated building sits in its own shade
  5. Machines that work on one clock: presses that stamp, cranks and gears that turn, arms that pick and place, finishing their stroke when they stop
  6. Snow that settles in clumps on roofs, ledges and tree tiers and never under a roof; ground and walls darkened and glossy after rain
  7. A raw WebGPU page with no engine that needs structures lit and shadowed with its own ground and sky

Pitfalls, in brief

  1. The demo needs WebGPU: the bake renders depth maps and gathers them in a compute pass, and the drawer culls, picks levels and fills indirect arguments in compute with storage buffers.
  2. Build off the frame. Four levels of a cabin take 40 to 270 ms on the CPU (the coplanar separation is most of it) and the bake 20 to 90 ms on the GPU: forge kinds one at a time with yieldTo returning a frame’s promise, show each as it is ready, and keep what you built (a packed kind is plain data: store it).
  3. Give every recipe the coplanar finder (forgeKind does: separateCoplanar).
  4. Sink bases a few centimetres into what they stand on.
  5. Bake with the ground under the structure (the bake adds one a few millimetres down), or every base reads open to the sky.
15 more in brief
  1. One kind’s levels can lose parts: level 1 drops parts under 30 cm or thinner than 6 cm, level 3 keeps the silhouette.
  2. Glowing roles (the recipe’s glow list) are never dropped or simplified and keep their light from level to level; far away they become glow points.
  3. Every pipeline beside the drawer must rebind its own groups 1 to 3 after a drawer call (the drawer leaves its own bound); the host’s bindPage does it for page draws.
  4. A pass that draws casters into the shadow map cannot also bind that map: the host gives the cascade passes their own group 0 with a 1×1 stand-in.
  5. Draw order in the scene pass: your ground, then drawContact (it multiplies what is under each footprint), then drawScene; glow points and anything transparent after.
  6. setInstances resets every record.
  7. Never scale the clock by how busy a machine is: change its drive (setDrive), which continues the work time and eases the rate; a cycle stop finishes the stroke on the rest pose.
  8. Snow needs a weather surface: createWeatherSurface (or the weather module of valley-weather) and pass its buffer as weatherSurface.
  9. The engine’s structures read only the snow from the weather surface; the library adds wet surfaces (darker, glossier, most where they face the sky).
  10. Under any snow cover the engine’s shader turns a face that looks straight down to NaN (normalize of zero in the snow’s lean toward up, and mix(N, NaN, 0) is still NaN): black dashes on the undersides of tree tiers and roof decks seen from below, spread by multisampling.
  11. Contact shadows are drawn for every copy, culled or not, and in the engine ignore the fog: far ones showed as dark dashes through it.
  12. The level cross-fade is a dither.
  13. Without a material set every role draws its flat values: base colour, metal, roughness, coat, glow.
  14. Pin a level (draw.set({ forceLod })) only to inspect: pinned at 0, a valley of copies costs every triangle; pinned at 3 the near ones are boxes.
  15. The drawer’s depth is reverse-Z (greater, cleared to 0) and its scene pass draws into the host’s HDR format; a page’s own pipelines in that pass must match both (and the sample count).
20 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s shape builder, occlusion bake, structure drawer, motion language, settled snow, their tests and the machine examples (built for his game and proven there); the library’s host, weather surface, demo, recipes and valley.

Krzysztof Narkowicz, ACES filmic tone mapping curve (2016): The fitted curve the host presents with.

Brian Karis, Real shading in Unreal Engine 4 (SIGGRAPH 2013): The GGX distribution, Schlick–Smith visibility, Fresnel and the analytic environment BRDF in the drawer’s light.

procedural buildingsprocedural architectureparametric modellingrecipesstructure recipebevelschamferextrudesweeploftrevolvelevel of detaillodlod cross-fadedithered fadegpu cullingfrustum cullingindirect drawdrawIndexedIndirectinstancingmany instancesambient occlusion bakevertex occlusioncavity

Near it in the frame