Skip to content

Commit

Permalink
fixup: fix special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Nov 12, 2024
1 parent 8ff19c3 commit eba7c4b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, drawSu
colorGen_t rgbGen = SetRgbGen( pStage );
alphaGen_t alphaGen = SetAlphaGen( pStage );

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

Tess_ComputeColor( pStage );
gl_genericShaderMaterial->SetUniform_Color( tess.svars.color );
Expand Down
13 changes: 11 additions & 2 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3602,7 +3602,7 @@ class u_ColorModulate :
{
this->SetValue( v );
}
void SetUniform_ColorModulate( colorGen_t colorGen, alphaGen_t alphaGen )
void SetUniform_ColorModulate( colorGen_t colorGen, alphaGen_t alphaGen, bool vertexOverbright = false )
{
vec4_t v;
bool needAttrib = false;
Expand All @@ -3616,7 +3616,16 @@ class u_ColorModulate :
{
case colorGen_t::CGEN_VERTEX:
needAttrib = true;
VectorSet( v, 1, 1, 1 );
if ( vertexOverbright )
{
// vertexOverbright is only needed for non-lightmapped cases. When there is a
// lightmap, this is done by multiplying with the overbright-scaled white image
VectorSet( v, tr.mapLightFactor, tr.mapLightFactor, tr.mapLightFactor );
}
else
{
VectorSet( v, 1, 1, 1 );
}
break;

case colorGen_t::CGEN_ONE_MINUS_VERTEX:
Expand Down
14 changes: 12 additions & 2 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,11 @@ void Render_generic3D( shaderStage_t *pStage )
colorGen_t rgbGen = SetRgbGen( pStage );
alphaGen_t alphaGen = SetAlphaGen( pStage );

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

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

// u_LightFactor
gl_lightMappingShader->SetUniform_LightFactor( tr.mapLightFactor );
gl_lightMappingShader->SetUniform_LightFactor(
lightMode == lightMode_t::FULLBRIGHT ? 1.0f : tr.mapLightFactor );

// u_ColorModulate
gl_lightMappingShader->SetUniform_ColorModulate( rgbGen, alphaGen );
Expand Down Expand Up @@ -2565,6 +2570,11 @@ void Tess_ComputeColor( shaderStage_t *pStage )
}
}

if ( pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP )
{
tess.svars.color *= tr.mapLightFactor;
}

// alphaGen
switch ( pStage->alphaGen )
{
Expand Down

0 comments on commit eba7c4b

Please sign in to comment.