Field notes

A morning in a beech wood. We walk on along a lane, looking up into the sun; the haze between the trunks is cut into shafts by the crowns, dust turns in them, and a bird of prey flies slowly on ahead of us through the light, on its way to a nest we never see. It loops every 18 seconds, the last frame leading straight back into the first. The wood can be turned to autumn and to winter. Nothing in it is a model or a picture loaded from a file: the trees, their leaves and bark, the bird and its feathers are made in the page as it opens.

Looking up through a beech wood into the morning sun: dark trunks and crowns at the sides, shafts of light in teal haze between them, and a bird of prey with spread wings high in the bright gap
Loop
18 s, closes on itself
Download
362 KB, all of it code
Triangles
about 5.3 million a frame
Trees
218 copies of 9
Leaf sprays
108,000, grown at load
Frame
about 7 ms on an M1 Max

A wood without an end

The eye walks on at a metre a second and never turns back, yet the loop closes. The wood is one strip, 18 metres long, laid end to end along the lane: walking 18 metres in 18 seconds brings the eye to exactly where it started, one strip on. Every tree that can be seen is a copy of one in the strip, so the picture at the end of the loop is the picture at its start.

For that to hold, everything that moves must come round a whole number of times in 18 seconds. The bird beats its wings 14 times, in two stretches with long glides between, and weaves once round a loose ring as it goes on with us. The wind runs in gusts along the wood, two a loop, and each leaf turns on its stalk a whole number of times at a speed of its own. The mist in the haze drifts once round a circle; each mote of dust twinkles a whole number of times.

One loop, as it plays.

Growing a beech

The beeches are grown in the page as it opens, eight of them in about 0.6 seconds: four tall, two of the middle tier, two saplings. They follow a beech’s habit as measured from a library tree: a trunk to a fork, seven or eight limbs rising from the top of the bole in a spiral, each forking once, then three or four orders of side shoots alternating left and right, each about half what is left of its parent and lying flatter, the way a beech holds its leaves in plates.

Thickness comes from the pipe model: a branch is as thick as all that grows from it, its cross-section the sum of its children’s, so the trunk is thick and twigs are thin without anyone saying how thick anything is. The foot flares. The inner part of every limb is bare, so a crown is several clouds of leaves at the ends of its limbs with dark limbs between them, not one green ball. Leaves come as sprays, four leaves on a twig on one card, broken into clumps by a smooth noise.

The tall crowns are shy of each other, as beeches are. Where two crowns meet, each keeps out of a ragged channel along the line half-way between them, and the sky shows through. Those channels are where the shafts come from.

Five million triangles

Grown, the eight trees are about 700,000 triangles together, one copy of each. The wood drawn is 218 copies of them, so a frame draws about 5.3 million triangles in some 285 draw calls. The copies share the trees’ vertices on the graphics card; each frame only a small record per copy changes (where it stands, how it is turned, how big, how far off). A tall tree is about 105,000 triangles, so 218 whole copies would be some 15 million. Three things bring that down to what is drawn:

  • Parts. Each tree is cut into eight compact lumps, and each lump of each copy is kept or dropped by whether its sphere is in view. Looking up with a wide lens, much of most crowns is out of the picture.
  • Farther, lighter. From 15 metres on a copy morphs, over ten metres, to one with 40% of its leaf cards, each grown so the crown keeps its density; the twigs thinner than 1.2 cm draw in to their own axis as it goes and are left out of the far copy. Its cards are two triangles, not four.
  • Nearest first. Copies are drawn from the eye outward, so most of what is behind is never shaded.
One frameCount
Triangles drawn (portrait, 1080 × 1920)5.3 million
Draw callsabout 285
Copies of a tree in view218
Triangles grown at load, all treesabout 700,000
Leaf sprays grown at loadabout 108,000
Bird: feathers, triangles190, 3,300
Motes of dust (snow in winter)20,000

Light in the air

The sun’s light is worked out once, seen from the sun. A deep opacity map records, for every ray from the sun, the first leaf it meets and then how many leaves it passes after that, in eight layers, so a place deep in a crown gets the light that has come through several leaves, green and dim. A second map does the same for the bark. Every surface in the picture asks the maps how much sun reaches it.

The shafts are the haze lit by that sun. For every pixel of a smaller picture, a march of 32 steps goes from the eye through the air to whatever the pixel shows, adding at each step what the haze there scatters towards the eye: the sun where the maps say it reaches, brightest looking towards the sun. The haze thins upwards, drifts in patches, and leaves the first eight metres from the eye clear, so the bird near us stays crisp and dark against the brightest air.

