Building the brain: a scroll-driven neural network in three.js
The background of this site is a brain — not a stock render, but a live three.js scene that the page scrolls into. Each section of the homepage owns a neuron inside it; a signal travels along an axon as you scroll, and a neuron fires the moment its section arrives. This post is about the three problems that turned out to matter.
Drawing a brain that reads as a brain
A point cloud with proximity edges looks like a cloud, not a brain. What finally worked was drawing the surface the way an illustrator would: long, smooth filaments that wander across the shell like sulci. Each filament is a random walk on a unit sphere (a tangent vector with momentum), mapped through a brain-shaped deformation — wide, flat-bottomed, an underside that rises toward the frontal lobe. The two strongest anatomical cues cost almost nothing: a cerebellum drawn as a stack of laminar rings, and a short stem angling down from the underside.
Bright "bead" nodes sit directly on the filaments, so every point of light belongs to a line. When the scroll journey later picks waypoints, it snaps them to the nearest bead — the neuron you dive toward is one the brain visibly had all along.
Mapping scroll to a journey
The scroll position maps to a piecewise progress value: integer k means "waypoint k reached", and the fraction between integers is smoothstep-eased so the signal dwells on a neuron, then glides to the next.
export function journeyProgress(scrollY: number, reaches: number[]): number {
for (let k = 0; k < reaches.length - 1; k++) {
const a = reaches[k];
const b = reaches[k + 1];
if (scrollY < b) {
if (scrollY <= a) return k;
const t = (scrollY - a) / Math.max(b - a, 1);
return k + t * t * (3 - 2 * t); // smoothstep: dwell, glide, land
}
}
return reaches.length - 1;
}The reaches array is measured from the DOM (each section's top crossing 45% of the viewport — the same band the scroll-spy nav uses), so the neuron fires exactly when the nav dot flips.
Keeping text readable over WebGL
Everything hard about this project was legibility, not rendering:
- Recede — the wireframe drops to a low opacity floor right after the hero, so content sections sit over a quiet mesh.
- Near-camera dissolve — as the dive continues, passed neurons get pushed toward the camera. Anything inside a near band fades to nothing instead of ballooning into a 300px ring over your paragraph.
- A trailing axon window — the signal line only draws a window behind its tip, and the trail retracts to a stub while you dwell on a section. A line that lies across resting text is worse than no line.
One more trick worth stealing: the palette never hardcodes colors. A probe element resolves CSS custom properties (the design tokens) to pixels, so the WebGL scene re-reads the theme on toggle and matches light mode for free.
