Choose one way:
1) Traditional camera-based script: just add “DynamicFog” or “DynamicFog Exclusive” script to your camera. It will show up in the Game view. Customize it using the custom inspector.
Dynamic Fog & Mist: recommended script for most situations.
Dynamic Fog & Mist Exclusive: variant of the main script with Render Scale option which results in better performance on mobile.
2) Post-Processing Extensions (compatible with LWRP and URP 7.2.0)
Support for Post-Processing Stack v2 is included. This option requires Unity 2018.1 or later (LWRP) or Unity 2018.3 or later (URP). You also need to have PostProcessing Stack V2 package installed (you can install it from the Package Manager).
Then import the package named “PostProcessingSupport.unitypackage” included in DynamicFog folder.
Important: if you opt for the post-processing extensions, don’t add the script to the camera: Dynamic Fog effects will be available as pluggable effects in Post-Processing Profiles and Volumes.
3) Custom Fog materials
A collection of materials and shaders are provided that have the fog effect integrated in their shaders so they offer the fastest performance available! However, if you choose this path, then you need to use these materials and not the image effects or Post-Processing Extensions above.
Important: you should use one of the options above, do not mix them.
The image effect is controlled by the script DynamicFog.cs that you add to your camera. The image effect overlays a layer of fog on top of the image every frame. The fog is computed using the depth of each pixel on the screen rendered by the camera. The farther the pixel the thicker the fog.
The Post-Processing Extensions are the same image effect shaders but rewritten to work with Unity Post-Processing Stack. They are also compatible with SRP.
On the other hand, the fog materials use custom shaders that integrate the fog calculation. There’s no full screen blit nor full screen fog computation but instead the color of the objects are modified depending on the distance to the camera. Since there’s no separate full-screen blit pass, using fog materials could be faster on old mobile devices.
Finally, if you need a top-down view, fog of war effect that occludes game area and allows you to clear custom zones, the fog of war prefab provides you the best performance.
Only if you’re really concerned about performance (eg. mobile), use the fog materials or the fog of war prefab. Otherwise use the other options (full-screen image effect or post-processing stack extensions).
Demo scenes 1-4 show examples of the full-screen image effect whereas demo scene 5 shows how to use fog materials to create a simple arcade game.