Prompt specification
Build or customize the Three.js 3D scene "Three colored light overlap circles" 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: Three colored light overlap circles
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-colored-light-overlap-circles-x1525
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing additive RGB light mixing. Project red, green, and blue light disks onto a neutral screen with additive blending; label the ideal display model and keep individual source controls independent. Low-poly.
Working Three.js Starter (three-colored-light-overlap-circles-x1525):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Additive RGB — Ideal Display Model</title>
<style>
:root {
color-scheme: dark;
--bg: #080c12;
--panel: rgba(13, 18, 25, 0.88);
--line: rgba(255, 255, 255, 0.11);
--text: #edf3fa;
--muted: #91a0af;
--red: #ff3547;
--green: #2df27c;
--blue: #3f7cff;
}
* {
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;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 48% 45%,
transparent 25%,
rgba(2, 5, 9, 0.16) 67%,
rgba(2, 5, 9, 0.62) 100%
);
}
.intro {
position: fixed;
top: 28px;
left: 30px;
width: min(540px, calc(100vw - 410px));
pointer-events: none;
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: #9eacba;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: #7b8a99;
}
h1 {
margin: 0;
font-size: clamp(38px, 5vw, 66px);
font-weight: 650;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
max-width: 470px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.model-pill {
display: inline-flex;
align-items: center;
gap: 14px;
margin-top: 19px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 7px;
background: rgba(10, 14, 20, 0.64);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
}
.model-pill span {
color: #b4c0cb;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
}
.model-pill b {
color: #ffffff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
font-weight: 500;
}
.panel {
position: fixed;
top: 24px;
right: 24px;
width: 326px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.4),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(20px) saturate(120%);
scrollbar-width: thin;
scrollbar-color: #34404d transparent;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.panel-title {
color: #aab7c4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
}
.mini-button {
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 6px;
background: rgba(255, 255, 255, 0.045);
color: #dce5ed;
cursor: pointer;
font-size: 10px;
transition: background 150ms ease, border-color 150ms ease;
}
.mini-button:hover {
border-color: rgba(255, 255, 255, 0.24);
background: rgba(255, 255, 255, 0.09);
}
.source-card {
--source: #ffffff;
--level: 85%;
padding: 13px 13px 11px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.028);
transition: opacity 160ms ease, border-color 160ms ease;
}
.source-card + .source-card {
margin-top: 9px;
}
.source-card:hover {
border-color: rgba(255, 255, 255, 0.17);
}
.source-card.is-off {
opacity: 0.48;
}
.source-head {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 10px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--source);
box-shadow: 0 0 16px var(--source);
}
.source-name {
font-size: 12px;
font-weight: 700;
}
.source-name small {
display: block;
margin-top: 2px;
color: #778694;
font-size: 9px;
font-weight: 500;
letter-spacing: 0.05em;
}
output {
min-width: 38px;
color: var(--source);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 15px 0 0;
padding: 0;
border-radius: 999px;
appearance: none;
background:
linear-gradient(
to right,
var(--source) 0 var(--level),
#29333e var(--level) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid #10151b;
border-radius: 50%;
appearance: none;
background: var(--source);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #10151b;
border-radius: 50%;
background: var(--source);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}
input[type="range"]:focus-visible {
outline: 2px solid rgba(255, 255, 255, 0.45);
outline-offset: 5px;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #596775;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
}
.paths-row {
display: flex;
align-items: center;
justify-content: space-between;
margin: 14px 2px 16px;
color: #8493a1;
font-size: 10px;
}
.paths-row label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.paths-row input {
width: 14px;
height: 14px;
margin: 0;
accent-color: #7e91a3;
}
.model-card {
padding: 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
background:
linear-gradient(
145deg,
rgba(255, 255, 255, 0.05),
rgba(255, 255, 255, 0.018)
);
}
.model-label {
color: #95a3b0;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
}
.equation {
margin: 10px 0 7px;
color: #f2f7fb;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 16px;
letter-spacing: -0.04em;
}
.equation .r {
color: var(--red);
}
.equation .g {
color: var(--green);
}
.equation .b {
color: var(--blue);
}
.model-description {
margin: 0;
color: #788795;
font-size: 10px;
line-height: 1.55;
}
.output-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.075);
}
#outputSample {
width: 31px;
height: 31px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 6px;
background: #fff;
box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.28);
}
.output-copy strong {
display: block;
color: #c9d3dc;
font-size: 10px;
font-weight: 700;
}
.output-copy span {
display: block;
margin-top: 3px;
color: #687785;
font-size: 9px;
}
.legend {
position: fixed;
bottom: 24px;
left: 28px;
display: flex;
align-items: center;
gap: 15px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 8px;
background: rgba(9, 13, 18, 0.7);
color: #768694;
font-size: 9px;
letter-spacing: 0.06em;
pointer-events: none;
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 6px;
height: 6px;
border-radius: 50%;
}
.legend-divider {
width: 1px;
height: 13px;
background: rgba(255, 255, 255, 0.12);
}
#webglError {
position: fixed;
inset: 50% auto auto 50%;
width: min(420px, calc(100vw - 40px));
padding: 24px;
transform: translate(-50%, -50%);
border: 1px solid #394452;
border-radius: 12px;
background: #111820;
color: #e4ebf2;
text-align: center;
line-height: 1.6;
}
@media (max-width: 760px) {
.intro {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
h1 {
font-size: 38px;
}
.subtitle {
max-width: 310px;
margin-top: 10px;
font-size: 11px;
}
.model-pill {
margin-top: 12px;
padding: 7px 9px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 42vh;
padding: 13px;
border-radius: 12px;
}
.source-card {
padding: 10px 11px 9px;
}
.source-card + .source-card {
margin-top: 7px;
}
.paths-row {
margin: 10px 2px 12px;
}
.model-card {
padding: 12px;
}
.legend {
bottom: calc(42vh + 23px);
left: 12px;
gap: 9px;
padding: 7px 9px;
font-size: 8px;
}
.camera-hint,
.legend-divider {
display: none;
}
}
@media (max-height: 650px) and (min-width: 761px) {
.panel {
top: 12px;
right: 12px;
max-height: calc(100vh - 24px);
}
.intro {
top: 18px;
left: 20px;
}
.legend {
bottom: 14px;
left: 20px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="vignette"></div>
<header class="intro">
<div class="eyebrow">Optics Lab / Channel Mixing</div>
<h1>Additive RGB</h1>
<p class="subtitle">
Three independent light sources project onto one neutral surface.
Overlapping red, green, and blue channels add together.
</p>
<div class="model-pill">
<span>IDEAL DISPLAY MODEL</span>
<b>I(x) = R(x) + G(x) + B(x)</b>
</div>
</header>
<aside class="panel" aria-label="RGB source controls">
<div class="panel-header">
<div class="panel-title">SOURCE CONTROLS</div>
<button class="mini-button" id="resetSources" type="button">Reset</button>
</div>
<div class="source-card" id="card-red" style="--source: var(--red); --level: 85%;">
<div class="source-head">
<span class="swatch"></span>
<div class="source-name">
Red
<small>R CHANNEL</small>
</div>
<output id="value-red" for="red">85%</output>
</div>
<input
id="red"
type="range"
min="0"
max="100"
value="85"
aria-label="Red source intensity"
>
<div class="range-labels"><span>OFF</span><span>100%</span></div>
</div>
<div class="source-card" id="card-green" style="--source: var(--green); --level: 85%;">
<div class="source-head">
<span class="swatch"></span>
<div class="source-name">
Green
<small>G CHANNEL</small>
</div>
<output id="value-green" for="green">85%</output>
</div>
<input
id="green"
type="range"
min="0"
max="100"
value="85"
aria-label="Green source intensity"
>
<div class="range-labels"><span>OFF</span><span>100%</span></div>
</div>
<div class="source-card" id="card-blue" style="--source: var(--blue); --level: 85%;">
<div class="source-head">
<span class="swatch"></span>
<div class="source-name">
Blue
<small>B CHANNEL</small>
</div>
<output id="value-blue" for="blue">85%</output>
</div>
<input
id="blue"
type="range"
min="0"
max="100"
value="85"
aria-label="Blue source intensity"
>
<div class="range-labels"><span>OFF</span><span>100%</span></div>
</div>
<div class="paths-row">
<label>
<input id="showPaths" type="checkbox" checked>
Show light paths
</label>
<button class="mini-button" id="resetView" type="button">Recenter view</button>
</div>
<div class="model-card">
<div class="model-label">IDEAL ADDITIVE DISPLAY MODEL</div>
<div class="equation">
I = <span class="r">R</span> + <span class="g">G</span> + <span class="b">B</span>
</div>
<p class="model-description">
Each slider controls exactly one projector. At full overlap, the three
channel contributions sum toward white.
</p>
<div class="output-row">
<div id="outputSample" aria-label="Combined RGB output color"></div>
<div class="output-copy">
<strong>Triple-overlap output</strong>
<span>Channel-wise radiance addition</span>
</div>
</div>
</div>
</aside>
<footer class="legend">
<span class="legend-item">
<i class="legend-dot" style="background: var(--red)"></i> RED
</span>
<span class="legend-item">
<i class="legend-dot" style="background: var(--green)"></i> GREEN
</span>
<span class="legend-item">
<i class="legend-dot" style="background: var(--blue)"></i> BLUE
</span>
<span class="legend-divider"></span>
<span class="camera-hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RECENTER</span>
</footer>
<div id="webglError" hidden>
This demonstration requires WebGL. Please open it in a modern browser
with hardware acceleration enabled.
</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 viewport = document.getElementById("viewport");
const errorMessage = document.getElementById("webglError");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
errorMessage.hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D additive RGB projection demonstration"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080c12);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const FLOOR_Y = -2.58;
const SCREEN_Z = -2.46;
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(0xb8d4ee, 0x080a0e, 0.85)
);
const keyLight = new THREE.DirectionalLight(0xdce9f7, 1.55);
keyLight.position.set(5, 10, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x496bff, 0.7);
rimLight.position.set(-9, 5, -3);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Ground and projection screen
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1016,
roughness: 0.93,
metalness: 0.08
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(38, 28),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = FLOOR_Y;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
32,
32,
0x334354,
0x18222c
);
grid.position.y = FLOOR_Y + 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.52;
scene.add(grid);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x252d37,
roughness: 0.72,
metalness: 0.28,
flatShading: true
});
const bezelMaterial = new THREE.MeshStandardMaterial({
color: 0x394550,
roughness: 0.58,
metalness: 0.35,
flatShading: true
});
const screenMaterial = new THREE.MeshStandardMaterial({
color: 0x12171d,
roughness: 0.98,
metalness: 0
});
const screenFrame = new THREE.Mesh(
new THREE.BoxGeometry(11.8, 6.55, 0.34),
frameMaterial
);
screenFrame.position.set(0, 0.65, -2.68);
screenFrame.castShadow = true;
screenFrame.receiveShadow = true;
scene.add(screenFrame);
const screenSurface = new THREE.Mesh(
new THREE.PlaneGeometry(11.15, 5.92),
screenMaterial
);
screenSurface.position.set(0, 0.65, -2.49);
screenSurface.receiveShadow = true;
scene.add(screenSurface);
const bezelDepth = 0.14;
for (const x of [-5.56, 5.56]) {
const bezel = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 6.35, bezelDepth),
bezelMaterial
);
bezel.position.set(x, 0.65, -2.46);
bezel.castShadow = true;
scene.add(bezel);
}
for (const y of [-2.43, 3.73]) {
const bezel = new THREE.Mesh(
new THREE.BoxGeometry(11.25, 0.18, bezelDepth),
bezelMaterial
);
bezel.position.set(0, y, -2.46);
bezel.castShadow = true;
scene.add(bezel);
}
// Small supports behind the screen.
for (const x of [-4.35, 4.35]) {
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.26, 0.5, 0.4),
frameMaterial
);
support.position.set(x, -2.36, -2.72);
support.castShadow = true;
scene.add(support);
}
// -------------------------------------------------------------------------
// Canvas-generated scene labels
// -------------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 384;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 4, 4, 376, 88, 16);
context.fillStyle = "rgba(8, 12, 17, 0.88)";
context.fill();
context.strokeStyle = color;
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.font = "700 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 192, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 30;
return sprite;
}
const screenLabel = makeLabel("NEUTRAL SCREEN", "#9aa8b6");
screenLabel.position.set(-4.65, -2.16, -2.35);
screenLabel.scale.set(1.72, 0.43, 1);
scene.add(screenLabel);
// -------------------------------------------------------------------------
// Projectors, additive beams, and projected disks
// -------------------------------------------------------------------------
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x2b3540,
roughness: 0.76,
metalness: 0.24,
flatShading: true
});
const barrelMaterial = new THREE.MeshStandardMaterial({
color: 0x111820,
roughness: 0.62,
metalness: 0.4,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x657685,
transparent: true,
opacity: 0.4
});
const sourceDefinitions = [
{
id: "red",
label: "RED / R",
color: 0xff3547,
css: "#ff3547",
source: [-5.0, 1.18, 3.8],
target: [-2.25, 1.02, SCREEN_Z],
defaultIntensity: 85
},
{
id: "green",
label: "GREEN / G",
color: 0x2df27c,
css: "#2df27c",
source: [-0.1, -0.72, 4.85],
target: [0.0, 0.62, SCREEN_Z],
defaultIntensity: 85
},
{
id: "blue",
label: "BLUE / B",
color: 0x3f7cff,
css: "#3f7cff",
source: [4.95, 1.28, 3.8],
target: [2.25, 1.02, SCREEN_Z],
defaultIntensity: 85
}
];
function createProjector(definition) {
const sourcePosition = new THREE.Vector3(...definition.source);
const targetPosition = new THREE.Vector3(...definition.target);
const projector = new THREE.Group();
projector.position.copy(sourcePosition);
projector.lookAt(targetPosition);
const bodyGeometry = new THREE.CylinderGeometry(
0.46,
0.56,
1.18,
8,
1,
false
);
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.rotation.x = Math.PI / 2;
body.castShadow = true;
body.receiveShadow = true;
projector.add(body);
const bodyEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry),
edgeMaterial
);
bodyEdges.rotation.x = Math.PI / 2;
projector.add(bodyEdges);
const lensBarrel = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.39, 0.24, 12, 1, false),
barrelMaterial
);
lensBarrel.rotation.x = Math.PI / 2;
lensBarrel.position.z = 0.67;
lensBarrel.castShadow = true;
projector.add(lensBarrel);
const lensMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.75,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const lens = new THREE.Mesh(
new THREE.CircleGeometry(0.255, 16),
lensMaterial
);
lens.position.z = 0.805;
lens.renderOrder = 8;
projector.add(lens);
const lensRim = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.045, 6, 12),
barrelMaterial
);
lensRim.position.z = 0.81;
projector.add(lensRim);
// Rear indicator makes the source color visible from the camera side.
const rearSignal = new THREE.Mesh(
new THREE.CircleGeometry(0.14, 8),
lensMaterial.clone()
);
rearSignal.position.z = -0.605;
rearSignal.rotation.y = Math.PI;
rearSignal.renderOrder = 8;
projector.add(rearSignal);
const pointLight = new THREE.PointLight(
definition.color,
0,
11,
2
);
pointLight.position.set(0, 0, 0.86);
projector.add(pointLight);
scene.add(projector);
// Low-poly stand and base.
const postHeight = Math.max(
0.65,
sourcePosition.y - FLOOR_Y - 0.62
);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(
0.09,
0.14,
postHeight,
6,
1,
false
),
barrelMaterial
);
post.position.set(
sourcePosition.x,
FLOOR_Y + postHeight / 2,
sourcePosition.z
);
post.castShadow = true;
scene.add(post);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.66, 0.8, 0.18, 8),
bodyMaterial
);
base.position.set(
sourcePosition.x,
FLOOR_Y + 0.09,
sourcePosition.z
);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseRing = new THREE.Mesh(
new THREE.RingGeometry(0.7, 0.76, 8),
new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.28,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
})
);
baseRing.rotation.x = -Math.PI / 2;
baseRing.position.set(
sourcePosition.x,
FLOOR_Y + 0.015,
sourcePosition.z
);
scene.add(baseRing);
// The beam widens from the projector to the screen.
const direction = targetPosition.clone().sub(sourcePosition);
const beamLength = direction.length();
direction.normalize();
const beamMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.05,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(
1.95,
0.055,
beamLength,
16,
1,
true
),
beamMaterial
);
beam.position.copy(sourcePosition).add(targetPosition).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
beam.renderOrder = 3;
scene.add(beam);
// The actual projected disk on the neutral screen.
const diskMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.88,
blending: THREE.AdditiveBlending,
depthWrite: false,
depthTest: true,
side: THREE.DoubleSide,
toneMapped: false
});
const disk = new THREE.Mesh(
new THREE.CircleGeometry(1.95, 40),
diskMaterial
);
disk.position.copy(targetPosition);
disk.renderOrder = 10;
scene.add(disk);
const ringMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.16,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const diskRing = new THREE.Mesh(
new THREE.RingGeometry(1.94, 1.985, 40),
ringMaterial
);
diskRing.position.copy(targetPosition);
diskRing.position.z += 0.008;
diskRing.renderOrder = 11;
scene.add(diskRing);
const label = makeLabel(definition.label, definition.css);
label.position.set(
sourcePosition.x,
sourcePosition.y + 1.05,
sourcePosition.z
);
label.scale.set(1.75, 0.44, 1);
scene.add(label);
return {
...definition,
sourcePosition,
targetPosition,
intensity: definition.defaultIntensity / 100,
diskMaterial,
ringMaterial,
beamMaterial,
beam,
lensMaterial,
rearSignalMaterial: rearSignal.material,
pointLight
};
}
const sources = sourceDefinitions.map(createProjector);
// -------------------------------------------------------------------------
// Independent source controls
// -------------------------------------------------------------------------
const outputSample = document.getElementById("outputSample");
let showPaths = true;
function updateCombinedSample() {
const r = Math.round(255 * sources[0].intensity);
const g = Math.round(255 * sources[1].intensity);
const b = Math.round(255 * sources[2].intensity);
outputSample.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
outputSample.setAttribute(
"aria-label",
`Combined red ${r}, green ${g}, blue ${b}`
);
}
function updateSource(source) {
const value = source.intensity;
source.diskMaterial.opacity = 0.88 * value;
source.ringMaterial.opacity = 0.16 * value;
source.beamMaterial.opacity = 0.05 * value;
source.beam.visible = showPaths && value > 0.001;
source.lensMaterial.opacity = 0.78 * value;
source.rearSignalMaterial.opacity = 0.78 * value;
source.pointLight.intensity = 11 * value;
const slider = document.getElementById(source.id);
const output = document.getElementById(`value-${source.id}`);
const card = document.getElementById(`card-${source.id}`);
slider.style.setProperty("--level", `${Math.round(value * 100)}%`);
output.value = `${Math.round(value * 100)}%`;
card.classList.toggle("is-off", value <= 0.001);
}
for (const source of sources) {
const slider = document.getElementById(source.id);
slider.addEventListener("input", () => {
source.intensity = Number(slider.value) / 100;
updateSource(source);
updateCombinedSample();
});
updateSource(source);
}
updateCombinedSample();
document.getElementById("showPaths").addEventListener("change", (event) => {
showPaths = event.target.checked;
for (const source of sources) {
updateSource(source);
}
});
document.getElementById("resetSources").addEventListener("click", () => {
for (const source of sources) {
const slider = document.getElementById(source.id);
source.intensity = source.defaultIntensity / 100;
slider.value = String(source.defaultIntensity);
updateSource(source);
}
updateCombinedSample();
});
// -------------------------------------------------------------------------
// Custom camera controls — no external controls/addons
// -------------------------------------------------------------------------
const view = {
azimuth: 0.34,
polar: 1.13,
distance: window.innerWidth < 760 ? 25.5 : 18.2
};
const desiredView = {
azimuth: view.azimuth,
polar: view.polar,
distance: view.distance
};
const cameraTarget = new THREE.Vector3(0, 0.22, -0.65);
function resetView() {
desiredView.azimuth = 0.34;
desiredView.polar = 1.13;
desiredView.distance = window.innerWidth < 760 ? 25.5 : 18.2;
}
function updateCamera() {
const horizontal = Math.sin(view.polar) * view.distance;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(view.azimuth),
cameraTarget.y + Math.cos(view.polar) * view.distance,
cameraTarget.z + horizontal * Math.cos(view.azimuth)
);
camera.lookAt(cameraTarget);
}
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.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.azimuth -= deltaX * 0.006;
desiredView.polar = THREE.MathUtils.clamp(
desiredView.polar - deltaY * 0.005,
0.48,
1.47
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event &&
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const delta =
event.deltaMode === 1
? event.deltaY * 16
: event.deltaY;
desiredView.distance = THREE.MathUtils.clamp(
desiredView.distance + delta * 0.012,
10.5,
31
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("resetView").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const activeTag = document.activeElement?.tagName;
if (activeTag === "INPUT" || activeTag === "BUTTON") return;
const step = 0.08;
if (event.key === "ArrowLeft") {
desiredView.azimuth += step;
event.preventDefault();
} else if (event.key === "ArrowRight") {
desiredView.azimuth -= step;
event.preventDefault();
} else if (event.key === "ArrowUp") {
desiredView.polar = Math.max(0.48, desiredView.polar - step);
event.preventDefault();
} else if (event.key === "ArrowDown") {
desiredView.polar = Math.min(1.47, desiredView.polar + step);
event.preventDefault();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (width < 760) {
desiredView.distance = Math.max(desiredView.distance, 25.5);
}
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
const smoothing = 0.11;
view.azimuth +=
(desiredView.azimuth - view.azimuth) * smoothing;
view.polar +=
(desiredView.polar - view.polar) * smoothing;
view.distance +=
(desiredView.distance - view.distance) * smoothing;
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```