Voice particle cloud 3D hero
Sixteen thousand points of light listen as a breathing sphere, think as a spinning knot and speak as a sound ribbon. Push them with the cursor; click for a ripple.
"use client";
import { useEffect, useRef, useState } from "react";
import * as THREE from "three";
import "./voice-hero.css";
type Mode = "listen" | "think" | "speak";
type VoiceHeroProps = {
title?: string;
text?: string;
cta?: { label: string; href: string };
/** What the visitor hears in each state: who is talking and what they say. */
script?: Record<Mode, { who: string; line: string }>;
};
const MODES: { id: Mode; label: string }[] = [
{ id: "listen", label: "Listening" },
{ id: "think", label: "Thinking" },
{ id: "speak", label: "Speaking" },
];
const DEFAULT_SCRIPT: Record<Mode, { who: string; line: string }> = {
listen: { who: "You", line: "Move my 3pm with Dana to Thursday, same time." },
think: { who: "Murmur", line: "Checking Dana's calendar and yours…" },
speak: {
who: "Murmur",
line: "Done. Thursday at 3pm, and I've let Dana know.",
},
};
const WEIGHTS: Record<Mode, THREE.Vector3> = {
listen: new THREE.Vector3(1, 0, 0),
think: new THREE.Vector3(0, 1, 0),
speak: new THREE.Vector3(0, 0, 1),
};
const vertex = /* glsl */ `
uniform float uTime;
uniform float uLevel;
uniform float uSize;
uniform float uPixel;
uniform vec3 uW;
uniform vec3 uMouse;
uniform float uMouseOn;
uniform vec3 uPulseAt;
uniform float uPulse;
attribute vec3 aA;
attribute vec3 aB;
attribute vec3 aC;
attribute float aR;
varying float vGlow;
varying float vR;
void main() {
// Listening: a breathing sphere that shivers with the voice it hears.
vec3 a = aA * (1.0 + 0.05 * sin(uTime * 1.4 + aR * 6.2831)
+ uLevel * 0.22 * sin(uTime * 11.0 + aA.y * 5.0));
// Speaking: a ribbon of sound whose height follows the voice.
vec3 c = aC;
float env = exp(-pow(c.x * 0.75, 2.0));
c.y = (sin(c.x * 3.4 - uTime * 5.0) * 0.6 + sin(c.x * 8.0 + uTime * 3.0) * 0.22)
* env * (0.18 + uLevel * 1.5) * (0.55 + 0.45 * cos(c.z * 3.0 + uTime));
vec3 p = a * uW.x + aB * uW.y + c * uW.z;
// Mid-morph the points scatter a little, so the change reads as a swirl.
float between = 1.0 - max(uW.x, max(uW.y, uW.z));
p += vec3(sin(aR * 40.0 + uTime), cos(aR * 31.0 + uTime * 1.3), sin(aR * 23.0 - uTime)) * between * 1.1;
vec4 wp = modelMatrix * vec4(p, 1.0);
vec3 d = wp.xyz - uMouse;
float push = uMouseOn * smoothstep(1.2, 0.0, length(d));
wp.xyz += normalize(d + 1e-4) * push * 0.6;
float pd = length(wp.xyz - uPulseAt);
float ring = exp(-pow((pd - uPulse * 5.0) * 3.0, 2.0)) * (1.0 - uPulse);
wp.xyz += normalize(wp.xyz - uPulseAt + 1e-4) * ring * 0.4;
vGlow = clamp(push + ring, 0.0, 1.0);
vR = aR;
vec4 mv = viewMatrix * wp;
gl_Position = projectionMatrix * mv;
gl_PointSize = uSize * uPixel * (0.55 + aR * 0.9) * (1.0 + vGlow * 0.8) / -mv.z;
}
`;
const fragment = /* glsl */ `
uniform vec3 uA;
uniform vec3 uB;
uniform vec3 uC;
varying float vGlow;
varying float vR;
void main() {
float d = length(gl_PointCoord - 0.5);
if (d > 0.5) discard;
float a = smoothstep(0.5, 0.0, d);
vec3 col = mix(uA, uB, smoothstep(0.2, 0.9, vR));
col = mix(col, uC, vGlow);
gl_FragColor = vec4(col * a, a);
}
`;
/**
* VoiceHero
* - Thousands of points live in one shader. Each point knows three homes: a sphere (listening),
* a knot (thinking) and a sound ribbon (speaking); the mode tweens between them.
* - The cursor pushes points away; a click sends a ripple through them.
* - The transcript types itself for each mode; the modes cycle on their own until you pick one.
*/
export function VoiceHero({
title = "Say it once. Murmur sorts the calendar.",
text = "A voice assistant for your meetings. It listens, checks everyone's calendar and books the time, out loud or in a whisper.",
cta = { label: "Join the beta", href: "#murmur-beta" },
script = DEFAULT_SCRIPT,
}: VoiceHeroProps) {
const rootRef = useRef<HTMLElement>(null);
const stageRef = useRef<HTMLDivElement>(null);
const modeRef = useRef<Mode>("listen");
const pickedRef = useRef(false);
const [mode, setMode] = useState<Mode>("listen");
const [failed, setFailed] = useState(false);
const choose = (m: Mode) => {
pickedRef.current = true;
modeRef.current = m;
setMode(m);
};
// Cycle through the modes on its own until the visitor picks one.
useEffect(() => {
if (
pickedRef.current ||
matchMedia("(prefers-reduced-motion: reduce)").matches
)
return;
const id = window.setTimeout(() => {
if (pickedRef.current) return;
const next =
MODES[(MODES.findIndex((m) => m.id === mode) + 1) % MODES.length].id;
modeRef.current = next;
setMode(next);
}, 5200);
return () => clearTimeout(id);
}, [mode]);
useEffect(() => {
const root = rootRef.current;
const stage = stageRef.current;
if (!root || !stage) return;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: false, alpha: true });
} catch {
const id = requestAnimationFrame(() => setFailed(true));
return () => cancelAnimationFrame(id);
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);
camera.position.set(0, 0, 8);
/* ---- Three homes for every point ---- */
const small = Math.min(stage.clientWidth, stage.clientHeight) < 520;
const N = small ? 9000 : 16000;
const aA = new Float32Array(N * 3);
const aB = new Float32Array(N * 3);
const aC = new Float32Array(N * 3);
const aR = new Float32Array(N);
const knot = new THREE.TorusKnotGeometry(1.05, 0.3, 320, 28, 2, 3);
const kp = knot.attributes.position;
const golden = Math.PI * (3 - Math.sqrt(5));
const cols = Math.ceil(Math.sqrt(N * 3));
const rowsN = Math.ceil(N / cols);
for (let i = 0; i < N; i++) {
// Sphere: a Fibonacci spiral, so the points are evenly spread.
const y = 1 - (i / (N - 1)) * 2;
const r = Math.sqrt(1 - y * y);
const th = golden * i;
const rad = 1.55 + (Math.random() - 0.5) * 0.06;
aA.set([Math.cos(th) * r * rad, y * rad, Math.sin(th) * r * rad], i * 3);
// Knot: a random vertex of a torus knot, nudged off the surface.
const k = Math.floor(Math.random() * kp.count);
aB.set(
[
kp.getX(k) + (Math.random() - 0.5) * 0.08,
kp.getY(k) + (Math.random() - 0.5) * 0.08,
kp.getZ(k) + (Math.random() - 0.5) * 0.08,
],
i * 3,
);
// Ribbon: a long, thin grid; the shader lifts it into a wave.
const cx = i % cols;
const cz = Math.floor(i / cols);
aC.set([(cx / cols - 0.5) * 3.8, 0, (cz / rowsN - 0.5) * 0.9], i * 3);
aR[i] = Math.random();
}
knot.dispose();
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.BufferAttribute(aA, 3));
geo.setAttribute("aA", new THREE.BufferAttribute(aA, 3));
geo.setAttribute("aB", new THREE.BufferAttribute(aB, 3));
geo.setAttribute("aC", new THREE.BufferAttribute(aC, 3));
geo.setAttribute("aR", new THREE.BufferAttribute(aR, 1));
geo.boundingSphere = new THREE.Sphere(new THREE.Vector3(), 6);
const uniforms = {
uTime: { value: 0 },
uLevel: { value: 0 },
uSize: { value: small ? 34 : 30 },
uPixel: { value: renderer.getPixelRatio() },
uW: { value: WEIGHTS.listen.clone() },
uMouse: { value: new THREE.Vector3(99, 99, 0) },
uMouseOn: { value: 0 },
uPulseAt: { value: new THREE.Vector3() },
uPulse: { value: 1 },
uA: { value: new THREE.Color("#ff6a3d") },
uB: { value: new THREE.Color("#b9a7ff") },
uC: { value: new THREE.Color("#fff4d6") },
};
const mat = new THREE.ShaderMaterial({
uniforms,
vertexShader: vertex,
fragmentShader: fragment,
transparent: true,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geo, mat);
const group = new THREE.Group();
group.add(points);
scene.add(group);
const resize = (w: number, h: number) => {
if (w < 2 || h < 2) return;
renderer.setSize(w, h, false);
camera.aspect = w / h;
camera.updateProjectionMatrix();
const wide = camera.aspect > 1.05;
// Narrow: centre the cloud in the top ~300px, above the copy, and fit it to the width.
const halfH =
Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * camera.position.z;
group.position.set(
wide ? Math.min(2.4, camera.aspect * 1.45) : 0,
wide ? 0 : halfH * (1 - 340 / h),
0,
);
group.scale.setScalar(
wide
? Math.min(1, camera.aspect * 0.7)
: Math.min(0.7, camera.aspect * 1.2),
);
};
const ro = new ResizeObserver(([e]) =>
resize(e.contentRect.width, e.contentRect.height),
);
ro.observe(stage);
/* ---- Pointer: push and ripple ---- */
const ray = new THREE.Raycaster();
const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const ndc = new THREE.Vector2();
const hit = new THREE.Vector3();
let mouseOn = 0;
const toWorld = (e: PointerEvent) => {
const r = stage.getBoundingClientRect();
ndc.set(
((e.clientX - r.left) / r.width) * 2 - 1,
-((e.clientY - r.top) / r.height) * 2 + 1,
);
ray.setFromCamera(ndc, camera);
return ray.ray.intersectPlane(plane, hit);
};
const onMove = (e: PointerEvent) => {
if (toWorld(e)) {
uniforms.uMouse.value.copy(hit);
mouseOn = 1;
}
};
const onLeave = () => {
mouseOn = 0;
};
const onDown = (e: PointerEvent) => {
if (!toWorld(e)) return;
uniforms.uPulseAt.value.copy(hit);
uniforms.uPulse.value = 0;
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
stage.addEventListener("pointerdown", onDown);
/* ---- Loop ---- */
let raf = 0;
let visible = true;
let level = 0;
let spin = 0;
const t0 = performance.now();
let last = t0;
const loop = (now: number) => {
raf = 0;
if (!visible || document.hidden) return;
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
const t = (now - t0) / 1000;
const m = modeRef.current;
// A made-up voice: syllables (fast wobble) inside words (slow gate) with pauses.
const syll = 0.5 + 0.5 * Math.sin(t * 14) * Math.sin(t * 5.3);
const words = Math.max(0, Math.sin(t * 1.7) + Math.sin(t * 0.9) * 0.6);
const voice = Math.min(1, syll * words);
const want = m === "speak" ? voice : m === "listen" ? voice * 0.55 : 0;
level += (want - level) * (reduce ? 1 : 0.15);
uniforms.uW.value.lerp(WEIGHTS[m], reduce ? 1 : 1 - Math.pow(0.02, dt));
uniforms.uTime.value = reduce ? 0 : t;
uniforms.uLevel.value = reduce ? 0 : level;
uniforms.uMouseOn.value += (mouseOn - uniforms.uMouseOn.value) * 0.12;
if (uniforms.uPulse.value < 1)
uniforms.uPulse.value = Math.min(1, uniforms.uPulse.value + dt * 0.9);
if (!reduce) {
spin += dt * (m === "think" ? 0.9 : 0.18);
group.rotation.set(
m === "speak" ? 0.35 : Math.sin(t * 0.3) * 0.2,
m === "speak" ? 0 : spin,
0,
);
points.rotation.y += (0 - points.rotation.y) * 0.05;
} else {
group.rotation.set(m === "speak" ? 0.35 : 0.2, 0.6, 0);
}
root.style.setProperty("--level", level.toFixed(3));
renderer.render(scene, camera);
raf = requestAnimationFrame(loop);
};
const wake = () => {
if (!raf && visible && !document.hidden) {
last = performance.now();
raf = requestAnimationFrame(loop);
}
};
const io = new IntersectionObserver(([e]) => {
visible = e.isIntersecting;
wake();
});
io.observe(stage);
document.addEventListener("visibilitychange", wake);
wake();
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
io.disconnect();
document.removeEventListener("visibilitychange", wake);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
stage.removeEventListener("pointerdown", onDown);
geo.dispose();
mat.dispose();
renderer.dispose();
renderer.forceContextLoss();
renderer.domElement.remove();
};
}, []);
const line = script[mode];
return (
<section
ref={rootRef}
className="gu-murmur"
data-mode={mode}
data-failed={failed || undefined}
aria-labelledby="gu-murmur-title"
>
<div ref={stageRef} className="gu-murmur__stage" aria-hidden="true" />
{failed && <div className="gu-murmur__fallback" aria-hidden="true" />}
<header className="gu-murmur__bar">
<a className="gu-murmur__mark" href="#">
<span aria-hidden="true" />
murmur
</a>
<a className="gu-murmur__ghost" href="#murmur-how">
How it works
</a>
</header>
<div className="gu-murmur__copy">
<h1 id="gu-murmur-title">{title}</h1>
<p>{text}</p>
<div className="gu-murmur__modes" role="group" aria-label="Show Murmur">
{MODES.map((m) => (
<button
key={m.id}
type="button"
aria-pressed={mode === m.id}
onClick={() => choose(m.id)}
>
<i aria-hidden="true" />
{m.label}
</button>
))}
</div>
<figure className="gu-murmur__said">
<figcaption>{line.who}</figcaption>
<blockquote key={mode} aria-live="polite">
<span className="sr-only">{line.line}</span>
<span aria-hidden="true">
{Array.from(line.line).map((ch, i) => (
<span key={i} style={{ animationDelay: `${i * 26}ms` }}>
{ch}
</span>
))}
</span>
</blockquote>
</figure>
<a className="gu-murmur__cta" href={cta.href}>
{cta.label}
</a>
</div>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Voice particle cloud 3D hero
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A dark hero for a voice assistant ("Murmur"). The product is shown as a cloud of ~16,000 glowing points (three.js, one ShaderMaterial) that changes shape with the assistant's state: a breathing sphere while listening, a spinning torus knot while thinking, a rippling ribbon of sound while speaking.
## Layout and look
- Section min-height 720px, background #0b0d14 with faint lilac and coral glows behind the cloud. Text #f1ece4, muted #9a97a6, coral #ff6a3d, lilac #b9a7ff.
- Top bar: a dot logo that swells and glows with the voice level, wordmark "murmur", outlined "How it works" link.
- Left column (max 520px): big tight h1, muted paragraph, a pill segmented control (Listening / Thinking / Speaking, the pressed one has a pulsing coral dot), a transcript block (speaker name + words that type in letter by letter, a coral left border, lilac while the visitor is speaking), and a coral button whose glow follows the voice level.
- The cloud sits right of the copy on wide screens and above it on narrow ones.
## The 3D scene
1. Each point has three attributes: aA (Fibonacci sphere, r 1.55), aB (a random vertex of TorusKnotGeometry(1.05, 0.3, 320, 28, 2, 3) with jitter), aC (a 3.8 × 0.9 grid). Plus aR, a random 0–1 value.
2. Vertex shader: position = aA·w.x + aB·w.y + ribbon·w.z. The sphere breathes and shivers with uLevel. The ribbon's height is two sine waves × a gaussian envelope × the level. Mid-morph, points scatter by (1 − max weight), so changes read as a swirl.
3. Cursor: raycast onto the z = 0 plane; points within 1.2 units are pushed away and brighten. Click: a ring travels out from the click point and lifts the points it passes.
4. Points are round, soft, additive, sized by depth. Colour runs from coral to lilac by aR, turning pale gold where pushed.
5. The voice level is made up: fast syllable wobble × slow word gate with pauses. It is full while speaking, about half while listening, and zero while thinking.
## Behaviour
- Modes cycle every 5.2s until the visitor presses one. Weights tween toward the target each frame (about 1.2s).
- The knot spins faster while thinking; the ribbon tilts toward the viewer while speaking.
- Rendering pauses off screen and in hidden tabs; on unmount dispose everything and call `forceContextLoss()`.
- Without WebGL a blurred CSS orb stands in.
## Accessibility
The canvas is decorative. The mode buttons use aria-pressed. The transcript is an aria-live blockquote with the full sentence in an sr-only span; the typing letters are aria-hidden.
## Reduced motion
No auto-cycle, no breathing or drift, instant morphs, no typing.
## Props
title, text, cta ({ label, href }), script (per mode: { who, line }).
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: three. Translate it faithfully; do not add new libraries unless my framework needs them.
### VoiceHero.tsx
```tsx
"use client";
import { useEffect, useRef, useState } from "react";
import * as THREE from "three";
import "./voice-hero.css";
type Mode = "listen" | "think" | "speak";
type VoiceHeroProps = {
title?: string;
text?: string;
cta?: { label: string; href: string };
/** What the visitor hears in each state: who is talking and what they say. */
script?: Record<Mode, { who: string; line: string }>;
};
const MODES: { id: Mode; label: string }[] = [
{ id: "listen", label: "Listening" },
{ id: "think", label: "Thinking" },
{ id: "speak", label: "Speaking" },
];
const DEFAULT_SCRIPT: Record<Mode, { who: string; line: string }> = {
listen: { who: "You", line: "Move my 3pm with Dana to Thursday, same time." },
think: { who: "Murmur", line: "Checking Dana's calendar and yours…" },
speak: {
who: "Murmur",
line: "Done. Thursday at 3pm, and I've let Dana know.",
},
};
const WEIGHTS: Record<Mode, THREE.Vector3> = {
listen: new THREE.Vector3(1, 0, 0),
think: new THREE.Vector3(0, 1, 0),
speak: new THREE.Vector3(0, 0, 1),
};
const vertex = /* glsl */ `
uniform float uTime;
uniform float uLevel;
uniform float uSize;
uniform float uPixel;
uniform vec3 uW;
uniform vec3 uMouse;
uniform float uMouseOn;
uniform vec3 uPulseAt;
uniform float uPulse;
attribute vec3 aA;
attribute vec3 aB;
attribute vec3 aC;
attribute float aR;
varying float vGlow;
varying float vR;
void main() {
// Listening: a breathing sphere that shivers with the voice it hears.
vec3 a = aA * (1.0 + 0.05 * sin(uTime * 1.4 + aR * 6.2831)
+ uLevel * 0.22 * sin(uTime * 11.0 + aA.y * 5.0));
// Speaking: a ribbon of sound whose height follows the voice.
vec3 c = aC;
float env = exp(-pow(c.x * 0.75, 2.0));
c.y = (sin(c.x * 3.4 - uTime * 5.0) * 0.6 + sin(c.x * 8.0 + uTime * 3.0) * 0.22)
* env * (0.18 + uLevel * 1.5) * (0.55 + 0.45 * cos(c.z * 3.0 + uTime));
vec3 p = a * uW.x + aB * uW.y + c * uW.z;
// Mid-morph the points scatter a little, so the change reads as a swirl.
float between = 1.0 - max(uW.x, max(uW.y, uW.z));
p += vec3(sin(aR * 40.0 + uTime), cos(aR * 31.0 + uTime * 1.3), sin(aR * 23.0 - uTime)) * between * 1.1;
vec4 wp = modelMatrix * vec4(p, 1.0);
vec3 d = wp.xyz - uMouse;
float push = uMouseOn * smoothstep(1.2, 0.0, length(d));
wp.xyz += normalize(d + 1e-4) * push * 0.6;
float pd = length(wp.xyz - uPulseAt);
float ring = exp(-pow((pd - uPulse * 5.0) * 3.0, 2.0)) * (1.0 - uPulse);
wp.xyz += normalize(wp.xyz - uPulseAt + 1e-4) * ring * 0.4;
vGlow = clamp(push + ring, 0.0, 1.0);
vR = aR;
vec4 mv = viewMatrix * wp;
gl_Position = projectionMatrix * mv;
gl_PointSize = uSize * uPixel * (0.55 + aR * 0.9) * (1.0 + vGlow * 0.8) / -mv.z;
}
`;
const fragment = /* glsl */ `
uniform vec3 uA;
uniform vec3 uB;
uniform vec3 uC;
varying float vGlow;
varying float vR;
void main() {
float d = length(gl_PointCoord - 0.5);
if (d > 0.5) discard;
float a = smoothstep(0.5, 0.0, d);
vec3 col = mix(uA, uB, smoothstep(0.2, 0.9, vR));
col = mix(col, uC, vGlow);
gl_FragColor = vec4(col * a, a);
}
`;
/**
* VoiceHero
* - Thousands of points live in one shader. Each point knows three homes: a sphere (listening),
* a knot (thinking) and a sound ribbon (speaking); the mode tweens between them.
* - The cursor pushes points away; a click sends a ripple through them.
* - The transcript types itself for each mode; the modes cycle on their own until you pick one.
*/
export function VoiceHero({
title = "Say it once. Murmur sorts the calendar.",
text = "A voice assistant for your meetings. It listens, checks everyone's calendar and books the time, out loud or in a whisper.",
cta = { label: "Join the beta", href: "#murmur-beta" },
script = DEFAULT_SCRIPT,
}: VoiceHeroProps) {
const rootRef = useRef<HTMLElement>(null);
const stageRef = useRef<HTMLDivElement>(null);
const modeRef = useRef<Mode>("listen");
const pickedRef = useRef(false);
const [mode, setMode] = useState<Mode>("listen");
const [failed, setFailed] = useState(false);
const choose = (m: Mode) => {
pickedRef.current = true;
modeRef.current = m;
setMode(m);
};
// Cycle through the modes on its own until the visitor picks one.
useEffect(() => {
if (
pickedRef.current ||
matchMedia("(prefers-reduced-motion: reduce)").matches
)
return;
const id = window.setTimeout(() => {
if (pickedRef.current) return;
const next =
MODES[(MODES.findIndex((m) => m.id === mode) + 1) % MODES.length].id;
modeRef.current = next;
setMode(next);
}, 5200);
return () => clearTimeout(id);
}, [mode]);
useEffect(() => {
const root = rootRef.current;
const stage = stageRef.current;
if (!root || !stage) return;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: false, alpha: true });
} catch {
const id = requestAnimationFrame(() => setFailed(true));
return () => cancelAnimationFrame(id);
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 50);
camera.position.set(0, 0, 8);
/* ---- Three homes for every point ---- */
const small = Math.min(stage.clientWidth, stage.clientHeight) < 520;
const N = small ? 9000 : 16000;
const aA = new Float32Array(N * 3);
const aB = new Float32Array(N * 3);
const aC = new Float32Array(N * 3);
const aR = new Float32Array(N);
const knot = new THREE.TorusKnotGeometry(1.05, 0.3, 320, 28, 2, 3);
const kp = knot.attributes.position;
const golden = Math.PI * (3 - Math.sqrt(5));
const cols = Math.ceil(Math.sqrt(N * 3));
const rowsN = Math.ceil(N / cols);
for (let i = 0; i < N; i++) {
// Sphere: a Fibonacci spiral, so the points are evenly spread.
const y = 1 - (i / (N - 1)) * 2;
const r = Math.sqrt(1 - y * y);
const th = golden * i;
const rad = 1.55 + (Math.random() - 0.5) * 0.06;
aA.set([Math.cos(th) * r * rad, y * rad, Math.sin(th) * r * rad], i * 3);
// Knot: a random vertex of a torus knot, nudged off the surface.
const k = Math.floor(Math.random() * kp.count);
aB.set(
[
kp.getX(k) + (Math.random() - 0.5) * 0.08,
kp.getY(k) + (Math.random() - 0.5) * 0.08,
kp.getZ(k) + (Math.random() - 0.5) * 0.08,
],
i * 3,
);
// Ribbon: a long, thin grid; the shader lifts it into a wave.
const cx = i % cols;
const cz = Math.floor(i / cols);
aC.set([(cx / cols - 0.5) * 3.8, 0, (cz / rowsN - 0.5) * 0.9], i * 3);
aR[i] = Math.random();
}
knot.dispose();
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.BufferAttribute(aA, 3));
geo.setAttribute("aA", new THREE.BufferAttribute(aA, 3));
geo.setAttribute("aB", new THREE.BufferAttribute(aB, 3));
geo.setAttribute("aC", new THREE.BufferAttribute(aC, 3));
geo.setAttribute("aR", new THREE.BufferAttribute(aR, 1));
geo.boundingSphere = new THREE.Sphere(new THREE.Vector3(), 6);
const uniforms = {
uTime: { value: 0 },
uLevel: { value: 0 },
uSize: { value: small ? 34 : 30 },
uPixel: { value: renderer.getPixelRatio() },
uW: { value: WEIGHTS.listen.clone() },
uMouse: { value: new THREE.Vector3(99, 99, 0) },
uMouseOn: { value: 0 },
uPulseAt: { value: new THREE.Vector3() },
uPulse: { value: 1 },
uA: { value: new THREE.Color("#ff6a3d") },
uB: { value: new THREE.Color("#b9a7ff") },
uC: { value: new THREE.Color("#fff4d6") },
};
const mat = new THREE.ShaderMaterial({
uniforms,
vertexShader: vertex,
fragmentShader: fragment,
transparent: true,
depthWrite: false,
blending: THREE.AdditiveBlending,
});
const points = new THREE.Points(geo, mat);
const group = new THREE.Group();
group.add(points);
scene.add(group);
const resize = (w: number, h: number) => {
if (w < 2 || h < 2) return;
renderer.setSize(w, h, false);
camera.aspect = w / h;
camera.updateProjectionMatrix();
const wide = camera.aspect > 1.05;
// Narrow: centre the cloud in the top ~300px, above the copy, and fit it to the width.
const halfH =
Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * camera.position.z;
group.position.set(
wide ? Math.min(2.4, camera.aspect * 1.45) : 0,
wide ? 0 : halfH * (1 - 340 / h),
0,
);
group.scale.setScalar(
wide
? Math.min(1, camera.aspect * 0.7)
: Math.min(0.7, camera.aspect * 1.2),
);
};
const ro = new ResizeObserver(([e]) =>
resize(e.contentRect.width, e.contentRect.height),
);
ro.observe(stage);
/* ---- Pointer: push and ripple ---- */
const ray = new THREE.Raycaster();
const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const ndc = new THREE.Vector2();
const hit = new THREE.Vector3();
let mouseOn = 0;
const toWorld = (e: PointerEvent) => {
const r = stage.getBoundingClientRect();
ndc.set(
((e.clientX - r.left) / r.width) * 2 - 1,
-((e.clientY - r.top) / r.height) * 2 + 1,
);
ray.setFromCamera(ndc, camera);
return ray.ray.intersectPlane(plane, hit);
};
const onMove = (e: PointerEvent) => {
if (toWorld(e)) {
uniforms.uMouse.value.copy(hit);
mouseOn = 1;
}
};
const onLeave = () => {
mouseOn = 0;
};
const onDown = (e: PointerEvent) => {
if (!toWorld(e)) return;
uniforms.uPulseAt.value.copy(hit);
uniforms.uPulse.value = 0;
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
stage.addEventListener("pointerdown", onDown);
/* ---- Loop ---- */
let raf = 0;
let visible = true;
let level = 0;
let spin = 0;
const t0 = performance.now();
let last = t0;
const loop = (now: number) => {
raf = 0;
if (!visible || document.hidden) return;
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
const t = (now - t0) / 1000;
const m = modeRef.current;
// A made-up voice: syllables (fast wobble) inside words (slow gate) with pauses.
const syll = 0.5 + 0.5 * Math.sin(t * 14) * Math.sin(t * 5.3);
const words = Math.max(0, Math.sin(t * 1.7) + Math.sin(t * 0.9) * 0.6);
const voice = Math.min(1, syll * words);
const want = m === "speak" ? voice : m === "listen" ? voice * 0.55 : 0;
level += (want - level) * (reduce ? 1 : 0.15);
uniforms.uW.value.lerp(WEIGHTS[m], reduce ? 1 : 1 - Math.pow(0.02, dt));
uniforms.uTime.value = reduce ? 0 : t;
uniforms.uLevel.value = reduce ? 0 : level;
uniforms.uMouseOn.value += (mouseOn - uniforms.uMouseOn.value) * 0.12;
if (uniforms.uPulse.value < 1)
uniforms.uPulse.value = Math.min(1, uniforms.uPulse.value + dt * 0.9);
if (!reduce) {
spin += dt * (m === "think" ? 0.9 : 0.18);
group.rotation.set(
m === "speak" ? 0.35 : Math.sin(t * 0.3) * 0.2,
m === "speak" ? 0 : spin,
0,
);
points.rotation.y += (0 - points.rotation.y) * 0.05;
} else {
group.rotation.set(m === "speak" ? 0.35 : 0.2, 0.6, 0);
}
root.style.setProperty("--level", level.toFixed(3));
renderer.render(scene, camera);
raf = requestAnimationFrame(loop);
};
const wake = () => {
if (!raf && visible && !document.hidden) {
last = performance.now();
raf = requestAnimationFrame(loop);
}
};
const io = new IntersectionObserver(([e]) => {
visible = e.isIntersecting;
wake();
});
io.observe(stage);
document.addEventListener("visibilitychange", wake);
wake();
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
io.disconnect();
document.removeEventListener("visibilitychange", wake);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
stage.removeEventListener("pointerdown", onDown);
geo.dispose();
mat.dispose();
renderer.dispose();
renderer.forceContextLoss();
renderer.domElement.remove();
};
}, []);
const line = script[mode];
return (
<section
ref={rootRef}
className="gu-murmur"
data-mode={mode}
data-failed={failed || undefined}
aria-labelledby="gu-murmur-title"
>
<div ref={stageRef} className="gu-murmur__stage" aria-hidden="true" />
{failed && <div className="gu-murmur__fallback" aria-hidden="true" />}
<header className="gu-murmur__bar">
<a className="gu-murmur__mark" href="#">
<span aria-hidden="true" />
murmur
</a>
<a className="gu-murmur__ghost" href="#murmur-how">
How it works
</a>
</header>
<div className="gu-murmur__copy">
<h1 id="gu-murmur-title">{title}</h1>
<p>{text}</p>
<div className="gu-murmur__modes" role="group" aria-label="Show Murmur">
{MODES.map((m) => (
<button
key={m.id}
type="button"
aria-pressed={mode === m.id}
onClick={() => choose(m.id)}
>
<i aria-hidden="true" />
{m.label}
</button>
))}
</div>
<figure className="gu-murmur__said">
<figcaption>{line.who}</figcaption>
<blockquote key={mode} aria-live="polite">
<span className="sr-only">{line.line}</span>
<span aria-hidden="true">
{Array.from(line.line).map((ch, i) => (
<span key={i} style={{ animationDelay: `${i * 26}ms` }}>
{ch}
</span>
))}
</span>
</blockquote>
</figure>
<a className="gu-murmur__cta" href={cta.href}>
{cta.label}
</a>
</div>
</section>
);
}
```
### voice-hero.css
```css
/* Murmur: a night-dark hero where the product is a cloud of light that listens. */
.gu-murmur {
--bg: #0b0d14;
--text: #f1ece4;
--muted: #9a97a6;
--line: rgb(241 236 228 / 0.14);
--coral: #ff6a3d;
--lilac: #b9a7ff;
--focus: #b9a7ff;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--level: 0;
position: relative;
container-type: inline-size;
min-height: 720px;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(
60% 70% at 72% 50%,
rgb(185 167 255 / 0.12),
transparent 70%
),
radial-gradient(40% 50% at 80% 60%, rgb(255 106 61 / 0.1), transparent 70%),
var(--bg);
color: var(--text);
font-family:
system-ui,
-apple-system,
"Segoe UI",
sans-serif;
line-height: 1.5;
}
.gu-murmur *,
.gu-murmur *::before,
.gu-murmur *::after {
box-sizing: border-box;
}
.gu-murmur a {
color: inherit;
}
.gu-murmur :focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
.gu-murmur .sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.gu-murmur__stage {
position: absolute;
inset: 0;
z-index: 0;
cursor: crosshair;
}
.gu-murmur__stage canvas {
display: block;
width: 100%;
height: 100%;
}
.gu-murmur__bar,
.gu-murmur__copy {
position: relative;
z-index: 1;
}
.gu-murmur__bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24px 5%;
}
.gu-murmur__mark {
display: inline-flex;
align-items: center;
gap: 10px;
font-size: 1.25rem;
font-weight: 700;
letter-spacing: -0.02em;
text-decoration: none;
}
/* The logo is a dot that swells with the voice level. */
.gu-murmur__mark span {
width: 14px;
aspect-ratio: 1;
border-radius: 50%;
background: radial-gradient(circle at 35% 35%, #fff4d6, var(--coral) 60%);
box-shadow: 0 0 calc(6px + var(--level) * 18px) rgb(255 106 61 / 0.7);
transform: scale(calc(1 + var(--level) * 0.5));
}
.gu-murmur__ghost {
padding: 10px 16px;
border: 1px solid var(--line);
border-radius: 999px;
font-size: 0.9rem;
text-decoration: none;
transition: border-color 0.3s var(--ease);
}
.gu-murmur__ghost:hover {
border-color: rgb(241 236 228 / 0.5);
}
.gu-murmur__copy {
width: min(520px, 46cqi);
margin-left: 5%;
padding: 64px 0 72px;
pointer-events: none;
}
.gu-murmur__copy a,
.gu-murmur__copy button {
pointer-events: auto;
}
.gu-murmur__copy h1 {
margin: 0 0 18px;
font-size: clamp(2.4rem, 5.2cqi, 4.2rem);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.035em;
text-wrap: balance;
animation: gu-murmur-rise 1s var(--ease) both;
}
.gu-murmur__copy > p {
margin: 0 0 32px;
max-width: 42ch;
color: var(--muted);
font-size: 1.05rem;
animation: gu-murmur-rise 1s var(--ease) 0.1s both;
}
/* Mode switch: the pressed button's dot pulses like a recording light. */
.gu-murmur__modes {
display: inline-flex;
gap: 4px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgb(11 13 20 / 0.6);
backdrop-filter: blur(10px);
animation: gu-murmur-rise 1s var(--ease) 0.2s both;
}
.gu-murmur__modes button {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 40px;
padding: 0 16px;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 0.9rem;
cursor: pointer;
transition:
background-color 0.35s var(--ease),
color 0.35s var(--ease);
}
.gu-murmur__modes button:hover {
color: var(--text);
}
.gu-murmur__modes button[aria-pressed="true"] {
background: var(--text);
color: var(--bg);
}
.gu-murmur__modes i {
width: 7px;
aspect-ratio: 1;
border-radius: 50%;
background: currentColor;
opacity: 0.4;
}
.gu-murmur__modes button[aria-pressed="true"] i {
background: var(--coral);
opacity: 1;
animation: gu-murmur-dot 1.1s ease-in-out infinite;
}
/* The transcript: who is talking, and their words typing in. */
.gu-murmur__said {
min-height: 104px;
margin: 22px 0 28px;
padding: 16px 18px;
border-left: 2px solid var(--coral);
background: linear-gradient(90deg, rgb(255 106 61 / 0.1), transparent);
animation: gu-murmur-rise 1s var(--ease) 0.3s both;
}
.gu-murmur[data-mode="listen"] .gu-murmur__said {
border-color: var(--lilac);
background: linear-gradient(90deg, rgb(185 167 255 / 0.1), transparent);
}
.gu-murmur__said figcaption {
margin-bottom: 4px;
font-size: 0.8rem;
color: var(--muted);
}
.gu-murmur__said blockquote {
margin: 0;
font-size: 1.2rem;
line-height: 1.35;
letter-spacing: -0.01em;
}
.gu-murmur__said blockquote > span[aria-hidden] span {
animation: gu-murmur-type 0.28s var(--ease) both;
}
.gu-murmur[data-mode="think"] .gu-murmur__said blockquote {
color: var(--muted);
font-style: italic;
}
.gu-murmur__cta {
display: inline-flex;
align-items: center;
min-height: 50px;
padding: 0 26px;
border-radius: 999px;
background: var(--coral);
color: #1a0d08 !important;
font-weight: 700;
text-decoration: none;
box-shadow: 0 0 calc(var(--level) * 34px) rgb(255 106 61 / 0.55);
transition: transform 0.35s var(--ease);
animation: gu-murmur-rise 1s var(--ease) 0.4s both;
}
.gu-murmur__cta:hover {
transform: translateY(-2px);
}
@keyframes gu-murmur-rise {
from {
opacity: 0;
transform: translateY(20px);
}
}
@keyframes gu-murmur-type {
from {
opacity: 0;
filter: blur(3px);
}
to {
opacity: 1;
filter: none;
}
}
@keyframes gu-murmur-dot {
50% {
transform: scale(1.6);
opacity: 0.5;
}
}
/* No WebGL: a soft glowing orb instead of the point cloud. */
.gu-murmur__fallback {
position: absolute;
right: 10%;
top: 50%;
width: 34cqi;
aspect-ratio: 1;
border-radius: 50%;
translate: 0 -50%;
background:
radial-gradient(circle at 40% 35%, rgb(255 244 214 / 0.6), transparent 40%),
radial-gradient(circle, var(--coral), var(--lilac) 60%, transparent 72%);
filter: blur(6px);
opacity: 0.7;
}
@container (max-width: 760px) {
.gu-murmur__copy {
width: auto;
margin: 0 5%;
padding-top: 300px;
}
.gu-murmur__modes {
display: flex;
}
.gu-murmur__modes button {
flex: 1;
justify-content: center;
padding: 0 8px;
}
.gu-murmur__fallback {
top: 180px;
left: 50%;
right: auto;
width: 60cqi;
translate: -50% -50%;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-murmur *,
.gu-murmur *::before {
animation: none !important;
}
}
```
You might also want
Next piece: 3D artist portfolioLiquid blob album 3D hero
Components, advanced, needs three
Contour map 3D hero
Components, advanced, needs three
Glass prism 3D hero
Components, advanced, needs three