From c227b42c51821c630aefcafeb17469fd5bb1ef7a Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 20 Dec 2017 03:04:39 +0000 Subject: [PATCH] GLWorld_CreateShaders: do fog fully in the fragment shader. Fixes a regression introduced in 0.93.0 when we switched from fixed-function fog to GLSL (for world polys), reported by ItEndsWithTens It was visible on large polygons. For a test case, see: https://sourceforge.net/p/quakespasm/bugs/24/ git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1544 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/r_world.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Quake/r_world.c b/Quake/r_world.c index e39f33dc..4371078c 100644 --- a/Quake/r_world.c +++ b/Quake/r_world.c @@ -832,14 +832,14 @@ void GLWorld_CreateShaders (void) "attribute vec2 TexCoords;\n" "attribute vec2 LMCoords;\n" "\n" + "varying vec3 VertVarying;\n" + "\n" "void main()\n" "{\n" " gl_TexCoord[0] = vec4(TexCoords, 0.0, 0.0);\n" " gl_TexCoord[1] = vec4(LMCoords, 0.0, 0.0);\n" " gl_Position = gl_ModelViewProjectionMatrix * vec4(Vert, 1.0);\n" - " // fog\n" - " vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(Vert, 1.0));\n" - " gl_FogFragCoord = abs(ecPosition.z);\n" + " VertVarying = Vert;\n" "}\n"; const GLchar *fragSource = \ @@ -852,6 +852,9 @@ void GLWorld_CreateShaders (void) "uniform bool UseOverbright;\n" "uniform bool UseAlphaTest;\n" "uniform float Alpha;\n" + "\n" + "varying vec3 VertVarying;\n" + "\n" "void main()\n" "{\n" " vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n" @@ -864,7 +867,11 @@ void GLWorld_CreateShaders (void) " result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n" " result = clamp(result, 0.0, 1.0);\n" " // apply GL_EXP2 fog (from the orange book)\n" - " float fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n" + " // needs to be done fully in the fragment shader to match fixed-function's quality\n" + " // (visible on large polygons / large texture scales)\n" + " vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(VertVarying, 1.0));\n" + " float fogFragCoord = abs(ecPosition.z);\n" + " float fog = exp(-gl_Fog.density * gl_Fog.density * fogFragCoord * fogFragCoord);\n" " fog = clamp(fog, 0.0, 1.0);\n" " result = mix(gl_Fog.color, result, fog);\n" " result.a = Alpha;\n"