Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5179,9 +5179,9 @@ void RE_LoadWorldMap( const char *name )
}
}

/* Used in GLSL code for the GLSL implementation
without color clamping and normalization. */
if ( !tr.legacyOverBrightClamping )
/* Set GLSL overbright parameters if the legacy clamped overbright isn't used
and the lighting mode is not fullbright. */
if ( !tr.legacyOverBrightClamping && tr.lightMode != lightMode_t::FULLBRIGHT )
{
tr.mapLightFactor = pow( 2, tr.mapOverBrightBits );
tr.mapInverseLightFactor = 1.0f / tr.mapLightFactor;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ void Render_lightMapping( shaderStage_t *pStage )
// u_InverseLightFactor
/* HACK: use sign to know if there is a light or not, and
then if it will receive overbright multiplication or not. */
bool cancelOverBright = pStage->cancelOverBright || lightMode == lightMode_t::FULLBRIGHT;
bool cancelOverBright = pStage->cancelOverBright;
float inverseLightFactor = cancelOverBright ? tr.mapInverseLightFactor : -tr.mapInverseLightFactor;
gl_lightMappingShader->SetUniform_InverseLightFactor( inverseLightFactor );

Expand Down
44 changes: 33 additions & 11 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5239,35 +5239,57 @@ static void FinishStages()
? gl_shaderManager.getDeformShaderIndex( shader.deforms, shader.numDeforms )
: 0;

bool isOpaqueShader = false;

for ( size_t s = 0; s < numStages; s++ )
{
shaderStage_t *stage = &stages[ s ];

stage->deformIndex = deformIndex;

// We should cancel overbright if there is no light stage.
stage->cancelOverBright = shaderHasNoLight;
// SRC1 and DST0 are reset to zero in ParseStage (no blending).
bool isOpaque = !( stage->stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) );

// A shader is not opaque if all stages are not opaques.
isOpaqueShader |= isOpaque;

if ( shaderHasNoLight )
{
// We should not cancel overbright if there is no light and it's not using blendFunc dst_color.
bool blendFunc_dstColor = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;
bool blendFunc_srcDstColor = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_DST_COLOR;

if ( blendFunc_dstColor )
{
stage->cancelOverBright = false;
}
// We should cancel overbright if there is no light stage, unless it's using blendFunc dst_color.
stage->cancelOverBright = !blendFunc_srcDstColor;

// We should not cancel overbright if that's a non-opaque decal.
bool isDecal = shader.sort == Util::ordinal(shaderSort_t::SS_DECAL);
// SRC1 and DST0 are reset to zero in ParseStage (no blending).
bool isOpaque = !( stage->stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) );

if ( isDecal )
{
// We should not cancel overbright if that's a non-opaque decal.
stage->cancelOverBright = isOpaque;
}
}
else
{
if ( isOpaqueShader )
{
// We we should not cancel overbright if the light stage is applied on an opaque surface;
stage->cancelOverBright = false;
}
else
{
bool blendFunc_add = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_ONE
&& ( stage->stateBits & GLS_DSTBLEND_BITS ) == GLS_DSTBLEND_ONE;

if ( blendFunc_add )
{
stage->cancelOverBright = true;
}
else
{
stage->cancelOverBright = false;
}
}
}

// Available textures.
bool hasNormalMap = stage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr;
Expand Down