The Fog of War - How to do it?

So, one of my projects I am looking at is a RTS, an improvement on my older title, Zombies vs. Knights. Among the more standard RTS systems that need to be in for the game to be effective, is a ‘Fog of War’ system.

I’ve managed to find old forum posts, but reasonably few concrete details on how one would implement such a system; in a modern Unity version, how would I implement Fog of War in a performant way, using Unity Free?

Is the fog going to be based on sight or exploration? If it’s exploration, you could handle this with a simple tile map and have the edges have special tiles to help them blend in to one another smoothly. If it’s real time… that’s trickier.

There are a couple Asset Store packages for this. The non-RT methods seem to involve laying a translucent plane over your map and using vertex colors to “brighten” vertexes on the plane that surround your units. A distance / line of sight check can help you determine enemy visibility. You can use a couple planes, like opaque black for unexplored territory, gray for explored but not visible territory, or high ground / low ground, etc.)

1 Like

I guess the easiest way is to have a subdivided plane over the entire map, and just set vert cols for anything requiring visibility. There’s faster but much more complex ways (all shaders use a vertex macro and step func) but that’s only a requirement if you’re up against a fill rate wall on really low-end hardware. A single pass of a fog mesh shouldn’t be too bad. You really wouldn’t need multiple planes.

1 Like

Fholm has a few open source assets, one of them being Fog of War. I haven’t looked at it, but you can check it out here: GitHub - fholm/unityassets: Assorted unity assets and utilities

1 Like

@OutSpoken_Gaming - Great link, thanks for sharing that!

Thanks to everyone else who chimed in also. I’m working with some of these approaches - I might have something in the Small Works Programming thread in a couple of weeks, thanks to this (I’m slogging through Network code right now.)

Much appreciated!

1 Like

Works well :smile:

I think a good question would be which type of fog of war are you striving for?

There are FOW types where everything is “dark” except areas your units have explored. After they have explored an area it is no longer “dark” but it is over cast or in “shadows”, sort of like Baldur’s Gate.

I prefer types like Star Wars: Empires at War, where the map is open but you can only see things that are in range of your units, if the enemy units are not in range of your units they are not visible on screen but are there moving across the terrain to an unknown destination. This can be extended to resource nodes in RTS games too.

This also gives you an extra trick where unit scale can have an effect on visibility between units. Something that is very big could be spotted further away than say a small platoon of enemy troops.