How to Add Fog of War to Your Game
Fog of war hides what the player has not seen and blurs what they saw long ago. Here is how to model it, the numbers to start with, and the bugs to test for.

Key takeaways
- Model fog as a small grid with three states per cell (unseen, explored, visible), separate from how it is drawn.
- Recompute vision only when a viewer crosses a cell, not every frame, and draw the result as one blurred texture over the world.
- Enemies hidden by fog must also be hidden from sound, the minimap, targeting and the HUD, or the fog leaks.
To add fog of war, keep a coarse grid over your map where each cell is unseen, explored or visible. Every frame that a unit or the player moves into a new cell, clear the visible flags, mark the cells inside each viewer's sight radius as visible (and explored), then draw a dark layer over the world: fully black where unseen, dimmed where explored, clear where visible. Enemies and pickups only render in visible cells. That is the whole mechanic; the rest is tuning and plugging leaks.
The three states, and why you need all three
Many first attempts use two states: hidden or shown. That works for a dungeon crawler where the map simply reveals as you walk, but it loses the most interesting part of fog of war, which is memory. In strategy games and many top-down action games, the player remembers terrain they have seen but does not get live information about it.
- Unseen: drawn solid black (or a parchment texture). Nothing inside renders, not even terrain.
- Explored: terrain and buildings draw dimmed, around 40 to 60 percent darkness, often desaturated. Moving units do not draw. Static enemy structures can draw as the player last saw them, a "ghost" that may be out of date.
- Visible: everything draws normally and updates live.
Decide which kind of game you are making. An exploration game (a roguelike floor, a metroidvania room) usually only needs the reveal: once explored, a cell stays fully clear. A competitive or tactical game needs the full three-state model, because the whole point is that what you saw a minute ago may have changed.
Grid size, sight radius and update rate
Fog lives on its own grid, not on your pixels. A fog cell the size of one map tile is the natural choice (32 or 48 px in a 2D game, 1 to 2 meters in 3D). Finer cells cost more and look no better once you blur the edges. Starting values that work for most top-down games:
- Player sight radius: 6 to 8 cells. Small enough that the edge of the screen is often dark on a phone, large enough to react to an enemy walking in.
- Scout or tower radius: 1.5 to 2 times the player's. Vision is a resource, so units that grant more of it are worth building or protecting.
- Enemy sight radius: the same rules as the player's, usually a little smaller. If enemies see further than the player, sneaking feels unfair.
- Update rate: recompute when any viewer changes cell, or at most 10 times a second. Fog does not need 60 updates a second; the eye cannot tell.
- Edge softness: blur the fog texture over 1 to 2 cells and fade newly revealed cells in over 0.2 to 0.3 seconds, so reveals feel like light, not tiles popping.
Radius only, or real line of sight
The simplest vision is a circle: every cell within the radius becomes visible. It is fast, readable and right for open maps. The moment your map has walls the player expects to hide behind, a circle feels wrong, because you can see through stone.
Line of sight fixes that. For each cell inside the radius, trace a line from the viewer to the cell and stop at the first wall. On a grid this is called shadowcasting, and the standard recursive version handles a radius of 8 in well under a millisecond. A cheaper approximation casts 60 to 120 rays in a circle and marks every cell each ray crosses until it hits a wall. Both make corridors and doorways matter: standing in a doorway shows a cone of the room, which is exactly the tension a stealth or horror game wants.
- Mark walls themselves as visible when a ray hits them, or rooms look like they float in darkness with no edges.
- Make doors and tall grass vision blockers that can change at runtime. A door that opens should trigger a recompute right away.
- Elevation (optional): units on high ground see over low walls; units below do not see up. One extra rule, a lot of tactics.
The bugs fog of war usually causes
Fog that looks right can still give information away. Almost every fog bug is a leak: some other system that knows where hidden things are and tells the player. Test for each of these on purpose:
- 01Sound leaks. An enemy footstep or gunshot that plays at full volume from inside the fog reveals position. Either mute hidden sources, or (better, and more fun) play them muffled and without a precise direction.
- 02Minimap leaks. The minimap draws enemy dots from the full unit list instead of the visible list. Every other view must read from the same fog grid.
- 03Targeting leaks. Auto-aim, tap-to-target or a "nearest enemy" ability that locks onto a unit in the fog. Filter targets by visibility before anything else.
- 04Shadow and particle leaks. A hidden unit's shadow, dust or projectile drawn on a visible cell. Projectiles entering vision should appear; their shooter should not.
- 05Health bars and names. UI attached to enemies often renders on a layer above the fog. Hide it with the unit.
- 06Pop-in at the edge. Units appear abruptly as they cross the boundary. Fade them in over 0.15 seconds, the same as the fog.
- 07Save files. The explored grid is part of progress. Store it compactly (a bit per cell, or run-length encoded) or reloading a save hides the whole map again.
In multiplayer, there is one more rule: the server must not send hidden units to clients at all. If the data reaches the browser, a curious player can read it, and the fog becomes decoration. For a single-player game this does not matter; for anything competitive it is the only fog that counts.
How fog combines with other mechanics
- Enemy AI. Enemies should obey their own fog. Give each one a perception check (in sight radius, line of sight clear) rather than letting it chase the player through walls. See simple enemy AI that feels smart for perception states that pair well with this.
- Light and day-night. Shrink the sight radius at night (by 30 to 50 percent) and let torches or lamps add their own small vision circles. Fog and lighting then tell one story.
- Procedural maps. A generated dungeon is more exciting under fog, because the layout is new each run. Reveal the explored grid per floor and reset it on the next one, as in a roguelike.
- Scouting items and abilities. A flare that reveals a circle for 5 seconds, a map scroll that marks a floor as explored but not visible, a ward that grants vision where it is placed. Fog turns information into loot.
A fog of war brief to paste
Name the states, the radius values and the leaks you want closed. Ask for the numbers as dials so you can tune them while playing; on Startbase every dial the agent adds appears in the engine panel of the games template.
Add fog of war to my top-down game. Keep a fog grid at one cell per map tile with three states: unseen (solid black), explored (terrain drawn at 50% darkness, no moving units) and visible (normal). The player sees 7 cells, the watchtower sees 12, using shadowcasting so walls and closed doors block sight and walls themselves show. Recompute only when a viewer changes cell or a door opens. Draw the fog as one blurred texture with a 0.25 second fade on reveal. Hidden enemies must not render, show on the minimap, be targetable or show health bars; their sounds play muffled. Save the explored grid with the game. Expose sight radius, explored darkness and fade time as dials.
After the first build, walk the player along a wall with an enemy on the other side, open a door, and pause the game while an enemy is hidden. If anything gives the enemy away, describe exactly what you saw. Save a checkpoint before switching from radius vision to line of sight, so you can compare the feel of both.
Frequently asked questions
What is fog of war in games?
Fog of war hides the parts of the map the player cannot currently see. Unexplored areas are black, explored areas are dimmed and show terrain but not enemies, and areas inside a unit's sight are fully visible and live.
Is fog of war expensive to run in a browser game?
Not if you keep it on a coarse grid, recompute only when a viewer changes cell, and draw it as one small blurred texture. A radius of 8 with shadowcasting costs far less than a millisecond per update.
How do I stop fog of war from revealing enemies through sound or the minimap?
Make every system read from the same visibility grid: rendering, the minimap, targeting, health bars and audio. Hidden sounds can play muffled without precise direction instead of being muted entirely.
Should enemies be affected by fog of war too?
Yes. Enemies that can see through walls or further than the player make stealth and ambushes feel unfair. Give them a sight radius and line of sight with the same rules.

