What runs when
Nothing here is a film. The clouds are real volumes, marched every frame where the wind has put them; the lightning’s light is traced through them as they move. What is done ahead is only what does not change: where the clouds must stand to be seen as a head, and how far every bit of empty air is from the nearest cloud.
| When | What | Where |
|---|---|---|
| Once, offline | Ten clouds of a free pack are packed to 8 bits a voxel at half size; Suzanne and the dragon are turned into grids of distances from their skin; the lighthouse, its rock and its keeper are built | tools/pack-clouds.py, suzanne-cloud.py, dragon-cloud.py, lighthouse.py |
| Once, offline | Where each cloud goes, for the page’s usual settings: a search of a few seconds, kept as 7 KB | src/collage/arrange.ts, src/drift/laid.json |
| Once, at page load | The ten clouds go into one 3D texture, with smaller copies of it for skipping and for shade; a distance field is made over it; six bolts are grown | src/drift/index.ts, src/bolt.ts |
| Every frame | Where each cloud is; a little more of the bolts’ light; the march; the bolts, the lighthouse, the water; lens and film curve | src/drift/drift.wgsl, show.wgsl, three-house.ts |
| When a setting asks | The search again, in workers, if the clouds’ number or sizes are changed | src/collage/worker.ts |
It runs on three.js’s WebGPU renderer, inside a small sketch runner. The lighthouse, its rock and its keeper are a three.js scene with a node material, drawn twice a frame into pictures that the page’s own passes, written straight in WGSL, go on drawing into on the same device: the clouds, the bolts and their light, the water. A second page is the same storm without three.js drawing anything. The two come out the same, pixel for pixel but for a few in a flash, and as fast.
Shapes found in clouds
The first tries filled the shape of a head with vapour, and looked like it: fog poured into a mould. What was wanted was the other thing, the face you find in a real cloud. So the clouds are left alone. They are whole clouds from a pack of volumes, kept upright, and only their places are chosen: which cloud, turned how far, mirrored or not, leaning a little, how large, and where.
The choosing is a search by simulated annealing. Each cloud is first drawn flat from twelve sides, as how much of it a ray from the front goes through. A try at an arrangement is the sum of those pictures, seen in perspective from where the eye will be; it is scored against the outline of the shape, cell by cell, on a grid of 6 cm cells. Sixty thousand small changes are tried for Suzanne and ninety thousand for the dragon, each kept if it is better and sometimes if it is not.
score = Σ over cells weight · ( covered(cell) − wanted(cell) )² covered = 1 − exp( −depth of cloud before the cell · 40 ) wanted = 1 inside the outline, 0 outside weight = 1, + 3 in the eyes, + 2 round them (the dragon: + 3 in the air close outside it, × 6 between its jaws, × 2 over its head)
Likeness is asked for only at this coarse scale and only from the front, so close to, the clouds are just clouds. What made the head read was not more cloud but less: two gaps kept open for her eyes, and lightning routed behind them so that they glow. The dragon has no eyes to keep; it is read by its gaps instead, the open jaws, the air between its coils and under its neck.




