I’ve been working on a new real-time strategy game called Burnt for Beacons. It is set on a frozen planet covered in snow. Every unit in the game leaves tracks that slowly fade as snowfall reclaims them. The tracks aren’t just set dressing – they are critically important to the game: your opponents uncover previously carved tracks revealed through the fog-of-war to learn where you have been and where you are going, potentially giving them a decisive edge.
I’ve set out with a handful of goals and constraints:
- Tracks last around 5 minutes before the snowfall buries them.
- Tracks are per-player knowledge: what you’ve seen and what your opponents have seen may not be the same.
- Replays are seekable: you can skip to any part of the replay within seconds.
- Replays should be at most a few tens of MB.
- The largest maps are up to 5km × 5km with ~10,000 units and 16 players.
While the scale target in the last point is something seen in other RTS games (e.g. Beyond All Reason or Supreme Commander), the combination of all of these presents unique technical challenges: How do you render 5 minutes of tracks for 10,000 units? How do you store them? How do you rapidly restore them during a replay without making the replays huge?
This post goes into technical detail of the last couple of days of work on this system, taking it from the initial implementation that used 384MB to only cover at most 4% of the map and with no replay seek support to meeting all the goals with just a few hundred MB of RAM for the whole map and up to 1MB/min in replays in the worst case.
How other games do it
Most games that leave tracks use one of two tricks, and they only work because tracks aren’t as critical to the game.
Decals that fade. The most popular approach, particularly in RTS games, is where each stretch of track is a textured quad on the ground that fades out over a lifetime. Beyond All Reason on the Recoil engine is a good example. Tracks lay a stretched quad as the unit moves in one direction and it fades over tens of seconds. Tracks are only created when the unit is visible. As a purely visual track system, this works perfectly fine for BAR.

A deformation map around the camera. Third-person games with deep snow keep a heightmap centred on the camera, render the player and nearby characters into it, and let the window scroll as the camera moves around. Outside of an area (~50m x 50m) tracks are dropped. The idea has been around for a long time and it’s still the approach in God of War Ragnarök (GDC 2023). It works really well when there’s only a handful of characters in a relatively small active area.

