Skip to content

Commit 59ebf7b

Browse files
committed
Make global fog independent of view direction
For calculating the distance in fog in the global fog shader, only the distance along the viewing axis was counted. This made it so there is less fog when look at something from the corner of your eye than when you look at it directly. This behavior matches fogQuake3 but there is really no reason to do it. Count the whole distance instead of only distance along view axis.
1 parent 5a8ea99 commit 59ebf7b

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,8 @@ GLShader_fogGlobal::GLShader_fogGlobal() :
26392639
u_UnprojectMatrix( this ),
26402640
u_Color_Float( this ),
26412641
u_Color_Uint( this ),
2642-
u_FogDistanceVector( this )
2642+
u_ViewOrigin( this ),
2643+
u_FogDensity( this )
26432644
{
26442645
}
26452646

src/engine/renderer/gl_shader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3481,7 +3481,8 @@ class GLShader_fogGlobal :
34813481
public u_UnprojectMatrix,
34823482
public u_Color_Float,
34833483
public u_Color_Uint,
3484-
public u_FogDistanceVector
3484+
public u_ViewOrigin,
3485+
public u_FogDensity
34853486
{
34863487
public:
34873488
GLShader_fogGlobal();

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ uniform sampler2D u_DepthMap;
2929

3030
uniform colorPack u_Color;
3131

32-
uniform vec4 u_FogDistanceVector;
32+
uniform vec3 u_ViewOrigin;
33+
uniform float u_FogDensity;
3334
uniform mat4 u_UnprojectMatrix;
3435

3536
DECLARE_OUTPUT(vec4)
@@ -45,7 +46,7 @@ void main()
4546
P.xyz /= P.w;
4647

4748
// calculate the length in fog (t is always 1 if eye is in fog)
48-
st.s = dot(P.xyz, u_FogDistanceVector.xyz) + u_FogDistanceVector.w;
49+
st.s = distance(u_ViewOrigin, P.xyz) * u_FogDensity;
4950
st.t = 1.0;
5051

5152
vec4 color = texture2D(u_ColorMap, st);

src/engine/renderer/tr_backend.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,20 +1377,8 @@ void RB_RenderGlobalFog()
13771377

13781378
GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
13791379

1380-
// all fogging distance is based on world Z units
1381-
vec4_t fogDistanceVector;
1382-
vec3_t local;
1383-
VectorSubtract( backEnd.orientation.origin, backEnd.viewParms.orientation.origin, local );
1384-
fogDistanceVector[ 0 ] = -backEnd.orientation.modelViewMatrix[ 2 ];
1385-
fogDistanceVector[ 1 ] = -backEnd.orientation.modelViewMatrix[ 6 ];
1386-
fogDistanceVector[ 2 ] = -backEnd.orientation.modelViewMatrix[ 10 ];
1387-
fogDistanceVector[ 3 ] = DotProduct( local, backEnd.viewParms.orientation.axis[ 0 ] );
1388-
1389-
// scale the fog vectors based on the fog's thickness
1390-
VectorScale( fogDistanceVector, fog->tcScale, fogDistanceVector );
1391-
fogDistanceVector[ 3 ] *= fog->tcScale;
1392-
1393-
gl_fogGlobalShader->SetUniform_FogDistanceVector( fogDistanceVector );
1380+
gl_fogGlobalShader->SetUniform_FogDensity( fog->tcScale );
1381+
gl_fogGlobalShader->SetUniform_ViewOrigin( backEnd.viewParms.orientation.origin );
13941382
SetUniform_Color( gl_fogGlobalShader, fog->color );
13951383
}
13961384

0 commit comments

Comments
 (0)