Prompt specification
Build or customize the Three.js 3D scene "Shadow-casting gnomon disk" 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: Shadow-casting gnomon disk
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shadow-casting-gnomon-disk-x1253
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows sunlight and cast shadows. Place a vertical post at the center of a marked horizontal disk with one directional light; moving the light must shift the shadow consistently across the surface. Low-poly.
Working Three.js Starter (shadow-casting-gnomon-disk-x1253):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sunlight and Shadow</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9dde2;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(320px, calc(100vw - 40px));
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 16px;
color: #f5f2e9;
background: rgba(20, 35, 37, 0.84);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 5px;
color: #f8c85e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0 0 8px;
font-size: 25px;
font-weight: 750;
letter-spacing: -0.03em;
}
.intro {
margin: 0 0 19px;
color: #b9c7c7;
font-size: 13px;
line-height: 1.5;
}
.control {
margin-top: 15px;
}
.control-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 13px;
font-weight: 650;
}
output {
min-width: 48px;
padding: 3px 7px;
border-radius: 7px;
color: #fff3c7;
background: rgba(248, 200, 94, 0.12);
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, #f7c453, #526d70);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fff8e8;
border-radius: 50%;
appearance: none;
background: #eeb83e;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fff8e8;
border-radius: 50%;
background: #eeb83e;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 19px;
padding-top: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-size: 13px;
}
.toggle-row label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: #efbb47;
}
button {
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
color: #f5f2e9;
background: rgba(255, 255, 255, 0.07);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
}
.hint {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
padding: 9px 12px;
border-radius: 9px;
color: rgba(255, 255, 255, 0.9);
background: rgba(20, 35, 37, 0.68);
font-size: 12px;
backdrop-filter: blur(8px);
pointer-events: none;
}
@media (max-width: 600px) {
.panel {
top: 10px;
left: 10px;
width: min(285px, calc(100vw - 20px));
padding: 16px;
}
.hint {
right: 10px;
bottom: 10px;
font-size: 11px;
}
}
</style>
</head>
<body>
<div class="panel">
<p class="eyebrow">Directional-light study</p>
<h1>Sunlight & Shadow</h1>
<p class="intro">
Move the sun around the marked disk. The octagonal post casts a
real-time directional shadow.
</p>
<div class="control">
<div class="control-header">
<label for="azimuth">Sun azimuth</label>
<output id="azimuthValue" for="azimuth">135°</output>
</div>
<input id="azimuth" type="range" min="0" max="360" step="1" value="135">
</div>
<div class="control">
<div class="control-header">
<label for="elevation">Sun elevation</label>
<output id="elevationValue" for="elevation">34°</output>
</div>
<input id="elevation" type="range" min="22" max="72" step="1" value="34">
</div>
<div class="toggle-row">
<label for="animate">
<input id="animate" type="checkbox">
Animate sun
</label>
<button id="reset" type="button">Reset</button>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Shift-drag to move the sun</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------- Renderer / scene ----------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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.05;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9dde2);
scene.fog = new THREE.Fog(0xc9dde2, 38, 85);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
// Custom orbit controls: no addons are used.
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const orbit = {
theta: 0.68,
phi: 1.02,
radius: 17.5
};
const orbitGoal = { ...orbit };
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function updateCamera(dt = 1) {
const blend = 1 - Math.exp(-12 * dt);
orbit.theta += (orbitGoal.theta - orbit.theta) * blend;
orbit.phi += (orbitGoal.phi - orbit.phi) * blend;
orbit.radius += (orbitGoal.radius - orbit.radius) * blend;
spherical.set(orbit.radius, orbit.phi, orbit.theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
updateCamera();
// ---------- Ground and marked disk ----------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x9eae91,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.09;
ground.receiveShadow = true;
scene.add(ground);
const diskMaterial = new THREE.MeshStandardMaterial({
color: 0xd4bd8e,
roughness: 0.95,
metalness: 0,
flatShading: true
});
const disk = new THREE.Mesh(
new THREE.CylinderGeometry(8.5, 8.5, 0.16, 40),
diskMaterial
);
disk.position.y = 0;
disk.castShadow = true;
disk.receiveShadow = true;
scene.add(disk);
// Markings are slightly above the disk so they remain crisp in shadow.
const markingColor = 0x5b625b;
function addCircle(radius, opacity = 0.5) {
const points = [];
const segments = 96;
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0.095,
Math.sin(angle) * radius
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: markingColor,
transparent: true,
opacity
})
);
scene.add(line);
}
addCircle(1.05, 0.72);
addCircle(3.0, 0.38);
addCircle(5.0, 0.38);
addCircle(7.0, 0.38);
addCircle(8.18, 0.72);
const radialPoints = [];
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
radialPoints.push(
new THREE.Vector3(
Math.cos(angle) * 1.15,
0.095,
Math.sin(angle) * 1.15
),
new THREE.Vector3(
Math.cos(angle) * 8.05,
0.095,
Math.sin(angle) * 8.05
)
);
}
const radialMarks = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(radialPoints),
new THREE.LineBasicMaterial({
color: markingColor,
transparent: true,
opacity: 0.32
})
);
scene.add(radialMarks);
// ---------- Low-poly central post ----------
const postMaterial = new THREE.MeshStandardMaterial({
color: 0x2b6260,
emissive: 0x0b1b1c,
emissiveIntensity: 0.45,
roughness: 0.78,
metalness: 0.05,
flatShading: true
});
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.47, 4.6, 8),
postMaterial
);
post.position.y = 2.38;
post.castShadow = true;
post.receiveShadow = true;
scene.add(post);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x214849,
emissive: 0x081313,
emissiveIntensity: 0.35,
roughness: 0.9,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.7, 0.76, 0.18, 8),
baseMaterial
);
base.position.y = 0.17;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// ---------- The single directional light ----------
const sun = new THREE.DirectionalLight(0xffedc4, 3.4);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11.5;
sun.shadow.camera.right = 11.5;
sun.shadow.camera.top = 11.5;
sun.shadow.camera.bottom = -11.5;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
sun.shadow.camera.updateProjectionMatrix();
// Keeping the target fixed makes the post's shadow rotate and lengthen
// consistently as the light moves.
sun.target.position.set(0, 0, 0);
scene.add(sun);
scene.add(sun.target);
// A visual, non-light-emitting sun marker.
const sunMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.68, 1),
new THREE.MeshBasicMaterial({ color: 0xffc84f })
);
scene.add(sunMarker);
let sunAzimuth = THREE.MathUtils.degToRad(135);
let sunElevation = THREE.MathUtils.degToRad(34);
let animating = false;
const azimuthInput = document.querySelector("#azimuth");
const elevationInput = document.querySelector("#elevation");
const azimuthValue = document.querySelector("#azimuthValue");
const elevationValue = document.querySelector("#elevationValue");
const animateCheckbox = document.querySelector("#animate");
const resetButton = document.querySelector("#reset");
const SUN_DISTANCE = 24;
function updateSun() {
const horizontalDistance =
Math.cos(sunElevation) * SUN_DISTANCE;
sun.position.set(
Math.sin(sunAzimuth) * horizontalDistance,
Math.sin(sunElevation) * SUN_DISTANCE,
Math.cos(sunAzimuth) * horizontalDistance
);
sun.target.position.set(0, 0, 0);
sun.target.updateMatrixWorld();
sun.updateMatrixWorld();
sunMarker.position.copy(sun.position);
}
function syncSunUI() {
const azimuthDegrees =
((THREE.MathUtils.radToDeg(sunAzimuth) % 360) + 360) % 360;
const elevationDegrees = THREE.MathUtils.radToDeg(sunElevation);
azimuthInput.value = azimuthDegrees.toFixed(0);
elevationInput.value = elevationDegrees.toFixed(0);
azimuthValue.textContent = `${Math.round(azimuthDegrees)}°`;
elevationValue.textContent = `${Math.round(elevationDegrees)}°`;
}
function stopAnimation() {
animating = false;
animateCheckbox.checked = false;
}
azimuthInput.addEventListener("input", () => {
stopAnimation();
sunAzimuth = THREE.MathUtils.degToRad(Number(azimuthInput.value));
syncSunUI();
updateSun();
});
elevationInput.addEventListener("input", () => {
stopAnimation();
sunElevation = THREE.MathUtils.degToRad(Number(elevationInput.value));
syncSunUI();
updateSun();
});
animateCheckbox.addEventListener("change", () => {
animating = animateCheckbox.checked;
});
resetButton.addEventListener("click", () => {
stopAnimation();
sunAzimuth = THREE.MathUtils.degToRad(135);
sunElevation = THREE.MathUtils.degToRad(34);
orbitGoal.theta = 0.68;
orbitGoal.phi = 1.02;
orbitGoal.radius = 17.5;
syncSunUI();
updateSun();
});
syncSunUI();
updateSun();
// ---------- Direct pointer controls ----------
const canvas = renderer.domElement;
const pointer = {
active: false,
id: -1,
x: 0,
y: 0,
mode: "camera"
};
canvas.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.mode = event.shiftKey ? "sun" : "camera";
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.mode === "sun") {
stopAnimation();
sunAzimuth =
(sunAzimuth - dx * 0.008 + Math.PI * 2) % (Math.PI * 2);
sunElevation = THREE.MathUtils.clamp(
sunElevation - dy * 0.006,
THREE.MathUtils.degToRad(22),
THREE.MathUtils.degToRad(72)
);
syncSunUI();
updateSun();
} else {
orbitGoal.theta -= dx * 0.006;
orbitGoal.phi = THREE.MathUtils.clamp(
orbitGoal.phi - dy * 0.005,
0.28,
Math.PI / 2.05
);
}
});
function releasePointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = -1;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
orbitGoal.radius = THREE.MathUtils.clamp(
orbitGoal.radius * Math.exp(event.deltaY * 0.001),
9,
28
);
},
{ passive: false }
);
// ---------- Resize and render loop ----------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (animating) {
sunAzimuth =
(sunAzimuth + THREE.MathUtils.degToRad(9) * dt) %
(Math.PI * 2);
syncSunUI();
updateSun();
}
updateCamera(dt);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```