Ninety thousand points, one draw call
The portrait on this site turns into a globe, a helix and a running track as you scroll. Nothing is created or destroyed on the way. Here is how that works.
The home page of this site has one object in it. It is a cloud of 90,000 points, and it stays on screen from the first pixel to the last. When you scroll, the points do not fade out and get replaced. They travel. The portrait becomes a stream, the stream becomes a neural network, and sixteen formations later the same points are a portrait again.
I wanted that because it says the thing I care about in one image: everything I have built is made of the same material.
One buffer in, one buffer out #
Each formation is a plain function. It takes a count and returns two arrays: where every point should sit, and how it should look (how much accent colour, how big).
The GPU holds two copies of that data at a time, aFrom and aTo. Scrolling never touches them. It only changes a single number, uMix, between 0 and 1. The vertex shader does the rest:
// every point leaves and arrives on its own schedule
float stagger = 0.5;
float t = clamp(uMix * (1.0 + stagger) - aRand.x * stagger, 0.0, 1.0);
t = t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
vec3 a = spinY(aFrom, uAngle.x);
vec3 b = spinY(aTo, uAngle.y);
vec3 p = mix(a, b, t);aRand.x is a random number baked into each point. Subtracting it means no two points start moving at the same moment, which is the difference between a crossfade and a flock. The third line is an ease, so nothing starts or stops with a jerk.
Turn the stagger off below and drag again. Every point now moves in step, and the flock turns back into a crossfade.
The buffers are rewritten only when you cross from one pair of formations into the next. That is a few megabytes, once per chapter, not once per frame.
Scroll is the clock #
There is no timeline. Every section of the page has an anchor, the point where it sits in the middle of the screen. Between two anchors I take how far you are, then squeeze it:
const m = smoothstep(0.2, 0.8, raw);The first and last fifth of the distance do nothing. That gives each formation a moment to hold still while you read, and puts all the motion in the middle, where you are scrolling anyway.
What went wrong #
Colours turned to mud. Each chapter has its own palette, and I first blended them at the same rate as the points. Halfway between the yellow-green of the endurance chapter and the black of the next one, the whole page was olive. The fix was to stop blending. Colours now cut over in a narrow window:
const cm = smoothstep(0.47, 0.53, m);The frame counter read 30. I spent a while looking for the slow part of the shader. The laptop was on battery at 16%, and Chrome had halved the frame rate to save power. On the charger it ran at 60. Measure on mains.
Phones could not read it. On a wide screen the formation sits beside the words. On a phone there is no beside. Each chapter now opens with a clear window onto its formation, and the words arrive on a solid background underneath.
What it costs #
| Device | Points |
|---|---|
| Desktop | 90,000 |
| Four cores or fewer | 60,000 |
| Phone | 42,000 |
It is one draw call whatever the count. If you have asked your system for less motion, the swirl between formations is switched off, but the formations still follow your scroll, because that movement is yours.
Most formations are one short function. The portrait is the odd one out: it is a photo, cut out from its background, with points dropped more densely where the image is darker. Everything else is arithmetic.