Skip to content

Commit 8d4039a

Browse files
committed
fixup: premultiply divisor
1 parent 7c2c022 commit 8d4039a

13 files changed

+64
-45
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
16151615
u_ModelMatrix( this ),
16161616
u_ProjectionMatrixTranspose( this ),
16171617
u_ModelViewProjectionMatrix( this ),
1618-
u_LightFactor( this ),
1618+
u_LightDivisor( this ),
16191619
u_ColorModulate( this ),
16201620
u_Color( this ),
16211621
u_Bones( this ),
@@ -1654,7 +1654,7 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
16541654
u_ViewOrigin( this ),
16551655
u_ModelMatrix( this ),
16561656
u_ModelViewProjectionMatrix( this ),
1657-
u_LightFactor( this ),
1657+
u_LightDivisor( this ),
16581658
u_Bones( this ),
16591659
u_VertexInterpolation( this ),
16601660
u_ReliefDepthScale( this ),
@@ -1975,7 +1975,7 @@ GLShader_skybox::GLShader_skybox( GLShaderManager *manager ) :
19751975
u_AlphaThreshold( this ),
19761976
u_ModelMatrix( this ),
19771977
u_ModelViewProjectionMatrix( this ),
1978-
u_LightFactor( this ),
1978+
u_LightDivisor( this ),
19791979
u_VertexInterpolation( this ),
19801980
GLDeformStage( this ),
19811981
GLCompileMacro_USE_ALPHA_TESTING( this )
@@ -1992,7 +1992,7 @@ GLShader_fogQuake3::GLShader_fogQuake3( GLShaderManager *manager ) :
19921992
GLShader( "fogQuake3", ATTR_POSITION | ATTR_QTANGENT, manager ),
19931993
u_ModelMatrix( this ),
19941994
u_ModelViewProjectionMatrix( this ),
1995-
u_LightFactor( this ),
1995+
u_LightDivisor( this ),
19961996
u_Color( this ),
19971997
u_Bones( this ),
19981998
u_VertexInterpolation( this ),
@@ -2021,7 +2021,7 @@ GLShader_fogGlobal::GLShader_fogGlobal( GLShaderManager *manager ) :
20212021
u_ViewMatrix( this ),
20222022
u_ModelViewProjectionMatrix( this ),
20232023
u_UnprojectMatrix( this ),
2024-
u_LightFactor( this ),
2024+
u_LightDivisor( this ),
20252025
u_Color( this ),
20262026
u_FogDistanceVector( this ),
20272027
u_FogDepthVector( this )
@@ -2100,7 +2100,7 @@ void GLShader_portal::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
21002100
GLShader_contrast::GLShader_contrast( GLShaderManager *manager ) :
21012101
GLShader( "contrast", ATTR_POSITION, manager ),
21022102
u_ModelViewProjectionMatrix( this ),
2103-
u_LightFactor( this )
2103+
u_LightDivisor( this )
21042104
{
21052105
}
21062106

src/engine/renderer/gl_shader.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,21 @@ class u_LightFactor :
13191319
}
13201320
};
13211321

1322+
class u_LightDivisor :
1323+
GLUniform1f
1324+
{
1325+
public:
1326+
u_LightDivisor( GLShader *shader ) :
1327+
GLUniform1f( shader, "u_LightDivisor" )
1328+
{
1329+
}
1330+
1331+
void SetUniform_LightDivisor( const float lightDivisor )
1332+
{
1333+
this->SetValue( lightDivisor );
1334+
}
1335+
};
1336+
13221337
class u_TextureMatrix :
13231338
GLUniformMatrix4f
13241339
{
@@ -2285,7 +2300,7 @@ class GLShader_generic :
22852300
public u_ModelMatrix,
22862301
public u_ProjectionMatrixTranspose,
22872302
public u_ModelViewProjectionMatrix,
2288-
public u_LightFactor,
2303+
public u_LightDivisor,
22892304
public u_ColorModulate,
22902305
public u_Color,
22912306
public u_Bones,
@@ -2316,7 +2331,7 @@ class GLShader_lightMapping :
23162331
public u_ViewOrigin,
23172332
public u_ModelMatrix,
23182333
public u_ModelViewProjectionMatrix,
2319-
public u_LightFactor,
2334+
public u_LightDivisor,
23202335
public u_Bones,
23212336
public u_VertexInterpolation,
23222337
public u_ReliefDepthScale,
@@ -2519,7 +2534,7 @@ class GLShader_skybox :
25192534
public u_AlphaThreshold,
25202535
public u_ModelMatrix,
25212536
public u_ModelViewProjectionMatrix,
2522-
public u_LightFactor,
2537+
public u_LightDivisor,
25232538
public u_VertexInterpolation,
25242539
public GLDeformStage,
25252540
public GLCompileMacro_USE_ALPHA_TESTING
@@ -2533,7 +2548,7 @@ class GLShader_fogQuake3 :
25332548
public GLShader,
25342549
public u_ModelMatrix,
25352550
public u_ModelViewProjectionMatrix,
2536-
public u_LightFactor,
2551+
public u_LightDivisor,
25372552
public u_Color,
25382553
public u_Bones,
25392554
public u_VertexInterpolation,
@@ -2556,7 +2571,7 @@ class GLShader_fogGlobal :
25562571
public u_ViewMatrix,
25572572
public u_ModelViewProjectionMatrix,
25582573
public u_UnprojectMatrix,
2559-
public u_LightFactor,
2574+
public u_LightDivisor,
25602575
public u_Color,
25612576
public u_FogDistanceVector,
25622577
public u_FogDepthVector
@@ -2616,7 +2631,7 @@ class GLShader_portal :
26162631
class GLShader_contrast :
26172632
public GLShader,
26182633
public u_ModelViewProjectionMatrix,
2619-
public u_LightFactor
2634+
public u_LightDivisor
26202635
{
26212636
public:
26222637
GLShader_contrast( GLShaderManager *manager );

src/engine/renderer/glsl_source/contrast_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424

2525
uniform sampler2D u_ColorMap;
2626

27-
uniform float u_LightFactor;
27+
uniform float u_LightDivisor;
2828

2929
const vec4 LUMINANCE_VECTOR = vec4(0.2125, 0.7154, 0.0721, 0.0);
3030

@@ -59,7 +59,7 @@ void main()
5959
color += f(texture2D(u_ColorMap, st + vec2(1.0, 1.0) * scale));
6060
color *= 0.25;
6161

62-
color.rgb /= u_LightFactor;
62+
color.rgb *= u_LightDivisor;
6363

6464
outputColor = color;
6565
}

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2525
uniform sampler2D u_ColorMap; // fog texture
2626
uniform sampler2D u_DepthMap;
2727

28-
uniform float u_LightFactor;
28+
uniform float u_LightDivisor;
2929
uniform vec3 u_ViewOrigin;
3030
uniform vec4 u_FogDistanceVector;
3131
uniform vec4 u_FogDepthVector;
@@ -56,7 +56,7 @@ void main()
5656

5757
vec4 color = texture2D(u_ColorMap, st);
5858

59-
color.rgb /= u_LightFactor;
59+
color.rgb *= u_LightDivisor;
6060

6161
outputColor = u_Color * color;
6262
}

src/engine/renderer/glsl_source/fogQuake3_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424

2525
uniform sampler2D u_ColorMap;
2626

27-
uniform float u_LightFactor;
27+
uniform float u_LightDivisor;
2828
IN(smooth) vec3 var_Position;
2929
IN(smooth) vec2 var_TexCoords;
3030
IN(smooth) vec4 var_Color;
@@ -37,7 +37,7 @@ void main()
3737

3838
color *= var_Color;
3939

40-
color.rgb /= u_LightFactor;
40+
color.rgb *= u_LightDivisor;
4141

4242
outputColor = color;
4343

src/engine/renderer/glsl_source/generic_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ uniform sampler2D u_ColorMap;
2626
uniform float u_AlphaThreshold;
2727

2828
#if !defined(GENERIC_2D)
29-
uniform float u_LightFactor;
29+
uniform float u_LightDivisor;
3030
#endif
3131

3232
IN(smooth) vec2 var_TexCoords;
@@ -60,7 +60,7 @@ void main()
6060
color *= var_Color;
6161

6262
#if !defined(GENERIC_2D) && !defined(USE_DEPTH_FADE)
63-
color.rgb /= u_LightFactor;
63+
color.rgb *= u_LightDivisor;
6464
#endif
6565

