Prompt specification
Build or customize the Three.js 3D scene "Small stream ending in a plateau basin" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Small stream ending in a plateau basin
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-stream-ending-in-a-plateau-basin-x3046
Scene Description Prompt:
Create a standalone cutaway scene in one HTML file using Three.js from cdnjs. Create a compact Altiplano vignette with mountain runoff entering a closed low area. Show that water accumulates or evaporates without a modeled outlet to the sea.
Working Three.js Starter (small-stream-ending-in-a-plateau-basin-x3046):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Altiplano — Closed Basin Cutaway</title>
<style>
:root {
color-scheme: light;
--ink: #18333a;
--muted: #5e7478;
--panel: rgba(248, 251, 249, 0.82);
--line: rgba(24, 51, 58, 0.14);
--blue: #087f9c;
--aqua: #40b7bf;
--orange: #c86f42;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(430px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 45px rgba(43, 70, 73, 0.11),
inset 0 1px rgba(255, 255, 255, 0.68);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(200, 111, 66, 0.13);
content: "";
}
h1 {
max-width: 390px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.basin-chip {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(8, 127, 156, 0.18);
border-radius: 999px;
background: rgba(8, 127, 156, 0.075);
color: #17697c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.basin-chip svg {
width: 13px;
height: 13px;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
width: 246px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 40px rgba(43, 70, 73, 0.1);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.control-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.modes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.modes button {
min-width: 0;
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: var(--muted);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 750;
transition: 160ms ease;
}
.modes button:hover {
border-color: rgba(8, 127, 156, 0.35);
color: var(--ink);
}
.modes button.active {
border-color: rgba(8, 127, 156, 0.35);
background: rgba(8, 127, 156, 0.11);
color: #086d83;
}
.readout {
margin-top: 14px;
}
.readout-row {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
}
#phase {
font-size: 11px;
font-weight: 800;
}
#level {
color: var(--blue);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
font-weight: 800;
}
.meter {
position: relative;
height: 6px;
margin-top: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(24, 51, 58, 0.1);
}
.meter::after {
position: absolute;
inset: 0;
background: linear-gradient(90deg, #a9dfe3, #168ca5);
content: "";
transform: scaleX(var(--fill, 0.5));
transform-origin: left;
transition: transform 80ms linear;
}
.control-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.legend {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 14px;
max-width: calc(100vw - 48px);
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 13px;
background: rgba(248, 251, 249, 0.72);
box-shadow: 0 10px 30px rgba(43, 70, 73, 0.08);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 17px;
height: 5px;
border-radius: 99px;
}
.swatch.runoff {
background: #118cb2;
}
.swatch.water {
background: #45b6bb;
}
.swatch.vapor {
background: #d5e7e4;
box-shadow: 0 0 0 1px rgba(24, 51, 58, 0.12);
}
.swatch.divide {
background: var(--orange);
}
.camera-help {
position: absolute;
right: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 11px;
background: rgba(248, 251, 249, 0.68);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(10px);
}
#labels,
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 4;
}
#leaders line {
stroke: rgba(24, 51, 58, 0.48);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.label {
position: absolute;
max-width: 180px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 9px;
background: rgba(248, 251, 249, 0.82);
box-shadow: 0 8px 22px rgba(43, 70, 73, 0.09);
color: var(--ink);
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.label strong {
display: block;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.045em;
text-transform: uppercase;
}
.label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.label.orange strong {
color: #a95c37;
}
.label.blue strong {
color: #08738b;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.intro p {
display: none;
}
h1 {
max-width: 320px;
font-size: 31px;
}
.basin-chip {
margin-top: 10px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
width: 218px;
padding: 12px;
}
.control-note,
.camera-help,
.legend {
display: none;
}
.label {
max-width: 135px;
padding: 6px 8px;
}
.label span {
display: none;
}
.label.optional {
display: none;
}
}
</style>
</head>
<body>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<div class="hud">
<section class="intro">
<div class="eyebrow">Hydrologic diorama · Altiplano</div>
<h1>A basin with nowhere to drain</h1>
<p>
Mountain runoff enters a closed high-altitude depression. Water spreads
inward and can return to the atmosphere; no channel or modeled outlet
carries it to the sea.
</p>
<div class="basin-chip">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M3 18c2.8 0 3.8-7 9-7s6.2 7 9 7M5 15V9m3 6V6m8 9v-7m3 7V8"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
Closed drainage basin
</div>
</section>
<section class="controls" aria-label="Water balance controls">
<div class="control-title">Water balance</div>
<div class="modes" role="group" aria-label="Simulation mode">
<button class="active" data-mode="cycle">Cycle</button>
<button data-mode="accumulate">Accumulate</button>
<button data-mode="evaporate">Evaporate</button>
</div>
<div class="readout">
<div class="readout-row">
<span id="phase">Accumulating</span>
<span id="level">−0.55 m</span>
</div>
<div class="meter" id="meter"></div>
</div>
<p class="control-note">
The front face is a diagrammatic cut, not a physical drainage opening.
</p>
</section>
<div class="legend" aria-label="Scene legend">
<span class="legend-item"><i class="swatch runoff"></i>Runoff</span>
<span class="legend-item"><i class="swatch water"></i>Stored water</span>
<span class="legend-item"><i class="swatch vapor"></i>Evaporation</span>
<span class="legend-item"><i class="swatch divide"></i>Watershed divide</span>
</div>
<div class="camera-help">Drag to orbit · Wheel/pinch to zoom · Double-click to reset</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e8);
scene.fog = new THREE.Fog(0xdce9e8, 29, 56);
const camera = new THREE.PerspectiveCamera(
37,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0x8b755b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d9, 3.1);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xa8dce2, 0.7);
rimLight.position.set(10, 5, -10);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Terrain height field
// -------------------------------------------------------------------------
const X_MIN = -8.5;
const X_MAX = 8.5;
const Z_MIN = -4.8;
const Z_MAX = 2.4;
const BASIN_Y = -2.85;
function terrainHeight(x, z) {
const mountain =
4.45 *
Math.exp(
-Math.pow((x + 4.65) / 1.78, 2) -
Math.pow((z + 1.48) / 1.38, 2)
);
const rearRidge =
1.35 *
Math.exp(
-Math.pow((x - 0.15) / 4.25, 2) -
Math.pow((z + 3.25) / 1.22, 2)
);
const easternDivide =
0.82 *
Math.exp(
-Math.pow((x - 6.35) / 1.42, 2) -
Math.pow((z + 0.65) / 1.72, 2)
);
const basin =
2.38 *
Math.exp(
-Math.pow((x - 1.1) / 3.2, 2) -
Math.pow((z - 0.1) / 2.7, 2)
);
const texture =
0.045 * Math.sin(x * 1.7 + z * 0.4) * Math.cos(z * 1.35) +
0.025 * Math.sin(x * 3.3 - z * 2.1);
return 0.86 + mountain + rearRidge + easternDivide - basin + texture;
}
function terrainColor(height) {
const color = new THREE.Color();
if (height > 3.75) {
color.set(0xe8eeee);
} else if (height > 2.65) {
color.set(0x969b95);
} else if (height > 1.55) {
color.set(0xa89b82);
} else if (height > 0.65) {
color.set(0xb7a77b);
} else if (height > -0.2) {
color.set(0xc0ad7c);
} else {
color.set(0xc9b98d);
}
return color;
}
function createTerrain() {
const nx = 92;
const nz = 58;
const dx = (X_MAX - X_MIN) / nx;
const dz = (Z_MAX - Z_MIN) / nz;
const positions = [];
const colors = [];
function pushTriangle(a, b, c, tint) {
positions.push(...a, ...b, ...c);
for (let i = 0; i < 3; i++) {
colors.push(tint.r, tint.g, tint.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const x0 = X_MIN + ix * dx;
const z0 = Z_MIN + iz * dz;
const x1 = x0 + dx;
const z1 = z0 + dz;
const p00 = [x0, terrainHeight(x0, z0), z0];
const p01 = [x0, terrainHeight(x0, z1), z1];
const p10 = [x1, terrainHeight(x1, z0), z0];
const p11 = [x1, terrainHeight(x1, z1), z1];
const centerHeight =
(p00[1] + p01[1] + p10[1] + p11[1]) * 0.25;
const tint = terrainColor(centerHeight);
const variation =
0.965 +
0.055 *
(0.5 +
0.5 *
Math.sin((ix * 12.9898 + iz * 78.233 + 4.1) * 0.71));
tint.multiplyScalar(variation);
pushTriangle(p00, p01, p10, tint);
pushTriangle(p10, p01, p11, tint);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.94,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
createTerrain();
// -------------------------------------------------------------------------
// Exposed geological section
// -------------------------------------------------------------------------
function makeSectionMaterial(color, roughness = 0.96) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
side: THREE.DoubleSide
});
}
const alluviumMaterial = makeSectionMaterial(0x987653);
const sedimentMaterial = makeSectionMaterial(0xc2925f);
const clayMaterial = makeSectionMaterial(0x5f7479);
function addQuad(target, a, b, c, d) {
target.push(...a, ...b, ...c, ...a, ...c, ...d);
}
function createFrontSection() {
const alluvium = [];
const sediment = [];
const clay = [];
const segments = 78;
for (let i = 0; i < segments; i++) {
const x0 = X_MIN + (i / segments) * (X_MAX - X_MIN);
const x1 = X_MIN + ((i + 1) / segments) * (X_MAX - X_MIN);
const h0 = terrainHeight(x0, Z_MAX);
const h1 = terrainHeight(x1, Z_MAX);
const a0 = h0 - 0.34;
const a1 = h1 - 0.34;
const s0 = Math.max(BASIN_Y + 0.12, h0 - 1.12);
const s1 = Math.max(BASIN_Y + 0.12, h1 - 1.12);
addQuad(
alluvium,
[x0, a0, Z_MAX],
[x1, a1, Z_MAX],
[x1, h1, Z_MAX],
[x0, h0, Z_MAX]
);
addQuad(
sediment,
[x0, s0, Z_MAX],
[x1, s1, Z_MAX],
[x1, a1, Z_MAX],
[x0, a0, Z_MAX]
);
addQuad(
clay,
[x0, BASIN_Y, Z_MAX],
[x1, BASIN_Y, Z_MAX],
[x1, s1, Z_MAX],
[x0, s0, Z_MAX]
);
}
for (const [data, material] of [
[alluvium, alluviumMaterial],
[sediment, sedimentMaterial],
[clay, clayMaterial]
]) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(data, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
}
const rimPoints = [];
for (let i = 0; i <= 100; i++) {
const x = THREE.MathUtils.lerp(X_MIN, X_MAX, i / 100);
rimPoints.push(new THREE.Vector3(x, terrainHeight(x, Z_MAX) + 0.025, Z_MAX));
}
const rim = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(rimPoints),
new THREE.LineBasicMaterial({
color: 0x675d4f,
transparent: true,
opacity: 0.55
})
);
scene.add(rim);
}
createFrontSection();
const base = new THREE.Mesh(
new THREE.BoxGeometry(17.25, 0.34, 7.45),
new THREE.MeshStandardMaterial({
color: 0x63777a,
roughness: 0.85
})
);
base.position.set(0, BASIN_Y - 0.17, (Z_MIN + Z_MAX) * 0.5);
base.receiveShadow = true;
scene.add(base);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xd4e2df,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = BASIN_Y - 0.36;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Topographic contour lines, including a highlighted basin divide
// -------------------------------------------------------------------------
function createContour(level, color, opacity) {
const nx = 104;
const nz = 66;
const dx = (X_MAX - X_MIN) / nx;
const dz = (Z_MAX - Z_MIN) / nz;
const positions = [];
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const x = X_MIN + ix * dx;
const z = Z_MIN + iz * dz;
const corners = [
[x, z],
[x + dx, z],
[x + dx, z + dz],
[x, z + dz]
];
const heights = corners.map(([cx, cz]) =>
terrainHeight(cx, cz)
);
const intersections = [];
for (let edge = 0; edge < 4; edge++) {
const next = (edge + 1) % 4;
const ha = heights[edge];
const hb = heights[next];
if ((ha < level) !== (hb < level)) {
const t = (level - ha) / (hb - ha);
intersections.push([
THREE.MathUtils.lerp(
corners[edge][0],
corners[next][0],
t
),
level + 0.035,
THREE.MathUtils.lerp(
corners[edge][1],
corners[next][1],
t
)
]);
}
}
if (intersections.length === 2) {
positions.push(...intersections[0], ...intersections[1]);
} else if (intersections.length === 4) {
positions.push(
...intersections[0],
...intersections[1],
...intersections[2],
...intersections[3]
);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
scene.add(line);
}
for (const level of [0.15, 0.75, 1.35, 1.95, 2.55, 3.15, 3.75]) {
createContour(level, 0x5f695f, 0.13);
}
createContour(0.42, 0xc46b42, 0.72);
// -------------------------------------------------------------------------
// Runoff channel and moving water particles
// -------------------------------------------------------------------------
const runoffXZ = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-5.15, 0, -1.65),
new THREE.Vector3(-4.65, 0, -1.35),
new THREE.Vector3(-4.0, 0, -0.9),
new THREE.Vector3(-3.25, 0, -0.58),
new THREE.Vector3(-2.45, 0, -0.28),
new THREE.Vector3(-1.55, 0, -0.12),
new THREE.Vector3(-0.55, 0, 0.0),
new THREE.Vector3(0.55, 0, 0.12)
],
false,
"catmullrom",
0.4
);
function makeRunoffCurve(offset) {
const points = [];
for (let i = 0; i <= 100; i++) {
const p = runoffXZ.getPoint(i / 100);
p.y = terrainHeight(p.x, p.z) + offset;
points.push(p);
}
return new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.15);
}
const darkChannelCurve = makeRunoffCurve(0.075);
const blueChannelCurve = makeRunoffCurve(0.155);
const darkChannel = new THREE.Mesh(
new THREE.TubeGeometry(darkChannelCurve, 130, 0.13, 7, false),
new THREE.MeshStandardMaterial({
color: 0x536f6c,
roughness: 0.8
})
);
darkChannel.receiveShadow = true;
scene.add(darkChannel);
const blueChannel = new THREE.Mesh(
new THREE.TubeGeometry(blueChannelCurve, 130, 0.055, 7, false),
new THREE.MeshStandardMaterial({
color: 0x168eb4,
emissive: 0x073c4b,
emissiveIntensity: 0.18,
roughness: 0.38
})
);
scene.add(blueChannel);
const runoffParticles = [];
const runoffGeometry = new THREE.SphereGeometry(0.075, 10, 8);
for (let i = 0; i < 24; i++) {
const particle = new THREE.Mesh(
runoffGeometry,
new THREE.MeshBasicMaterial({
color: i % 3 === 0 ? 0xa8edf1 : 0x4ec5d0,
transparent: true,
opacity: 0.95
})
);
particle.userData.offset = i / 24;
scene.add(particle);
runoffParticles.push(particle);
}
const arrowGeometry = new THREE.ConeGeometry(0.13, 0.36, 8);
const up = new THREE.Vector3(0, 1, 0);
for (const t of [0.27, 0.53, 0.77]) {
const tangent = blueChannelCurve.getTangentAt(t).normalize();
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({ color: 0xc7f3f2 })
);
arrow.position.copy(blueChannelCurve.getPointAt(t));
arrow.position.y += 0.08;
arrow.quaternion.setFromUnitVectors(up, tangent);
scene.add(arrow);
}
// -------------------------------------------------------------------------
// Water surface and exposed water section
// -------------------------------------------------------------------------
const waterUniforms = {
uLevel: { value: -0.55 },
uTime: { value: 0 }
};
const terrainGLSL = `
float terrainHeight(vec2 p) {
float mountain =
4.45 * exp(
-pow((p.x + 4.65) / 1.78, 2.0) -
pow((p.y + 1.48) / 1.38, 2.0)
);
float rearRidge =
1.35 * exp(
-pow((p.x - 0.15) / 4.25, 2.0) -
pow((p.y + 3.25) / 1.22, 2.0)
);
float easternDivide =
0.82 * exp(
-pow((p.x - 6.35) / 1.42, 2.0) -
pow((p.y + 0.65) / 1.72, 2.0)
);
float basin =
2.38 * exp(
-pow((p.x - 1.1) / 3.2, 2.0) -
pow((p.y - 0.1) / 2.7, 2.0)
);
float texture =
0.045 * sin(p.x * 1.7 + p.y * 0.4) * cos(p.y * 1.35) +
0.025 * sin(p.x * 3.3 - p.y * 2.1);
return 0.86 + mountain + rearRidge + easternDivide - basin + texture;
}
`;
const waterVertex = `
varying vec3 vWorldPosition;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`;
const waterFragment = `
uniform float uLevel;
uniform float uTime;
varying vec3 vWorldPosition;
${terrainGLSL}
void main() {
float bed = terrainHeight(vWorldPosition.xz);
if (bed > uLevel) discard;
float depth = clamp((uLevel - bed) / 1.55, 0.0, 1.0);
float shoreline = smoothstep(0.0, 0.12, uLevel - bed);
vec3 shallow = vec3(0.24, 0.68, 0.70);
vec3 deep = vec3(0.025, 0.36, 0.48);
float ripple =
0.025 *
sin(vWorldPosition.x * 7.0 + uTime * 0.8) *
cos(vWorldPosition.z * 5.0 - uTime * 0.55);
vec3 color = mix(shallow, deep, smoothstep(0.08, 0.95, depth));
color += ripple;
gl_FragColor = vec4(color, shoreline * 0.82);
}
`;
const waterSurfaceMaterial = new THREE.ShaderMaterial({
uniforms: waterUniforms,
vertexShader: waterVertex,
fragmentShader: waterFragment,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const waterSurfaceGeometry = new THREE.PlaneGeometry(10.3, 5.2, 104, 60);
waterSurfaceGeometry.rotateX(-Math.PI / 2);
const waterSurface = new THREE.Mesh(
waterSurfaceGeometry,
waterSurfaceMaterial
);
waterSurface.position.set(1.0, -0.55, -0.2);
waterSurface.renderOrder = 3;
scene.add(waterSurface);
const waterCutFragment = `
uniform float uLevel;
uniform float uTime;
varying vec3 vWorldPosition;
${terrainGLSL}
void main() {
float bed = terrainHeight(vec2(vWorldPosition.x, ${Z_MAX.toFixed(1)}));
if (vWorldPosition.y < bed + 0.004 || vWorldPosition.y > uLevel) {
discard;
}
float depth = uLevel - vWorldPosition.y;
float band =
0.035 * sin(vWorldPosition.y * 24.0 - uTime * 0.7);
vec3 color = mix(
vec3(0.08, 0.55, 0.64),
vec3(0.025, 0.34, 0.45),
clamp(depth / 1.4, 0.0, 1.0)
);
gl_FragColor = vec4(color + band, 0.64);
}
`;
const waterCutMaterial = new THREE.ShaderMaterial({
uniforms: waterUniforms,
vertexShader: waterVertex,
fragmentShader: waterCutFragment,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const waterCut = new THREE.Mesh(
new THREE.PlaneGeometry(9.4, 3.6),
waterCutMaterial
);
waterCut.position.set(1.0, -0.15, Z_MAX + 0.014);
waterCut.renderOrder = 4;
scene.add(waterCut);
// -------------------------------------------------------------------------
// Ripples and evaporation vapor
// -------------------------------------------------------------------------
const ripples = [];
for (const [x, z, speed] of [
[0.85, -0.2, 0.24],
[2.35, -0.55, 0.18],
[1.65, 0.65, 0.21]
]) {
const material = new THREE.MeshBasicMaterial({
color: 0xd7ffff,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.28, 0.305, 48),
material
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(x, -0.54, z);
ripple.userData = { x, z, speed, offset: Math.random() };
scene.add(ripple);
ripples.push(ripple);
}
function createVaporTexture() {
const canvas = document.createElement("canvas");
canvas.width = 64;
canvas.height = 64;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
32,
32,
0,
32,
32,
31
);
gradient.addColorStop(0, "rgba(255,255,255,0.95)");
gradient.addColorStop(0.35, "rgba(225,247,246,0.55)");
gradient.addColorStop(1, "rgba(225,247,246,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 64, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const vaporTexture = createVaporTexture();
const vaporParticles = [];
for (let i = 0; i < 28; i++) {
const material = new THREE.SpriteMaterial({
map: vaporTexture,
color: 0xe9ffff,
transparent: true,
opacity: 0,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 5;
sprite.userData = {
x: THREE.MathUtils.lerp(-0.6, 3.6, Math.random()),
z: THREE.MathUtils.lerp(-1.25, 1.65, Math.random()),
offset: Math.random(),
speed: THREE.MathUtils.lerp(0.09, 0.17, Math.random()),
drift: THREE.MathUtils.lerp(0.12, 0.42, Math.random())
};
scene.add(sprite);
vaporParticles.push(sprite);
}
// Small conceptual dots show local infiltration and storage, not an outlet.
const infiltrationDots = [];
const infiltrationGeometry = new THREE.SphereGeometry(0.055, 8, 6);
for (let i = 0; i < 14; i++) {
const x = THREE.MathUtils.lerp(-1.45, 3.65, Math.random());
const dot = new THREE.Mesh(
infiltrationGeometry,
new THREE.MeshBasicMaterial({
color: 0x66c7d0,
transparent: true,
opacity: 0.65
})
);
dot.userData = {
x,
bed: terrainHeight(x, Z_MAX),
offset: Math.random()
};
dot.position.z = Z_MAX + 0.035;
scene.add(dot);
infiltrationDots.push(dot);
}
// -------------------------------------------------------------------------
// Projected HTML annotations
// -------------------------------------------------------------------------
const labelsRoot = document.getElementById("labels");
const leadersRoot = document.getElementById("leaders");
const labelDefinitions = [
{
title: "Mountain runoff",
detail: "Snowmelt feeds the channel",
className: "blue",
anchor: () => blueChannelCurve.getPointAt(0.25),
offset: [-108, -60]
},
{
title: "Closed low area",
detail: "Runoff spreads inward",
className: "blue",
anchor: () => new THREE.Vector3(1.0, waterLevel + 0.08, 0.0),
offset: [-55, 66]
},
{
title: "Evaporation",
detail: "Water returns to the atmosphere",
className: "",
anchor: () => new THREE.Vector3(1.3, waterLevel + 1.25, 0.0),
offset: [94, -35]
},
{
title: "No surface outlet",
detail: "No modeled route to the sea",
className: "orange",
anchor: () =>
new THREE.Vector3(
6.15,
terrainHeight(6.15, 0.85) + 0.2,
0.85
),
offset: [92, -48]
},
{
title: "Impermeable basin floor",
detail: "Local storage; the cut is not an opening",
className: "orange optional",
anchor: () => new THREE.Vector3(1.0, -1.72, Z_MAX + 0.03),
offset: [-15, 88]
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `label ${definition.className}`;
element.innerHTML = `
<strong>${definition.title}</strong>
<span>${definition.detail}</span>
`;
labelsRoot.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
leadersRoot.appendChild(line);
definition.element = element;
definition.line = line;
}
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.25, -0.55);
const cameraState = {
theta: 0.66,
phi: 1.02,
radius: 21.8,
desiredTheta: 0.66,
desiredPhi: 1.02,
desiredRadius: 21.8
};
function resetCamera() {
cameraState.desiredTheta = 0.66;
cameraState.desiredPhi = 1.02;
cameraState.desiredRadius =
innerWidth < 700 ? 25.5 : 21.8;
}
function updateCamera() {
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.desiredTheta,
0.085
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.desiredPhi,
0.085
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.desiredRadius,
0.09
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
const pointerMap = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
const previous = pointerMap.get(event.pointerId);
if (pointerMap.size === 1) {
cameraState.desiredTheta -=
(event.clientX - previous.x) * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi -
(event.clientY - previous.y) * 0.005,
0.5,
1.46
);
} else if (pointerMap.size === 2) {
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius *
(previousPinchDistance / distance),
13,
34
);
}
previousPinchDistance = distance;
return;
}
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) =>
event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
13,
34
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Water-balance modes
// -------------------------------------------------------------------------
let mode = "cycle";
let simulationTime = 0;
let waterLevel = -0.55;
let isRising = true;
let evaporationStrength = 0.65;
const modeButtons = [...document.querySelectorAll("[data-mode]")];
const phaseElement = document.getElementById("phase");
const levelElement = document.getElementById("level");
const meterElement = document.getElementById("meter");
for (const button of modeButtons) {
button.addEventListener("click", () => {
mode = button.dataset.mode;
for (const item of modeButtons) {
item.classList.toggle("active", item === button);
}
});
}
function smooth01(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updateWaterBalance(dt) {
simulationTime += dt;
if (mode === "cycle") {
const duration = 36;
const phase = simulationTime % duration;
if (phase < 22) {
isRising = true;
waterLevel = THREE.MathUtils.lerp(
-0.55,
0.12,
smooth01(phase / 22)
);
evaporationStrength = 0.52;
} else {
isRising = false;
waterLevel = THREE.MathUtils.lerp(
0.12,
-0.38,
smooth01((phase - 22) / 14)
);
evaporationStrength = 1.0;
}
} else if (mode === "accumulate") {
isRising = true;
const phase = simulationTime % 28;
waterLevel = THREE.MathUtils.lerp(
-0.55,
0.12,
smooth01(phase / 28)
);
evaporationStrength = 0.62;
} else {
isRising = false;
const phase = simulationTime % 28;
waterLevel = THREE.MathUtils.lerp(
0.12,
-0.46,
smooth01(phase / 28)
);
evaporationStrength = 1.0;
}
waterUniforms.uLevel.value = waterLevel;
waterSurface.position.y = waterLevel;
const normalized = THREE.MathUtils.clamp(
(waterLevel + 0.65) / 0.85,
0,
1
);
meterElement.style.setProperty("--fill", normalized.toFixed(3));
const signedLevel = `${waterLevel < 0 ? "−" : "+"}${Math.abs(
waterLevel
).toFixed(2)} m`;
levelElement.textContent = signedLevel;
const phaseText =
mode === "accumulate"
? "Accumulating"
: mode === "evaporate"
? "Evaporating"
: isRising
? "Accumulating"
: "Evaporating";
if (phaseElement.textContent !== phaseText) {
phaseElement.textContent = phaseText;
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateAnnotations() {
const width = innerWidth;
const height = innerHeight;
for (const definition of labelDefinitions) {
const anchor = definition.anchor().clone();
const projected = anchor.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const scale = width < 760 ? 0.65 : 1;
const labelX = THREE.MathUtils.clamp(
anchorX + definition.offset[0] * scale,
75,
width - 75
);
const labelY = THREE.MathUtils.clamp(
anchorY + definition.offset[1] * scale,
95,
height - 85
);
definition.element.style.left = `${labelX}px`;
definition.element.style.top = `${labelY}px`;
definition.element.style.display = visible ? "block" : "none";
definition.line.setAttribute("x1", anchorX);
definition.line.setAttribute("y1", anchorY);
definition.line.setAttribute("x2", labelX);
definition.line.setAttribute("y2", labelY);
definition.line.style.display = visible ? "block" : "none";
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateWaterBalance(dt);
updateCamera();
waterUniforms.uTime.value = time;
const runoffSpeed = isRising ? 0.072 : 0.045;
for (const particle of runoffParticles) {
const t = (time * runoffSpeed + particle.userData.offset) % 1;
const point = blueChannelCurve.getPointAt(t);
point.y = terrainHeight(point.x, point.z) + 0.22;
particle.position.copy(point);
particle.material.opacity =
isRising ? 0.95 : 0.55 + 0.25 * Math.sin(time * 2 + t * 9);
}
for (const ripple of ripples) {
const p = (time * ripple.userData.speed + ripple.userData.offset) % 1;
ripple.position.y = waterLevel + 0.025;
ripple.scale.setScalar(0.7 + p * 2.6);
ripple.material.opacity = (1 - p) * 0.25;
}
for (const sprite of vaporParticles) {
const p = (time * sprite.userData.speed + sprite.userData.offset) % 1;
const lateral =
Math.sin(time * 0.7 + sprite.userData.offset * 12) *
sprite.userData.drift;
sprite.position.set(
sprite.userData.x + lateral * p,
waterLevel + 0.08 + p * 2.35,
sprite.userData.z + Math.cos(time * 0.5 + p * 4) * 0.12
);
const size = 0.25 + p * 0.85;
sprite.scale.set(size, size * 1.35, 1);
sprite.material.opacity =
Math.sin(Math.PI * p) * 0.42 * evaporationStrength;
}
for (const dot of infiltrationDots) {
const p = (time * 0.12 + dot.userData.offset) % 1;
dot.position.x = dot.userData.x;
dot.position.y = dot.userData.bed - 0.04 - p * 0.72;
dot.material.opacity = (1 - p) * 0.68;
}
updateAnnotations();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
leadersRoot.setAttribute("viewBox", `0 0 ${innerWidth} ${innerHeight}`);
}
addEventListener("resize", resize);
resize();
updateCamera();
animate();
</script>
</body>
</html>
```