Feature Library

Terrain world: eroded ground drawn as a clipmap, shaped by a replayable brush

5.90 GPU · 0.26 CPU ms
A still of the Terrain world: eroded ground drawn as a clipmap, shaped by a replayable brush demo
Still
The live demo starts when it’s in view.Pick a brush and drag on the ground; weather it; rise to the far view

The HaTac engine’s terrain kit, lifted out whole in raw WebGPU.

Landforms (basins, valleys, plateaus, lakes, vistas) are rasterised on the GPU into erosion’s inputs, a hydraulic and thermal erosion bake runs once on the GPU and is read back into CPU fields (height, soil, wetness, slope, exposed rock, flow), and those fields are the authority: a deterministic brush raises, lowers, flattens, smooths, levels pads, grades ramps and cuts channels on them, bit for bit the same on every machine, each gesture an entry on a journal that replays exactly and whose edited tiles are checkpoint columns. The same fields, cut into GPU tiles, are drawn as nested clipmap rings with toroidal caches, morphed so rings never seam or pop, whose near grid is one vertex a sample on every tier, with their own cascaded shadow pass; a coarse backdrop seamed round the editable ground carries the rings to the horizon, and the exact drawn height (ring, triangle and morph) stands anything placed on the ground. The demo is a steep valley with banded rock walls, gullies, conifers, boulders and a tarn under a hazy afternoon sky, which the viewer digs, raises and levels, then weathers again with the rain.

What it costs a frame

5.90 ms
0.26 ms
GPU
5.90 ms
CPU, median
0.26 ms
CPU, 95th pct
0.35 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 5.89–6.01, CPU 0.24–0.26 ms). What ran: Alone: the bare terrain as two clipmaps (the 768 m valley at 1.5 m a sample and 16 km of ranges at 16 m) with their rings tinted, three 2048² shadow cascades drawn from the terrain itself, the sky host’s sky and haze, at 1920×1080; the camera circles slowly, so rings move and toroidal strips refill every few frames. 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.77 ms
1% low ?
56 fps
Varies by ?
±0.42 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.02 ms17.98 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.77 ms
p95 ?
17.43 ms
p99 ?
17.75 ms
Slowest ?
18.08 ms
Mean ?
16.71 ms
Standard deviation ?
0.42 ms
1% low ?
56 fps
0.1% low ?
55 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.4 ms

Input

No input during this run.

Memory

JavaScript heap ?
93.4 → 94.1 MB
Growth ?
+0.78 MB

Browser

JavaScript a frame ?
0.26 ms
All tasks a frame ?
0.89 ms
Layout / style ?
0.00 / 0.14 ms
Main thread busy ?
5%

Garbage collection

Collections ?
6 (5 minor, 1 major)
Pauses ?
4.8 ms in all, longest 1.1

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

What it’s for

  1. The ground of an open world or a strategy map: eroded valleys and ranges baked once, drawn to the horizon at one draw per ring
  2. A builder or a colony game where players terraform: raise, dig, level a pad for a building, cut a channel, with saves and replays that match bit for bit
  3. A lockstep or server-checked multiplayer world whose ground edits must agree on every machine
  4. Placing trees, grass, props or units so they stand exactly on the ground as drawn at every distance and tier
  5. A landscape hero or a map editor that re-weathers what the user shaped
  6. A terrain sandbox for teaching erosion, drainage and how clipmaps follow the eye

Pitfalls, in brief

  1. The demo needs WebGPU: the landforms, the erosion and the clipmap’s cull and caches are compute passes into storage buffers, and there is no WebGL path.
  2. Never make the near grid a tier setting.
  3. Stand drawn things on the drawn surface, not on the CPU height.
  4. Rings are reach, and missing tiles are holes.
  5. Put the editable ground’s edges on the backdrop’s vertex lattice at every ring that can meet them.
14 more in brief
  1. The backdrop is sunk under the ground, so terrain-render’s gradients for its last samples outside the seam lean into the hole (a lit or dark strip one backdrop cell wide along the seam).
  2. A closed erosion bake gathers water along its edges: flow, wetness and deposits line the border.
  3. Pass the frame group without the shadow map (a 1 × 1 stand-in at binding 3) to prepare and to the shadow passes, and the one with the map to the scene: a pass cannot draw into the map and bind it.
  4. Snap each shadow cascade to whole texels in the light’s own plane and push receivers off the surface by a texel or two along the normal, more as the sun grazes the slope: the first try left long acne bands on slopes the low sun skimmed, and an unsnapped cascade crawls as the camera moves.
  5. In a material, take every derivative before any branch, and cap them: across a silhouette a 2 × 2 quad straddles the near hill and the far one, the raw derivatives ask the maps for their last mip, and every crest gets a line of the material’s mean colour.
  6. Bound all heights, edits included, with heightRange: the culler extrudes every patch through it (and through the skirt).
  7. A river stroke carves relative to the ground under it, so a channel that grows under the pointer must be rebuilt from the gesture’s start each time (preview mode “rebuild”); applying each new segment on top cut pits where segments overlap.
  8. Keep the brush deterministic: only + − × ÷ and Math.sqrt, abs, min, max, floor and ceil in anything that writes a field (no Math.exp, pow, atan, sin, cos or hypot: engines differ in the last bit), dyadic cell sizes so sample positions are exact, and validateStroke on anything from players or the network (applyStroke throws on what it rejects).
  9. Attach the checkpoint tracker to the freshly baked grid before the first edit, and route every write through it: re-weathering writes heights outside applyStroke, so the host calls the tracker’s observer for each sample before it writes it, or a rewind would leave the weathered tiles behind.
  10. Weathering runs on the GPU: a replay gives the same ground on the same adapter, and may differ in the last bits on another (a known gap).
  11. A pipeline that fails to compile rejects the renderer’s ready with the WGSL messages: catch it.
  12. Stand thousands of instances on the clipmap in the vertex shader with CLIPMAP_DRAWN_WGSL (the heights in a storage buffer, the rings in a uniform written each frame with the prepare eye): the demo’s 1,300 trees and 100 boulders ride the rings’ morph exactly, at no CPU cost.
  13. A landform narrower than a few cells of the grid it is baked on, or one the talus can fill, does not survive the bake: the demo’s gullies, drawn as valley landforms on the 16 m ranges, came out flat.
  14. Budget the bake, and keep it the same on every tier: the erosion’s working rectangle is about 120 bytes a sample while it runs (1024² is about 120 MiB) and the CPU fields hold six floats a sample after it.
19 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 terrain kit (built for his game and proven there), the library host and the demo’s valley.

Xing Mei, Philippe Decaudin & Bao-Gang Hu, Fast Hydraulic Erosion Simulation and Visualization on GPU (2007): The pipe model the erosion bake follows (outflow, transport, erosion and deposition); the engine’s README links it. Re-written, no code taken.

Arul Asirvatham & Hugues Hoppe, Terrain Rendering Using GPU-Based Geometry Clipmaps (GPU Gems 2, 2005): Nested rings round the eye, toroidal updates and the transition morph; the engine’s terrain design cites it.

Ken Perlin, Improving Noise (2002): The quintic fade of the gradient noise.

Steven Worley, A Cellular Texture Basis Function (1996): The cellular noise.

terrainheightfieldclipmapgeometry clipmapslodlevel of detailmorphgeomorphingtoroidal cachestreamingerosionhydraulic erosionthermal erosiontaluslandformsprocedural terrainnoisegradient noisefbmridged noisedomain warpcellular noiseterraformingbrush

Near it in the frame