Looking the maps up at every step was most of the cost of a frame: four scattered reads from 4096-pixel maps, at a centimetre’s detail the air cannot show. So the sun in the air is baked once into a small volume of its own, 512 by 512 by 48 in the sun’s frame, each cell the mean of sixteen looks over its footprint, and the march reads it once a step. That alone saved 4.7 milliseconds a frame (with the culling below, a frame went from 12.6 to 6.6), and against a 256-step reference the picture is the same within a grey level.

Three versions of one frame: the full picture; the wood without the haze, dark and clear; and the haze alone, bright shafts fanning out from the sun
One frame, the picture without the air, and the air alone.

The bird

The bird is about 190 separate feathers on a body and head, posed every frame. Its wing is three bones whose angles are held at four places along the arm and blended smoothly between, so the wing bends as one surface, and the stroke runs out along it as a wave: the hand trails the arm. It beats slowly, a deep downstroke and a shallow upstroke as a big bird’s are, and on the way up the hand draws back and the outer primaries turn on their shafts to open slots.

Its shape is drawn. A small editor (outline.html) puts a photograph of a real owl seen from below behind three curves, the wing, the tail and the body with its head, and the bird is built to them: every flight feather is made as long as it takes for its tip to reach the drawn outline, the arm laid under the drawn leading edge, the body turned round the drawn half width.

The outline editor: the wing, the tail and the body drawn as smooth curves with points, the bird's feathers laid out under them The bird from straight below against pale sky: broad rounded wings, a fanned tail and a round head
The outline as drawn over a photograph, and the bird built to it.

Against the sun its flight and tail feathers let the light through, golden, as an owl’s do: all of each vane beyond the coverts, more towards its free edge and tip, the dark bars showing as shadows in it. The coverts lie stacked and stay dark, so the bird keeps its dark shape.

Out of its way

The bird keeps one path through the wood, and at the right of its weave that path ran through a low limb of a middle-tier beech: some of its branches were in front of the bird, some through it. So, as the page opens, the bird’s swept wings and stroke are traced over the whole loop, and a limb they would touch sags out of the way, the least that clears it: lowered more the farther out from its base, smoothly from nothing at the trunk, with every twig and leaf on it, as a low beech limb hangs. It keeps its reach, so it still passes between us and the bird, under it now. Every other tree is left as it grew.

The same moment in winter twice: on the left bare branches cross through the bird's wings; on the right the same limb hangs a little lower and its branches pass in front of the bird
In winter, where the limbs show: as grown (left), and sagging under the bird (right).

Three seasons

The buttons at the top turn the wood. In autumn each tree turns at its own pace, so some go wholly yellow with copper at the tips, some half, some stay green; within a crown the top and the outside turn first, and branch-sized patches together. A turned leaf keeps its own light and shade, a little lighter, and glows gold against the sun; the light that comes down through the leaves turns golden too.

In winter the leaves fall card by card, the earliest trees and the outsides first, but the young beeches and the low parts of the middle ones keep theirs, dried to a pale copper, as beeches do. A fallen card shows a bare beech twig drawn as the page opens. The sun’s maps are drawn again as the leaves fall, the light turns pale and grey, and the dust becomes snow. In spring the leaves come back green.

The same moment in summer, autumn and winter: green crowns; crowns turning yellow; bare grey branches in pale mist with snow
Summer, autumn, winter.

Pictures drawn at load

The leaves and the bark are pictures too, and they are drawn in the page as well: a spray of four ovate leaves on a reddish twig, pleated along their straight veins and mottled, laid out where the cards expect them; the bark smooth and grey, with fine lenticels, a little lichen and the eye a fallen branch leaves, repeating round a limb and along it. Each is matched to the colour and the spread of light of the library pictures it replaced, so the wood kept its look.

The drawn leaf spray, four green leaves on a twig, and a strip of grey bark
The leaf spray and the bark, as drawn.

How it is checked

  • The loop. The last frame and the first are drawn and compared, blurred to take out the shafts’ grain: the jump over the loop point is no bigger than an ordinary step between two frames.
  • Nothing pops. Over the loop, at 30 frames a second, no tree that can be seen comes into the list of copies or leaves it.
  • Culling changes nothing. The picture drawn whole tree by whole tree and lump by lump differs in fewer than ten pixels of two million.
  • The bird is clear. Every point of the bird, over the loop, is at least 0.67 metres from any leaf or twig.

Add ?gui to the address for the panel and a frame meter, ?portrait for the 540 × 960 frame it was composed in, ?season=0..2 to hold a season.

Made with

  • Everything on screen is drawn in the browser with three.js, WebGPU and its shading language TSL, from code, through ssam.
  • The beeches follow Botaniq’s Fagus sylvatica, measured to grow them; nothing of Botaniq’s is shipped.

From Trapnest

Six stories from the Trapnest archive on light, flight, and worlds grown in the browser.

Explore Trapnest