Back to Devlog

Devlog 4 min read

Rewriting the fog of war: three states, no objects

The first version put one object per tile on the map and switched them all on and off every frame. The new one is a grid of stamps and a single screen-sized quad that reads depth. Why the obvious implementation is the expensive one, and what the three states cost.

A camp and its palisades seen from above, under open sky

The first fog of war in Stone Tribes was the one everybody writes first: a grid of tiles, one object per tile, and every frame you walk the grid and switch each tile on or off depending on who can see it. It works on paper. On a real map it was the heaviest thing on screen, and it had to go.

Why the obvious version is the expensive one

Two costs hide in that description, and both grow with the map rather than with the action.

The first is the objects themselves. A map worth playing on is thousands of tiles, so it is thousands of things the engine has to carry, sort and draw, most of them doing nothing. The second is the sweep: every frame, the whole grid is visited, including the nine tenths of it that nobody walked near since the last frame.

So the rewrite started from the opposite end: pay for what moved, and nothing else.

A grid of stamps

Vision is recomputed about twelve times a second, not every frame — the eye cannot tell, and it divides the work by five straight away.

Each pass stamps the tiles that are visible right now, and clears only the tiles the previous pass had revealed. Nothing walks the rest of the map. A pass therefore costs what your tribe can see, not what the map contains, and a map twice as large costs the same as a small one. Between two passes, the fog costs nothing at all, because there is nothing to update.

One quad, read from depth

The second half of the problem is drawing it. The tempting answer is a dark plane laid over the ground, and it is wrong: trees, rocks and rooftops poke out of it. You get black ground with a lit forest standing in it.

What is drawn instead is a single quad in front of the camera. For each pixel it reads how far away the scene is, rebuilds the point in the world that pixel is looking at, asks the grid what is known about that point, and darkens accordingly. A tree in the unexplored dark is dark, because the pixels of the tree are the ones being tested — not the ground under it.

The three states, and the lie in the middle one

Visible is live: you see what is there.

Explored is memory, and memory is where it gets interesting. A building you have already seen stays on the map in the state you last saw it in, while the people are hidden. Walk away from an enemy camp and it keeps the shape you left it with. Something built there since you left is invisible to you — it was never seen, so it is not remembered.

So the explored state is allowed to be wrong, and that is exactly what it is for. If it updated itself behind your back it would not be memory, it would be a map.

Never seen is black, and it is the only honest one.

One case needed deciding. A building razed while you were not looking is gone for everyone — but you did not see it fall. The fog keeps a tinted copy of it standing where it was, and takes it away the moment you look again. You get to be wrong, and then corrected, which is the same contract as everything else here.

A camp sunk in darkness, barely readable
Never seen is black, and it is the only one of the three states that is honest.

What it changes for the player

Two limits follow from the fog rather than from the interface. The commander camera is bounded by what you have explored, so you cannot scroll across a map you have never walked. Placing a building needs what is visible, not what you remember — you cannot build into a corner on the strength of an old memory.

And because you never control a unit directly, the fog does something it does not do in most strategy games: it is your scouts’ behaviour, written before the fight, that decides what you are allowed to know. The rules you write end up being the ones that lift the dark.

Get the game on Steam Play the free demo

Keep reading