Shader Graph Fog Node return Inverted density value when fog mode is linear. - URP 8.2.0

The Issue-
when useing linear fog, Shader graph Fog node’ density value returns inverted.
Image blow are just apply Fog node’s density value to color at unlit master

-Linear

-Exponential

-Exponential Squared is as same as exponential.

-Turn off value Is always black as expect.

Additional Info -
So, I just put one minus node to fix inverted fog issue.
But problem is when toggle off the fog for level edit or inspect scene, every things get’s fully fogged. Because turn off value gone black to white :smile:.

I have sent a bug report with this, but it would take some time I guess.
so, If anyone knows work around this, please let me know.

Thanks.

4 Likes

Resurrecting this old thread because I have the same issue. Was this ever solved?

issue exists in URP/ShaderGraph 10.5 with Unity 2020.3.16f1.844
Is there an Issue Tracker @sstese86 ?

This seems to be also happening with 2021.3.16f1, using shader graph with built-in pipeline.

1 Like

For us I created a solution using custom nodes. I digged around in the internal HLSL code and found a MixFogColor function in ShaderVariablesFunctions.hlsl that seems to calculate the fog correctly, I copied the function into a custom hlsl file and used that in my custom node. It seems linear fog is now working as expected.

compute_fog_custom.hlsl:

#include <UnityShaderVariables.cginc>

float3 MixFogColorCustom(float3 fragColor, float3 fogColor, float fogFactor)
{
    #if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
    real fogIntensity = ComputeFogIntensity(fogFactor);
    fragColor = lerp(fogColor, fragColor, fogIntensity);
    #endif
    return fragColor;
}

void MixFog_float(float3 fragColor, float3 fogColor, float fogFactor, out float3 resultColor)
{
    resultColor = float3(MixFogColorCustom(fragColor, fogColor, fogFactor));
}