Fog, Mini Map, Render to Texture problem.

Okay, so I created a mini map using a seperate camera above the player that renders to a render texture. I play the game everything works as expected.

Then I enabled fog, and thats when the mini map didnt work anymore. The fog shows up on the second camera and I cannot figure out how to not have fog render in that camera.

I First added a script to my camera to turn off the fog render setting…

public class Camera_NoFog : MonoBehaviour
{
    private bool revertFogState = false;
    void OnPreRender()
    {
        revertFogState = RenderSettings.fog;
        RenderSettings.fog = false;
    }
    void OnPostRender()
    {
        RenderSettings.fog = true;
    }

but that did not solve the issue. I also have a sky camera in the scene for panning clouds and the script worked fine to not have the fog render on the clouds, but it did not work for the mini map camera. I am assuming that it perhaps has something to do with it rendering to a render texture but I am not sure.

I also tried different types of fog (Standard Fog, Global Fog component on the main camera, and also the post process bundle from the Unity Store). The Global Fog is completely broken on my machine…

I have searched the internet for this but have not found a solution that works.

Any ideas?

Here are some screenshots of my problem. First NO FOG…

WITH FOG

and the global height fog… Which didnt fix the minimap, but thought Id put the shot up anyway

Thanks in advance,

Cade

Maybe endabling/disabling keywords on the shader can do the trick Unity - Scripting API: Shader.EnableKeyword

Fog support is compiled into the shader and you can probably find more about it in the docs Unity - Manual: Declaring and using shader keywords in HLSL

It would then be a matter of finding the right keyword and enabling/disabling it properly. I would assume that there is another way entirely, that is less of a hack and more the intended way. I am sure some one on the forum can help you further.

Thanks for the reply, unfortunately, the enable keywords didn’t do the trick, I may end up writing my own fog component , but i figure there should be a way to fix this. Thanks again

Are there any ideas on this?

maybe overriding the fog parameters in the shader could work. It’s a similar approach to the keyword thing. The shader variable is called “unity_FogParams”. it is a float4 and contains the parameters for the linear/exp/exp2 settings. Try overriding them before drawing using Unity - Scripting API: Shader.GetGlobalVector

Maybe this does the trick. Also not sure if unity updates the fog parameters every frame, so you might have to reset them in the shader manually afterwards.

Good luck! :smile: