Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make overbright settings fully configurable (default no clamping version) #1364

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1034,7 +1034,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 @@ -1244,7 +1244,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 @@ -1371,7 +1371,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 @@ -4152,7 +4152,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 @@ -4393,16 +4393,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 @@ -5208,7 +5224,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 @@ -1804,7 +1804,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 @@ -2971,8 +2971,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 @@ -82,8 +82,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_materialSystem( "r_materialSystem", "Use Material System", Cvar::NONE, false );
Expand Down Expand Up @@ -1131,8 +1132,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_fastsky );
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 @@ -2606,14 +2606,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 @@ -2737,8 +2737,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_materialSystem;
Expand Down