How do I add fog?

I want to add some simple height fog to my scene, just to make some pits fade out into blackness without having to completely reconfigure my lighting. Since all my pits need to be opaque by a universal height in my scene, height fog sounds like the best option.

However, when I look at the "global fog" that comes with Unity, I have no option to adjust the color of the fog, making it only gray. I curiously don't have any options for adjusting the strength of the distance fog, either.
I tried a google search and it only directed me to an outdated version of Unity.

I tried downloading a free height fog asset from the unity story, but the useless readme doesn't actually give me instructions on how to actually apply it to my scene.

What am I missing here? There should be something built-in to the engine, but I can't find anything on how to actually customize this properly. How do I add height fog to my scene?

Hi Marcscaleb! One simple workaround is creating a fog image (that is also a transparent png) and uploading it to Unity and making it a sprite. Then, apply it to a cube and I think your problem is solved? I don't really know of any other solutions, but if this one works, let me know! Have a great day/night!

1 Like

If you use built-in RP there is no volumetric fog, this exists only in HDRP as it is computationally expensive.

The solution above is typically used by game devs to simulate fog if the player cannot enter that area or view it from a sharp angle. For looking down into a pit one or two layers of transparent planes or quads should suffice to fog out the bottom. Basically works the same as „cheap“ water effects. You can apply some shader that simply increments the texture offset for a movement effect or animate the rotation and scale of the plane just minimally to make the fog appear less static.

1 Like

Technically a player can still enter the "pit" if colliders on the mentioned textured/shaded object are disabled, right? Also, I wouldn't call that solution "cheap". If you are or have access to a good art program or artist, the fog material/shader could look just as good as the engine's built in fog maker.

I've been looking a little closer, and the "global fog" that I added seems to be from the outdated (but still surprisingly useful) "Standard Assets" package; I had added that to my project so I could add a couple effects I needed.

I'm really surprised that there isn't an option to adjust the fog color, or many other factors. But if I could adjust the fog color, it would be perfect for my needs.
I opened up the script and the shader it uses thinking I could find the variable that sets the color and change it, but I simply cannot discern where it is getting the color from.
The shader mentions a variable "half4 unity_FogColor" but I don't see where this is getting assigned (but I don't know anything about shader language)

I don't suppose anyone could help me out with that?

I agree, the standard assets thingy still has lots of little gems in it... rough gems, but still useful today. Source: many of my games are still using gems I pulled out of there, like Shadow Projectors for one example.

Took me a minute to track it down but apparently that unity_FogColor is sourced directly from the RenderSettings.

This means all you need is to change RenderSettings.fogColor and off you go. I just verified it all seems to behave in a Unity2018 project.

Go into Window -> Rendering -> Lighting Settings and enable fog long enough to change the color, then disable it (most likely), or if you like leave it on.

If you want to change it at runtime, I used this script:

using UnityEngine;

// @kurtdekker - ultra cheesy color-driver... copies
// the public Color field into RenderSettings.fogColor

public class FogColorDriver : MonoBehaviour
    public Color color = Color.yellow;

    void Update()
        RenderSettings.fogColor = color;