The search takes three to six seconds, so its answers for the usual settings are kept with the page, 7 KB of places. It runs again, off the main thread, only when a setting that changes the arrangement is touched.
Going by on the wind
All the clouds ride one wind, which takes them 17 units across in a loop and round again. Besides it each has a way of its own: the higher ones go faster, each wanders and turns a little, and they stand further apart the longer it is from their moment. Those ways are made from the sine and one less the cosine of where the loop is, so they are exactly nothing at one instant: the only moment the clouds stand where the search put them.
place(cloud, t) = where it was put + wind(t) + own speed · sin(φ) · T/2π + spread · (1 − cos φ)/2 φ = 2π (t − its moment) / T T = 40 s Suzanne’s moment 10 s, the dragon’s 30 s
The wind is not even. It drops to a fifth of its speed as each shape comes together and makes it up between, so a shape lingers; it comes in faster than it leaves, with a gust between, so the two halves of the loop do not look like a slide being changed. None of that moves a cloud at its moment, and all of it comes round in 40 seconds, so the loop closes without a join.
Eight more clouds stand further back, kept clear of where the shapes form, so the sky is never empty and the shapes are not the only things in it.
Marching clouds that move
A still version of this stamps the clouds into one block of 90 million voxels and marches that. It cannot be remade every frame. So here nothing is stamped: the ten clouds lie side by side in one 3D texture, and each of the 43 clouds in the sky is one small matrix that takes a place in the world to a place in that texture. A ray asks the clouds it is in, and the densest answer wins.
Asked naively that is far too much asking. Four things cut it down, each checked to leave the picture as it was:
- Tiles. For each 16 × 16 pixels of the picture, which clouds can show there at all, as 64 bits.
- The clouds a ray is in. A ray keeps the clouds whose boxes it is inside at that step, and works them out again only where it enters or leaves one.
- A distance field. Made once at load in half a second: for every two voxels each way of every cloud, how far the nearest cloud that could be seen is. A step in empty air reads nothing more and leaps that far.
- Never asking the loser. A coarse copy holds the most there is in each eight voxels; a cloud whose most is under what another has already given is not read.
| For each marched pixel | Suzanne’s moment | The dragon’s |
|---|---|---|
| Steps along the ray | 7.2 | 10.6 |
| of them in cloud that shows | 1.1 | 1.9 |
| Reads of a cloud’s voxels | 5.6 | 8.6 |
| before the distance field | 15.0 | 24.7 |
The march runs on 0.8 million pixels whatever the window’s size, and is brought up to the screen by a Catmull-Rom filter, which keeps the clouds’ edges where a soft one blurs them. The fine fraying of those edges is noise that belongs to each cloud and turns with it; when it belonged to the sky, clouds seemed to change their shape between one flash and the next, as they slid through it unseen in the dark.
The bolts
A bolt is grown cell by cell from one waypoint to the next, after Yun and others (2017): each new cell is chosen by how hard the place it is going pulls, over how hard what has already grown pushes. Waypoints give it its route and the zigzag between; forks and sparks come off it the same way. Six are grown when the page loads, three for each shape: behind Suzanne’s eyes, through her ears, out of her chin to the sea; out of the dragon’s jaws to the water, behind the gaps of its coils, along its back.
They are drawn as ribbons that face the eye, a white core and a wide soft skin, 8,580 pieces in all. How much cloud stands between each piece and the eye is worked out once a piece in a pass of its own, 64 looks through the clouds from each of its ends, so a bolt goes behind a cloud and comes out again without any sorting. The same is done towards the eye’s image under the water, for the bolt’s reflection.
A loop has 56 strikes, each flickering up to three times more as real ones do, and more of them fall while a shape is there. A strike belongs to the bolts of whichever shape’s time it is. Bolts ride with their cloud; the ones that come down to the sea strike only while the wind has dropped under 45% of its speed, so that a bolt standing on the water is not seen to slide along it.
Their light
Lightning inside a cloud is seen as the cloud. That light is traced, not guessed: 197,000 photons leave each bolt from along its length and wander through a coarse copy of the clouds, turned aside again and again, leaving a little light in every cell of a 128 × 88 × 96 grid they pass through. The grid rides the wind with whichever shape’s time it is.



Since the clouds move, the light is traced over and over, 8,192 photons a frame. Three things about that were learnt the hard way:
- The same photons every time. With new random ones each time, the grain of the light changed several times a second and read as the cloud itself shifting.
- A little every frame. A big lot on every other frame made heavy frames and light ones by turns, and the heavy ones missed the screen’s refresh. That alone was the difference between 44 and 54 frames a second at the dragon.
- Detail shaded towards the bolts, not towards where the traced light happens to grow brighter, which flips with every strike.
Clouds outside the grid are lit more simply: each bolt is taken as a line of light, dimming with distance, with three looks through the cloud’s own coarse copy for its shadow side. Moonlight and the sky’s are kept in another grid, an eighth of it worked out again each frame.
Sea, rain and air
The sea is a plane with ten sine waves on it, mostly coming towards the eye, each fading out before it would be smaller than a pixel so the far water does not glitter. What it shows of the clouds is a second, coarser march along each pixel’s reflected ray. The bolts are drawn again upside down into a picture half the size, and the water looks into that along the same ray, blurred a little down the screen: the long wavering streaks.


Rain falls where there is cloud above, known from a small map of the cloud cover made every other frame. It is 24 looks along each ray through streaks of noise that fall twenty times in a loop, and it is dark until a bolt close by lights it. Far off, over the horizon, other storms flicker in the quiet between the two shapes; the air round each near strike glows; far clouds and far water fade a little towards the colour of the sky.
The lighthouse
The lighthouse, its rock and its keeper are ordinary triangles, 13,500 of them, built by a script in Blender and drawn by three.js after the clouds with a depth buffer, so the tower hides the bolts behind it. It is lit by each bolt from the side that bolt is on, with glints on the wet rock; by its own lamp close to; and by the moon hardly at all. Two beams turn once in eight seconds, seen in the air as light scattered towards the eye and on the bases of the clouds as they pass over.


The picture
Everything is added up in light, not in screen colours, and only then turned into a picture. The curve that does it is AgX, which takes very bright colour towards white as film does, where a simpler curve pushes it to a flat hard orange. After it the darks are leant a little blue and the lights warm. What glows spreads through seven halvings of the picture and back, a little redder than it left, and colours part slightly towards the corners, as in a lens.





