From 4523f348ca48784369b9c10024c42a4fbe1eed9d Mon Sep 17 00:00:00 2001 From: VReaperV Date: Tue, 21 Jan 2025 14:35:17 +0300 Subject: [PATCH 1/6] Fix r_forceAmbient comparison r_forceAmbient ranges in [0.0; 0.3], while tmpAmbient is in range of [0; 255]. --- src/engine/renderer/tr_bsp.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index a5bfab45ee..fd94e581f0 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4106,10 +4106,11 @@ void R_LoadLightGrid( lump_t *l ) tmpDirected[ 2 ] = in->directed[ 2 ]; tmpDirected[ 3 ] = 255; - if ( tmpAmbient[0] < r_forceAmbient.Get() && - tmpAmbient[1] < r_forceAmbient.Get() && - tmpAmbient[2] < r_forceAmbient.Get() ) { - VectorSet( tmpAmbient, r_forceAmbient.Get(), r_forceAmbient.Get(), r_forceAmbient.Get() ); + 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 ) From 95b7ed6dfdcc69777e38d366d538ba136475553f Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 23 Jan 2025 01:17:15 +0300 Subject: [PATCH 2/6] Use -1 for map-value in r_forceAmbient Allow using 0 as an actual value. --- src/engine/renderer/tr_bsp.cpp | 2 +- src/engine/renderer/tr_init.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index fd94e581f0..ea49e490c6 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4335,7 +4335,7 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) // check for ambient color else if ( !Q_stricmp( keyname, "_color" ) || !Q_stricmp( keyname, "ambientColor" ) ) { - if ( r_forceAmbient.Get() == 0 ) { + if ( r_forceAmbient.Get() == -1 ) { sscanf( value, "%f %f %f", &tr.ambientLight[0], &tr.ambientLight[1], &tr.ambientLight[2] ); diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index bcd1dc30db..8d48484432 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -242,8 +242,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA cvar_t *r_wolfFog; cvar_t *r_noFog; - Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid", Cvar::NONE, - 0.125f, 0.0f, 0.3f ); + Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", Cvar::NONE, + 0.125f, -1.0f, 0.3f ); Cvar::Cvar r_ambientScale( "r_ambientScale", "Scale lightGrid produced by ambientColor keyword by this much", Cvar::CHEAT, 1.0 ); cvar_t *r_lightScale; cvar_t *r_debugSort; From af9e23e6c6ed3dc2bacc35351dc0ef89c69e4709 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 23 Jan 2025 01:19:39 +0300 Subject: [PATCH 3/6] 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 ea49e490c6..d306379f29 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4106,13 +4106,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 ); @@ -4125,6 +4118,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 ) From 805df593dc20e9ccd842659abe346a9cb07d58d3 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Mon, 27 Jan 2025 02:33:16 +0300 Subject: [PATCH 4/6] Only check for ambient color with ambientColor key `_color` is used by q3map2 for some internal purposes, so don't use it here. --- src/engine/renderer/tr_bsp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index d306379f29..bc7a21ae00 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4338,7 +4338,7 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) } // check for ambient color - else if ( !Q_stricmp( keyname, "_color" ) || !Q_stricmp( keyname, "ambientColor" ) ) + else if ( !Q_stricmp( keyname, "ambientColor" ) ) { if ( r_forceAmbient.Get() == -1 ) { sscanf( value, "%f %f %f", &tr.ambientLight[0], &tr.ambientLight[1], From 59e4ee8dcd99f5bf0d1314a144fc5415df181da6 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 30 Jan 2025 02:57:20 +0300 Subject: [PATCH 5/6] Set r_forceAmbient to -1 by default This cvar used to have no effect after lightGrid code was moved to GLSL, so disable it by default to keep the lighting the same. --- src/engine/renderer/tr_init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 8d48484432..1b2b1d1138 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -243,7 +243,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA cvar_t *r_noFog; Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", Cvar::NONE, - 0.125f, -1.0f, 0.3f ); + -1.0f, -1.0f, 0.3f ); Cvar::Cvar r_ambientScale( "r_ambientScale", "Scale lightGrid produced by ambientColor keyword by this much", Cvar::CHEAT, 1.0 ); cvar_t *r_lightScale; cvar_t *r_debugSort; From 66f668c250a3355aa335ce8d9da754a26e40d94c Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 2 Mar 2025 16:38:45 +0300 Subject: [PATCH 6/6] Set r_forceAmbient to Cvar::CHEAT --- src/engine/renderer/tr_init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 1b2b1d1138..7156dcf52d 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -242,8 +242,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA cvar_t *r_wolfFog; cvar_t *r_noFog; - Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", Cvar::NONE, - -1.0f, -1.0f, 0.3f ); + Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", + Cvar::CHEAT, -1.0f, -1.0f, 0.3f ); Cvar::Cvar r_ambientScale( "r_ambientScale", "Scale lightGrid produced by ambientColor keyword by this much", Cvar::CHEAT, 1.0 ); cvar_t *r_lightScale; cvar_t *r_debugSort;