Apex GP

Devlog

Rain, standing water and spray: most of the work was finding what was broken

Water that had never pooled, a drag term that diverged, tyre tracks baked into every road. What it took to make rain, wet asphalt and spray in Apex GP read as real, with the numbers.

I'm one developer making an open-wheel racing game, Apex GP. This round was meant to be art: make rain, wet asphalt, standing water and spray look like the real thing. Most of it turned out to be diagnosis. Several of these effects weren't under-tuned. They were broken in ways that no amount of tuning would have fixed. This post goes through them with the measurements.

First, so nobody goes looking for it: none of this is in the 0.10.0 packages on itch.io. Those were built on the morning of 20 October, before this work started. It's in my development builds now.

The rain itself

The rain streaks aren't particles. The shader computes them from the camera's velocity. Measured cost: 0.04 ms.

Standing water had never pooled

Standing water had never pooled a single drop in any shipped build. The mask that decides where water collects samples a macro noise texture. That texture imports as sRGB, so texture() returns linear values: blue comes back at about 0.21, not the 0.41 that's in the file. The old threshold was 0.5–0.66. Against linear values it crossed on about 0.7 % of the road at full wetness. I could have moved that threshold around for a long time without finding out that the value it was compared against was about half what I thought it was.

The new mask works at two scales. Two blue samples give a "lake" of about 30 m and a "pond" of about 9 m, and a green-channel term biases the water into low spots. The threshold is 0.46 - 0.15 * wetness.

To measure coverage rather than judge it by eye, I mirrored the same mask on the CPU and ran it headless. In heavy rain, water now covers 22.7 % of the road on Spa-Franchecamps and on Silverstown, and 30.3 % on Monte Carla. In light rain it's 13.9 %.

Chase view of a car on a wet straight in heavy rain, with pools of standing water on the left
Heavy rain on Spa-Franchecamps, chase camera. The dark patches on the left are pools from the new mask. Captured in-engine during this work.

Wetness belongs to the weather, not to the rain

Wetness used to follow the rain intensity. Now each weather has an equilibrium soak level, SOAK: 0.55 for light rain, 1.0 for heavy rain, and 0.0 for clear, cloudy and overcast. Each weather also has its own drying rate per second. So a shower glazes the track but can't fill it, and a soaked track under overcast stays damp for minutes.

Measured at the same camera against the dry frame: in light rain, 5.2 % of the pixels are more than 6 % brighter. In heavy rain, 15.2 % are.

Aquaplaning is a grip term, and only a grip term

This is the one place in the round where I added to the physics, and my first attempt was wrong. It reduced grip and also added drag. But wheel_drag is a fraction of the tyre's capped load, and the clean-tyre path never zeroes it. So the value accumulated on every wet tick, and the slip model diverged. The test harness drove one car to 332 m/s.

Now it's mu *= lerp(1, 0.80, depth) and nothing else. Nothing is sampled below wetness 0.6, which leaves dry running bit-identical: the physics probe's checksum is unchanged at 6fce746d6839b81aecf7754f10306afc.

Tyre tracks baked into every road

The road had a permanent pair of tyre tracks baked into it. They were drawn from the racing-line channel along the whole lap, on every circuit, whether or not any car had driven there.

Now the cars lay their own tracks as they drive. Each tyre has a ring buffer of at most 48 quads, which costs two draw calls per car, and the tracks are scaled by wetness, so a dry track is untouched. The baked pair is gone. The road keeps only the broad rubbered band of the racing line.

A car on a soaked, mirror-like straight under a clear sky, with two dark tyre tracks behind it
Clear sky over a soaked track: for this still the test harness holds the track fully wet, where a race would let the sun dry it. The two dark lanes behind the car are tracks it laid itself, and the shadow sits under the tyres. Captured in-engine during this work.

Spray: smaller reads as wetter

The plume is now fine droplets, 260 per car. The soft puffs that used to carry it were 0.5–0.95 m across and grew ×3.8, and a 3.6 m puff reads as cotton wool, not water. They're now 0.12–0.30 m and grow ×2.6. The splash off standing water is 200 droplets of 0.02–0.055 m, thrown at 4–10 m/s.

Chase view of a car in heavy rain throwing a plume of fine droplets off its rear tyres
Heavy rain, chase camera, the car running through standing water. The plume is fine droplets now, with only small soft puffs left in it. Captured in-engine during this work.

The shadow slid off the tyres

The car's contact shadow was a decal parented to the body. So it inherited the body's pitch and roll, and under braking it slid off the tyres. It's now placed every step at the average height of the tyre contacts.

A floodlight bank the phone renderer can't draw

One thing from this round can't ship on phones. I tried real lamps in the floodlight banks, three per mast. On the Mobile renderer the road's luminance went from 0.154 to 0.019, which is black. That renderer shades each object from at most 8 spot lights, and a 64 m road chunk already overlaps about 30 mast spots.

It didn't pay off on Forward+ either. Real lamp reflections don't read from a chase camera: a lamp 22 m up has its mirror image only 2–7 m ahead of the camera, under the car or below the frame.

What I'd take from it

The three biggest defects here were a colour-space mismatch, a term that accumulated and was never reset, and a texture channel drawn along every lap. None of them would have yielded to tuning. Each one showed up as something measurable that couldn't be right: 0.7 % coverage, a car at 332 m/s, tyre tracks on a lap no car had driven.

The game

Apex GP is at apexgp.racing. Circuit names are parodies of the real places, and all teams, drivers and sponsors are fictional.

AI assistance

The code, shaders and some assets in Apex GP were produced with AI tools, under my direction. Some front-end media and the announcer voice lines were generated with AI models, and the credits page marks them as such.

— Phil

← All devlog posts · RSS