Skip to content

Commit eba7c4b

Browse files
committed
fixup: fix special cases
1 parent 8ff19c3 commit eba7c4b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/engine/renderer/Material.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, drawSu
226226
colorGen_t rgbGen = SetRgbGen( pStage );
227227
alphaGen_t alphaGen = SetAlphaGen( pStage );
228228

229-
gl_genericShaderMaterial->SetUniform_ColorModulate( rgbGen, alphaGen );
229+
bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && drawSurf->bspSurface;
230+
gl_genericShaderMaterial->SetUniform_ColorModulate( rgbGen, alphaGen, mayUseVertexOverbright );
230231

231232
Tess_ComputeColor( pStage );
232233
gl_genericShaderMaterial->SetUniform_Color( tess.svars.color );

src/engine/renderer/gl_shader.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,7 +3602,7 @@ class u_ColorModulate :
36023602
{
36033603
this->SetValue( v );
36043604
}
3605-
void SetUniform_ColorModulate( colorGen_t colorGen, alphaGen_t alphaGen )
3605+
void SetUniform_ColorModulate( colorGen_t colorGen, alphaGen_t alphaGen, bool vertexOverbright = false )
36063606
{
36073607
vec4_t v;
36083608
bool needAttrib = false;
@@ -3616,7 +3616,16 @@ class u_ColorModulate :
36163616
{
36173617
case colorGen_t::CGEN_VERTEX:
36183618
needAttrib = true;
3619-
VectorSet( v, 1, 1, 1 );
3619+
if ( vertexOverbright )
3620+
{
3621+
// vertexOverbright is only needed for non-lightmapped cases. When there is a
3622+
// lightmap, this is done by multiplying with the overbright-scaled white image
3623+
VectorSet( v, tr.mapLightFactor, tr.mapLightFactor, tr.mapLightFactor );
3624+
}
3625+
else
3626+
{
3627+
VectorSet( v, 1, 1, 1 );
3628+
}
36203629
break;
36213630

36223631
case colorGen_t::CGEN_ONE_MINUS_VERTEX:

src/engine/renderer/tr_shade.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,11 @@ void Render_generic3D( shaderStage_t *pStage )
924924
colorGen_t rgbGen = SetRgbGen( pStage );
925925
alphaGen_t alphaGen = SetAlphaGen( pStage );
926926

927-
gl_genericShader->SetUniform_ColorModulate( rgbGen, alphaGen );
927+
// Here, it's safe to multiply the overbright factor for vertex lighting into the color gen`
928+
// since the `generic` fragment shader only takes a single input color. `lightMapping` on the
929+
// hand needs to know the real diffuse color, hence the separate u_LightFactor.
930+
bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && tess.bspSurface;
931+
gl_genericShader->SetUniform_ColorModulate( rgbGen, alphaGen, mayUseVertexOverbright );
928932

929933
// u_Color
930934
gl_genericShader->SetUniform_Color( tess.svars.color );
@@ -1121,7 +1125,8 @@ void Render_lightMapping( shaderStage_t *pStage )
11211125
gl_lightMappingShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );
11221126

11231127
// u_LightFactor
1124-
gl_lightMappingShader->SetUniform_LightFactor( tr.mapLightFactor );
1128+
gl_lightMappingShader->SetUniform_LightFactor(
1129+
lightMode == lightMode_t::FULLBRIGHT ? 1.0f : tr.mapLightFactor );
11251130

11261131
// u_ColorModulate
11271132
gl_lightMappingShader->SetUniform_ColorModulate( rgbGen, alphaGen );
@@ -2565,6 +2570,11 @@ void Tess_ComputeColor( shaderStage_t *pStage )
25652570
}
25662571
}
25672572

2573+
if ( pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP )
2574+
{
2575+
tess.svars.color *= tr.mapLightFactor;
2576+
}
2577+
25682578
// alphaGen
25692579
switch ( pStage->alphaGen )
25702580
{

0 commit comments

Comments
 (0)