Skip to content

Commit 5a8ea99

Browse files
committed
A little bit of fog-related cleanup
Document uniforms; use DotProduct function; use DECLARE_OUTPUT.
1 parent 0443aa6 commit 5a8ea99

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

src/engine/renderer/Material.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,9 @@ void BindShaderFog( Material* material ) {
11061106
float eyeT;
11071107
vec4_t fogDepthVector;
11081108
if ( fog->hasSurface ) {
1109-
fogDepthVector[0] = fog->surface[0] * backEnd.orientation.axis[0][0] +
1110-
fog->surface[1] * backEnd.orientation.axis[0][1] + fog->surface[2] * backEnd.orientation.axis[0][2];
1111-
fogDepthVector[1] = fog->surface[0] * backEnd.orientation.axis[1][0] +
1112-
fog->surface[1] * backEnd.orientation.axis[1][1] + fog->surface[2] * backEnd.orientation.axis[1][2];
1113-
fogDepthVector[2] = fog->surface[0] * backEnd.orientation.axis[2][0] +
1114-
fog->surface[1] * backEnd.orientation.axis[2][1] + fog->surface[2] * backEnd.orientation.axis[2][2];
1109+
fogDepthVector[0] = DotProduct( fog->surface, backEnd.orientation.axis[ 0 ] );
1110+
fogDepthVector[1] = DotProduct( fog->surface, backEnd.orientation.axis[ 1 ] );
1111+
fogDepthVector[2] = DotProduct( fog->surface, backEnd.orientation.axis[ 2 ] );
11151112
fogDepthVector[3] = -fog->surface[3] + DotProduct( backEnd.orientation.origin, fog->surface );
11161113

11171114
eyeT = DotProduct( backEnd.orientation.viewOrigin, fogDepthVector ) + fogDepthVector[3];

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ uniform colorPack u_Color;
3232
uniform vec4 u_FogDistanceVector;
3333
uniform mat4 u_UnprojectMatrix;
3434

35-
#if __VERSION__ > 120
36-
out vec4 outputColor;
37-
#else
38-
#define outputColor gl_FragColor
39-
#endif
35+
DECLARE_OUTPUT(vec4)
4036

4137
void main()
4238
{
@@ -48,9 +44,8 @@ void main()
4844
vec4 P = u_UnprojectMatrix * vec4(gl_FragCoord.xy, depth, 1.0);
4945
P.xyz /= P.w;
5046

51-
// calculate the length in fog (t is always 0 if eye is in fog)
47+
// calculate the length in fog (t is always 1 if eye is in fog)
5248
st.s = dot(P.xyz, u_FogDistanceVector.xyz) + u_FogDistanceVector.w;
53-
// st.s = vertexDistanceToCamera;
5449
st.t = 1.0;
5550

5651
vec4 color = texture2D(u_ColorMap, st);

src/engine/renderer/glsl_source/fogQuake3_fp.glsl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2626

2727
uniform sampler2D u_FogMap;
2828

29-
IN(smooth) vec3 var_Position;
3029
IN(smooth) vec2 var_TexCoords;
3130
IN(smooth) vec4 var_Color;
3231

@@ -41,8 +40,4 @@ void main()
4140
color *= var_Color;
4241

4342
outputColor = color;
44-
45-
#if 0
46-
outputColor = vec4(vec3(1.0, 0.0, 0.0), color.a);
47-
#endif
4843
}

src/engine/renderer/glsl_source/fogQuake3_vp.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ uniform colorPack u_ColorGlobal;
3434
uniform mat4 u_ModelMatrix;
3535
uniform mat4 u_ModelViewProjectionMatrix;
3636

37-
uniform vec4 u_FogDistanceVector;
38-
uniform vec4 u_FogDepthVector;
37+
uniform vec4 u_FogDistanceVector; // view axis in model coordinates, scaled by fog density
38+
uniform vec4 u_FogDepthVector; // fog plane in model coordinates
3939
uniform float u_FogEyeT;
4040

4141
OUT(smooth) vec3 var_Position;
42+
43+
// var_TexCoords.s is distance from viewer to vertex dotted with view axis
44+
// var_TexCoords.t is the fraction of the viewer-to-vertex ray which is inside fog
4245
OUT(smooth) vec2 var_TexCoords;
4346
OUT(smooth) vec4 var_Color;
4447

src/engine/renderer/tr_shade.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,12 +1613,9 @@ void Render_fog( shaderStage_t* pStage )
16131613
vec4_t fogDepthVector;
16141614
if ( fog->hasSurface )
16151615
{
1616-
fogDepthVector[ 0 ] = fog->surface[ 0 ] * backEnd.orientation.axis[ 0 ][ 0 ] +
1617-
fog->surface[ 1 ] * backEnd.orientation.axis[ 0 ][ 1 ] + fog->surface[ 2 ] * backEnd.orientation.axis[ 0 ][ 2 ];
1618-
fogDepthVector[ 1 ] = fog->surface[ 0 ] * backEnd.orientation.axis[ 1 ][ 0 ] +
1619-
fog->surface[ 1 ] * backEnd.orientation.axis[ 1 ][ 1 ] + fog->surface[ 2 ] * backEnd.orientation.axis[ 1 ][ 2 ];
1620-
fogDepthVector[ 2 ] = fog->surface[ 0 ] * backEnd.orientation.axis[ 2 ][ 0 ] +
1621-
fog->surface[ 1 ] * backEnd.orientation.axis[ 2 ][ 1 ] + fog->surface[ 2 ] * backEnd.orientation.axis[ 2 ][ 2 ];
1616+
fogDepthVector[ 0 ] = DotProduct( fog->surface, backEnd.orientation.axis[ 0 ] );
1617+
fogDepthVector[ 1 ] = DotProduct( fog->surface, backEnd.orientation.axis[ 1 ] );
1618+
fogDepthVector[ 2 ] = DotProduct( fog->surface, backEnd.orientation.axis[ 2 ] );
16221619
fogDepthVector[ 3 ] = -fog->surface[ 3 ] + DotProduct( backEnd.orientation.origin, fog->surface );
16231620

16241621
eyeT = DotProduct( backEnd.orientation.viewOrigin, fogDepthVector ) + fogDepthVector[ 3 ];

0 commit comments

Comments
 (0)