Search Unity

Fog, Mini Map, Render to Texture problem.

Discussion in 'General Graphics' started by cade9007, Mar 24, 2017.

  1. cade9007

    cade9007

    Joined:
    Jun 8, 2013
    Posts:
    12
    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...

    Code (CSharp):
    1. public class Camera_NoFog : MonoBehaviour
    2. {
    3.     private bool revertFogState = false;
    4.     void OnPreRender()
    5.     {
    6.         revertFogState = RenderSettings.fog;
    7.         RenderSettings.fog = false;
    8.     }
    9.     void OnPostRender()
    10.     {
    11.         RenderSettings.fog = true;
    12.     }
    13.  
    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
     
  2. Lost-in-the-Garden

    Lost-in-the-Garden

    Joined:
    Nov 18, 2015
    Posts:
    176
    Maybe endabling/disabling keywords on the shader can do the trick https://docs.unity3d.com/ScriptReference/Shader.EnableKeyword.html

    Fog support is compiled into the shader and you can probably find more about it in the docs https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html

    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.
     
  3. cade9007

    cade9007

    Joined:
    Jun 8, 2013
    Posts:
    12
    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
     
  4. cade9007

    cade9007

    Joined:
    Jun 8, 2013
    Posts:
    12
    Are there any ideas on this?
     
  5. Lost-in-the-Garden

    Lost-in-the-Garden

    Joined:
    Nov 18, 2015
    Posts:
    176
    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 https://docs.unity3d.com/ScriptReference/Shader.GetGlobalVector.html

    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! :D