Prompt specification
Build or customize the Three.js 3D scene "Beacon behind a low ridge" 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: Beacon behind a low ridge
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/beacon-behind-a-low-ridge-x1325
Scene Description Prompt:
Place a stylized observer and beacon across a low ridge, with their sightline visibly blocked by terrain. One HTML file with Three.js from cdnjs.
Working Three.js Starter (beacon-behind-a-low-ridge-x1325):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Signal Lost — Observer and Beacon</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6df;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #173b3a;
}
.panel {
position: absolute;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 18px;
background: rgba(244, 248, 241, 0.72);
box-shadow: 0 18px 50px rgba(37, 66, 54, 0.13);
backdrop-filter: blur(14px);
}
.eyebrow {
display: block;
margin-bottom: 6px;
color: #71827b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 14px;
color: #687a73;
font-size: 13px;
}
.status {
display: flex;
align-items: center;
gap: 9px;
padding-top: 13px;
border-top: 1px solid rgba(36, 76, 65, 0.12);
color: #a94b32;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: #e76f48;
box-shadow: 0 0 0 5px rgba(231, 111, 72, 0.14);
}
#blocked-label {
position: absolute;
left: 50%;
top: 50%;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 9px;
color: #fff8ee;
background: rgba(165, 66, 43, 0.88);
box-shadow: 0 8px 24px rgba(87, 41, 27, 0.2);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, -125%);
white-space: nowrap;
}
#blocked-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(165, 66, 43, 0.72);
content: "";
transform: translateX(-50%);
}
.controls {
position: absolute;
right: 22px;
bottom: 20px;
padding: 9px 12px;
border-radius: 999px;
color: rgba(31, 67, 60, 0.68);
background: rgba(247, 250, 244, 0.62);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
@media (max-width: 600px) {
.panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="panel">
<span class="eyebrow">Field Study 07</span>
<h1>Signal Lost</h1>
<p class="subtitle">Observer and beacon positioned beyond a low ridge.</p>
<div class="status">
<span class="status-dot"></span>
Terrain blocks direct sight
</div>
</div>
<div id="blocked-label">Sight blocked</div>
<div class="controls">Drag to orbit · Scroll to zoom</div>
</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(0xdce6df);
scene.fog = new THREE.Fog(0xdce6df, 17, 34);
const camera = new THREE.PerspectiveCamera(
40,
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf4fff7, 0x52675e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d3, 3.2);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xa8d8e0, 1.1);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Terrain
// -------------------------------------------------------------------------
function hash(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
return value - Math.floor(value);
}
function terrainHeight(x, z) {
// A broad, low ridge running along the Z axis.
const ridge =
2.08 *
Math.exp(-Math.pow(x / 1.68, 4)) *
Math.exp(-Math.pow(Math.abs(z) / 3.55, 6));
const rolling =
0.075 * Math.sin(x * 1.22 + z * 0.38) +
0.055 * Math.sin(z * 1.48 - x * 0.26) +
0.025 * Math.cos(x * 2.7 + z * 1.9);
return -0.04 + ridge + rolling;
}
let terrainGeometry = new THREE.PlaneGeometry(18, 10, 54, 30);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
terrainPositions.setY(i, terrainHeight(x, z));
}
terrainGeometry = terrainGeometry.toNonIndexed();
terrainGeometry.computeVertexNormals();
const terrainPosition = terrainGeometry.attributes.position;
const terrainColors = new Float32Array(terrainPosition.count * 3);
const lowColor = new THREE.Color(0x477862);
const highColor = new THREE.Color(0x91ad82);
const faceColor = new THREE.Color();
for (let i = 0; i < terrainPosition.count; i += 3) {
const averageHeight =
(terrainPosition.getY(i) +
terrainPosition.getY(i + 1) +
terrainPosition.getY(i + 2)) /
3;
const blend = THREE.MathUtils.clamp((averageHeight + 0.12) / 2.25, 0, 1);
faceColor.lerpColors(lowColor, highColor, blend);
const variation =
(hash(terrainPosition.getX(i), terrainPosition.getZ(i)) - 0.5) * 0.055;
faceColor.offsetHSL(0, 0, variation);
for (let j = 0; j < 3; j++) {
terrainColors[(i + j) * 3] = faceColor.r;
terrainColors[(i + j) * 3 + 1] = faceColor.g;
terrainColors[(i + j) * 3 + 2] = faceColor.b;
}
}
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(terrainColors, 3)
);
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(18.35, 0.48, 10.35),
new THREE.MeshStandardMaterial({
color: 0x315348,
roughness: 0.92
})
);
plinth.position.y = -0.31;
plinth.receiveShadow = true;
scene.add(plinth);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xd5ddd4,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.56;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Stylized observer
// -------------------------------------------------------------------------
const observerX = -4.55;
const observerZ = -0.28;
const observerGround = terrainHeight(observerX, observerZ);
const observer = new THREE.Group();
observer.position.set(observerX, observerGround, observerZ);
scene.add(observer);
const navy = new THREE.MeshStandardMaterial({
color: 0x193c49,
roughness: 0.82
});
const teal = new THREE.MeshStandardMaterial({
color: 0x2f8178,
roughness: 0.78
});
const orange = new THREE.MeshStandardMaterial({
color: 0xef7047,
roughness: 0.76
});
const skin = new THREE.MeshStandardMaterial({
color: 0xe7b68f,
roughness: 0.92
});
const dark = new THREE.MeshStandardMaterial({
color: 0x182d30,
roughness: 0.8
});
function mesh(geometry, material, parent, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(geometry, material);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
// Shoes and legs.
for (const side of [-1, 1]) {
mesh(
new THREE.BoxGeometry(0.34, 0.13, 0.2),
dark,
observer,
0.04,
0.075,
side * 0.14
);
mesh(
new THREE.CylinderGeometry(0.105, 0.12, 0.4, 8),
navy,
observer,
0,
0.32,
side * 0.14
);
}
// Torso, coat, and backpack.
mesh(
new THREE.CylinderGeometry(0.26, 0.31, 0.58, 10),
teal,
observer,
0,
0.8,
0
);
const backpack = mesh(
new THREE.BoxGeometry(0.26, 0.48, 0.36),
orange,
observer,
-0.25,
0.84,
0
);
backpack.rotation.z = -0.04;
// Scarf.
mesh(
new THREE.CylinderGeometry(0.2, 0.2, 0.12, 10),
orange,
observer,
0,
1.11,
0
);
// Head, hat, and nose.
mesh(new THREE.SphereGeometry(0.235, 12, 9), skin, observer, 0.02, 1.32, 0);
mesh(
new THREE.SphereGeometry(0.255, 12, 8),
teal,
observer,
0,
1.45,
0
).scale.set(1, 0.64, 1);
mesh(
new THREE.SphereGeometry(0.065, 8, 6),
skin,
observer,
0.24,
1.31,
0
);
// Telescope.
const telescope = mesh(
new THREE.CylinderGeometry(0.085, 0.105, 0.68, 12),
navy,
observer,
0.45,
1.39,
0
);
telescope.rotation.z = -Math.PI / 2;
const lens = mesh(
new THREE.CylinderGeometry(0.094, 0.094, 0.035, 16),
new THREE.MeshStandardMaterial({
color: 0x9ee4e4,
emissive: 0x3e8e91,
emissiveIntensity: 0.32,
roughness: 0.24,
metalness: 0.15
}),
observer,
0.81,
1.39,
0
);
lens.rotation.z = -Math.PI / 2;
function makeRod(a, b, radius, material, parent) {
const direction = new THREE.Vector3().subVectors(b, a);
const rod = mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 8),
material,
parent
);
rod.position.copy(a).add(b).multiplyScalar(0.5);
rod.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return rod;
}
makeRod(
new THREE.Vector3(0.1, 1.03, 0.15),
new THREE.Vector3(0.38, 1.3, 0.09),
0.075,
teal,
observer
);
makeRod(
new THREE.Vector3(0.1, 1.03, -0.15),
new THREE.Vector3(0.38, 1.31, -0.07),
0.075,
teal,
observer
);
// -------------------------------------------------------------------------
// Stylized beacon
// -------------------------------------------------------------------------
const beaconX = 4.48;
const beaconZ = -0.28;
const beaconGround = terrainHeight(beaconX, beaconZ);
const beacon = new THREE.Group();
beacon.position.set(beaconX, beaconGround, beaconZ);
scene.add(beacon);
const towerMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e0c9,
roughness: 0.72
});
const towerStripe = new THREE.MeshStandardMaterial({
color: 0xdd6844,
roughness: 0.72
});
const metal = new THREE.MeshStandardMaterial({
color: 0x294a4d,
roughness: 0.5,
metalness: 0.38
});
mesh(
new THREE.CylinderGeometry(0.53, 0.59, 0.17, 12),
metal,
beacon,
0,
0.085,
0
);
mesh(
new THREE.CylinderGeometry(0.18, 0.34, 1.18, 12),
towerMaterial,
beacon,
0,
0.73,
0
);
mesh(
new THREE.CylinderGeometry(0.285, 0.32, 0.18, 12),
towerStripe,
beacon,
0,
0.43,
0
);
mesh(
new THREE.CylinderGeometry(0.21, 0.24, 0.15, 12),
towerStripe,
beacon,
0,
1.03,
0
);
mesh(
new THREE.CylinderGeometry(0.39, 0.3, 0.12, 12),
metal,
beacon,
0,
1.38,
0
);
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0xffbe58,
emissive: 0xff7b25,
emissiveIntensity: 1.8,
roughness: 0.22
});
const lamp = mesh(
new THREE.SphereGeometry(0.2, 16, 12),
lampMaterial,
beacon,
0,
1.59,
0
);
// Cage around the lamp.
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
makeRod(
new THREE.Vector3(Math.cos(angle) * 0.25, 1.4, Math.sin(angle) * 0.25),
new THREE.Vector3(Math.cos(angle) * 0.25, 1.8, Math.sin(angle) * 0.25),
0.018,
metal,
beacon
);
}
mesh(
new THREE.CylinderGeometry(0.34, 0.28, 0.12, 12),
metal,
beacon,
0,
1.83,
0
);
const beaconLight = new THREE.PointLight(0xff8a37, 2.2, 4.2, 2);
beaconLight.position.set(0, 1.59, 0);
beacon.add(beaconLight);
// -------------------------------------------------------------------------
// Line of sight: rendered through the scene so the ridge physically hides it.
// -------------------------------------------------------------------------
const rayStart = new THREE.Vector3(
observerX + 0.84,
observerGround + 1.39,
observerZ
);
const rayEnd = new THREE.Vector3(
beaconX,
beaconGround + 1.59,
beaconZ
);
const rayDirection = new THREE.Vector3().subVectors(rayEnd, rayStart);
const rayLength = rayDirection.length();
const rayMidpoint = new THREE.Vector3()
.addVectors(rayStart, rayEnd)
.multiplyScalar(0.5);
function makeRay(radius, opacity) {
const ray = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, rayLength, 12, 1, true),
new THREE.MeshBasicMaterial({
color: 0x9cf8f3,
transparent: true,
opacity,
depthTest: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
ray.position.copy(rayMidpoint);
ray.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
rayDirection.clone().normalize()
);
scene.add(ray);
return ray;
}
const rayCore = makeRay(0.018, 0.94);
const rayGlow = makeRay(0.075, 0.12);
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 10, 8),
new THREE.MeshBasicMaterial({ color: 0xd4fff7 })
);
scene.add(pulse);
// Find where the sight ray first meets the terrain.
function findTerrainImpact(start, end) {
let previousT = 0;
for (let i = 1; i <= 1200; i++) {
const t = i / 1200;
const point = new THREE.Vector3().lerpVectors(start, end, t);
const surface = terrainHeight(point.x, point.z);
if (point.y <= surface) {
let low = previousT;
let high = t;
for (let j = 0; j < 24; j++) {
const middle = (low + high) * 0.5;
const test = new THREE.Vector3().lerpVectors(start, end, middle);
if (test.y <= terrainHeight(test.x, test.z)) {
high = middle;
} else {
low = middle;
}
}
return new THREE.Vector3().lerpVectors(start, end, high);
}
previousT = t;
}
return null;
}
const impactPoint = findTerrainImpact(rayStart, rayEnd);
if (impactPoint) {
const impactMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.11),
new THREE.MeshBasicMaterial({ color: 0xff8b50 })
);
impactMarker.position.copy(impactPoint);
impactMarker.position.y += 0.13;
scene.add(impactMarker);
}
// -------------------------------------------------------------------------
// Small environmental details
// -------------------------------------------------------------------------
const rockMaterials = [
new THREE.MeshStandardMaterial({ color: 0x738277, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x879184, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x66776f, roughness: 1, flatShading: true })
];
const rockPositions = [
[-3.25, 1.65, 0.7],
[-2.8, -1.65, 0.55],
[2.9, 1.5, 0.62],
[3.4, -1.7, 0.75],
[-1.4, 2.65, 0.46],
[1.7, 2.55, 0.5],
[-0.35, -2.8, 0.38],
[0.8, 3.1, 0.4]
];
for (const [x, z, scale] of rockPositions) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
rockMaterials[Math.floor(hash(x, z) * rockMaterials.length)]
);
rock.position.set(x, terrainHeight(x, z) + scale * 0.43, z);
rock.scale.set(1.1, 0.78, 0.9);
rock.rotation.set(hash(x, 1) * 2, hash(z, 2) * 3, hash(x, z) * 2);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Custom orbit controls — no addons required.
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.78, 0);
const spherical = new THREE.Spherical(13.5, 1.14, 0.16);
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
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 deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.48,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius + event.deltaY * 0.012,
8.5,
20
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
spherical.set(13.5, 1.14, 0.16);
updateCamera();
});
// -------------------------------------------------------------------------
// Responsive HUD projection and animation
// -------------------------------------------------------------------------
const blockedLabel = document.getElementById("blocked-label");
const projected = new THREE.Vector3();
function updateBlockedLabel() {
if (!impactPoint) {
blockedLabel.style.display = "none";
return;
}
projected.copy(impactPoint);
projected.y += 0.42;
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
blockedLabel.style.display = visible ? "block" : "none";
if (visible) {
blockedLabel.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
blockedLabel.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
let firstResize = true;
function resize() {
const aspect = innerWidth / innerHeight;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
if (firstResize && aspect < 0.8) {
spherical.radius = 18;
updateCamera();
}
firstResize = false;
}
addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Beacon pulse.
const beaconPulse = 0.5 + 0.5 * Math.sin(elapsed * 3.1);
lampMaterial.emissiveIntensity = 1.4 + beaconPulse * 1.25;
beaconLight.intensity = 1.5 + beaconPulse * 1.8;
// A pulse travels along the actual line and disappears behind the ridge.
const rayT = (elapsed * 0.18) % 1;
pulse.position.lerpVectors(rayStart, rayEnd, rayT);
rayGlow.material.opacity = 0.095 + Math.sin(elapsed * 2.4) * 0.025;
updateBlockedLabel();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```