unity-game-engineshaderfogshader-graph

Unity 2021.3.20 Built-in ShaderGraph 12.1.10 Fog Density inverted in linear fog and showing wrong fog colors on far objects


Unity Shader Graph Fog node shows density inverted when using Linear Fog. Also not properly showing the color of the fog on far objects.

enter image description here enter image description here enter image description here enter image description here


Solution

  • Seems we are missing one step in the fog calculation. This custom node fix the issue.

    Custom node body:

    fogIntensity = 0;
    
    #if defined(FOG_EXP)
        fogIntensity = 1 - saturate(exp2(-fogFactor));
    
    #elif defined(FOG_EXP2)
        fogIntensity = 1 - saturate(exp2(-fogFactor * fogFactor));
    
    #elif defined(FOG_LINEAR)
        fogIntensity = 1 - fogFactor;
    
    #endif
    

    Custom node Settings:

    enter image description here.

    Custom node usage:

    enter image description here

    Results:

    enter image description here

    enter image description here

    enter image description here