Skip to content

Commit e76f648

Browse files
committed
fixup: hack to cancel overbright on glow maps
1 parent a9e5076 commit e76f648

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/engine/renderer/glsl_source/lightMapping_fp.glsl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,26 @@ void main()
173173
color.rgb += 0.7 * emission;
174174
#endif
175175

176+
/* HACK: use sign to know if there is a light or not, and
177+
then if it will receive overbright multiplication or not. */
178+
if ( u_LightFactor > 0 )
179+
{
180+
color.rgb /= u_LightFactor;
181+
}
182+
176183
#if defined(r_glowMapping)
177184
// Blend glow map.
178-
color.rgb += texture2D(u_GlowMap, texCoords).rgb;
179-
#endif
185+
vec3 glow = texture2D(u_GlowMap, texCoords).rgb;
186+
187+
/* HACK: use sign to know if there is a light or not, and
188+
then if it will receive overbright multiplication or not. */
189+
if ( u_LightFactor < 0 )
190+
{
191+
glow /= - u_LightFactor;
192+
}
180193

181-
color.rgb /= u_LightFactor;
194+
color.rgb += glow;
195+
#endif
182196

183197
outputColor = color;
184198

src/engine/renderer/tr_shade.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,22 @@ void SetNormalScale( shaderStage_t *pStage, vec3_t normalScale )
576576
normalScale[ 2 ] *= r_normalScale->value;
577577
}
578578

579-
static float cancelLightFactor( shaderStage_t *pStage )
579+
static float cancelLightFactor( shaderStage_t *pStage, bool hack = false )
580580
{
581581
// We should cancel overbrightBits if there is no light,
582582
// and it's not using blendFunc dst_color.
583583
bool blendFunc_dstColor = ( pStage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;
584584

585-
return ( pStage->shaderHasNoLight && !blendFunc_dstColor ) ? tr.mapLightFactor : 1.0f;
585+
if ( hack )
586+
{
587+
/* HACK: use sign to know if there is a light or not, and
588+
then if it will receive overbright multiplication or not. */
589+
return ( pStage->shaderHasNoLight && !blendFunc_dstColor ) ? tr.mapLightFactor : - tr.mapLightFactor;
590+
}
591+
else
592+
{
593+
return ( pStage->shaderHasNoLight && !blendFunc_dstColor ) ? tr.mapLightFactor : 1.0f;
594+
}
586595
}
587596

588597
// *INDENT-ON*
@@ -1078,7 +1087,7 @@ static void Render_lightMapping( shaderStage_t *pStage )
10781087
gl_lightMappingShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );
10791088

10801089
// u_LightFactor
1081-
gl_lightMappingShader->SetUniform_LightFactor( cancelLightFactor( pStage ) );
1090+
gl_lightMappingShader->SetUniform_LightFactor( cancelLightFactor( pStage, true ) );
10821091

10831092
// u_ColorModulate
10841093
gl_lightMappingShader->SetUniform_ColorModulate( colorGen, alphaGen );

0 commit comments

Comments
 (0)