Prompt specification
Build or customize the Three.js 3D scene "Tree Canopy Shadow on a Bench" 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: Tree Canopy Shadow on a Bench
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tree-canopy-shadow-on-a-bench-x3969
Scene Description Prompt:
A stylized tree casts its actual canopy shadow across a bench as sunlight direction changes. Three.js from cdnjs, one HTML file.
Working Three.js Starter (tree-canopy-shadow-on-a-bench-x3969):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Sun & Shade — Canopy Shadow Study</title>
<style>
:root {
color-scheme: light;
--ink: #17342d;
--muted: #58716a;
--glass: rgba(250, 253, 246, 0.84);
--line: rgba(35, 73, 61, 0.14);
--accent: #e9983f;
--accent-dark: #c97525;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdedf;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #41675d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.sun-mark {
position: relative;
width: 16px;
height: 16px;
border-radius: 50%;
background: #f4ad4d;
box-shadow: 0 0 0 4px rgba(244, 173, 77, 0.18);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 58px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
text-shadow: 0 2px 18px rgba(255, 255, 255, 0.28);
}
.subtitle {
max-width: 330px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.badge {
position: fixed;
top: 28px;
right: 28px;
z-index: 5;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--glass);
box-shadow: 0 10px 32px rgba(31, 65, 55, 0.08);
backdrop-filter: blur(12px);
color: #41665c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #62a769;
box-shadow: 0 0 0 4px rgba(98, 167, 105, 0.13);
}
.panel {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 6;
width: min(350px, calc(100vw - 48px));
padding: 18px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--glass);
box-shadow:
0 18px 50px rgba(35, 65, 54, 0.14),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(16px) saturate(1.15);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.live {
color: #5b8a62;
font-size: 9px;
letter-spacing: 0.13em;
}
.control {
margin-top: 14px;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: #3e5d54;
font-size: 12px;
font-weight: 700;
}
output {
min-width: 48px;
padding: 3px 7px;
border-radius: 7px;
background: rgba(255, 255, 255, 0.65);
color: #9d5c21;
text-align: center;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
90deg,
rgba(226, 146, 59, 0.85),
rgba(80, 127, 103, 0.55)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fffaf0;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 8px rgba(100, 63, 27, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #fffaf0;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(100, 63, 27, 0.25);
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
margin-top: 17px;
}
button {
min-height: 40px;
border: 0;
border-radius: 11px;
padding: 0 14px;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
color 150ms ease;
}
button:hover {
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#animate {
color: white;
background: var(--ink);
}
#animate[aria-pressed="true"] {
color: #6f461c;
background: #f5c681;
}
#reset {
color: #49665e;
background: rgba(44, 82, 70, 0.09);
}
.hint {
position: fixed;
right: 26px;
bottom: 28px;
z-index: 5;
color: rgba(31, 62, 53, 0.64);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
#error {
position: fixed;
inset: 0;
z-index: 20;
display: none;
place-items: center;
padding: 30px;
background: #d8e6df;
text-align: center;
}
@media (max-width: 650px) {
.brand {
top: 20px;
left: 20px;
}
.subtitle,
.badge,
.hint {
display: none;
}
.panel {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 15px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="brand">
<div class="eyebrow">
<span class="sun-mark"></span>
Sun & Shade
</div>
<h1>Canopy<br />Shadow Study</h1>
<p class="subtitle">
Move the sunlight and watch the tree's real projected shadow travel
across the wooden bench.
</p>
</header>
<div class="badge">Real-time shadow map</div>
<section class="panel" aria-label="Sunlight controls">
<div class="panel-title">
<span>Directional light</span>
<span class="live">Live projection</span>
</div>
<div class="control">
<div class="control-row">
<label for="azimuth">Sun azimuth</label>
<output id="azimuthValue" for="azimuth">165°</output>
</div>
<input
id="azimuth"
type="range"
min="90"
max="230"
step="1"
value="165"
/>
</div>
<div class="control">
<div class="control-row">
<label for="elevation">Sun elevation</label>
<output id="elevationValue" for="elevation">36°</output>
</div>
<input
id="elevation"
type="range"
min="15"
max="75"
step="1"
value="36"
/>
</div>
<div class="actions">
<button id="animate" type="button" aria-pressed="false">
Animate sunlight
</button>
<button id="reset" type="button">Reset</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div id="error">
<div>
<h2>WebGL is unavailable</h2>
<p>This scene needs a browser with WebGL enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const errorPanel = document.querySelector("#error");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
errorPanel.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9dde0);
scene.fog = new THREE.Fog(0xc9dde0, 24, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Direct camera controls, implemented without addons.
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.45, 1.7, -0.45);
const desiredCamera = {
theta: 0.56,
phi: 1.14,
radius: 13.6
};
const currentCamera = { ...desiredCamera };
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-12 * dt);
currentCamera.theta = THREE.MathUtils.lerp(
currentCamera.theta,
desiredCamera.theta,
smoothing
);
currentCamera.phi = THREE.MathUtils.lerp(
currentCamera.phi,
desiredCamera.phi,
smoothing
);
currentCamera.radius = THREE.MathUtils.lerp(
currentCamera.radius,
desiredCamera.radius,
smoothing
);
const sinPhi = Math.sin(currentCamera.phi);
const cosPhi = Math.cos(currentCamera.phi);
camera.position.set(
cameraTarget.x +
currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
cameraTarget.y + currentCamera.radius * cosPhi,
cameraTarget.z +
currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(cameraTarget);
}
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.38,
1.43
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
7,
23
);
},
{ passive: false }
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xe3f5ff,
0x71805f,
1.35
);
scene.add(hemisphere);
const sunTarget = new THREE.Vector3(0, 0.65, 0);
const sunDirection = new THREE.Vector3();
const sun = new THREE.DirectionalLight(0xffedc4, 3.8);
sun.castShadow = true;
sun.target.position.copy(sunTarget);
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 46;
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.018;
sun.shadow.camera.updateProjectionMatrix();
scene.add(sun, sun.target);
const state = {
azimuth: 165,
elevation: 36,
animated: false,
phase: 0
};
function updateSun() {
const azimuth = THREE.MathUtils.degToRad(state.azimuth);
const elevation = THREE.MathUtils.degToRad(state.elevation);
const horizontal = Math.cos(elevation);
sunDirection.set(
Math.cos(azimuth) * horizontal,
Math.sin(elevation),
Math.sin(azimuth) * horizontal
);
sun.position.copy(sunTarget).addScaledVector(sunDirection, 19);
sun.target.position.copy(sunTarget);
sun.target.updateMatrixWorld();
}
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const islandMaterial = new THREE.MeshStandardMaterial({
color: 0xaecb98,
roughness: 1
});
const distantGroundMaterial = new THREE.MeshStandardMaterial({
color: 0xb9cfa9,
roughness: 1
});
const mulchMaterial = new THREE.MeshStandardMaterial({
color: 0x806246,
roughness: 1
});
const barkMaterial = new THREE.MeshStandardMaterial({
color: 0x785036,
roughness: 0.95,
flatShading: true
});
const barkLightMaterial = new THREE.MeshStandardMaterial({
color: 0x936743,
roughness: 0.95,
flatShading: true
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xc97943,
roughness: 0.72
});
const woodDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xa95e35,
roughness: 0.78
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x304b46,
roughness: 0.56,
metalness: 0.28
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4e8c50,
roughness: 0.92,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x61a15a,
roughness: 0.92,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x397647,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x76ad60,
roughness: 0.92,
flatShading: true
})
];
function shadowMesh(geometry, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function rodBetween(
start,
end,
bottomRadius,
topRadius,
material,
segments = 9
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = shadowMesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
length,
segments
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// ------------------------------------------------------------
// Ground and diorama
// ------------------------------------------------------------
const distantGround = shadowMesh(
new THREE.PlaneGeometry(80, 80),
distantGroundMaterial,
false,
true
);
distantGround.rotation.x = -Math.PI / 2;
distantGround.position.y = -0.31;
scene.add(distantGround);
const island = shadowMesh(
new THREE.CylinderGeometry(8.2, 8.35, 0.3, 72),
islandMaterial,
false,
true
);
island.position.y = -0.15;
scene.add(island);
const mulch = shadowMesh(
new THREE.CylinderGeometry(1.25, 1.3, 0.08, 40),
mulchMaterial,
false,
true
);
mulch.position.set(-2.8, 0.045, 0.05);
scene.add(mulch);
// ------------------------------------------------------------
// Stylized tree
// ------------------------------------------------------------
const tree = new THREE.Group();
tree.position.set(-2.8, 0.08, 0.05);
scene.add(tree);
const trunk = shadowMesh(
new THREE.CylinderGeometry(0.23, 0.43, 3.45, 10),
barkMaterial
);
trunk.position.y = 1.73;
tree.add(trunk);
tree.add(
rodBetween(
[0.02, 2.1, 0],
[-0.72, 3.45, -0.2],
0.14,
0.075,
barkLightMaterial
),
rodBetween(
[0.04, 2.35, 0.02],
[0.86, 3.58, 0.12],
0.13,
0.065,
barkMaterial
),
rodBetween(
[0.02, 2.45, 0.02],
[0.12, 3.75, -0.78],
0.11,
0.055,
barkLightMaterial
),
rodBetween(
[0.02, 2.4, 0],
[-0.25, 3.6, 0.78],
0.11,
0.055,
barkMaterial
),
rodBetween(
[-0.56, 3.18, -0.12],
[-0.92, 4.15, -0.3],
0.07,
0.035,
barkLightMaterial
),
rodBetween(
[0.63, 3.35, 0.08],
[0.93, 4.12, 0.3],
0.07,
0.035,
barkLightMaterial
)
);
const canopyGeometry = new THREE.IcosahedronGeometry(1, 1);
const canopyPieces = [
[-0.78, 3.55, 0.02, 1.00, 0.92, 0.98, 0],
[-0.05, 4.12, -0.12, 1.18, 1.12, 1.02, 1],
[0.78, 3.62, 0.08, 1.04, 0.92, 0.94, 2],
[-0.08, 3.25, -0.63, 0.91, 0.80, 0.82, 1],
[0.28, 3.35, 0.63, 0.98, 0.84, 0.86, 0],
[-0.96, 4.13, -0.28, 0.77, 0.71, 0.76, 3],
[0.83, 4.13, 0.32, 0.78, 0.70, 0.74, 0],
[-0.14, 4.93, -0.02, 0.88, 0.81, 0.87, 1],
[-0.51, 4.64, 0.40, 0.66, 0.60, 0.65, 3],
[0.43, 4.65, -0.38, 0.68, 0.61, 0.66, 2]
];
canopyPieces.forEach((piece, index) => {
const [x, y, z, sx, sy, sz, materialIndex] = piece;
const leaf = shadowMesh(
canopyGeometry,
leafMaterials[materialIndex]
);
leaf.position.set(x, y, z);
leaf.scale.set(sx, sy, sz);
leaf.rotation.set(
index * 0.31,
index * 0.47,
index * 0.19
);
tree.add(leaf);
});
// Small low-poly vegetation around the tree.
const grassGeometry = new THREE.ConeGeometry(0.045, 0.27, 3);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x5f9653,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 34; i++) {
const angle = i * 2.39996;
const radius = 1.55 + (i % 7) * 0.28;
const grass = shadowMesh(grassGeometry, grassMaterial);
grass.position.set(
-2.8 + Math.cos(angle) * radius,
0.15,
0.05 + Math.sin(angle) * radius
);
grass.rotation.y = angle;
grass.scale.y = 0.75 + (i % 4) * 0.12;
scene.add(grass);
}
// ------------------------------------------------------------
// Bench
// ------------------------------------------------------------
const bench = new THREE.Group();
bench.position.set(1.25, 0, -1.15);
bench.rotation.y = -0.045;
scene.add(bench);
// Seat slats.
for (let i = -2; i <= 2; i++) {
const slat = shadowMesh(
new THREE.BoxGeometry(0.255, 0.11, 0.78),
i % 2 === 0 ? woodMaterial : woodDarkMaterial
);
slat.position.set(i * 0.285, 0.75, 0.02);
bench.add(slat);
}
// Backrest slats.
for (let i = 0; i < 3; i++) {
const slat = shadowMesh(
new THREE.BoxGeometry(2.86, 0.17, 0.115),
i === 1 ? woodDarkMaterial : woodMaterial
);
slat.position.set(0, 1.01 + i * 0.235, -0.365);
slat.rotation.x = -0.055;
bench.add(slat);
}
// Side frames and legs.
for (const x of [-1.13, 1.13]) {
bench.add(
rodBetween(
[x, 0.06, 0.29],
[x, 0.72, 0.25],
0.055,
0.055,
frameMaterial
),
rodBetween(
[x, 0.06, -0.28],
[x, 1.53, -0.39],
0.055,
0.055,
frameMaterial
),
rodBetween(
[x, 0.68, 0.27],
[x, 1.43, -0.37],
0.048,
0.048,
frameMaterial
),
rodBetween(
[x, 0.91, 0.27],
[x, 1.42, -0.38],
0.045,
0.045,
frameMaterial
)
);
}
// Cross supports under the seat.
bench.add(
rodBetween(
[-1.13, 0.61, 0.18],
[1.13, 0.61, 0.18],
0.035,
0.035,
frameMaterial
),
rodBetween(
[-1.13, 0.61, -0.25],
[1.13, 0.61, -0.25],
0.035,
0.035,
frameMaterial
)
);
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const azimuthInput = document.querySelector("#azimuth");
const elevationInput = document.querySelector("#elevation");
const azimuthValue = document.querySelector("#azimuthValue");
const elevationValue = document.querySelector("#elevationValue");
const animateButton = document.querySelector("#animate");
const resetButton = document.querySelector("#reset");
function syncUI() {
azimuthInput.value = Math.round(state.azimuth);
elevationInput.value = Math.round(state.elevation);
azimuthValue.textContent = `${Math.round(state.azimuth)}°`;
elevationValue.textContent = `${Math.round(state.elevation)}°`;
}
azimuthInput.addEventListener("input", () => {
state.animated = false;
state.azimuth = Number(azimuthInput.value);
animateButton.setAttribute("aria-pressed", "false");
animateButton.textContent = "Animate sunlight";
syncUI();
});
elevationInput.addEventListener("input", () => {
state.animated = false;
state.elevation = Number(elevationInput.value);
animateButton.setAttribute("aria-pressed", "false");
animateButton.textContent = "Animate sunlight";
syncUI();
});
animateButton.addEventListener("click", () => {
state.animated = !state.animated;
animateButton.setAttribute("aria-pressed", String(state.animated));
animateButton.textContent = state.animated
? "Pause sunlight"
: "Animate sunlight";
});
resetButton.addEventListener("click", () => {
state.azimuth = 165;
state.elevation = 36;
state.animated = false;
state.phase = 0;
desiredCamera.theta = 0.56;
desiredCamera.phi = 1.14;
desiredCamera.radius = 13.6;
animateButton.setAttribute("aria-pressed", "false");
animateButton.textContent = "Animate sunlight";
syncUI();
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (state.animated) {
state.phase += dt * 0.26;
state.azimuth = 165 + Math.sin(state.phase) * 20;
state.elevation =
39 + Math.sin(state.phase * 0.63 + 0.4) * 8;
syncUI();
}
updateSun();
updateCamera(dt);
renderer.render(scene, camera);
}
syncUI();
updateSun();
updateCamera(1);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```