Prompt specification
Build or customize the Three.js 3D scene "Delta distributary relief tile" 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: Delta distributary relief tile
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/delta-distributary-relief-tile-x1129
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing river deltas and distributaries. Sculpt a triangular sediment plain with several shallow branching channels entering a calm basin; show channel mouths and coastline as distinct connected geometric features. Low-poly.
Working Three.js Starter (delta-distributary-relief-tile-x1129):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Low-Poly River Delta</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bb9b9;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #f6f2df;
text-shadow: 0 2px 12px rgba(17, 35, 34, 0.5);
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
padding: 15px 18px 14px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 12px;
background: rgba(27, 53, 51, 0.57);
box-shadow: 0 12px 32px rgba(25, 45, 43, 0.15);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 5px;
color: #b9d6c8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
font-weight: 680;
letter-spacing: -0.035em;
line-height: 1;
}
.subtitle {
margin-top: 8px;
color: rgba(246, 242, 223, 0.72);
font-size: 12px;
}
.legend {
position: absolute;
left: 24px;
bottom: 24px;
display: grid;
gap: 8px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 11px;
background: rgba(27, 53, 51, 0.52);
backdrop-filter: blur(10px);
font-size: 11px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: rgba(246, 242, 223, 0.9);
}
.swatch {
width: 17px;
height: 8px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 10px;
background: rgba(27, 53, 51, 0.52);
color: rgba(246, 242, 223, 0.82);
backdrop-filter: blur(10px);
font-size: 11px;
letter-spacing: 0.01em;
}
button {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 7px;
margin-left: 10px;
padding: 6px 10px;
color: #f6f2df;
background: rgba(255, 255, 255, 0.08);
font: inherit;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.16);
}
@media (max-width: 640px) {
.title-card {
top: 14px;
left: 14px;
right: 14px;
}
.subtitle {
display: none;
}
.legend {
left: 14px;
bottom: 14px;
}
.controls {
right: 14px;
bottom: 14px;
max-width: 180px;
text-align: right;
}
.controls .desktop {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Procedural coastal study</div>
<h1>Sediment Delta</h1>
<div class="subtitle">Branching distributaries entering a calm depositional basin</div>
</section>
<section class="legend">
<div class="legend-row">
<span class="swatch" style="background:#8f9a68"></span>
<span>Triangular sediment plain</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#4d99a1"></span>
<span>Active channels</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#d5bd83"></span>
<span>Channel banks and coastline</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#5f8f96"></span>
<span>Calm basin</span>
</div>
</section>
<div class="controls">
<span class="desktop">Drag to orbit · wheel to zoom</span>
<span class="desktop">Double-click to reset</span>
<button id="reset" type="button">Reset view</button>
</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 setup
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bb9b9);
scene.fog = new THREE.Fog(0x9bb9b9, 48, 92);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
160
);
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe8f1df, 0x526455, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8bc, 3.1);
sun.position.set(-18, 31, -9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fc8c4, 0.8);
fill.position.set(24, 12, 22);
scene.add(fill);
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(min, max, value) {
const t = clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function seededRandom(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(73421);
function signedArea(polygon) {
let area = 0;
for (let i = 0; i < polygon.length; i++) {
const a = polygon[i];
const b = polygon[(i + 1) % polygon.length];
area += a.x * b.z - b.x * a.z;
}
return area;
}
function cross2(a, b, c) {
return (b.x - a.x) * (c.z - a.z) -
(b.z - a.z) * (c.x - a.x);
}
// Clip a polygon against a convex polygon in the X/Z plane.
function clipToConvex(subject, clipPolygon) {
const orientation = signedArea(clipPolygon) >= 0 ? 1 : -1;
let output = subject.slice();
for (let i = 0; i < clipPolygon.length && output.length; i++) {
const a = clipPolygon[i];
const b = clipPolygon[(i + 1) % clipPolygon.length];
const input = output;
output = [];
let s = input[input.length - 1];
let sInside = orientation * cross2(a, b, s) >= -0.00001;
for (const e of input) {
const eInside = orientation * cross2(a, b, e) >= -0.00001;
if (eInside !== sInside) {
const ds = cross2(a, b, s);
const de = cross2(a, b, e);
const t = ds / (ds - de);
output.push({
x: lerp(s.x, e.x, t),
z: lerp(s.z, e.z, t)
});
}
if (eInside) {
output.push(e);
}
s = e;
sInside = eInside;
}
}
return output;
}
function addTriangle(positions, colors, a, b, c, color) {
// Force upward-facing triangles for terrain and water surfaces.
const ab = b.clone().sub(a);
const ac = c.clone().sub(a);
if (ab.cross(ac).y < 0) {
const temp = b;
b = c;
c = temp;
}
positions.push(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
if (color) {
colors.push(
color.r, color.g, color.b,
color.r, color.g, color.b,
color.r, color.g, color.b
);
}
}
function makeFacetedGeometry(positions, colors) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
if (colors.length) {
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
}
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function coastZ(x) {
return 10.45 +
0.38 * Math.sin(x * 0.48) +
0.18 * Math.sin(x * 1.31 + 0.4);
}
function waterHeight(z) {
const t = clamp((z + 18) / 26, 0, 1);
return 0.035 + 1.08 * Math.pow(1 - t, 1.12);
}
// ---------------------------------------------------------------------
// River network
// ---------------------------------------------------------------------
const pathDefinitions = [
{
name: "Main trunk",
startWidth: 0.52,
endWidth: 1.25,
points: [
[0.0, -17.6],
[-0.5, -13.5],
[0.8, -9.7],
[-0.5, -5.2],
[1.2, -1.5],
[0.4, 2.2],
[1.4, 5.7],
[0.2, coastZ(0.2)]
]
},
{
name: "Western distributary",
startWidth: 0.29,
endWidth: 1.05,
points: [
[-0.5, -5.2],
[-4.4, -3.1],
[-7.4, 0.0],
[-8.6, 3.4],
[-10.4, 7.0],
[-12.4, coastZ(-12.4)]
]
},
{
name: "Eastern distributary",
startWidth: 0.31,
endWidth: 1.1,
points: [
[1.2, -1.5],
[4.3, -0.6],
[6.9, 2.0],
[8.2, 5.2],
[10.1, coastZ(10.1)]
]
},
{
name: "Central distributary",
startWidth: 0.27,
endWidth: 0.92,
points: [
[0.4, 2.2],
[-2.4, 3.5],
[-4.0, 5.7],
[-4.8, coastZ(-4.8)]
]
}
];
const sampledPaths = pathDefinitions.map((definition) => {
const curve = new THREE.CatmullRomCurve3(
definition.points.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.28
);
const divisions = Math.max(22, definition.points.length * 4);
const points = curve.getSpacedPoints(divisions);
return {
...definition,
samples: points.map((point, index) => {
const t = index / divisions;
const widthT = smoothstep(0, 1, t);
return {
x: point.x,
z: point.z,
y: waterHeight(point.z),
width: lerp(definition.startWidth, definition.endWidth, widthT)
};
})
};
});
const channelSegments = [];
for (const path of sampledPaths) {
for (let i = 0; i < path.samples.length - 1; i++) {
channelSegments.push({
a: path.samples[i],
b: path.samples[i + 1]
});
}
}
function nearestChannel(x, z) {
let bestScore = Infinity;
let bestDistance = 0;
let bestWidth = 0;
let bestY = 0;
for (const segment of channelSegments) {
const dx = segment.b.x - segment.a.x;
const dz = segment.b.z - segment.a.z;
const lengthSquared = dx * dx + dz * dz;
const u = lengthSquared > 0
? clamp(
((x - segment.a.x) * dx + (z - segment.a.z) * dz) /
lengthSquared,
0,
1
)
: 0;
const px = segment.a.x + dx * u;
const pz = segment.a.z + dz * u;
const distance = Math.hypot(x - px, z - pz);
const width = lerp(segment.a.width, segment.b.width, u);
const y = lerp(segment.a.y, segment.b.y, u);
const score = distance - width;
if (score < bestScore) {
bestScore = score;
bestDistance = distance;
bestWidth = width;
bestY = y;
}
}
return {
distance: bestDistance,
width: bestWidth,
waterY: bestY,
edgeDistance: bestDistance - bestWidth
};
}
function terrainHeight(x, z) {
const t = clamp((z + 18) / 26, 0, 1);
let base = 0.18 + 1.45 * Math.pow(1 - t, 1.12);
// Outside the coastal front, the procedural surface grades into the sea.
if (z > 8) {
base = lerp(0.18, 0.015, smoothstep(8, 11.2, z));
}
const noise =
Math.sin(x * 1.12 + z * 0.63) * 0.065 +
Math.sin(z * 2.05 - x * 0.38) * 0.032 +
Math.cos(x * 0.47 - z * 1.21) * 0.025;
base += noise * (0.35 + 0.65 * (1 - t));
// Gently lower the two sides of the triangular plain.
const halfWidth = Math.max(0.01, 21 * t);
const crossSection = clamp(Math.abs(x) / halfWidth, 0, 1);
if (t > 0.05) {
base *= 1 - 0.48 * Math.pow(crossSection, 3.4);
base += 0.075 * Math.sin(Math.PI * crossSection) * (1 - t);
}
const channel = nearestChannel(x, z);
if (channel.edgeDistance < 0.46) {
const carve = 1 - smoothstep(
channel.width,
channel.width + 0.46,
channel.distance
);
const channelBed = channel.waterY - 0.17;
base = lerp(base, Math.min(base, channelBed), carve);
}
return Math.max(0.008, base);
}
// ---------------------------------------------------------------------
// Calm faceted basin
// ---------------------------------------------------------------------
const basinPolygon = [];
const basinSegments = 40;
for (let i = 0; i < basinSegments; i++) {
const angle = i / basinSegments * Math.PI * 2;
basinPolygon.push({
x: Math.cos(angle) * 31,
z: 21 + Math.sin(angle) * 19
});
}
const seaPositions = [];
const seaColors = [];
const seaLow = new THREE.Color(0x477f89);
const seaHigh = new THREE.Color(0x6ca0a1);
const seaFaceColor = new THREE.Color();
for (let x = -35; x < 35; x += 3.5) {
for (let z = -2; z < 43; z += 3.5) {
const cells = [
[
{ x, z },
{ x: x + 3.5, z },
{ x, z: z + 3.5 }
],
[
{ x: x + 3.5, z },
{ x: x + 3.5, z: z + 3.5 },
{ x, z: z + 3.5 }
]
];
for (const cell of cells) {
const clipped = clipToConvex(cell, basinPolygon);
if (clipped.length < 3) continue;
for (let i = 1; i < clipped.length - 1; i++) {
const a = new THREE.Vector3(clipped[0].x, 0, clipped[0].z);
const b = new THREE.Vector3(clipped[i].x, 0, clipped[i].z);
const c = new THREE.Vector3(clipped[i + 1].x, 0, clipped[i + 1].z);
const mix = 0.43 + random() * 0.32;
seaFaceColor.copy(seaLow).lerp(seaHigh, mix);
seaFaceColor.multiplyScalar(0.96 + random() * 0.08);
addTriangle(seaPositions, seaColors, a, b, c, seaFaceColor);
}
}
}
}
const seaGeometry = makeFacetedGeometry(seaPositions, seaColors);
const seaMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.38,
metalness: 0.04,
transparent: true,
opacity: 0.98,
flatShading: true
});
const basin = new THREE.Mesh(seaGeometry, seaMaterial);
basin.receiveShadow = true;
scene.add(basin);
// ---------------------------------------------------------------------
// Triangular, carved sediment plain
// ---------------------------------------------------------------------
const deltaPolygon = [
{ x: 0, z: -18 },
{ x: 21, z: 8 },
{ x: -21, z: 8 }
];
const terrainPositions = [];
const terrainColors = [];
const dryLow = new THREE.Color(0xc4b37b);
const dryHigh = new THREE.Color(0x7d9066);
const bankSand = new THREE.Color(0xd4c28c);
const terrainFaceColor = new THREE.Color();
const terrainStep = 0.8;
for (let x = -21; x < 21; x += terrainStep) {
for (let z = -18; z < 8; z += terrainStep) {
const cells = [
[
{ x, z },
{ x: x + terrainStep, z },
{ x, z: z + terrainStep }
],
[
{ x: x + terrainStep, z },
{ x: x + terrainStep, z: z + terrainStep },
{ x, z: z + terrainStep }
]
];
for (const cell of cells) {
const clipped = clipToConvex(cell, deltaPolygon);
if (clipped.length < 3) continue;
for (let i = 1; i < clipped.length - 1; i++) {
const p0 = clipped[0];
const p1 = clipped[i];
const p2 = clipped[i + 1];
const centerX = (p0.x + p1.x + p2.x) / 3;
const centerZ = (p0.z + p1.z + p2.z) / 3;
const centerY = terrainHeight(centerX, centerZ);
const a = new THREE.Vector3(p0.x, terrainHeight(p0.x, p0.z), p0.z);
const b = new THREE.Vector3(p1.x, terrainHeight(p1.x, p1.z), p1.z);
const c = new THREE.Vector3(p2.x, terrainHeight(p2.x, p2.z), p2.z);
const heightMix = clamp(centerY / 1.5, 0, 1);
terrainFaceColor.copy(dryLow).lerp(dryHigh, heightMix);
const channel = nearestChannel(centerX, centerZ);
if (channel.edgeDistance < 0.58) {
terrainFaceColor.lerp(
bankSand,
1 - smoothstep(0.05, 0.58, channel.edgeDistance)
);
}
terrainFaceColor.multiplyScalar(0.94 + random() * 0.12);
addTriangle(
terrainPositions,
terrainColors,
a,
b,
c,
terrainFaceColor
);
}
}
}
}
const terrainGeometry = makeFacetedGeometry(terrainPositions, terrainColors);
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.91,
metalness: 0,
flatShading: true
});
const delta = new THREE.Mesh(terrainGeometry, terrainMaterial);
delta.castShadow = true;
delta.receiveShadow = true;
scene.add(delta);
// ---------------------------------------------------------------------
// Continuous channel surfaces and raised pale bank ribbons
// ---------------------------------------------------------------------
const channelPositions = [];
const channelColors = [];
const channelLow = new THREE.Color(0x347f8a);
const channelHigh = new THREE.Color(0x68adb0);
const channelFaceColor = new THREE.Color();
const bankPositions = [];
const bankColors = [];
const bankLow = new THREE.Color(0xc5ad73);
const bankHigh = new THREE.Color(0xe0cf99);
const bankFaceColor = new THREE.Color();
function pathNormal(samples, index) {
const previous = samples[Math.max(0, index - 1)];
const next = samples[Math.min(samples.length - 1, index + 1)];
const tx = next.x - previous.x;
const tz = next.z - previous.z;
const length = Math.hypot(tx, tz) || 1;
return {
x: -tz / length,
z: tx / length
};
}
for (const path of sampledPaths) {
const samples = path.samples;
// Faceted water ribbon.
for (let i = 0; i < samples.length - 1; i++) {
const p0 = samples[i];
const p1 = samples[i + 1];
const n0 = pathNormal(samples, i);
const n1 = pathNormal(samples, i + 1);
const a = new THREE.Vector3(
p0.x + n0.x * p0.width,
p0.y,
p0.z + n0.z * p0.width
);
const b = new THREE.Vector3(
p0.x - n0.x * p0.width,
p0.y,
p0.z - n0.z * p0.width
);
const c = new THREE.Vector3(
p1.x + n1.x * p1.width,
p1.y,
p1.z + n1.z * p1.width
);
const d = new THREE.Vector3(
p1.x - n1.x * p1.width,
p1.y,
p1.z - n1.z * p1.width
);
channelFaceColor.copy(channelLow).lerp(
channelHigh,
0.35 + random() * 0.5
);
addTriangle(channelPositions, channelColors, a, b, c, channelFaceColor);
addTriangle(channelPositions, channelColors, b, d, c, channelFaceColor);
}
// Two separate bank strips hug each channel and visually meet the coast.
for (const side of [1, -1]) {
for (let i = 0; i < samples.length - 1; i++) {
const p0 = samples[i];
const p1 = samples[i + 1];
const n0 = pathNormal(samples, i);
const n1 = pathNormal(samples, i + 1);
const inner0 = new THREE.Vector3(
p0.x + n0.x * (p0.width + 0.035) * side,
0,
p0.z + n0.z * (p0.width + 0.035) * side
);
const outer0 = new THREE.Vector3(
p0.x + n0.x * (p0.width + 0.34) * side,
0,
p0.z + n0.z * (p0.width + 0.34) * side
);
const inner1 = new THREE.Vector3(
p1.x + n1.x * (p1.width + 0.035) * side,
0,
p1.z + n1.z * (p1.width + 0.035) * side
);
const outer1 = new THREE.Vector3(
p1.x + n1.x * (p1.width + 0.34) * side,
0,
p1.z + n1.z * (p1.width + 0.34) * side
);
inner0.y = Math.max(
p0.y + 0.012,
terrainHeight(inner0.x, inner0.z) + 0.024
);
inner1.y = Math.max(
p1.y + 0.012,
terrainHeight(inner1.x, inner1.z) + 0.024
);
outer0.y = terrainHeight(outer0.x, outer0.z) + 0.024;
outer1.y = terrainHeight(outer1.x, outer1.z) + 0.024;
bankFaceColor.copy(bankLow).lerp(
bankHigh,
0.25 + random() * 0.7
);
addTriangle(
bankPositions,
bankColors,
inner0,
outer0,
inner1,
bankFaceColor
);
addTriangle(
bankPositions,
bankColors,
outer0,
outer1,
inner1,
bankFaceColor
);
}
}
}
const channelGeometry = makeFacetedGeometry(
channelPositions,
channelColors
);
const channelMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.26,
metalness: 0.08,
transparent: true,
opacity: 0.96,
flatShading: true,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const channels = new THREE.Mesh(channelGeometry, channelMaterial);
channels.castShadow = true;
channels.receiveShadow = true;
scene.add(channels);
const bankGeometry = makeFacetedGeometry(bankPositions, bankColors);
const bankMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.88,
metalness: 0,
flatShading: true,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const banks = new THREE.Mesh(bankGeometry, bankMaterial);
banks.castShadow = true;
banks.receiveShadow = true;
scene.add(banks);
// ---------------------------------------------------------------------
// Distinct connected coastal shelf, interrupted by channel mouths
// ---------------------------------------------------------------------
const mouths = sampledPaths.map((path) => {
const endpoint = path.samples[path.samples.length - 1];
return {
x: endpoint.x,
z: endpoint.z,
width: endpoint.width
};
});
const gaps = mouths
.map((mouth) => ({
left: mouth.x - mouth.width * 0.9 - 0.28,
right: mouth.x + mouth.width * 0.9 + 0.28
}))
.sort((a, b) => a.left - b.left);
const coastPieces = [];
let coastStart = -21;
for (const gap of gaps) {
if (gap.left > coastStart) {
coastPieces.push([coastStart, gap.left]);
}
coastStart = Math.max(coastStart, gap.right);
}
if (coastStart < 21) {
coastPieces.push([coastStart, 21]);
}
const coastPositions = [];
const coastColors = [];
const coastLow = new THREE.Color(0xb9a56f);
const coastHigh = new THREE.Color(0xdfcb91);
const coastFaceColor = new THREE.Color();
for (const [pieceStart, pieceEnd] of coastPieces) {
const subdivisions = Math.max(1, Math.ceil((pieceEnd - pieceStart) / 1.8));
for (let i = 0; i < subdivisions; i++) {
const x0 = lerp(pieceStart, pieceEnd, i / subdivisions);
const x1 = lerp(pieceStart, pieceEnd, (i + 1) / subdivisions);
const inner0 = new THREE.Vector3(x0, 0.185, 8);
const inner1 = new THREE.Vector3(x1, 0.185, 8);
const outer0 = new THREE.Vector3(x0, 0.018, coastZ(x0));
const outer1 = new THREE.Vector3(x1, 0.018, coastZ(x1));
coastFaceColor.copy(coastLow).lerp(
coastHigh,
0.2 + random() * 0.72
);
addTriangle(
coastPositions,
coastColors,
inner0,
outer0,
inner1,
coastFaceColor
);
addTriangle(
coastPositions,
coastColors,
outer0,
outer1,
inner1,
coastFaceColor
);
}
}
const coastGeometry = makeFacetedGeometry(coastPositions, coastColors);
const coastMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.86,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
const coastline = new THREE.Mesh(coastGeometry, coastMaterial);
coastline.castShadow = true;
coastline.receiveShadow = true;
scene.add(coastline);
// ---------------------------------------------------------------------
// Subtle silt plumes at the connected channel mouths
// ---------------------------------------------------------------------
const plumeMaterials = [];
for (const mouth of mouths) {
const positions = [];
const colors = [];
const plumeColor = new THREE.Color(0x8eafa0);
const y = 0.012;
const start = new THREE.Vector3(mouth.x, y, mouth.z + 0.1);
const left = new THREE.Vector3(
mouth.x - mouth.width * 0.72,
y,
mouth.z + 0.35
);
const farLeft = new THREE.Vector3(
mouth.x - mouth.width * 1.55,
y,
mouth.z + 3.1
);
const farRight = new THREE.Vector3(
mouth.x + mouth.width * 1.55,
y,
mouth.z + 3.35
);
const right = new THREE.Vector3(
mouth.x + mouth.width * 0.72,
y,
mouth.z + 0.35
);
addTriangle(positions, colors, start, left, farLeft, plumeColor);
addTriangle(positions, colors, start, farLeft, farRight, plumeColor);
addTriangle(positions, colors, start, farRight, right, plumeColor);
const geometry = makeFacetedGeometry(positions, colors);
const material = new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.3,
depthWrite: false,
side: THREE.DoubleSide
});
plumeMaterials.push(material);
scene.add(new THREE.Mesh(geometry, material));
}
// ---------------------------------------------------------------------
// Sparse, quiet basin ripples
// ---------------------------------------------------------------------
const ripplePositions = [];
for (let i = 0; i < 55; i++) {
const x = lerp(-27, 27, random());
const z = lerp(12, 37, random());
const ellipseValue =
(x * x) / (29 * 29) +
((z - 21) * (z - 21)) / (17.5 * 17.5);
if (ellipseValue > 0.92) continue;
const length = lerp(0.8, 2.7, random());
ripplePositions.push(
x, 0.027, z,
x + length, 0.027, z + lerp(-0.12, 0.12, random())
);
}
const rippleGeometry = new THREE.BufferGeometry();
rippleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(ripplePositions, 3)
);
const rippleMaterial = new THREE.LineBasicMaterial({
color: 0xd0e3d8,
transparent: true,
opacity: 0.19,
depthWrite: false
});
scene.add(new THREE.LineSegments(rippleGeometry, rippleMaterial));
// ---------------------------------------------------------------------
// Custom camera controls
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.25, 4.8),
radius: 48,
yaw: 0.56,
polar: 0.92,
minRadius: 25,
maxRadius: 76,
minPolar: 0.32,
maxPolar: 1.38
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x +
controls.radius * sinPolar * Math.sin(controls.yaw),
controls.target.y +
controls.radius * Math.cos(controls.polar),
controls.target.z +
controls.radius * sinPolar * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.radius = 48;
controls.yaw = 0.56;
controls.polar = 0.92;
controls.target.set(0, 0.25, 4.8);
updateCamera();
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
let previousPointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
previousPointer = {
x: event.clientX,
y: event.clientY
};
}
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && previousPointer) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
controls.yaw -= dx * 0.0055;
controls.polar = clamp(
controls.polar - dy * 0.0045,
controls.minPolar,
controls.maxPolar
);
previousPointer = {
x: event.clientX,
y: event.clientY
};
updateCamera();
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
controls.radius = clamp(
controls.radius *
(previousPinchDistance / Math.max(distance, 1)),
controls.minRadius,
controls.maxRadius
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
previousPointer = null;
previousPinchDistance = 0;
} else if (pointers.size === 1) {
const only = [...pointers.values()][0];
previousPointer = { x: only.x, y: only.y };
previousPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
controls.radius = clamp(
controls.radius * factor,
controls.minRadius,
controls.maxRadius
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Barely perceptible breathing of the silt plumes.
plumeMaterials.forEach((material, index) => {
material.opacity =
0.27 + Math.sin(elapsed * 0.45 + index * 1.7) * 0.035;
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```