Unfortunately, neither of these really works for our game:
- The volume is too high for decals. At 10k units a single tick lays 4,000 to 14,000 stamps. Five minutes of persistence means tens of millions of live marks: far too much to render.
- We can’t limit to just where the camera is. As a critical component of the gameplay, the tracks need to be placed whether you were looking or not.
- Storing a complete heightfield is impractical. At 5km × 5km with ~10cm granularity even 8-bit height resolution with the naive approach is 2.5GB, much more than we’d want to budget for tracks alone.
Where it started: a fixed GPU pool
Until yesterday the whole track system lived on the GPU. It started as a 16-bit heightfield with virtual pages and a cap on the number of active pages. There were two maps:
| Map | Coarse layer | Detail atlas |
|---|---|---|
| Used for | Zoomed out, or no detail page | Active tiles at normal zoom |
| Texel | about 1.25m | 12.5cm |
| Format | RG16F | RGB8 |
| Size | 4096² | 8192² (1024 x 256²) |
| Layout | Covers whole map | 32m square tiles (4% of map, LRU eviction) |
And because tracks are per-player, we also had two copies: the truth, and what you’d seen (local player only).
As units moved on the map, they would stamp their tread marks (with berms) onto the coarse map and then into the detail map as GPU draws, allocating (and evicting) a page if needed. This would happen even for off-screen units because it is important to be able to discover tracks even when you didn’t witness their creation.
This worked well enough in small skirmishes with hundreds of units, but simply could not work at scale.
- The detail pool covered only around 4% of a 5km map so pages were constantly evicted.
- Despite only serving 4% of the map, it still used 384MB, which is tolerable, but way too big for 4%. There’s no simple way to scale this up.
- Changing player in replay views was incorrect since it only showed what the player saw since the change.
- Replay seeks were slow: tracks stamping over the past 5 minutes had to be replayed, taking several seconds in larger games.
The animation below shows an example of how this worked: new tracks were constantly churning the detail atlas, often leaving the camera looking at the coarse texture map, which did not meet the target visual quality.
The GPU only needs what it sees
If we look back at how other games approach this problem, you see two approaches with different trade-offs:
- Height fields (our detail maps) are cheap to render, but expensive to store.
- Decal lists (our stamps) are cheap to store, but expensive to render.
However, we don’t need to render all tiles at once. Only when zoomed fully out can you see the whole map, and the coarse layer is fine for that (and not too expensive). When zoomed in, you can only see a small fraction of the map, so there’s no reason for the detail map to be the source of truth for everything: we only need it for what you can see.
So what format do we use for storing off-screen track data? It needs to be more compact than texels by ~10x, but also relatively cheap to update since units are moving whether you are looking at them or not.
One idea was to keep an 8-bit, 12.5cm texel snapshot for live tiles (on the CPU), but compress them when quiet. A quick test with zlib on a sample AI match showed that tiles on average compress 14x, which was small enough. Some early benchmarks also showed that we could actually rasterise the tread stamps on the CPU for 10k units with relatively low cost (more on this later).
Unfortunately, average case is not worst case. Problems with this approach arise when units are moving all over the map: we need to compress to keep memory low, but you can’t stamp into a compressed map, so either you keep everything decompressed (huge memory) or you have to constantly decompress/stamp/compress again, which is far too slow even for the fastest compressors.
Storing tracks
Rather than trying to keep everything in a texel format (compressed or not), the next idea is to just keep the stamps themselves, in a log, and only turn a tile into texels when something needs to look at it.
We still need to do this efficiently though: 10k units can lay a lot of track in 5 minutes. The fastest units at the moment move ~20m/s. That’s 60,000km of track. At 10Hz granularity it’s 30 million track segments. A naive data structure of start/end vectors, timestamps, treadtype, etc. can easily be tens of bytes and push us over a GB, which is unacceptable. That’s ignoring any data structure overhead.
The approach we settled on:
- Quantize coordinates to ~0.1cm (1/1024m)
- Predict next position based on velocity and then use a variable length delta encode:
- 2 bytes: for steps up to ~6.3cm - typical when cruising in straight lines
- 3 bytes: for steps up to ~50cm - typical when jostling in battle
- 4 bytes: step up to 4m - rare.
- 10 bytes: whole keyframe, e.g. starting again after a stop.
These are written into blocks of up to 255 points to amortise data structure overhead and each 32m tile keeps a 12-byte reference to every block that touches it.
This works great: at just a few bytes per stamp on average, even with 30M stamps that’s under 100MB.
Ok, so how do we render this? When a tile comes into view, we then turn these stamps into texels again by rasterising the stamp list into the 256² texture and upload to the GPU. In typical scenes, we can do this relatively cheaply by stamping on the CPU and just budgeting how much stamping we do per frame. The GPU only keeps the 500 closest tiles.
Unfortunately, during dense battles a single tile can collect tens of thousands of stamps over 5 minutes and re-laying them when the camera moves over can be very slow. To combat this, we go back to our previous idea of storing texels again! Once an individual tile’s log passes a threshold of stamps (say, 10000) we eagerly rasterise it down to a texture and then pass it through zstd to losslessly compress it. Only newer stamps stay in the log. We also flatten tiles early if total log memory reaches a threshold to keep total work bounded. This strikes a good balance between memory and re-lay cost.
In the worst scenarios it can take a few frames for the view to catch up, but this is unnoticeable in practice since the camera is moving and the centre-most tiles fill in first.
Per-player knowledge
With every stamp on the CPU, each player’s view of the tracks becomes a rule instead of a second texture to keep in sync. The replay indexer records when each player last looked at every 8 m cell (10.8 MB for a 15-minute, 16-player match). A track is in your seen copy if you looked at its cell at or after the tick it was laid.
In live play, seen is updated by copying truth into it wherever you have vision. A replay, or a tile rebuilt from the log, lays the same stamps through the same rule on the same grid, so switching players in a replay now shows exactly what that player knew. A seen tile that’s identical to truth shares truth’s memory, and an observer keeps no seen copy at all.
Making stamping cheap
A tread stamp is an oriented rectangle along the path the unit just drove, about 2.8m across for a typical unit. Each texel takes the max of itself and a berm (the lip of snow pushed up beside each tread) and then the min of that and a trench (the rut, with a cleat ridge every 0.3m). Every 0.6m a unit lays the new stretch plus a second, trench-only stamp over the previous one, so the new berm doesn’t refill the old rut. At 10k units that’s 4,000 to 14,000 stamps a tick, and they overlap heavily, so every track texel gets evaluated four or five times.
With the log, most of those stamps aren’t laid when they arrive. Only the raw tiles near the camera take their stamps live, and everything else waits until a tile is rebuilt as the camera reaches it, a busy tile is flattened, or a replay seeks. Watching a 1k-unit battle with every unit on screen and moving is roughly 400 to 1,400 live stamps a tick. The bursts are what hurt: a camera jump to a busy base rebuilds 174 to 252 tiles at once, each re-laying everything in its log, and a seek re-lays five minutes of tracks across the whole map.
My first port of the stamp shader to D cost 88µs a stamp, and that version laid every stamp the moment it arrived, so replaying a 10k-unit match ran at 3 fps. Some quick wins cut that by about 5.6x. Then I spread the work across threads: each batch of stamps is bucketed by tile and the tiles are laid in parallel. Tiles never share texels, so there are no locks and the result is identical to laying them one at a time. That’s still the same amount of work, just spread over more cores, so the rest of this section is about making each stamp cheaper.
Prebaked sprites. The bigger win was not evaluating the shape at all at run time. Every gear’s shape is baked once into small sprites, each covering one 0.6 m step of track, at 64 headings and a handful of noise seeds. A stamp then lays the sprites centred on every multiple of 0.6m along its path, and each texel is just o = min(max(o, berm), trench).
![]()
A few details make that hold together:
- 0.6 m is two cleats, and every sprite is baked centred on a cleat boundary, so neighbouring sprites’ cleats line up under the min instead of erasing each other.
- The seed is a hash of the sprite’s index along the path, not a random draw. A replay re-lay lays exactly the same sprites, so per-player belief stays exact.
- 64 headings is 5.6° apart, which at the end of a 0.6 m sprite is under a texel of error.
Serial cost on the 10k-unit replay (11.2M stamps) went from 15.7 to 1.21 µs a stamp, 13×.
Then the inner loop. The first version scaled each sprite texel by the tile’s fade gain as a 16.16 fixed-point int, which widened every lane to 32 bits, and the release build kept a bounds check per lane. Rows are only about 20 texels wide, so even vectorised code spent its time on tails and on runtime checks for overlapping slices. The fixes:
- Fold the tile’s fade into its texels the first time it’s written in a fade step, so the loop has no scale at all.
- Pad every sprite row to a multiple of 8 with neutral texels, and lay a sprite that sits wholly inside its tile as a fixed-width block. LDC then emits
ldp q/smax.8h/smin.8h/stp qon ARM andpmaxsw/pminswwith SSE2 on x64: four vectors a row, no tail. - Give each worker a last-hit pointer into the sprite cache, which had a mutex the workers were contending on.
Here’s the D for a whole-sprite block. W is the sprite’s row pitch, 32 texels for the Wolverine:
void layBlock(uint W)(short[] o, size_t at, size_t stride, const(short)[] berm,
const(short)[] trench, uint v0, uint v1, bool withBerm) @trusted pure nothrow @nogc
{
foreach (v; v0 .. v1 + 1)
{
short* row = o.ptr + at + v * stride;
const(short)* b = berm.ptr + v * W, t = trench.ptr + v * W;
short[W] x = row[0 .. W]; // a local copy: nothing can alias it
if (withBerm)
foreach (i; 0 .. W)
x[i] = x[i] > b[i] ? x[i] : b[i];
foreach (i; 0 .. W)
x[i] = x[i] < t[i] ? x[i] : t[i];
row[0 .. W] = x[];
}
}And the whole inner loop LDC 1.41 makes of layBlock!32 for x86-64 at its SSE2 baseline (-O3 -release, no -mcpu). One iteration is one 32-texel sprite row: four 8-lane vectors of the tile, four of berm, four of trench, eight instructions of real work.
LBB36_5: ; one sprite row
movl %r8d, %esi
andl $-32, %esi
addq %rsi, %rsi ; byte offset of this row in the sprite
movdqu -48(%rdx), %xmm0 ; tile row, texels 0..7
movdqu -32(%rdx), %xmm1 ; 8..15
movdqu -16(%rdx), %xmm2 ; 16..23
movdqu (%rdx), %xmm3 ; 24..31
movdqu (%r9,%rsi), %xmm4 ; berm
pmaxsw %xmm0, %xmm4 ; max(tile, berm)
movdqu 16(%r9,%rsi), %xmm0
pmaxsw %xmm1, %xmm0
movdqu 32(%r9,%rsi), %xmm1
pmaxsw %xmm2, %xmm1
movdqu 48(%r9,%rsi), %xmm2
pmaxsw %xmm3, %xmm2
movdqu (%rax,%rsi), %xmm3 ; trench
pminsw %xmm4, %xmm3 ; min(that, trench)
movdqu 16(%rax,%rsi), %xmm4
pminsw %xmm0, %xmm4
movdqu 32(%rax,%rsi), %xmm0
pminsw %xmm1, %xmm0
movdqu 48(%rax,%rsi), %xmm1
pminsw %xmm2, %xmm1
movdqu %xmm3, -48(%rdx) ; store the row back
movdqu %xmm4, -32(%rdx)
movdqu %xmm0, -16(%rdx)
movdqu %xmm1, (%rdx)
addq $32, %r8 ; next sprite row
addq %rcx, %rdx ; next tile row (stride)
decq %rdi
jne LBB36_5No tail, no bounds checks, no widening: 16-bit lanes from load to store. The trench-only stamp gets its own copy of the loop with the pmaxsw half gone.
That took LDC from 1.21 to 0.74 µs a stamp, or 2.6 ms a tick across the workers if every stamp at 10k units were laid as it arrived.
Replays
A replay is just the command stream, re-run on the deterministic sim. To seek, we restore the nearest keyframe and simulate forward from there. Tracks aren’t part of the sim, so they come from a separate path history recorded alongside it, and a seek re-lays the last five minutes of it. Having the whole path history allows us to recreate per-player belief information on demand.
Path history. This was a polyline per unit at 32 bytes a vertex: 294 MB for a 10-minute 10k-unit match, far too much. It’s now 10.1 MB, about 1 MB a minute.
- Fewer vertices. A vertex is only kept where a straight line from the last one would stray more than 15 cm from where the unit actually drove. Any looser and the lines visibly cut corners. Units in a fight turn a lot, so this only took 9M vertices down to 4.9M.
- Predict each vertex, store the miss. Units tend to keep going the way they were going, so each vertex is predicted by carrying the last line on, and only the miss is stored, on a 10 cm grid.
- Entropy-code the misses. The misses are small and mostly zero, which is exactly what an adaptive range coder is good at: about 2.2 bytes a vertex.
Seeking at 10k units decodes just the last five minutes of path history (about 0.3s, however long the match) and re-lays the tracks. Currently this is done all upfront on seek rather than lazily like during the game, but that will be fixed soon.
Where it landed
This all landed over the past few days and is working well! There’s more work to improve the speed of the replay seeking and potentially optimise some of the most pathological cases, but it is in a usable state and I’m happy with this and it’s hitting all the targets.


