@@ -5239,35 +5239,57 @@ static void FinishStages()
5239
5239
? gl_shaderManager.getDeformShaderIndex ( shader.deforms , shader.numDeforms )
5240
5240
: 0 ;
5241
5241
5242
+ bool isOpaqueShader = false ;
5243
+
5242
5244
for ( size_t s = 0 ; s < numStages; s++ )
5243
5245
{
5244
5246
shaderStage_t *stage = &stages[ s ];
5245
5247
5246
5248
stage->deformIndex = deformIndex;
5247
5249
5248
- // We should cancel overbright if there is no light stage.
5249
- stage->cancelOverBright = shaderHasNoLight;
5250
+ // SRC1 and DST0 are reset to zero in ParseStage (no blending).
5251
+ bool isOpaque = !( stage->stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) );
5252
+
5253
+ // A shader is not opaque if all stages are not opaques.
5254
+ isOpaqueShader |= isOpaque;
5255
+
5256
+ bool blendFunc_srcDstColor = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;
5250
5257
5251
5258
if ( shaderHasNoLight )
5252
5259
{
5253
- // We should not cancel overbright if there is no light and it's not using blendFunc dst_color.
5254
- bool blendFunc_dstColor = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR ;
5260
+ // We should cancel overbright if there is no light stage, unless it's using blendFunc dst_color.
5261
+ stage->cancelOverBright = !blendFunc_srcDstColor ;
5255
5262
5256
- if ( blendFunc_dstColor )
5257
- {
5258
- stage->cancelOverBright = false ;
5259
- }
5260
-
5261
- // We should not cancel overbright if that's a non-opaque decal.
5262
5263
bool isDecal = shader.sort == Util::ordinal (shaderSort_t::SS_DECAL);
5263
- // SRC1 and DST0 are reset to zero in ParseStage (no blending).
5264
- bool isOpaque = !( stage->stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) );
5265
5264
5266
5265
if ( isDecal )
5267
5266
{
5267
+ // We should not cancel overbright if that's a non-opaque decal.
5268
5268
stage->cancelOverBright = isOpaque;
5269
5269
}
5270
5270
}
5271
+ else
5272
+ {
5273
+ if ( isOpaqueShader )
5274
+ {
5275
+ // We we should not cancel overbright if the light stage is applied on an opaque surface;
5276
+ stage->cancelOverBright = false ;
5277
+ }
5278
+ else
5279
+ {
5280
+ bool blendFunc_add = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_ONE
5281
+ && ( stage->stateBits & GLS_DSTBLEND_BITS ) == GLS_DSTBLEND_ONE;
5282
+
5283
+ if ( blendFunc_add )
5284
+ {
5285
+ stage->cancelOverBright = true ;
5286
+ }
5287
+ else
5288
+ {
5289
+ stage->cancelOverBright = false ;
5290
+ }
5291
+ }
5292
+ }
5271
5293
5272
5294
// Available textures.
5273
5295
bool hasNormalMap = stage->bundle [ TB_NORMALMAP ].image [ 0 ] != nullptr ;
0 commit comments