One frame, timed
Timed on the card itself, with timestamp queries, on an M1 Max in a 1400 × 900 window at twice the pixels, the page running and the governor off: once about Suzanne’s moment and once about the dragon’s. On a card of this kind the passes of a frame overlap, so the split between them is rough; the sums are sound.
| Pass | What it does | Suzanne, ms | The dragon, ms | |
|---|---|---|---|---|
| The march | Clouds, their reflection in the water, rain, the lamp’s beam, on 0.8 million pixels; and how much cloud hides each piece of the bolts | 11.4 | 14.0 | |
| The light, kept up | The coarse copy of the clouds, a slice of the moonlight, the rain’s cover, 8,192 photons, the bolts’ light mixed by how bright each is now | 1.4 | 1.6 | |
| To the screen | The march brought up to the window’s size; the bolts upside down, for the water | 0.45 | 0.5 | |
| Bolts and lighthouse | Ribbons and triangles, at full size | 0.1 | 0.1 | |
| Glow and film curve | Seven halvings and back, AgX, the grade | 0.4 | 0.4 | |
| A frame | 13.7 | 16.6 |
The march is most of it, and what it costs follows how many voxels it reads far more than how many pixels it draws: at a tenth of the pixels it took nearly as long. Every saving above was found by making the march count its own work, and none by guessing.
Kept at sixty
A frame at the dragon is close to the 16.7 ms a screen gives it, and machines differ. So the page watches the card’s own clock, from the first pass of a frame beginning to the last one ending. When that comes near what a frame may take, the march is eased: its steps a little longer, its rays stopped a little sooner, the water’s picture of the clouds coarser. When there is room again it goes back, slowly. Where a browser has no such clock, a cruder sign is used, how long work waits to be done, which only says that frames are queuing.


On an M1 Max, capped at 60 as a screen caps it: left alone, the loop averages 55 frames a second and falls to 46 while the dragon is there; governed, it holds 60 throughout, eased all the way for most of the dragon’s half. It has little in reserve there, so a slower machine or a far larger window will still fall short.
What is downloaded
| What | As | MB | |
|---|---|---|---|
| Ten clouds | 8 bits a voxel, the square root of density, half size, gzip | 7.46 | |
| The lighthouse, rock and keeper | glTF binary, colours at the corners | 0.98 | |
| The dragon’s outline | distances from its skin, a byte each, gzip | 0.53 | |
| Suzanne’s outline | the same | 0.25 | |
| three.js: its WebGPU renderer and node materials | JavaScript, gzip | 0.17 | |
| Code: the page, shaders, panel | JavaScript, gzip | 0.14 | |
| All of it | 9.53 |
The two outlines are read by the bolts that crawl over the shapes, and by the search if it is run again. Where the clouds go, the thing the page is about, is 7 KB inside the code.
How it is checked
- Every speed-up against none. Each one can be switched off, and the two pictures are taken at the same held moment and subtracted. The tiles, the clouds a ray is in and the bolts’ cover pass change no pixel; the leaps through empty air move the march’s dither and no more, under 0.4% of pixels.
- Work, not time. The machine it was made on was rarely quiet, and timings swung by more than the changes. The march was made to count its own steps and reads, which do not swing.
- Light that lags. Tracing fewer photons a frame means the light follows the clouds later. The loop was stepped a sixtieth at a time through four seconds of drifting at three rates of tracing; at a quarter of the first rate 0.5% of pixels differ, faintly.
- The seam. All 1,200 frames of the film are drawn with the page held at their moment, and the step from the last back to the first (0.45) is set beside the ten each side of it (0.31 to 0.37): a little more, and only the edges of clouds going by. Two films failed this before one passed. In the first a strike still fading at the join was cut off, where the bolts go over from the dragon to Suzanne: strikes now keep three seconds clear of it. In the second a cloud brightened in one frame there, as the block the light is worked out in went over to the other shape and left it to be lit as the far clouds are: that block now fades out for a second before it goes, and in again after.
- The picture, before the number. Twice a change made the page twice as fast by drawing nothing. Since then a frame is looked at before its time is believed.
What is not real
- The shapes are there from one side only, and only at one moment each. From anywhere else they are heaps of clouds.
- The clouds are ten, used 43 times over, turned and mirrored. They do not form or thin out; they are carried.
- Light is traced only inside a block that rides with the shape whose time it is. Clouds outside it are lit by a line of light and a guess at their own shadow.
- Photons scatter evenly in every direction and are traced through a much coarser copy of the clouds. Real cloud throws most light forwards.
- The rain is lit streaks of noise under a cloud, not drops; it makes no rings on the water.
- The keeper is a third larger than life, or he would be a few pixels.
- When the shape whose time it is changes, at the top and the middle of the loop, both are off the sides of a usual screen. On a very wide one it can be seen.
Made with: the clouds of CloudPack by JangaFX (CC0); Suzanne, from Blender; the dragon, from the Stanford 3D Scanning Repository. Methods used: Yun, Son, Choi, Kim and Yoon, Physically Inspired, Interactive Lightning Generation (2017) for the bolts; Kim and Lin, Physically Based Animation and Rendering of Lightning (2004) for a strike that flickers again down its channel; Kirkpatrick, Gelatt and Vecchi, Optimization by Simulated Annealing (1983); Jensen and Christensen, Efficient Simulation of Light Transport in Scenes with Participating Media using Photon Maps (1998), for light left along a photon’s path; Kulla and Fajardo, Importance Sampling Techniques for Path Tracing in Participating Media (2012), for looking along a ray by angle about a lamp; Sobotka’s AgX, in the fit by Wrensch.