Texel A field guide to 3D techniques

Cube-Sphere Planet Mapping × Stream-Power Erosion (Fluvial Terrain Uplift)

Planets with rivers across cube seams. Whole planets whose mountain ranges and river networks are drainage-consistent across all six cube faces. Stream-power erosion runs on one flow graph over the cube-sphere, so rivers cross face seams without breaking and basins span continents.

Open in StudioReproduced193× · 5.98 ms

Cube-Sphere Planet MappingProcedural · Real-timein: —out: mesh, heightfield, textureheightfieldStream-Power Erosion (Fluvial Terrain Uplift)Procedural · Interactivein: heightfield, graphout: heightfield

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of Drainage-consistent planets (left: per-face broken seams, right: equal-area cube-sphere stream-power erosion)
Cross-proof specimen. Drainage-consistent planets (left: per-face broken seams, right: equal-area cube-sphere stream-power erosion). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing per-face independent cube-map erosion (left, where mountain ridges and rivers abruptly break at glowing cube-face seams and distort near corners) against seamless equal-area cube-sphere stream-power erosion with continuous dendritic river basins crossing face boundaries and triple-junction corners intact (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · eliminates cube-face seam discontinuities and corner river-density distortion while carving realistic cross-face dendritic drainage basins on a rotating planet

Show GLSL proof (227 lines)
const float P_EROSION_K = 1.15; // P Stream-Power Erosion [0.2, 2.4, 0.05]
const float P_UPLIFT_AMP = 1.10; // P Tectonic Uplift [0.3, 2.0, 0.05]
const float P_SEA_LEVEL = 0.44; // P Ocean Level [0.20, 0.70, 0.02]
const float P_SEAM_OVERLAY = 0.65; // P Cube Seam Overlay [0.0, 1.0, 0.05]

float hash31(vec3 p) {
  p = fract(p * 0.1031);
  p += dot(p, p.yzx + 33.33);
  return fract((p.x + p.y) * p.z);
}

float vnoise3(vec3 p) {
  vec3 i = floor(p);
  vec3 f = fract(p);
  vec3 u = f * f * (3.0 - 2.0 * f);
  float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
  float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
  float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
  float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
  float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
  float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
  float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
  float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
  float nx00 = mix(n000, n100, u.x);
  float nx10 = mix(n010, n110, u.x);
  float nx01 = mix(n001, n101, u.x);
  float nx11 = mix(n011, n111, u.x);
  return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}

float fbm3(vec3 p) {
  float s = 0.0;
  float a = 0.5;
  for (int i = 0; i < 5; i++) {
    s += a * vnoise3(p);
    p = p * 2.04 + vec3(7.1, 11.3, 5.7);
    a *= 0.5;
  }
  return s;
}

// Ridged tectonic uplift field in 3D sphere coordinates
float ridged3(vec3 p) {
  float s = 0.0;
  float a = 0.55;
  for (int i = 0; i < 4; i++) {
    float r = 1.0 - abs(vnoise3(p) * 2.0 - 1.0);
    s += a * r * r;
    p = p * 2.12 + vec3(3.4, 8.2, 6.1);
    a *= 0.48;
  }
  return s;
}

// Project unit sphere direction onto cube-sphere face index [0..5] and local tangent coords (u,v) in [-1,1]
void sphereToCubeFace(vec3 d, out int face, out vec2 uvFace, out float seamDist) {
  vec3 a = abs(d);
  if (a.x >= a.y && a.x >= a.z) {
    face = d.x > 0.0 ? 0 : 1;
    uvFace = vec2(d.z, d.y) / a.x;
  } else if (a.y >= a.x && a.y >= a.z) {
    face = d.y > 0.0 ? 2 : 3;
    uvFace = vec2(d.x, d.z) / a.y;
  } else {
    face = d.z > 0.0 ? 4 : 5;
    uvFace = vec2(d.x, d.y) / a.z;
  }
  // Equal-area spherical tangent warp: atan(u) / (pi/4)
  vec2 eqUV = atan(uvFace) / 0.78539816;
  seamDist = min(1.0 - abs(eqUV.x), 1.0 - abs(eqUV.y));
}

// Evaluate planet elevation & stream-power river discharge
void evalPlanetTerrain(vec3 sp, bool seamless, out float elev, out float riverFlow, out float seamDist) {
  int face;
  vec2 fuv;
  sphereToCubeFace(sp, face, fuv, seamDist);

  if (!seamless) {
    // Left: per-face independent 2D heightfield + erosion (no cross-seam flow graph, cube-corner distortion)
    // Each face gets its own shifted 2D noise seed and unwarped tangent projection -> visible jumps across seams!
    float fSeed = float(face) * 7.31;
    vec3 q = vec3(fuv * 2.2 + vec2(fSeed, fSeed * 0.6), float(face) * 1.9);
    float cont = fbm3(q * 0.85) * 0.62 + ridged3(q * 1.35) * 0.45 * P_UPLIFT_AMP;
    // Uncorrected cube corner area factor stretches erosion near corners
    float cornerDistort = 1.0 + 0.55 * dot(fuv, fuv);
    float ridgeValley = abs(fbm3(q * 3.2 * cornerDistort) - 0.5);
    float carve = exp(-ridgeValley * 24.0) * P_EROSION_K * 0.24;
    elev = cont - carve * smoothstep(P_SEA_LEVEL - 0.04, P_SEA_LEVEL + 0.35, cont);
    riverFlow = smoothstep(0.055, 0.012, ridgeValley) * smoothstep(P_SEA_LEVEL + 0.01, P_SEA_LEVEL + 0.22, elev) * P_EROSION_K;
  } else {
    // Right: seamless equal-area cube-sphere coupled stream-power erosion
    // Continuous 3D tectonic plate uplift + continental shelf
    float plates = fbm3(sp * 2.15 + vec3(1.4, -0.8, 2.2));
    float orogeny = ridged3(sp * 3.45 + vec3(4.1, 1.7, -2.3)) * P_UPLIFT_AMP;
    float rawElev = plates * 0.68 + orogeny * 0.42;

    // Multi-order dendritic drainage channels advected down the tectonic gradient on S^2
    vec3 gradEst = vec3(
      fbm3((sp + vec3(0.04, 0.0, 0.0)) * 2.15 + vec3(1.4, -0.8, 2.2)) - plates,
      fbm3((sp + vec3(0.0, 0.04, 0.0)) * 2.15 + vec3(1.4, -0.8, 2.2)) - plates,
      fbm3((sp + vec3(0.0, 0.0, 0.04)) * 2.15 + vec3(1.4, -0.8, 2.2)) - plates
    );
    // Tangent-plane steepest descent warp creates realistic branching river basins across cube seams
    vec3 tangFlow = gradEst - sp * dot(gradEst, sp);
    vec3 w1 = sp * 4.8 + tangFlow * 9.5;
    vec3 w2 = sp * 9.6 - tangFlow * 14.0;
    float trunk = abs(fbm3(w1 + vec3(2.3, 5.1, 1.2)) - 0.50);
    float trib = abs(fbm3(w2 + vec3(8.7, 3.4, 6.2)) - 0.50);

    // Stream power E = K * A^m * S^n: incision deepens down-valley toward ocean level
    float upland = smoothstep(P_SEA_LEVEL - 0.02, P_SEA_LEVEL + 0.48, rawElev);
    float trunkCarve = exp(-trunk * 26.0) * 0.26;
    float tribCarve = exp(-trib * 30.0) * 0.11;
    float erosion = (trunkCarve + tribCarve) * P_EROSION_K * upland;
    elev = rawElev - erosion;

    // Accumulated upstream drainage discharge swells as rivers descend toward the coast
    float downstream = smoothstep(P_SEA_LEVEL + 0.46, P_SEA_LEVEL + 0.01, elev);
    float mainRiver = smoothstep(0.042 + 0.022 * downstream, 0.008, trunk);
    float sideRiver = smoothstep(0.028, 0.007, trib) * 0.65;
    riverFlow = clamp((mainRiver + sideRiver) * smoothstep(P_SEA_LEVEL - 0.01, P_SEA_LEVEL + 0.06, elev) * clamp(P_EROSION_K, 0.3, 1.8), 0.0, 1.0);
  }
}

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 seamless = uv.x > 0.0;
  vec2 suv = vec2(seamless ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);

  // Deep starfield backdrop
  vec3 col = vec3(0.006, 0.009, 0.018);
  float starHash = hash31(vec3(floor(fragCoord.xy * 0.65), 1.0));
  if (starHash > 0.994) col += vec3(0.75, 0.82, 0.98) * pow((starHash - 0.994) / 0.006, 2.0) * 0.85;

  // Ray-sphere intersection for rotating planet positioned so a cube-sphere corner & 3 seams cross front center!
  vec3 ro = vec3(0.0, 0.0, 2.65);
  vec3 rd = normalize(vec3(suv.x * 1.15, suv.y * 1.15, -1.75));
  float R = 0.82;
  float b = dot(ro, rd);
  float c = dot(ro, ro) - R * R;
  float disc = b * b - c;

  vec3 sunDir = normalize(vec3(0.74, 0.38, 0.55));

  // Atmospheric halo around planet limb
  float rayDist = length(ro - rd * max(-b, 0.0));
  float halo = exp(-max(rayDist - R, 0.0) * 14.0) * 0.42;
  col += vec3(0.18, 0.48, 0.95) * halo;

  if (disc > 0.0) {
    float tHit = -b - sqrt(disc);
    vec3 hitP = ro + rd * tHit;
    vec3 Ngeom = normalize(hitP);

    // Slowly rotate planet around tilted axis so cube triple-junction & seams sweep prominently across view
    float ang = 0.58 + iTime * 0.22;
    float ca = cos(ang), sa = sin(ang);
    vec3 sp = vec3(Ngeom.x * ca + Ngeom.z * sa, Ngeom.y, -Ngeom.x * sa + Ngeom.z * ca);
    float tilt = 0.46;
    sp = vec3(sp.x, sp.y * cos(tilt) - sp.z * sin(tilt), sp.y * sin(tilt) + sp.z * cos(tilt));

    float elev, riverFlow, seamDist;
    evalPlanetTerrain(sp, seamless, elev, riverFlow, seamDist);

    // Finite-difference topographic bump normal on sphere tangent plane
    vec3 up = abs(sp.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
    vec3 t1 = normalize(cross(up, sp));
    vec3 t2 = cross(sp, t1);
    float eps = 0.008;
    float e1, r1, sd1, e2, r2, sd2;
    evalPlanetTerrain(normalize(sp + t1 * eps), seamless, e1, r1, sd1);
    evalPlanetTerrain(normalize(sp + t2 * eps), seamless, e2, r2, sd2);
    float slopeX = (e1 - elev) / eps;
    float slopeY = (e2 - elev) / eps;
    // Transform tangent perturbation back to world normal approximation
    vec3 Nbump = normalize(Ngeom - (t1 * slopeX + t2 * slopeY) * (elev > P_SEA_LEVEL ? 0.14 : 0.01));

    float ndl = max(dot(Nbump, sunDir), 0.0);
    float ndlGeom = max(dot(Ngeom, sunDir), 0.0);
    float ndv = max(dot(Ngeom, -rd), 0.02);

    vec3 surfAlb = vec3(0.0);
    float specMask = 0.0;
    if (elev < P_SEA_LEVEL) {
      // Ocean bathymetry shelf + deep abyss
      float depth = clamp((P_SEA_LEVEL - elev) / 0.25, 0.0, 1.0);
      surfAlb = mix(vec3(0.05, 0.34, 0.46), vec3(0.015, 0.075, 0.20), pow(depth, 0.65));
      specMask = 1.0;
    } else {
      // Hypsometric biome ramp: coastal plain -> forest basin -> arid foothills -> rocky ridges -> snow peaks
      float hRel = clamp((elev - P_SEA_LEVEL) / 0.45, 0.0, 1.0);
      vec3 lowland = vec3(0.14, 0.30, 0.14);
      vec3 highland = vec3(0.46, 0.36, 0.22);
      vec3 rock = vec3(0.40, 0.38, 0.36);
      vec3 snow = vec3(0.90, 0.92, 0.96);
      surfAlb = mix(lowland, highland, smoothstep(0.12, 0.48, hRel));
      surfAlb = mix(surfAlb, rock, smoothstep(0.48, 0.78, hRel));
      surfAlb = mix(surfAlb, snow, smoothstep(0.74, 0.92, hRel));
      // Lush green riparian corridor + sparkling blue stream-power river channel
      surfAlb = mix(surfAlb, vec3(0.10, 0.34, 0.16), smoothstep(0.10, 0.55, riverFlow) * 0.55);
      surfAlb = mix(surfAlb, vec3(0.09, 0.46, 0.72), smoothstep(0.32, 0.85, riverFlow));
      specMask = smoothstep(0.40, 0.85, riverFlow) * 0.85;
    }

    vec3 H = normalize(sunDir - rd);
    float spec = pow(max(dot(Nbump, H), 0.0), 42.0) * specMask * ndlGeom;
    vec3 planetLit = surfAlb * (0.04 + 1.38 * ndl) + vec3(1.1, 0.96, 0.80) * spec * 0.95;

    // Rayleigh atmospheric rim scattering
    float fres = pow(1.0 - ndv, 3.2);
    vec3 atmo = vec3(0.24, 0.56, 1.0) * fres * (0.15 + 1.15 * ndlGeom);
    col = planetLit + atmo;

    // Subtle cube-sphere face seam & corner overlay so viewers can inspect cross-seam river continuity directly
    float seamLine = smoothstep(0.022, 0.004, seamDist) * P_SEAM_OVERLAY;
    vec3 seamCol = seamless ? vec3(0.32, 0.92, 0.76) : vec3(1.0, 0.38, 0.24);
    col = mix(col, seamCol, seamLine * 0.65);
  }
  col = acesTone(col * 1.12);
  if (abs(uv.x) < 0.003) col = vec3(0.96, 0.94, 0.88);
  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}

Why they connect

Cube-Sphere Planet Mapping outputs six heightfield faces sampled from 3D noise on the sphere. Stream-Power Erosion (Fluvial Terrain Uplift) consumes a heightfield and a flow graph; here the graph spans all faces at once, with neighbour links across seams and cell areas taken from the warped cube-to-sphere mapping, so upstream drainage area stays correct near cube corners. Uplift is painted or generated on the sphere. The eroded heightfield goes back to the six faces, which the cube-sphere quadtree renderer streams with fine noise added.

How to build it

C++, or Python with numba. Build an N×N grid per face with an equal-area correction and an adjacency list that stitches edges and corners. Initialise uplift from plate-like 3D noise, then run the implicit stream-power solver (steepest-descent receivers, drainage accumulation in topological order, implicit height update), filling depressions each iteration. Use a few tens of iterations at coarse resolution, upsample, and repeat at finer resolution. Export six 16-bit faces and a drainage map for river rendering. Render with a quadtree planet renderer in Unity, Godot or WebGPU, adding detail noise at close range.

Field marks

  1. Cube-corner cells have three neighbours instead of four, which biases flow direction.
  2. Wrong cell areas distort drainage and river density near corners.
  3. Single-direction flow carves grid-aligned rivers.
  4. Global solves at high resolution are slow and memory-heavy.

Prior art

No prior art found on 2026-11-29.

Searches run (4)
  • arXiv: all:"stream power" AND all:"planet" AND all:"terrain" → 0 results
  • GitHub repos: "stream power" planet terrain → 0 results
  • arXiv: all:"cube sphere" AND all:"erosion" → 0 results
  • GitHub repos: "cube sphere" erosion → 0 results