← DEGEN

// RIVER TOPOLOGY

HYDRAULIC EROSION ON GPU

The terrain above is a persistent heightfield stored in a ping-pong framebuffer. Every pixel is a packet of geological state: height, river depth, sediment load, flow velocity. Your mouse is a river. Your speed is its force.

HOW THE CARVING WORKS

Each frame, the simulation shader reads the previous state from one framebuffer and writes the next state to another. Then they swap. This is the ping-pong FBO pattern — the GPU equivalent of double buffering, except every pixel is a simulation cell running in parallel.

The state texture encodes four channels: R is terrain height, G is river channel depth, B is suspended sediment, A is flow velocity. When you click and drag, the shader measures your cursor speed. Fast strokes carve deep channels — carveRate = brush * mix(0.5, 3.0, speed). Slow movement deposits sediment. The asymmetry is the whole point: destruction is fast, construction is slow. Rivers work the same way.

Between mouse interactions, the terrain lives. River channels spread through neighbor averaging — each pixel samples its four cardinal neighbors and mixes toward their depth. Sediment moves downhill through the channels. Flow diffuses and decays. Simplex noise drives tectonic uplift, slowly pushing the terrain back up while erosion pulls it down.

The key insight: rivers are permanent. The decay rate for river channels is 0.9998 per frame — they persist for thousands of frames. Sediment decays at 0.998, flow at 0.995. This creates a visual hierarchy where your earliest gestures become geological features while your recent movements are still actively flowing. The landscape remembers every stroke.

01

MOUSE CARVING

Distance field from cursor position with aspect-ratio correction. Brush intensity scales with speed. Click-and-hold carves; velocity determines channel direction and depth accumulation rate.

02

DIFFUSION

4-neighbor Laplacian averaging for river spread, sediment transport, and flow decay. Each quantity diffuses at a different rate — rivers barely move, sediment flows faster through deeper channels.

03

TECTONIC UPLIFT

Domain-warped simplex noise adds slow terrain uplift. Without this, the terrain would erode to flatness. The noise field drifts over time, creating shifting pressure that keeps the landscape dynamic.

04

DISPLAY RENDER

5-octave FBM displaced by height state generates the terrain texture. Earth palette with 6 height bands. River channels overlay with blue-teal water, flow-driven shimmer, and sediment-highlighted banks.

GESTURE AS GEOLOGY

The interaction model here is co-authorship, not parameter tweaking. You don't adjust sliders or pick presets. You draw rivers with your hand, and the physics determines what those rivers become. Fast, decisive strokes cut canyons. Hesitant, slow movements build deltas. The landscape is a record of how you moved — not what you chose.

Real hydraulic erosion is the most powerful landscape sculptor on Earth. The Grand Canyon is a mouse stroke that lasted 6 million years. This shader compresses that timescale into gestures. The math is simplified — no thermal erosion, no wind, no tidal forces — but the core mechanism is real: water follows gravity, picks up material, and deposits it when velocity drops.