Taking a look at Unity Fog

May 07, 2019 at 10:00 am by nemirc

Unity Fog

After exploring the Post-process Stack in Unity, this time we will take a look at the Unity Fog.

Adding fog to your scenes can be used for various purposes. For example, you can use it to improve the atmosphere of your game, add a supernatural feel to it, or even as a way to overcome hardware limitations.

Did you know that the first Silent Hill games added fog as a way to hide the fact that they limited the amount of geometry that had to be drawn on screen?

Yes, the fog in those games was added because those systems were not powerful enough to draw an entire block, or series of blocks of the town, so, they came up with a creative solution: put a wall of thick fog and only draw what was in front of the fog.

Unity offers three different kinds of fog, linear, exponential, and exponential squared. Linear fog increases density based on a start and end setting.

Exponential increases the density exponentially based on distance, and exponential square is pretty much the same, but increases density faster. For our experiments, we will be using the same scene as last time.

The Fog settings can be found in the Unity Lighting tab, and while it’s very limited, it can still produce interesting results.

The first thing you notice is that you can change the fog color, which can be very useful depending on the goal you have. White/gray fog could be used as regular fog, but something like purple or green fog can add some “magic” to it, that can be good if you are going after a more supernatural look, or a “contaminated area” look. Imagine you are working on a scene where a virus was just released. You can use green or yellow fog to show how the air is contaminated.

With linear fog, you have full control on where the fog starts and ends, since it literally has a “start” and “end” setting, and that can be very useful depending on the situation. If you switch to exponential or exponential square, the start and ending settings are replaced with a “density” setting.

Based on my experience, the density setting can be very sensitive depending on your scene scale. In this specific setup, increasing the density setting for a linear fog by just a little, resulted in the scene completely covered in fog to the point I couldn’t see a thing, and that can make things tricky if you want to use this one instead of linear.

Another thing you can do in the fog settings is set the Halo and Cookie textures. Cookie textures are used to simulate stained glass, among other things. Halo textures are used to draw an effect around objects to simulate a concentration of atmospherics around it. While this can be used for anything, it’s more commonly used to draw the “halo of light” around a light source, or something that simulates a light source (like a light bulb model). Rather than setting a texture for every object that uses the effect, Unity lets you set the texture here in the light settings. You can see an example of the halo on the image above (look for the purple arrow).

One thing to keep in mind is how fog is drawn. To be drawn, the fog needs an object behind it. If no object is found, the game will draw the empty background (using either the camera’s background color, or the scene’s sky). Avoiding this is very easy, though. All you have to do is create a big plane that covers the entire camera’s field of vision, so there’s something to draw fog on top of.

While there are other, more powerful solutions to create fog in Unity, the default fog generator can be used to create nice results, specially if used with other effects. Besides, it’s compatible with pretty much any platform, meaning that you don’t need to worry about portability, unlike other fog generators.

Get Unity for free: https://unity.com/




Sign up for our newsletter

This website uses cookies to ensure you get the best experience possible More Info
Got it!