6666
outputColor = color;

src/engine/renderer/glsl_source/lightMapping_fp.glsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ uniform sampler2D u_MaterialMap;
2727
uniform sampler2D u_GlowMap;
2828

2929
uniform float u_AlphaThreshold;
30-
uniform float u_LightFactor;
30+
uniform float u_LightDivisor;
3131
uniform vec3 u_ViewOrigin;
3232

3333
IN(smooth) vec3 var_Position;
@@ -175,9 +175,9 @@ void main()
175175

176176
/* HACK: use sign to know if there is a light or not, and
177177
then if it will receive overbright multiplication or not. */
178-
if ( u_LightFactor > 0 )
178+
if ( u_LightDivisor > 0 )
179179
{
180-
color.rgb /= u_LightFactor;
180+
color.rgb *= u_LightDivisor;
181181
}
182182

183183
#if defined(r_glowMapping)
@@ -186,9 +186,9 @@ void main()
186186

187187
/* HACK: use sign to know if there is a light or not, and
188188
then if it will receive overbright multiplication or not. */
189-
if ( u_LightFactor < 0 )
189+
if ( u_LightDivisor < 0 )
190190
{
191-
glow /= - u_LightFactor;
191+
glow *= - u_LightDivisor;
192192
}
193193

194194
color.rgb += glow;

src/engine/renderer/glsl_source/skybox_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const float radiusWorld = 4096.0; // Value used by quake 3 skybox code
2626

2727
uniform samplerCube u_ColorMap;
2828

29-
uniform float u_LightFactor;
29+
uniform float u_LightDivisor;
3030
uniform sampler2D u_CloudMap;
3131

3232
uniform bool u_UseCloudMap;
@@ -75,7 +75,7 @@ void main()
7575
}
7676
#endif
7777

78-
color.rgb /= u_LightFactor;
78+
color.rgb *= u_LightDivisor;
7979

8080
outputColor = color;
8181
}

src/engine/renderer/tr_backend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,8 +2971,8 @@ void RB_RenderGlobalFog()
29712971

29722972
gl_fogGlobalShader->SetUniform_ViewOrigin( backEnd.viewParms.orientation.origin ); // world space
29732973

2974-
// u_LightFactor
2975-
gl_fogGlobalShader->SetUniform_LightFactor( tr.mapLightFactor );
2974+
// u_LightDivisor
2975+
gl_fogGlobalShader->SetUniform_LightDivisor( tr.mapLightDivisor );
29762976

29772977
{
29782978
fog_t *fog;
@@ -3070,8 +3070,8 @@ void RB_RenderBloom()
30703070

30713071
gl_contrastShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] );
30723072

3073-
// u_LightFactor
3074-
gl_contrastShader->SetUniform_LightFactor( tr.mapLightFactor );
3073+
// u_LightDivisor
3074+
gl_contrastShader->SetUniform_LightDivisor( tr.mapLightDivisor );
30753075

30763076
GL_BindToTMU( 0, tr.currentRenderImage[ backEnd.currentMainFBO ] );
30773077

src/engine/renderer/tr_bsp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6962,7 +6962,8 @@ void RE_LoadWorldMap( const char *name )
69626962

69636963
tr.worldLight = tr.lightMode;
69646964
tr.modelDeluxe = deluxeMode_t::NONE;
6965-
tr.mapLightFactor = 1;
6965+
tr.mapLightFactor = 1.0f;
6966+
tr.mapLightDivisor = 1.0f;
69666967

69676968
if ( tr.worldLight == lightMode_t::FULLBRIGHT )
69686969
{
@@ -7043,5 +7044,6 @@ void RE_LoadWorldMap( const char *name )
70437044
if ( !tr.mapClampOverBright )
70447045
{
70457046
tr.mapLightFactor = pow( 2, tr.mapOverBrightBits );
7047+
tr.mapLightDivisor = 1.0f / tr.mapLightFactor;
70467048
}
70477049
}

