Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Water4Advanced - Fog Reflection Problem

Discussion in 'Shaders' started by sdkfz250, Jan 21, 2016.

  1. sdkfz250

    sdkfz250

    Joined:
    Apr 17, 2015
    Posts:
    15
    Hi,

    I am currently using Unity 5.3.1 and by using global fog, far away objects (e.g. terrains) are reflected on the water plane (water4advanced) without any fog or haze effect. This looks absolutely awful as you can see.

    Can somebody help me to avoid this.

    Many thanks

    Michael


    water4.JPG
     
  2. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    The fog is applied only to the main camera. Reflection is rendered separately by a different camera. You have to add global fog to this camera as well.
     
  3. sdkfz250

    sdkfz250

    Joined:
    Apr 17, 2015
    Posts:
    15
    Michal,

    Many thanks for you answer. Can you help me and tell me how exactly to do this?

    Why a different camera? I set global fog by "Windows/Lighning/Fog".

    What different camera do you mean?

    Thanks

    Michael
     
  4. sdkfz250

    sdkfz250

    Joined:
    Apr 17, 2015
    Posts:
    15
    Instead of using the Fog Parameter from "Window/Lightning" I tried the GlobaFog Script on MainCamera. Nothing really changed and these reflections still are available without any fog-effect.

    From my understanding I guess that this is more a problem of the Water4Advanced shader.

    Michael
     
  5. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    Oh, sorry. I though you're using global fog image effect. I'm afraid standard fog won't work with the reflection. Reflection camera is using oblique near-plane projection matrix. I'm not going to bore you with the math. It just won't work. But you can use above image effect to fix this.
    There is secondary camera somewhere in your scene. Look for something like "Water reflection camera". This camera renders reflected part of the scene into texture and this texture is later applied to the water surface. Add above global fog script to this camera, disable height fog and it should work. This fog probably won't be 100% identical to the standard fog but hopefully it is good enough. Alternatively, you can add this global fog even to your main camera and disable standard fog completely.
    Note that global fog image effect can be costly if you are not using deferred rendering.
     
  6. Tarasevih

    Tarasevih

    Joined:
    Sep 20, 2014
    Posts:
    11
    I would like to know how the shader is used for water?
    Maybe he does not see the fog?