Prompt specification
Build or customize the Three.js 3D scene "Wall opening and a sunbeam" 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: Wall opening and a sunbeam
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wall-opening-and-a-sunbeam-x2237
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: wall opening and a sunbeam. Create a thick wall with one rectangular window and a floor plane. Cast a visible directional sunbeam through the opening so the illuminated patch has clear edges.
Working Three.js Starter (wall-opening-and-a-sunbeam-x2237):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Sunbeam</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9bdc8;
font-family: system-ui, sans-serif;
}
canvas {
display: block;
touch-action: none;
}
#info {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
padding: 10px 13px;
color: #fff7e8;
background: rgba(34, 31, 28, 0.72);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 7px;
font-size: 12px;
line-height: 1.5;
letter-spacing: 0.03em;
pointer-events: none;
backdrop-filter: blur(5px);
}
#info strong {
display: block;
margin-bottom: 2px;
font-size: 13px;
letter-spacing: 0.1em;
}
</style>
</head>
<body>
<div id="info">
<strong>VOXEL SUNBEAM</strong>
Drag to orbit · Scroll to zoom · Double-click to reset
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9bdc8);
scene.fog = new THREE.Fog(0xa9bdc8, 20, 44);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap;
document.body.appendChild(renderer.domElement);
const target = new THREE.Vector3(0, 1.75, 0.55);
let orbitTheta = 0.58;
let orbitPhi = 1.31;
let orbitRadius = 17;
function updateCamera() {
const sinPhi = Math.sin(orbitPhi);
camera.position.set(
target.x + orbitRadius * sinPhi * Math.sin(orbitTheta),
target.y + orbitRadius * Math.cos(orbitPhi),
target.z + orbitRadius * sinPhi * Math.cos(orbitTheta)
);
camera.lookAt(target);
}
updateCamera();
// Direct camera controls, implemented without Three.js addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbitTheta -= dx * 0.006;
orbitPhi = THREE.MathUtils.clamp(orbitPhi + dy * 0.005, 0.48, 1.48);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbitRadius = THREE.MathUtils.clamp(
orbitRadius * Math.exp(event.deltaY * 0.001),
10,
28
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
orbitTheta = 0.58;
orbitPhi = 1.31;
orbitRadius = 17;
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------------
// Shared values
// ------------------------------------------------------------------
const wallZ = 0;
const wallThickness = 0.8;
const wallHeight = 6;
const wallWidth = 14;
const windowMinX = -2;
const windowMaxX = 2;
const windowMinY = 1;
const windowMaxY = 3;
// Direction in which sunlight travels through the window.
const rayDirection = new THREE.Vector3(0.35, -0.8, 0.49).normalize();
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let value = Math.imul(seed ^ seed >>> 15, 1 | seed);
value = value + Math.imul(value ^ value >>> 7, 61 | value) ^ value;
return ((value ^ value >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(9137);
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xc8e4ff,
0x5b4b3e,
1.05
);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffdda1, 4.4);
sunlight.target.position.set(0, 0, 0);
sunlight.position
.copy(sunlight.target.position)
.addScaledVector(rayDirection, -22);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -10;
sunlight.shadow.camera.right = 10;
sunlight.shadow.camera.top = 10;
sunlight.shadow.camera.bottom = -10;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 50;
sunlight.shadow.bias = -0.0002;
sunlight.shadow.normalBias = 0.025;
sunlight.shadow.camera.updateProjectionMatrix();
scene.add(sunlight, sunlight.target);
// ------------------------------------------------------------------
// Textured floor plane
// ------------------------------------------------------------------
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 512;
const context = textureCanvas.getContext("2d");
const tileSize = 64;
for (let row = 0; row < 8; row++) {
for (let column = 0; column < 8; column++) {
const alternate = (row + column) % 2 === 0;
const shade = 105 + Math.floor(random() * 10);
context.fillStyle = alternate
? `rgb(${shade}, ${shade + 5}, ${shade + 3})`
: `rgb(${shade - 8}, ${shade - 3}, ${shade - 5})`;
context.fillRect(
column * tileSize + 1,
row * tileSize + 1,
tileSize - 2,
tileSize - 2
);
// Small deterministic variations keep the floor from looking flat.
for (let speck = 0; speck < 9; speck++) {
context.fillStyle = `rgba(255,255,255,${random() * 0.035})`;
context.fillRect(
column * tileSize + 3 + random() * 56,
row * tileSize + 3 + random() * 56,
1 + random() * 3,
1 + random() * 2
);
}
}
}
const floorTexture = new THREE.CanvasTexture(textureCanvas);
floorTexture.colorSpace = THREE.SRGBColorSpace;
floorTexture.wrapS = THREE.RepeatWrapping;
floorTexture.wrapT = THREE.RepeatWrapping;
floorTexture.repeat.set(4, 3.2);
floorTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 24),
new THREE.MeshStandardMaterial({
map: floorTexture,
color: 0xffffff,
roughness: 0.92,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.006;
floor.receiveShadow = true;
scene.add(floor);
// ------------------------------------------------------------------
// Thick wall built around one rectangular opening
// ------------------------------------------------------------------
const structuralMaterial = new THREE.MeshStandardMaterial({
color: 0x8e7358,
roughness: 0.9,
metalness: 0
});
function addWallBox(width, height, x, y) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(width, height, wallThickness),
structuralMaterial
);
block.position.set(x, y, wallZ);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
// Left wall section.
addWallBox(
windowMinX + wallWidth / 2,
wallHeight,
(wallWidth / 2 + windowMinX) / 2,
wallHeight / 2
);
// Right wall section.
addWallBox(
wallWidth / 2 - windowMaxX,
wallHeight,
(wallWidth / 2 + windowMaxX) / 2,
wallHeight / 2
);
// Sill below the opening.
addWallBox(
windowMaxX - windowMinX,
windowMinY,
0,
windowMinY / 2
);
// Lintel above the opening.
addWallBox(
windowMaxX - windowMinX,
wallHeight - windowMaxY,
0,
(wallHeight + windowMaxY) / 2
);
// ------------------------------------------------------------------
// Decorative voxel facade
// ------------------------------------------------------------------
const facadePositions = [];
for (let gridX = 0; gridX < 14; gridX++) {
const x = -6.5 + gridX;
for (let gridY = 0; gridY < 6; gridY++) {
const y = 0.5 + gridY;
const insideOpening =
x > windowMinX &&
x < windowMaxX &&
y > windowMinY &&
y < windowMaxY;
if (!insideOpening) {
facadePositions.push({ x, y });
}
}
}
const facade = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.94, 0.94, 0.14),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.87,
metalness: 0
}),
facadePositions.length * 2
);
const matrix = new THREE.Matrix4();
const instanceColor = new THREE.Color();
let instanceIndex = 0;
for (const position of facadePositions) {
const color = new THREE.Color().setHSL(
0.085,
0.25,
0.43 + random() * 0.09
);
// Front-facing voxel blocks.
matrix.makeTranslation(
position.x,
position.y,
wallThickness / 2 + 0.075
);
facade.setMatrixAt(instanceIndex, matrix);
facade.setColorAt(instanceIndex, color);
instanceIndex++;
// Matching blocks on the rear side.
matrix.makeTranslation(
position.x,
position.y,
-wallThickness / 2 - 0.075
);
facade.setMatrixAt(instanceIndex, matrix);
instanceColor.copy(color).multiplyScalar(0.82);
facade.setColorAt(instanceIndex, instanceColor);
instanceIndex++;
}
facade.instanceMatrix.needsUpdate = true;
facade.instanceColor.needsUpdate = true;
facade.castShadow = true;
facade.receiveShadow = true;
scene.add(facade);
// ------------------------------------------------------------------
// Polygon utilities for the exact light footprint
// ------------------------------------------------------------------
function cross2(ax, ay, bx, by) {
return ax * by - ay * bx;
}
function polygonArea(points) {
let area = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
area += a.x * b.y - b.x * a.y;
}
return area * 0.5;
}
function projectWindowToFloor(zPlane) {
const corners = [
[windowMinX, windowMinY],
[windowMaxX, windowMinY],
[windowMaxX, windowMaxY],
[windowMinX, windowMaxY]
];
return corners.map(([x, y]) => {
const travel = (0 - zPlane) / rayDirection.y;
return new THREE.Vector2(
x + rayDirection.x * travel,
zPlane + rayDirection.z * travel
);
});
}
function clipPolygon(subject, clipper) {
let output = subject.slice();
for (let i = 0; i < clipper.length; i++) {
const a = clipper[i];
const b = clipper[(i + 1) % clipper.length];
const edgeX = b.x - a.x;
const edgeY = b.y - a.y;
const input = output;
output = [];
const inside = point =>
cross2(edgeX, edgeY, point.x - a.x, point.y - a.y) >= -1e-7;
const intersection = (s, e) => {
const subjectX = e.x - s.x;
const subjectY = e.y - s.y;
const denominator = cross2(subjectX, subjectY, edgeX, edgeY);
if (Math.abs(denominator) < 1e-8) return null;
const offsetX = a.x - s.x;
const offsetY = a.y - s.y;
const amount = cross2(offsetX, offsetY, edgeX, edgeY) / denominator;
return new THREE.Vector2(
s.x + subjectX * amount,
s.y + subjectY * amount
);
};
for (let j = 0; j < input.length; j++) {
const s = input[j];
const e = input[(j + 1) % input.length];
const sInside = inside(s);
const eInside = inside(e);
if (sInside && eInside) {
output.push(e);
} else if (sInside && !eInside) {
const hit = intersection(s, e);
if (hit) output.push(hit);
} else if (!sInside && eInside) {
const hit = intersection(s, e);
if (hit) output.push(hit);
output.push(e);
}
}
}
return output;
}
// Project the front and rear edges of the thick opening onto the
// floor. Their intersection is the true clear-edged footprint.
let frontProjection = projectWindowToFloor(wallThickness / 2);
let rearProjection = projectWindowToFloor(-wallThickness / 2);
if (polygonArea(frontProjection) < 0) {
frontProjection.reverse();
}
if (polygonArea(rearProjection) < 0) {
rearProjection.reverse();
}
let footprint = clipPolygon(frontProjection, rearProjection);
if (footprint.length < 3) {
footprint = frontProjection;
}
const footprintCenter = new THREE.Vector2();
for (const point of footprint) {
footprintCenter.add(point);
}
footprintCenter.multiplyScalar(1 / footprint.length);
const patchPositions = [
footprintCenter.x,
0.014,
footprintCenter.y
];
for (const point of footprint) {
patchPositions.push(point.x, 0.014, point.y);
}
const patchIndices = [];
for (let i = 0; i < footprint.length; i++) {
patchIndices.push(
0,
i + 1,
(i + 1) % footprint.length + 1
);
}
const patchGeometry = new THREE.BufferGeometry();
patchGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(patchPositions, 3)
);
patchGeometry.setIndex(patchIndices);
patchGeometry.computeVertexNormals();
const lightPatch = new THREE.Mesh(
patchGeometry,
new THREE.MeshBasicMaterial({
color: 0xffd27c,
transparent: true,
opacity: 0.28,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
toneMapped: false,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
})
);
lightPatch.renderOrder = 1;
scene.add(lightPatch);
// ------------------------------------------------------------------
// Volumetric sunbeam
//
// A proxy box contains a ray-marched parallelepiped. The shader
// reconstructs the four aperture coordinates and tests each sample
// against the actual window bounds and floor.
// ------------------------------------------------------------------
const apertureZ = wallThickness / 2;
const beamLength = 4.6;
const proxyPoints = [];
for (const x of [windowMinX, windowMaxX]) {
for (const y of [windowMinY, windowMaxY]) {
const start = new THREE.Vector3(x, y, apertureZ);
const end = start.clone().addScaledVector(rayDirection, beamLength);
proxyPoints.push(start, end);
}
}
const proxyBounds = new THREE.Box3();
proxyBounds.setFromPoints(proxyPoints);
proxyBounds.expandByScalar(0.06);
const proxySize = new THREE.Vector3();
const proxyCenter = new THREE.Vector3();
proxyBounds.getSize(proxySize);
proxyBounds.getCenter(proxyCenter);
const beamMaterial = new THREE.ShaderMaterial({
uniforms: {
uCameraPosition: { value: camera.position.clone() },
uRayDirection: { value: rayDirection.clone() },
uApertureMin: {
value: new THREE.Vector3(windowMinX, windowMinY, apertureZ)
},
uApertureSize: {
value: new THREE.Vector2(
windowMaxX - windowMinX,
windowMaxY - windowMinY
)
},
uBeamLength: { value: beamLength },
uBoxMin: { value: proxyBounds.min.clone() },
uBoxMax: { value: proxyBounds.max.clone() },
uColor: { value: new THREE.Color(0xffd38a) },
uTime: { value: 0 }
},
vertexShader: `
varying vec3 vWorldPosition;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,
fragmentShader: `
precision highp float;
uniform vec3 uCameraPosition;
uniform vec3 uRayDirection;
uniform vec3 uApertureMin;
uniform vec2 uApertureSize;
uniform float uBeamLength;
uniform vec3 uBoxMin;
uniform vec3 uBoxMax;
uniform vec3 uColor;
uniform float uTime;
varying vec3 vWorldPosition;
vec2 intersectBox(vec3 rayOrigin, vec3 rayDirection) {
vec3 inverseDirection = 1.0 / rayDirection;
vec3 first = (uBoxMin - rayOrigin) * inverseDirection;
vec3 second = (uBoxMax - rayOrigin) * inverseDirection;
vec3 nearValues = min(first, second);
vec3 farValues = max(first, second);
float nearDistance = max(
max(nearValues.x, nearValues.y),
nearValues.z
);
float farDistance = min(
min(farValues.x, farValues.y),
farValues.z
);
return vec2(nearDistance, farDistance);
}
void main() {
vec3 rayOrigin = uCameraPosition;
vec3 direction = normalize(vWorldPosition - uCameraPosition);
vec2 boxHit = intersectBox(rayOrigin, direction);
float startDistance = max(boxHit.x, 0.0);
float endDistance = boxHit.y;
if (endDistance <= startDistance) {
discard;
}
const int sampleCount = 56;
float stepLength =
(endDistance - startDistance) / float(sampleCount);
float densitySum = 0.0;
for (int sampleIndex = 0;
sampleIndex < sampleCount;
sampleIndex++) {
float distanceAlongRay =
startDistance +
(float(sampleIndex) + 0.5) * stepLength;
vec3 point = rayOrigin + direction * distanceAlongRay;
// Recover the aperture point and travel distance.
float travel =
(point.z - uApertureMin.z) / uRayDirection.z;
float apertureX =
point.x - travel * uRayDirection.x;
float apertureY =
point.y - travel * uRayDirection.y;
float u =
(apertureX - uApertureMin.x) / uApertureSize.x;
float v =
(apertureY - uApertureMin.y) / uApertureSize.y;
float insideAperture =
step(0.0, u) *
step(u, 1.0) *
step(0.0, v) *
step(v, 1.0);
float insideLength =
step(0.0, travel) *
step(travel, uBeamLength);
float aboveFloor = step(0.008, point.y);
float horizontalEdge =
smoothstep(0.0, 0.055, u) *
(1.0 - smoothstep(0.945, 1.0, u));
float verticalEdge =
smoothstep(0.0, 0.055, v) *
(1.0 - smoothstep(0.945, 1.0, v));
float grain =
0.88 +
0.12 * sin(
dot(point, vec3(4.1, 7.7, 5.3)) +
uTime * 0.4
);
float density =
insideAperture *
insideLength *
aboveFloor *
horizontalEdge *
verticalEdge *
grain;
densitySum += density * stepLength;
}
float alpha =
(1.0 - exp(-densitySum * 0.22)) * 0.34;
gl_FragColor = vec4(uColor, alpha);
}
`,
transparent: true,
depthWrite: false,
side: THREE.FrontSide,
blending: THREE.AdditiveBlending
});
const beamVolume = new THREE.Mesh(
new THREE.BoxGeometry(proxySize.x, proxySize.y, proxySize.z),
beamMaterial
);
beamVolume.position.copy(proxyCenter);
beamVolume.renderOrder = 2;
scene.add(beamVolume);
// ------------------------------------------------------------------
// Subtle corner filaments help define the directional shaft.
// ------------------------------------------------------------------
const filamentPositions = [];
for (const x of [windowMinX, windowMaxX]) {
for (const y of [windowMinY, windowMaxY]) {
const travel = -y / rayDirection.y;
filamentPositions.push(
x, y, apertureZ + 0.01,
x + rayDirection.x * travel,
0.018,
apertureZ + rayDirection.z * travel
);
}
}
const filaments = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(filamentPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xffe1a5,
transparent: true,
opacity: 0.18,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
filaments.renderOrder = 3;
scene.add(filaments);
// ------------------------------------------------------------------
// Floating dust inside the sunbeam
// ------------------------------------------------------------------
const dustCount = 170;
const dustPositions = new Float32Array(dustCount * 3);
const dustSizes = new Float32Array(dustCount);
const dustAlphas = new Float32Array(dustCount);
const dustData = [];
for (let i = 0; i < dustCount; i++) {
const apertureX = THREE.MathUtils.lerp(
windowMinX,
windowMaxX,
random()
);
const apertureY = THREE.MathUtils.lerp(
windowMinY,
windowMaxY,
random()
);
const floorTravel = -apertureY / rayDirection.y;
const travel = random() * floorTravel;
dustData.push({
apertureX,
apertureY,
travel,
floorTravel
});
dustSizes[i] = 0.7 + random() * 1.2;
dustAlphas[i] = 0.35 + random() * 0.65;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
dustGeometry.setAttribute(
"aSize",
new THREE.BufferAttribute(dustSizes, 1)
);
dustGeometry.setAttribute(
"aAlpha",
new THREE.BufferAttribute(dustAlphas, 1)
);
const dustMaterial = new THREE.ShaderMaterial({
uniforms: {
uPixelRatio: { value: renderer.getPixelRatio() },
uColor: { value: new THREE.Color(0xffe4ae) }
},
vertexShader: `
uniform float uPixelRatio;
attribute float aSize;
attribute float aAlpha;
varying float vAlpha;
void main() {
vec4 viewPosition =
modelViewMatrix * vec4(position, 1.0);
gl_Position =
projectionMatrix * viewPosition;
gl_PointSize =
aSize *
uPixelRatio *
(22.0 / max(1.0, -viewPosition.z));
vAlpha = aAlpha;
}
`,
fragmentShader: `
uniform vec3 uColor;
varying float vAlpha;
void main() {
float radius = length(gl_PointCoord - vec2(0.5));
float alpha =
(1.0 - smoothstep(0.12, 0.5, radius)) * vAlpha;
if (alpha < 0.01) discard;
gl_FragColor = vec4(uColor, alpha * 0.8);
}
`,
transparent: true,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const dust = new THREE.Points(dustGeometry, dustMaterial);
dust.renderOrder = 4;
scene.add(dust);
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animateDust(elapsedTime) {
for (let i = 0; i < dustCount; i++) {
const particle = dustData[i];
const travel =
(particle.travel + elapsedTime * 0.075) %
particle.floorTravel;
dustPositions[i * 3] =
particle.apertureX + rayDirection.x * travel;
dustPositions[i * 3 + 1] =
particle.apertureY + rayDirection.y * travel;
dustPositions[i * 3 + 2] =
apertureZ + rayDirection.z * travel;
}
dustGeometry.attributes.position.needsUpdate = true;
}
renderer.setAnimationLoop(() => {
const elapsedTime = clock.getElapsedTime();
beamMaterial.uniforms.uTime.value = elapsedTime;
beamMaterial.uniforms.uCameraPosition.value.copy(camera.position);
animateDust(elapsedTime);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```