From b86dcf6c3715a5248f82066e4647587533c11792 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 11 Oct 2024 20:17:18 -0500 Subject: [PATCH] Make overbright settings fully configurable Change cvars so that all overbright settings can easily be tested. The current overbright-related cvars have a wonky asymmetric design that can make it impossible to test a setting without editing the map. Fix that. With this commit we can use r_overbrightDefaultExponent (0-3) and r_overbrightDefaultClamp (on/off) to control the default settings when the map doesn't say anything, and one more cvar r_overbrightIgnoreMapSettings to make those cvar values override the worldspawn values even if present. In the worldspawn entity mapOverBrightBits can stay as is, but forceLegacyOverBrightClamping drops the "force" (since it is no longer a one-way switch) and renames to just overbrightClamping. Fixes #1289. --- src/engine/renderer/tr_bsp.cpp | 44 ++++++++++++++++++++++---------- src/engine/renderer/tr_image.cpp | 6 ++--- src/engine/renderer/tr_init.cpp | 10 +++++--- src/engine/renderer/tr_local.h | 9 ++++--- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index d2ab28f214..9c57278032 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -667,7 +667,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName ) lightMapBuffer[( index * 4 ) + 2 ] = buf_p[( ( x + ( y * internalLightMapSize ) ) * 3 ) + 2 ]; lightMapBuffer[( index * 4 ) + 3 ] = 255; - if ( tr.forceLegacyOverBrightClamping ) + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( &lightMapBuffer[( index * 4 ) + 0 ] ); } @@ -1028,7 +1028,7 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf, in cv->verts[ i ].lightColor = Color::Adapt( verts[ i ].color ); - if ( tr.forceLegacyOverBrightClamping ) + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( cv->verts[ i ].lightColor.ToArray() ); } @@ -1238,7 +1238,7 @@ static void ParseMesh( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf ) points[ i ].lightColor = Color::Adapt( verts[ i ].color ); - if ( tr.forceLegacyOverBrightClamping ) + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( points[ i ].lightColor.ToArray() ); } @@ -1365,7 +1365,7 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf, cv->verts[ i ].lightColor = Color::Adapt( verts[ i ].color ); - if ( tr.forceLegacyOverBrightClamping ) + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( cv->verts[ i ].lightColor.ToArray() ); } @@ -4060,7 +4060,7 @@ void R_LoadLightGrid( lump_t *l ) tmpDirected[ 2 ] = in->directed[ 2 ]; tmpDirected[ 3 ] = 255; - if ( tr.forceLegacyOverBrightClamping ) + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( tmpAmbient ); R_ColorShiftLightingBytes( tmpDirected ); @@ -4301,16 +4301,32 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) continue; } - // check for mapOverBrightBits override - else if ( !Q_stricmp( keyname, "mapOverBrightBits" ) ) + if ( !r_overbrightIgnoreMapSettings.Get() ) { - tr.mapOverBrightBits = Math::Clamp( atof( value ), 0.0, 3.0 ); - } + // check for mapOverBrightBits override + if ( !Q_stricmp( keyname, "mapOverBrightBits" ) ) + { + tr.mapOverBrightBits = Math::Clamp( atof( value ), 0.0, 3.0 ); + continue; + } - // Force forceLegacyOverBrightClamping even if r_forceLegacyOverBrightClamping is false. - else if ( !Q_stricmp( keyname, "forceLegacyOverBrightClamping" ) && !Q_stricmp( value, "1" ) ) - { - tr.forceLegacyOverBrightClamping = true; + if ( !Q_stricmp( keyname, "overbrightClamping" ) ) + { + if ( !Q_stricmp( value, "0" ) ) + { + tr.legacyOverBrightClamping = false; + } + else if ( !Q_stricmp( value, "1" ) ) + { + tr.legacyOverBrightClamping = true; + } + else + { + Log::Warn( "invalid value for worldspawn key overbrightClamping" ); + } + + continue; + } } // check for deluxe mapping provided by NetRadiant's q3map2 @@ -5116,7 +5132,7 @@ void RE_LoadWorldMap( const char *name ) /* Used in GLSL code for the GLSL implementation without color clamping and normalization. */ - if ( !tr.forceLegacyOverBrightClamping ) + if ( !tr.legacyOverBrightClamping ) { tr.mapLightFactor = pow( 2, tr.mapOverBrightBits ); tr.mapInverseLightFactor = 1.0f / tr.mapLightFactor; diff --git a/src/engine/renderer/tr_image.cpp b/src/engine/renderer/tr_image.cpp index 0e424f1b9a..34d9160834 100644 --- a/src/engine/renderer/tr_image.cpp +++ b/src/engine/renderer/tr_image.cpp @@ -1812,7 +1812,7 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams ) return nullptr; } - if ( imageParams.bits & IF_LIGHTMAP && tr.forceLegacyOverBrightClamping ) + if ( imageParams.bits & IF_LIGHTMAP && tr.legacyOverBrightClamping ) { R_ProcessLightmap( pic[ 0 ], width, height, imageParams.bits ); } @@ -2979,8 +2979,8 @@ void R_InitImages() Because tr.overbrightBits is always 0, tr.identityLight is always 1.0f. We can entirely remove it. */ - tr.mapOverBrightBits = r_mapOverBrightBits.Get(); - tr.forceLegacyOverBrightClamping = r_forceLegacyOverBrightClamping.Get(); + tr.mapOverBrightBits = r_overbrightDefaultExponent.Get(); + tr.legacyOverBrightClamping = r_overbrightDefaultClamp.Get(); // create default texture and white texture R_CreateBuiltinImages(); diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 29682617de..20e02e91f2 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -80,8 +80,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Cvar::Cvar r_realtimeLighting( "r_realtimeLighting", "enable realtime light rendering", Cvar::NONE, true ); cvar_t *r_realtimeLightingCastShadows; cvar_t *r_precomputedLighting; - Cvar::Cvar r_mapOverBrightBits("r_mapOverBrightBits", "default map light color shift", Cvar::NONE, 2); - Cvar::Cvar r_forceLegacyOverBrightClamping("r_forceLegacyOverBrightClamping", "clamp over bright of legacy maps (enable multiplied color clamping and normalization)", Cvar::NONE, false); + Cvar::Cvar r_overbrightDefaultExponent("r_overbrightDefaultExponent", "default map light color shift (multiply by 2^x)", Cvar::NONE, 2); + Cvar::Cvar r_overbrightDefaultClamp("r_overbrightDefaultClamp", "clamp lightmap colors to 1 (in absence of map worldspawn value)", Cvar::NONE, false); + Cvar::Cvar r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false); Cvar::Range> r_lightMode("r_lightMode", "lighting mode: 0: fullbright (cheat), 1: vertex light, 2: grid light (cheat), 3: light map", Cvar::NONE, Util::ordinal(lightMode_t::MAP), Util::ordinal(lightMode_t::FULLBRIGHT), Util::ordinal(lightMode_t::MAP)); Cvar::Cvar r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true ); Cvar::Cvar r_preferBindlessTextures( "r_preferBindlessTextures", "use bindless textures even when material system is off", Cvar::NONE, false ); @@ -1127,8 +1128,9 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p r_subdivisions = Cvar_Get( "r_subdivisions", "4", CVAR_LATCH ); r_realtimeLightingCastShadows = Cvar_Get( "r_realtimeLightingCastShadows", "1", 0 ); r_precomputedLighting = Cvar_Get( "r_precomputedLighting", "1", CVAR_CHEAT | CVAR_LATCH ); - Cvar::Latch( r_mapOverBrightBits ); - Cvar::Latch( r_forceLegacyOverBrightClamping ); + Cvar::Latch( r_overbrightDefaultExponent ); + Cvar::Latch( r_overbrightDefaultClamp ); + Cvar::Latch( r_overbrightIgnoreMapSettings ); Cvar::Latch( r_lightMode ); Cvar::Latch( r_colorGrading ); Cvar::Latch( r_drawSky ); diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index b69b9dbb6f..e58e22964e 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2598,14 +2598,14 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED }; viewParms_t viewParms; - // r_mapOverbrightBits->integer, but can be overridden by mapper using the worldspawn + // r_overbrightDefaultExponent, but can be overridden by mapper using the worldspawn int mapOverBrightBits; // pow(2, mapOverbrightBits) float mapLightFactor; // 1 / mapLightFactor float mapInverseLightFactor; // May have to be true on some legacy maps: clamp and normalize multiplied colors. - bool forceLegacyOverBrightClamping; + bool legacyOverBrightClamping; orientationr_t orientation; // for current entity @@ -2727,8 +2727,9 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED }; extern Cvar::Cvar r_realtimeLighting; extern cvar_t *r_realtimeLightingCastShadows; extern cvar_t *r_precomputedLighting; - extern Cvar::Cvar r_mapOverBrightBits; - extern Cvar::Cvar r_forceLegacyOverBrightClamping; + extern Cvar::Cvar r_overbrightDefaultExponent; + extern Cvar::Cvar r_overbrightDefaultClamp; + extern Cvar::Cvar r_overbrightIgnoreMapSettings; extern Cvar::Range> r_lightMode; extern Cvar::Cvar r_colorGrading; extern Cvar::Cvar r_preferBindlessTextures;