0
\$\begingroup\$

I'm building an FPS with fog and I want to include a dynamic minimap, showing the locations of player and enemies in real time.
This is utilized by a second camera which is orthographic and looks at the scene from above.

In the minimap, I don't want to see the fog of course. I've hidden other things from the minimap by using layers and culling masks, however the fog does not belong into any specific layer.

So, how do I disable the fog on just one (or some) camera?

\$\endgroup\$
2
\$\begingroup\$

The way to solve this is by disabling the global fog just before the rendering process of the camera and re-enable it immediately afterwards.

TL;DR - attach the following script to the camera you wish to exclude from the fog

using UnityEngine;

public class NoFog : MonoBehaviour {

    bool doWeHaveFogInScene;

    private void Start() {
        doWeHaveFogInScene = RenderSettings.fog;
    }

    private void OnPreRender() {
        RenderSettings.fog = false;
    }
    private void OnPostRender() {
        RenderSettings.fog = doWeHaveFogInScene;
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.