Prompt specification
Build or customize the Three.js 3D scene "Point and area source comparison" 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: Point and area source comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/point-and-area-source-comparison-x1582
Scene Description Prompt:
Create a standalone HTML scene with Three.js from cdnjs comparing stylized geometric shadows under point and extended sources, using identical blockers.
Working Three.js Starter (point-and-area-source-comparison-x1582):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three.js Shadow Lab — Point vs Extended Source</title>
<style>
:root {
--bg: #090e1b;
--panel: rgba(15, 23, 42, 0.82);
--line: rgba(148, 163, 184, 0.2);
--text: #e5edf8;
--muted: #8da0bc;
--cyan: #64e5e2;
--gold: #ffd27a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 40%, rgba(45, 72, 112, 0.2), transparent 55%),
var(--bg);
}
canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.topbar {
position: absolute;
z-index: 5;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 34px);
font-weight: 650;
letter-spacing: -0.045em;
}
.subtitle {
margin-top: 8px;
max-width: 520px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.study-badge {
flex: 0 0 auto;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 13, 25, 0.55);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.divider {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: linear-gradient(
to bottom,
transparent,
rgba(148, 163, 184, 0.28) 18%,
rgba(148, 163, 184, 0.28) 82%,
transparent
);
pointer-events: none;
}
.panel-label {
position: absolute;
z-index: 4;
top: 116px;
left: 30px;
pointer-events: none;
}
.panel-label.extended {
left: calc(50% + 30px);
}
.panel-label .kicker {
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-label h2 {
margin: 0;
font-size: 20px;
font-weight: 650;
letter-spacing: -0.03em;
}
.panel-label p {
margin: 6px 0 0;
color: var(--muted);
font-size: 11px;
}
.point-accent {
color: #fff1bf;
}
.extended-accent {
color: var(--cyan);
}
.control-dock {
position: absolute;
z-index: 10;
right: 26px;
bottom: 24px;
width: min(360px, calc(100vw - 52px));
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.control-label {
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-value {
color: var(--gold);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 14px 0 4px;
accent-color: var(--cyan);
cursor: pointer;
}
.control-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
padding-top: 12px;
border-top: 1px solid rgba(148, 163, 184, 0.12);
}
.hint {
color: #7f92b0;
font-size: 10px;
line-height: 1.4;
}
button {
border: 1px solid rgba(100, 229, 226, 0.35);
border-radius: 8px;
padding: 7px 10px;
background: rgba(100, 229, 226, 0.08);
color: var(--cyan);
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
button:hover {
border-color: rgba(100, 229, 226, 0.75);
background: rgba(100, 229, 226, 0.15);
}
.legend {
position: absolute;
z-index: 4;
bottom: 28px;
left: 30px;
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
max-width: calc(100vw - 450px);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(100, 229, 226, 0.65);
}
.dot.gold {
background: var(--gold);
box-shadow: 0 0 10px rgba(255, 210, 122, 0.65);
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 18px;
right: 18px;
}
.subtitle,
.study-badge {
display: none;
}
.divider {
top: 50%;
right: 0;
bottom: auto;
left: 0;
width: auto;
height: 1px;
background: linear-gradient(
to right,
transparent,
rgba(148, 163, 184, 0.28) 18%,
rgba(148, 163, 184, 0.28) 82%,
transparent
);
}
.panel-label {
top: 78px;
left: 18px;
}
.panel-label.extended {
top: calc(50% + 18px);
left: 18px;
}
.panel-label h2 {
font-size: 16px;
}
.control-dock {
right: 16px;
bottom: 16px;
width: calc(100vw - 32px);
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene"></canvas>
<div class="divider"></div>
<header class="topbar">
<div>
<div class="eyebrow">Three.js / Shadow study 02</div>
<h1>Same solids. Different light.</h1>
<div class="subtitle">
A side-by-side study of geometric shadows cast by a single point
source and a finite extended source.
</div>
</div>
<div class="study-badge">4 identical blockers · live comparison</div>
</header>
<section class="panel-label">
<div class="kicker">01 / Point source</div>
<h2 class="point-accent">Crisp silhouette</h2>
<p>Single emitter · hard shadow boundary</p>
</section>
<section class="panel-label extended">
<div class="kicker">02 / Extended source</div>
<h2 class="extended-accent">Soft penumbra</h2>
<p>Finite emitter area · feathered shadow edge</p>
</section>
<div class="legend">
<span><i class="dot gold"></i> point emitter</span>
<span><i class="dot"></i> extended emitter</span>
<span>drag to orbit · scroll to zoom</span>
</div>
<section class="control-dock">
<div class="control-row">
<label class="control-label" for="source-size">
Extended source size
</label>
<span id="source-value" class="control-value">0.80 units</span>
</div>
<input
id="source-size"
type="range"
min="0.35"
max="1.40"
step="0.05"
value="0.80"
/>
<div class="control-footer">
<div class="hint">
Increasing the emitter area broadens the stylized penumbra.
</div>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
</main>
<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.getElementById("app");
const canvas = document.getElementById("scene");
const sizeInput = document.getElementById("source-size");
const sizeValue = document.getElementById("source-value");
const resetButton = document.getElementById("reset-view");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x090e1b, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
const scenePoint = new THREE.Scene();
const sceneExtended = new THREE.Scene();
scenePoint.background = new THREE.Color(0x10182b);
sceneExtended.background = new THREE.Color(0x10182b);
scenePoint.fog = new THREE.Fog(0x10182b, 16, 29);
sceneExtended.fog = new THREE.Fog(0x10182b, 16, 29);
const camera = new THREE.PerspectiveCamera(
34,
1,
0.1,
100
);
const target = new THREE.Vector3(0, 0.9, 0);
const orbit = {
azimuth: 0.73,
elevation: 0.78,
distance: 13.5
};
const SOURCE_CENTER = new THREE.Vector3(-4.1, 5.8, 3.7);
let sourceRadius = 0.8;
const softShadowGroup = new THREE.Group();
sceneExtended.add(softShadowGroup);
let extendedSourceGroup = new THREE.Group();
sceneExtended.add(extendedSourceGroup);
function updateCamera() {
const horizontal = Math.cos(orbit.elevation) * orbit.distance;
camera.position.set(
target.x + Math.sin(orbit.azimuth) * horizontal,
target.y + Math.sin(orbit.elevation) * orbit.distance,
target.z + Math.cos(orbit.azimuth) * horizontal
);
camera.lookAt(target);
}
updateCamera();
function addPanelLighting(scene) {
const hemisphere = new THREE.HemisphereLight(
0xb9d5ff,
0x182039,
1.55
);
scene.add(hemisphere);
const fill = new THREE.DirectionalLight(0x7799ff, 0.75);
fill.position.set(5, 7, 4);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffd38b, 0.28);
rim.position.set(-4, 4, -6);
scene.add(rim);
}
function makeGround(scene) {
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(18, 15),
new THREE.MeshStandardMaterial({
color: 0x17243c,
roughness: 0.93,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
16,
16,
0x425675,
0x263752
);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
const boundary = new THREE.Mesh(
new THREE.RingGeometry(4.9, 5.0, 96),
new THREE.MeshBasicMaterial({
color: 0x526786,
transparent: true,
opacity: 0.3,
side: THREE.DoubleSide
})
);
boundary.rotation.x = -Math.PI / 2;
boundary.position.y = 0.009;
scene.add(boundary);
}
function makeEdge(geometry, color = 0xd8e7ff, opacity = 0.22) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 24),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.renderOrder = 3;
return edges;
}
function addBlocker(
group,
blockers,
geometry,
color,
position,
rotation = [0, 0, 0],
castShadow = true
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.57,
metalness: 0.13,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
mesh.add(makeEdge(geometry));
group.add(mesh);
blockers.push(mesh);
return mesh;
}
/*
This exact function is used for both scenes, ensuring that the
blockers have identical dimensions, transforms, and materials.
*/
function addIdenticalBlockers(scene, castShadow) {
const group = new THREE.Group();
const blockers = [];
addBlocker(
group,
blockers,
new THREE.CylinderGeometry(0.7, 0.96, 2.65, 5),
0x38b8bd,
[-1.35, 1.325, -0.25],
[0.04, 0.3, 0.02],
castShadow
);
addBlocker(
group,
blockers,
new THREE.BoxGeometry(1.42, 1.42, 1.42),
0xf28b52,
[1.38, 0.71, -0.72],
[0.02, -0.28, 0.02],
castShadow
);
addBlocker(
group,
blockers,
new THREE.ConeGeometry(0.88, 2.12, 5),
0xe8c45d,
[0.18, 1.06, 1.38],
[0, 0.48, 0.03],
castShadow
);
addBlocker(
group,
blockers,
new THREE.DodecahedronGeometry(0.72, 0),
0x8b78d6,
[-2.45, 0.72, -1.62],
[0.08, 0.2, 0.12],
castShadow
);
scene.add(group);
group.updateMatrixWorld(true);
return blockers;
}
addPanelLighting(scenePoint);
addPanelLighting(sceneExtended);
makeGround(scenePoint);
makeGround(sceneExtended);
const pointBlockers = addIdenticalBlockers(scenePoint, true);
const extendedBlockers = addIdenticalBlockers(sceneExtended, false);
function makePointSource() {
const group = new THREE.Group();
group.position.copy(SOURCE_CENTER);
const light = new THREE.PointLight(
0xffefc2,
72,
22,
2
);
light.castShadow = true;
light.shadow.mapSize.set(1024, 1024);
light.shadow.camera.near = 0.1;
light.shadow.camera.far = 28;
light.shadow.bias = -0.0015;
light.shadow.normalBias = 0.025;
group.add(light);
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 20, 12),
new THREE.MeshBasicMaterial({ color: 0xfff3c6 })
);
group.add(core);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.36, 20, 12),
new THREE.MeshBasicMaterial({
color: 0xffd27a,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
group.add(halo);
scenePoint.add(group);
}
makePointSource();
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
group.clear();
}
function getExtendedSamples() {
const samples = [SOURCE_CENTER.clone()];
const count = 18;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
samples.push(
new THREE.Vector3(
SOURCE_CENTER.x + Math.cos(angle) * sourceRadius,
SOURCE_CENTER.y,
SOURCE_CENTER.z + Math.sin(angle) * sourceRadius
)
);
}
return samples;
}
function rebuildExtendedSource() {
disposeGroup(extendedSourceGroup);
extendedSourceGroup = new THREE.Group();
extendedSourceGroup.position.copy(SOURCE_CENTER);
sceneExtended.add(extendedSourceGroup);
const disk = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 0.075, 40),
new THREE.MeshBasicMaterial({
color: 0xffd27a,
transparent: true,
opacity: 0.22,
depthWrite: false
})
);
disk.scale.set(sourceRadius, 1, sourceRadius);
extendedSourceGroup.add(disk);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.018, 8, 64),
new THREE.MeshBasicMaterial({
color: 0x75f4ee,
transparent: true,
opacity: 0.8
})
);
ring.rotation.x = Math.PI / 2;
ring.scale.set(sourceRadius, sourceRadius, sourceRadius);
extendedSourceGroup.add(ring);
const center = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 16, 10),
new THREE.MeshBasicMaterial({ color: 0xffefc4 })
);
extendedSourceGroup.add(center);
const lightCount = 10;
for (let i = 0; i < lightCount; i++) {
const angle = (i / lightCount) * Math.PI * 2;
const emitter = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xfff0c1 })
);
emitter.position.set(
Math.cos(angle) * sourceRadius,
0.08,
Math.sin(angle) * sourceRadius
);
extendedSourceGroup.add(emitter);
const light = new THREE.PointLight(
0xffedbf,
8.5,
15,
2
);
light.position.copy(emitter.position);
extendedSourceGroup.add(light);
}
const centralLight = new THREE.PointLight(
0xffedbf,
28,
18,
2
);
extendedSourceGroup.add(centralLight);
}
/*
Convex hull of projected blocker vertices. The projected hull is
converted into a flat polygon on the ground, producing a deliberately
geometric shadow without requiring any external geometry library.
*/
function convexHull(points) {
if (points.length < 3) {
return points;
}
const sorted = points
.map((point) => ({ x: point.x, z: point.z }))
.sort((a, b) => a.x - b.x || a.z - b.z);
const cross = (o, a, b) =>
(a.x - o.x) * (b.z - o.z) -
(a.z - o.z) * (b.x - o.x);
const lower = [];
for (const point of sorted) {
while (
lower.length >= 2 &&
cross(
lower[lower.length - 2],
lower[lower.length - 1],
point
) <= 0
) {
lower.pop();
}
lower.push(point);
}
const upper = [];
for (let i = sorted.length - 1; i >= 0; i--) {
const point = sorted[i];
while (
upper.length >= 2 &&
cross(
upper[upper.length - 2],
upper[upper.length - 1],
point
) <= 0
) {
upper.pop();
}
upper.push(point);
}
lower.pop();
upper.pop();
return lower.concat(upper);
}
function projectBlocker(blocker, source, groundHeight = 0.015) {
blocker.updateWorldMatrix(true, false);
const position = blocker.geometry.attributes.position;
const projected = [];
const vertex = new THREE.Vector3();
for (let i = 0; i < position.count; i++) {
vertex.fromBufferAttribute(position, i);
vertex.applyMatrix4(blocker.matrixWorld);
if (vertex.y >= source.y - 0.01) {
continue;
}
const t =
(groundHeight - source.y) /
(vertex.y - source.y);
if (t <= 0) {
continue;
}
const p = new THREE.Vector3().copy(source);
p.addScaledVector(
new THREE.Vector3().subVectors(vertex, source),
t
);
projected.push(p);
}
return convexHull(projected);
}
function addShadowPolygon(hull, opacity, height = 0.015) {
if (hull.length < 3) {
return;
}
const shape = new THREE.Shape();
hull.forEach((point, index) => {
if (index === 0) {
shape.moveTo(point.x, -point.z);
} else {
shape.lineTo(point.x, -point.z);
}
});
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
const material = new THREE.MeshBasicMaterial({
color: 0x02050c,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = height;
mesh.renderOrder = 5;
softShadowGroup.add(mesh);
}
function rebuildSoftShadows() {
disposeGroup(softShadowGroup);
sceneExtended.add(softShadowGroup);
const samples = getExtendedSamples();
// Each finite source position contributes a slightly displaced
// geometric silhouette. Their overlap creates the penumbra.
for (const source of samples) {
for (const blocker of extendedBlockers) {
const hull = projectBlocker(blocker, source);
addShadowPolygon(hull, 0.055, 0.014 + sourceRadius * 0.0002);
}
}
// A denser central contribution creates the darkest region.
for (const blocker of extendedBlockers) {
const hull = projectBlocker(blocker, SOURCE_CENTER);
addShadowPolygon(hull, 0.24, 0.016);
}
}
rebuildExtendedSource();
rebuildSoftShadows();
/*
Minimal camera controls implemented locally.
Dragging changes azimuth/elevation; the wheel changes distance.
*/
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.azimuth -= deltaX * 0.006;
orbit.elevation = THREE.MathUtils.clamp(
orbit.elevation + deltaY * 0.004,
0.32,
1.36
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * (1 + event.deltaY * 0.001),
7.5,
20
);
updateCamera();
},
{ passive: false }
);
sizeInput.addEventListener("input", () => {
sourceRadius = Number(sizeInput.value);
sizeValue.textContent = `${sourceRadius.toFixed(2)} units`;
rebuildExtendedSource();
rebuildSoftShadows();
});
resetButton.addEventListener("click", () => {
orbit.azimuth = 0.73;
orbit.elevation = 0.78;
orbit.distance = 13.5;
updateCamera();
});
let stacked = false;
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
stacked = width < 760;
app.classList.toggle("stacked", stacked);
}
window.addEventListener("resize", resize);
resize();
function renderPanel(scene, x, y, width, height) {
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.clear(true, true, true);
renderer.render(scene, camera);
}
function animate() {
renderer.setScissorTest(false);
renderer.clear(true, true, true);
renderer.setScissorTest(true);
const width = window.innerWidth;
const height = window.innerHeight;
if (stacked) {
const halfHeight = Math.floor(height / 2);
renderPanel(
scenePoint,
0,
halfHeight,
width,
height - halfHeight
);
renderPanel(
sceneExtended,
0,
0,
width,
halfHeight
);
} else {
const halfWidth = Math.floor(width / 2);
renderPanel(
scenePoint,
0,
0,
halfWidth,
height
);
renderPanel(
sceneExtended,
halfWidth,
0,
width - halfWidth,
height
);
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```