Interactive Hydraulic Erosion on Heightfields × Plant Ecosystem Distribution Simulation × Space Colonization Tree Modeling
Forests that grow into the gaps. Biomes where terrain, plant placement and each tree's shape are linked. Erosion supplies wet valleys and dry ridges, an ecosystem simulation places species by moisture and competition, and every crown grows only into space its neighbours left free.
Open in StudioReproduced596× · 18.5 ms
Verified proof

Split-screen WebGL2 proof comparing an eroded terrain populated with uncoupled uniform symmetric trees (left, ignoring moisture flux and crown collisions) against hydraulic-erosion moisture channels steering species niches and space-colonization crowns that grow asymmetrically into light gaps while respecting neighbour crown shyness (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · couples hydraulic erosion flux maps to multi-species biome niches and neighbour-aware asymmetric gap-filling tree crowns
Show GLSL proof (209 lines)
const float P_EROSION_DEPTH = 0.85; // P Hydraulic Incision [0.2, 1.5, 0.05]
const float P_MOISTURE_GAIN = 1.15; // P Flux Moisture Coupling [0.2, 2.0, 0.05]
const float P_CROWN_SHY = 0.82; // P Gap-Seeking Crown Shyness [0.0, 1.4, 0.05]
const float P_FOREST_SCALE = 1.00; // P Forest Density [0.5, 1.6, 0.05]
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash22(i).x, hash22(i + vec2(1.0, 0.0)).x, u.x),
mix(hash22(i + vec2(0.0, 1.0)).x, hash22(i + vec2(1.0, 1.0)).x, u.x),
u.y
);
}
float fbm(vec2 p) {
float s = 0.0;
float a = 0.5;
mat2 m = mat2(0.8, 0.6, -0.6, 0.8);
for (int i = 0; i < 4; i++) {
s += a * vnoise(p);
p = m * p * 2.04 + vec2(2.7, 5.1);
a *= 0.5;
}
return s;
}
// Hydraulic erosion heightfield + analytical dendritic water-flux channel
void evalErodedTerrain(vec2 p, out float height, out float flux) {
float mainBend = 0.36 * sin(p.y * 1.55 + 0.4) + 0.14 * sin(p.y * 3.4);
float dMain = abs(p.x - mainBend);
float trib1 = abs((p.x - mainBend) * 0.72 + (p.y - 0.35) * 0.68);
float trib2 = abs((p.x - mainBend) * 0.68 - (p.y + 0.42) * 0.74);
float chMain = exp(-dMain * dMain * 5.8);
float chT1 = exp(-trib1 * trib1 * 11.0) * smoothstep(-0.2, 0.5, p.x - mainBend);
float chT2 = exp(-trib2 * trib2 * 11.0) * smoothstep(-0.2, 0.5, mainBend - p.x);
flux = clamp((chMain + 0.65 * chT1 + 0.65 * chT2) * P_MOISTURE_GAIN, 0.0, 1.35);
// Ridged mountain slopes incised by hydraulic gullies
float baseRidge = 0.55 * (1.0 - abs(2.0 * fbm(p * 1.1 + vec2(1.4, 2.2)) - 1.0));
float slopeSides = 0.42 * (dMain * dMain);
float microRills = 0.09 * fbm(p * 7.5 + vec2(0.0, flux * 2.0));
height = baseRidge + slopeSides - 0.46 * P_EROSION_DEPTH * min(flux, 1.0) + microRills;
}
float terrainH(vec2 p) {
float h, f;
evalErodedTerrain(p, h, f);
return h;
}
vec3 terrainN(vec2 p) {
float e = 0.02;
return normalize(vec3(
terrainH(p - vec2(e, 0.0)) - terrainH(p + vec2(e, 0.0)),
2.0 * e,
terrainH(p - vec2(0.0, e)) - terrainH(p + vec2(0.0, e))
));
}
vec3 acesTone(vec3 x) {
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool coupled = uv.x > 0.0;
vec2 suv = vec2(coupled ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
float sway = sin(iTime * 0.28) * 0.14;
vec3 ro = vec3(suv.x * 2.45 + sway, 2.25, suv.y * 2.85 + 1.15);
vec3 rd = normalize(vec3(0.0, -0.82, -0.57));
float t = 0.0;
for (int i = 0; i < 42; i++) {
vec3 q = ro + rd * t;
float d = q.y - terrainH(q.xz);
if (d < 0.004) break;
t += d * 0.55;
}
vec3 wp = ro + rd * t;
float h, flux;
evalErodedTerrain(wp.xz, h, flux);
vec3 N = terrainN(wp.xz);
float slope = 1.0 - N.y;
vec3 sunDir = normalize(vec3(0.72, 0.58, 0.38));
float ndl = max(dot(N, sunDir), 0.0);
// Base eroded terrain shading: alluvial silt in wet gullies, exposed granite on steep ridges
vec3 dryRidge = mix(vec3(0.52, 0.44, 0.34), vec3(0.38, 0.36, 0.34), smoothstep(0.08, 0.28, slope));
vec3 wetValley = vec3(0.20, 0.26, 0.16);
vec3 groundAlb = mix(dryRidge, wetValley, smoothstep(0.18, 0.78, flux));
// Stream water glint at deepest flux core
float stream = smoothstep(0.88, 1.08, flux);
vec3 col = groundAlb * (0.24 + 1.15 * ndl);
vec3 H = normalize(sunDir - rd);
float waterSpec = pow(max(dot(N, H), 0.0), 48.0);
col = mix(col, vec3(0.10, 0.22, 0.28) * (0.4 + 0.8 * ndl) + vec3(0.95, 0.90, 0.80) * waterSpec * 0.9, stream * 0.85);
// Tree placement & crown growth
float scale = 9.5 * P_FOREST_SCALE;
vec2 sp = wp.xz * scale;
vec2 cell = floor(sp);
vec2 frac = fract(sp);
if (!coupled) {
// Left: uncoupled uniform symmetric scatter ignoring moisture and neighbour collisions
float bestD = 9.0;
vec2 bestOff = vec2(0.0);
float bestR = 0.36;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 nb = vec2(float(x), float(y));
vec2 rnd = hash22(cell + nb + 7.1);
if (rnd.x > 0.58) continue;
vec2 pos = nb + 0.2 + 0.6 * rnd;
vec2 diff = frac - pos;
float d = length(diff);
if (d < bestD) {
bestD = d;
bestOff = diff;
}
}
}
float mask = smoothstep(bestR, bestR * 0.72, bestD);
float dome = sqrt(max(1.0 - pow(bestD / bestR, 2.0), 0.02));
vec3 cN = normalize(vec3(bestOff / bestR, dome));
float cl = 0.28 + 0.92 * max(dot(cN, normalize(vec3(sunDir.x, sunDir.z, 0.8))), 0.0);
vec3 genericGreen = vec3(0.18, 0.30, 0.14) * cl;
col = mix(col, genericGreen, mask);
} else {
// Right: ecosystem species by erosion flux + space-colonization crown leaning into light gaps
float d1 = 9.0;
float d2 = 9.0;
vec2 off1 = vec2(0.0);
vec2 pos1 = vec2(0.0);
vec2 pos2 = vec2(0.0);
float r1 = 0.0;
float flux1 = 0.0;
float rnd1 = 0.0;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 nb = vec2(float(x), float(y));
vec2 rnd = hash22(cell + nb + 13.7);
vec2 pos = nb + 0.15 + 0.70 * rnd;
vec2 worldTree = (cell + pos) / scale;
float th, tf;
evalErodedTerrain(worldTree, th, tf);
float tSlope = 1.0 - terrainN(worldTree).y;
// Ecological viability: too steep rocky crags and flooded stream cores stay open
if (tSlope > 0.34 || tf > 0.96) continue;
float suitability = smoothstep(0.05, 0.55, tf + 0.25) * smoothstep(0.36, 0.14, tSlope);
if (rnd.x > suitability * 0.92 + 0.12) continue;
float rad = mix(0.24, 0.48, clamp(tf * 1.1, 0.0, 1.0)) * (0.72 + 0.42 * rnd.y);
float d = length(frac - pos) / max(rad, 0.15);
if (d < d1) {
d2 = d1; pos2 = pos1;
d1 = d; pos1 = pos; off1 = frac - pos; r1 = rad; flux1 = tf; rnd1 = rnd.y;
} else if (d < d2) {
d2 = d; pos2 = pos;
}
}
}
// Space-colonization gap-seeking deformation: lean crown away from closest dominant neighbour
vec2 away = normalize(pos1 - pos2 + vec2(1e-4));
float gapBias = dot(normalize(off1 + vec2(1e-4)), away);
// Crown shyness channel between Voronoi competitors (d2 - d1 near 0)
float shyChannel = smoothstep(0.04, 0.24 * max(P_CROWN_SHY, 0.15), d2 - d1);
// Space-colonization branching lobe modulation
float ang = atan(off1.y, off1.x);
float lobes = 1.0 + 0.14 * sin(ang * 5.0 + rnd1 * 9.0) + 0.18 * P_CROWN_SHY * gapBias;
float effD = d1 / max(lobes, 0.55);
float mask = smoothstep(1.02, 0.72, effD) * mix(1.0, shyChannel, clamp(P_CROWN_SHY, 0.0, 1.0));
// Species colour by moisture niche: lush emerald/gold alder in wet valleys, deep spruce on dry ridges
vec3 drySpruce = vec3(0.08, 0.20, 0.13);
vec3 midOak = vec3(0.22, 0.35, 0.13);
vec3 wetAlder = vec3(0.36, 0.46, 0.16);
vec3 treeAlb = mix(drySpruce, mix(midOak, wetAlder, smoothstep(0.45, 0.85, flux1)), smoothstep(0.18, 0.65, flux1));
treeAlb *= (0.85 + 0.30 * rnd1);
// Space-colonization internal radial bough ribs visible inside crown
float branchRib = smoothstep(0.65, 0.95, sin(ang * 6.0 + effD * 4.5 + rnd1 * 6.0) * 0.5 + 0.5);
float dome = sqrt(max(1.0 - clamp(effD * effD, 0.0, 0.98), 0.02));
vec3 cN = normalize(vec3(off1 / max(r1, 0.15), dome * 1.1));
float cl = 0.22 + 1.05 * max(dot(cN, normalize(vec3(sunDir.x, sunDir.z, 0.85))), 0.0);
float foliageTex = 0.76 + 0.34 * fbm(wp.xz * 30.0 + rnd1 * 4.0) + 0.10 * branchRib;
vec3 treeCol = treeAlb * cl * foliageTex;
// Darken ambient occlusion in canopy understory
col *= (1.0 - 0.35 * smoothstep(1.35, 0.85, effD) * (1.0 - mask));
col = mix(col, treeCol, mask);
}
float haze = smoothstep(-0.28, 0.52, uv.y) * 0.24;
col = mix(col, vec3(0.66, 0.75, 0.82), haze);
col = acesTone(col * 1.12);
if (abs(uv.x) < 0.003) col = vec3(0.95, 0.93, 0.89);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Interactive Hydraulic Erosion on Heightfields outputs an eroded heightfield, and its water and sediment layers are exported beside it as a moisture texture. Plant Ecosystem Distribution Simulation consumes the heightfield and moisture texture and runs seeding, shading and competition over simulated years, producing a point-cloud of plants with species, age and size, plus a layout. Space Colonization Tree Modeling takes a point-cloud of attractors: for each surviving plant, attractors fill a species envelope and are then removed where they fall inside neighbouring crowns or below the terrain, so the branch graph, curves and mesh it grows lean toward light gaps and open slopes.
How to build it
Houdini or Python. Erode a large heightfield with a GPU grid erosion and write accumulated water flux as a moisture map. Run a Deussen-style individual-based simulation for a few dozen virtual years with per-species moisture and slope preferences. Growing every tree individually is too costly for big areas, so compute a competition signature per plant (direction and distance of the nearest dominant neighbours, plus slope aspect) and grow a library of trees per species over a small grid of signatures. Instance the nearest library entry per plant with matching rotation. Skin skeletons into tubes with Rotation-Minimizing Frames and scatter leaves. Export instances to the engine and use impostors for far LOD.
Field marks
- Flux maps overstate wetness in pits and flat basins and fill them with wetland species.
- Signature binning can make neighbouring trees visibly identical.
- Crowns from separate growth runs still intersect without a final collision pass.
- Ecological parameters need tuning or the simulation converges to monocultures.
Prior art
No prior art found on 2026-11-29.
Searches run (4)
- arXiv: all:"terrain erosion" AND all:"plant ecosystem" AND all:"tree modeling" → 0 results
- GitHub repos: "terrain erosion" "plant ecosystem" "tree modeling" → 0 results
- arXiv: all:"space colonization" AND all:"ecosystem" AND all:"terrain" → 0 results
- GitHub repos: "space colonization" ecosystem terrain → 0 results