From b8b09361387941dad75d46d08c78afe9844fbaf4 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 23 Jan 2025 01:19:39 +0300 Subject: [PATCH] Set lightGrid point colour to r_forceAmbient after overbright shift Avoid overflow and incorrect results due to the overbright shift. Also fix `r_forceAmbient` affecting lightGrid points inside of walls. --- src/engine/renderer/tr_bsp.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index f098114b1e..2f25cc9b37 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -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 ); @@ -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 )