Skip to content

Commit

Permalink
Make overbright settings fully configurable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slipher authored and illwieckz committed Oct 17, 2024
1 parent 4a39a08 commit b86dcf6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
44 changes: 30 additions & 14 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
}
Expand Down Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Cvar::Cvar<bool> r_realtimeLighting( "r_realtimeLighting", "enable realtime light rendering", Cvar::NONE, true );
cvar_t *r_realtimeLightingCastShadows;
cvar_t *r_precomputedLighting;
Cvar::Cvar<int> r_mapOverBrightBits("r_mapOverBrightBits", "default map light color shift", Cvar::NONE, 2);
Cvar::Cvar<bool> r_forceLegacyOverBrightClamping("r_forceLegacyOverBrightClamping", "clamp over bright of legacy maps (enable multiplied color clamping and normalization)", Cvar::NONE, false);
Cvar::Cvar<int> r_overbrightDefaultExponent("r_overbrightDefaultExponent", "default map light color shift (multiply by 2^x)", Cvar::NONE, 2);
Cvar::Cvar<bool> r_overbrightDefaultClamp("r_overbrightDefaultClamp", "clamp lightmap colors to 1 (in absence of map worldspawn value)", Cvar::NONE, false);
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false);
Cvar::Range<Cvar::Cvar<int>> 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<bool> r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true );
Cvar::Cvar<bool> r_preferBindlessTextures( "r_preferBindlessTextures", "use bindless textures even when material system is off", Cvar::NONE, false );
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 5 additions & 4 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -2727,8 +2727,9 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED };
extern Cvar::Cvar<bool> r_realtimeLighting;
extern cvar_t *r_realtimeLightingCastShadows;
extern cvar_t *r_precomputedLighting;
extern Cvar::Cvar<int> r_mapOverBrightBits;
extern Cvar::Cvar<bool> r_forceLegacyOverBrightClamping;
extern Cvar::Cvar<int> r_overbrightDefaultExponent;
extern Cvar::Cvar<bool> r_overbrightDefaultClamp;
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
extern Cvar::Cvar<bool> r_colorGrading;
extern Cvar::Cvar<bool> r_preferBindlessTextures;
Expand Down

0 comments on commit b86dcf6

Please sign in to comment.