src/engine/renderer/tr_local.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,9 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
28282828
// r_mapOverbrightBits->integer, but can be overridden by mapper using the worldspawn
28292829
int mapOverBrightBits;
28302830
// pow(2, mapOverbrightBits)
2831-
int mapLightFactor;
2831+
float mapLightFactor;
2832+
// 1 / mapLightFactor
2833+
float mapLightDivisor;
28322834
// May have to be true on some legacy maps: clamp and normalize multiplied colors.
28332835
bool mapClampOverBright;
28342836

src/engine/renderer/tr_shade.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,12 @@ static void Render_generic( shaderStage_t *pStage )
764764
break;
765765
}
766766

767-
// u_LightFactor
767+
// u_LightDivisor
768768
// We should cancel overbrightBits if there is no light,
769769
// and it's not using blendFunc dst_color.
770770
bool blendFunc_dstColor = ( pStage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;
771-
float lightFactor = ( pStage->shaderHasNoLight && !blendFunc_dstColor ) ? tr.mapLightFactor : 1.0f;
772-
gl_genericShader->SetUniform_LightFactor( lightFactor );
771+
float lightDivisor = ( pStage->shaderHasNoLight && !blendFunc_dstColor ) ? tr.mapLightDivisor : 1.0f;
772+
gl_genericShader->SetUniform_LightDivisor( lightDivisor );
773773

774774
// u_ColorModulate
775775
gl_genericShader->SetUniform_ColorModulate( rgbGen, alphaGen );
@@ -1090,13 +1090,13 @@ static void Render_lightMapping( shaderStage_t *pStage )
10901090
// u_DeformGen
10911091
gl_lightMappingShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );
10921092

1093-
// u_LightFactor
1093+
// u_LightDivisor
10941094
/* HACK: use sign to know if there is a light or not, and
10951095
then if it will receive overbright multiplication or not. */
10961096
bool blendFunc_dstColor = ( pStage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;
10971097
bool noLight = pStage->shaderHasNoLight || lightMode == lightMode_t::FULLBRIGHT;
1098-
float lightFactor = ( noLight && !blendFunc_dstColor ) ? tr.mapLightFactor : - tr.mapLightFactor;
1099-
gl_lightMappingShader->SetUniform_LightFactor( lightFactor );
1098+
float lightDivisor = ( noLight && !blendFunc_dstColor ) ? tr.mapLightDivisor : - tr.mapLightDivisor;
1099+
gl_lightMappingShader->SetUniform_LightDivisor( lightDivisor );
11001100

11011101
// u_ColorModulate
11021102
gl_lightMappingShader->SetUniform_ColorModulate( colorGen, alphaGen );
@@ -2100,8 +2100,8 @@ static void Render_skybox( shaderStage_t *pStage )
21002100
// bind u_ColorMap
21012101
GL_BindToTMU( 0, pStage->bundle[ TB_COLORMAP ].image[ 0 ] );
21022102

2103-
// u_LightFactor
2104-
gl_skyboxShader->SetUniform_LightFactor( tr.mapLightFactor );
2103+
// u_LightDivisor
2104+
gl_skyboxShader->SetUniform_LightDivisor( tr.mapLightDivisor );
21052105

21062106
gl_skyboxShader->SetRequiredVertexPointers();
21072107

@@ -2440,8 +2440,8 @@ static void Render_fog()
24402440

24412441
gl_fogQuake3Shader->BindProgram( 0 );
24422442

2443-
// u_LightFactor
2444-
gl_fogQuake3Shader->SetUniform_LightFactor( tr.mapLightFactor );
2443+
// u_LightDivisor
2444+
gl_fogQuake3Shader->SetUniform_LightDivisor( tr.mapLightDivisor );
24452445

24462446
gl_fogQuake3Shader->SetUniform_FogDistanceVector( fogDistanceVector );
24472447
gl_fogQuake3Shader->SetUniform_FogDepthVector( fogDepthVector );

src/engine/renderer/tr_sky.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ void Tess_StageIteratorSky()
115115

116116
gl_skyboxShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );
117117

118-
// u_LightFactor
119-
gl_skyboxShader->SetUniform_LightFactor( tr.mapLightFactor );
118+
// u_LightDivisor
119+
gl_skyboxShader->SetUniform_LightDivisor( tr.mapLightDivisor );
120120

121121
gl_skyboxShader->SetRequiredVertexPointers();
122122

0 commit comments

Comments
 (0)