Skip to content

Commit

Permalink
Set lightGrid point colour to r_forceAmbient after overbright shift
Browse files Browse the repository at this point in the history
Avoid overflow and incorrect results due to the overbright shift.

Also fix `r_forceAmbient` affecting lightGrid points inside of walls.
  • Loading branch information
VReaperV committed Jan 26, 2025
1 parent 959edd9 commit b8b0936
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4124,13 +4124,6 @@ void R_LoadLightGrid( lump_t *l )
tmpDirected[ 2 ] = in->directed[ 2 ];
tmpDirected[ 3 ] = 255;

const byte forceAmbientNormalised = floatToUnorm8( r_forceAmbient.Get() );
if ( tmpAmbient[0] < forceAmbientNormalised &&
tmpAmbient[1] < forceAmbientNormalised &&
tmpAmbient[2] < forceAmbientNormalised ) {
VectorSet( tmpAmbient, forceAmbientNormalised, forceAmbientNormalised, forceAmbientNormalised );
}

if ( tr.legacyOverBrightClamping )
{
R_ColorShiftLightingBytes( tmpAmbient );
Expand All @@ -4143,6 +4136,18 @@ void R_LoadLightGrid( lump_t *l )
directedColor[ j ] = tmpDirected[ j ] * ( 1.0f / 255.0f );
}

const float forceAmbient = r_forceAmbient.Get();
if ( ambientColor[0] < forceAmbient &&
ambientColor[1] < forceAmbient &&
ambientColor[2] < forceAmbient &&
/* Make sure we don't change the (0, 0, 0) points because those are points in walls,
which we'll fill up by interpolating nearby points later */
ambientColor[0] != 0 &&
ambientColor[1] != 0 &&
ambientColor[2] != 0 ) {
VectorSet( ambientColor, forceAmbient, forceAmbient, forceAmbient );
}

// standard spherical coordinates to cartesian coordinates conversion

// decode X as cos( lat ) * sin( long )
Expand Down

0 comments on commit b8b0936

Please sign in to comment.