Advertisement

Move fog plane to desired location?

Started by December 29, 2020 08:12 AM
1 comment, last by terrysworkstations 3 years, 10 months ago

Doing fog in shader. If I want to see fog on other side of plane and not see any fog on other side of plane because im doing a mountain scene or something. How can i adjust the plane to a specific location? Right now the plane stays at origin on the x axis.

if (gFogEnabled)

{

float fogDensity = 0.0001;

float kFogEpsilon = 0.0001;

float3 F = float3(1, 0, 0); //Plane

float3 C = gEyePosW; // Camera Position

float3 P = pin.PosW; //Pixel Position

float3 V = C - P; // To Eye Vector

float FV = dot(F, V);

float m;

if (dot(F, C) < 0)

{

m = 1;

}

else

{

m = 0;

}

float u1 = m * (dot(F, C) + dot(F, P));

float u2 = dot(F, P) * sign(dot(F, C));

float x = min(u2, 0.0);

x = 0.5 * fogDensity * -length(V) * (u1 - x * x / (abs(FV) + kFogEpsilon));

float f = saturate(exp2(-x));

litColor.rgb = litColor.rgb * f + gFogColor * (1 - f);

}

Nevermind, i fixed it by making the plane 4D instead of 3D.

This topic is closed to new replies.

Advertisement