Night drive
A mountain road and a pair of headlights.
scroll to build it up ↓
1 · THE LINEA road is a curvature signal
Changes to curvature make a curve make a road.
The plot is curvature κ = 1/R along the road. Each bend eases in, holds, and eases out. Slope and slope-of-slope are zero at both ends, so the steering wheel never jumps. Integrate κ for heading, integrate again for position, and that's the white line.
The road is redrawn from just ahead of the car as you drag.
2 · THE SURFACESweep a ribbon along it
Slide a cross-section down the curve to make the surface of the road.
Each vertex remembers two numbers: s, how far along,
and u, how far across. Everything drawn on the road is
a function of those two, evaluated per pixel, so there are no seams
between segments.
3 · ROLLBank into the bend
Real roads bank into corners. This one does too.
Roll is curvature again, clamped to a few degrees and smoothed over 30 m each way, so the lean starts before the bend and ends after it. The camera rides on the tilted surface.
4 · PITCHGive it hills
A second signal, grade, lifts the line. Crests hide the road beyond them; dips show more of it.
The ground is a heightfield that follows the road nearby and becomes hills further out. The depth buffer does the hiding: a crest covers whatever is behind it.
5 · LIGHTGood night sun
Now the only light is your headlights, and it doesn't reach far.
A low beam is a wedge of light that stops at a cutoff plane. Each pixel asks where its ray from the lamp would land on flat ground: dark at the bumper, a hot pool around ten meters, gone past the cutoff. Uphill the wedge reaches further; over a crest it shines into empty air.
6 · PAINTLines from two numbers
Edge lines where |u| = 3.25 m. A centre dash wherever s mod 12 is less than 3.
There is no line geometry. Paint is just a brighter albedo under the same light. It is also a little reflective, so the lines show further than the asphalt.
7 · REFLECTORSStuds in the paint
Retroreflectors send light straight back at you, so they are visible much further than the road and paint.
They are placed by the same (s, u) as the paint beneath
them: dense on the edge lines, one per dash in the centre. Each is a
few pixels, depth-tested like everything else — so the road ahead
becomes dotted curves that swing through bends and wink out behind
hills.
8 · AIRSomething for the light to hit
Fog cuts visibility. Dust and bugs show where the beam is.
Each speck is lit by the same beam function, sampled where it floats, and stretched by its motion relative to the car over one exposure. Slow ones are dots; near ones streak past.
9 · SKYA little sky
A faint gradient, a few dominant stars, ridgelines, sometimes a moon.
The sky is one dome fixed to the world, so it pans as the road turns. Trees catch the light that spills above the cutoff.
10 · THE DRIVERBrake for what you can see
Every bend has a top speed, and the driver slows early enough for all of them.
The dim curve is the corner limit, √(a/κ). The bright one is the fastest speed from which a comfortable brake still makes every corner ahead. The dot is the car.
11 · THE MAPWhere are we going
The GPS inset is the road as seen from above.
12 · DRIVEThat's all of it
Curvature and grade, swept into a ribbon and lit by one lamp.
Open the drive with every control, or watch it build itself.
space pause · h panel · g GPS