Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Shader Graph Vertical (Height) Fog?

Discussion in 'Shader Graph' started by UncleV89, Sep 27, 2019.

  1. UncleV89

    UncleV89

    Joined:
    Nov 7, 2014
    Posts:
    4
    Hey guys, i'm trying to create vertical (height) fog through the Shader Graph, so it should looks something like this:
    upload_2019-9-27_12-31-56.png
    as I understand the upper part uses Lit shader while the lower part smoothly flows into Unlit.

    I tried to achieve this effect through the emission chanel, but it still have some shades.
    upload_2019-9-27_12-37-11.png

    it works good only if i'm setting up the main color to black upload_2019-9-27_12-38-16.png

    the best option is to do it through the plane which fades objects when it crosses them, and I think that somehow this can be done by changing this water surface shader, but I don’t have enough knowledge to do this)
    upload_2019-9-27_12-54-45.png
    I'll be grateful for any help
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    Yep, try lerping the albedo to black at the same time.

    Really you should use the specular setup and also lerp the specular to black too. Use a constant specular color of 56, 56, 56 (roughly equivalent to a metallic of 0), or the output of the dielectric specular node, and fade it to black.
     
    ADNCG likes this.
  3. Nicotine_x

    Nicotine_x

    Joined:
    Mar 27, 2017
    Posts:
    2
    Here is solution for basic vertical fog

     
  4. jabbajack

    jabbajack

    Joined:
    Dec 28, 2012
    Posts:
    4
    Doesn't work for me.
    I tried to switch the surface mode to transparent as well.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    These examples are for a shader you'd put on a transparent quad and place where you want the fog to start. And yes, it must be transparent, otherwise it too is going to be drawn to the camera depth texture (what the Scene Depth node samples from), so the Scene Depth and Screen Position's A output (the currently rendered object's depth at that pixel) will match.

    If you want a height fog that you can apply to opaque objects, that'd be a very different shader. A simple version would be to use a world space Position G output and offset, scale, and clamp it (Saturate), then lerp the surface color to black and lerp your emission to the fog color. That won't exactly match the plane based methods, but it'll probably be close enough.
     
  6. Nicotine_x

    Nicotine_x

    Joined:
    Mar 27, 2017
    Posts:
    2
    Be rally carefull with variables values. In my emple I have fog fade within 3-5 meters. So tiny change in varable could cause total mess.
     
unityunity