top of page
  • Linkedin logo
  • Colour Collide Icon

Fog of War

Fog Of War: This will refer to a plane that obscures the player's vision.

As the player moves around, different areas will be revealed.

The Fog of War also prevents players seeing rooms or areas they do not have Line of Sight of.

FogOfWar_ObscuringDoor.gif
Fog of war_closed door HD_edited.jpg

In Breaching Shadows only areas within buildings are obscured, only revealing where the player* is. 

When the player is in range and Line of Sight, the Fog of War quickly disappears, later reappearing when the player no longer reveals an area.

(Physical objects will obscure the players view)

Implementation

I started by creating a plane to cover the parts of the building that should be obscured by the Fog of War

(The Material/Shader for the plane/fog was made by Daniel Betts)

FogOfWar_Plane.jpg

Since each point in 3D space that can be 'seen' or 'revealed' by the player must map/correlate to a point on the plane. I decided to generate the 'Detectable Points' from the plane.

Therefore, whenever a Detectable Point gets seen, it can map directly to the plane.

Fog Of War example with gizmo.jpg

(Left squares represent 'Detectable Points', how precise detection can be represented)

Next I checked if the player has 'Line of Sight' to the 'Detectable Points' using multithreaded raycasts with Unity's RaycastCommand. Then I allowed for calculating the raycasts over several frames for performance. Below is a Gizmo that displays whether a raycast was blocked, or if it revealed a 'Detectable Point'.

FogOfWar_RaycastGizmo.jpg

Red = no Line of Sight to Detectable Point

Green = Line of Sight to Detectable Point

One of the playable characters had a device which could reveal the Fog of War regardless of Line of Sight.

This involved revealing 'Detectable Points' regardless of Line of Sight.

DeviceReveal.jpg

Flexibility

The system does not manually place a grid of points, but instead places points based off a mesh. This allows different shapes/point density, for example a sphere could be used, or the mesh could exclude a portion for a window.

Points can be set to always remain a set opacity, or to have a different max opaqueness. This is useful for keeping partially visible areas, or enforcing no visibility in areas that are out of bounds, or between walls/floors.

Conclusion

The Fog of War system was an intricate challenge that has satisfying results. Some smaller details such as the fading in and out of the Fog were not covered.

The system was designed to be flexible to a given mesh, therefore the system would work on meshes of various shapes. For example, given a dome or sphere.

Awareness of how a system can be optimised is beneficial during design, especially when dealing with potentially intensive physics approaches such as raycasts.

The Detectable Points update visually every frame (fade in/fade out) for example, giving a smooth outcome, even though the Line of Sight can be calculated over multiple frames if necessary. (reducing raycast overhead)

© 2023 by Site Name. Proudly created with Wix.com

bottom of page