Using the fog node with a unlit master node being active result in the return value of the density being completely black (understand 0). When a PBR master node is active however the density value is correct. This is happening on URP 7.1.7/unity 2019.3 and URP 7.1.8/unity 2020. Has anyone encountered this problem and how can it be solved?
Hello, I’m currently trying to add fog to a shader and have the exact same issue.
Did you already reported it as a bug ?
Issue has already been reported: Unity Issue Tracker - [Shader Graph] Fog Node density returns 0 when it is connected to an Unlit Master Node
1 Like
Thank you very much !
Hey I finally got around to fixing this issue. I ended up implementing a exponential squared fog since this is what we would be using but the other formulas are as follows and people can implement them easily.
Linear Fog = (FogEnd - ViewpointDistance) / (FogEnd - FogStart)
Exponential Fog = 1.0 / 2.71828 power (ViewpointDistance * FogDensity)
Exponential Fog 2 = 1.0 / 2.71828 power ((ViewpointDistance * FogDensity) * (ViewpointDistance * FogDensity))
I’m also uploading the relevant nodes in the shader graph.
1 Like
Code from the URP Core.hlsl
real ComputeFogIntensity(real fogFactor)
{
real fogIntensity = 0.0h;
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#if defined(FOG_EXP)
// factor = exp(-density*z)
// fogFactor = density*z compute at vertex
fogIntensity = saturate(exp2(-fogFactor));
#elif defined(FOG_EXP2)
// factor = exp(-(density*z)^2)
// fogFactor = density*z compute at vertex
fogIntensity = saturate(exp2(-fogFactor * fogFactor));
#elif defined(FOG_LINEAR)
fogIntensity = fogFactor;
#endif
#endif
return fogIntensity;
}
13 Likes