Skip to content

Commit 85ae75e

Browse files
committed
implement different overbright exponents for legacy maps and maps with color linearization
1 parent 15d3e53 commit 85ae75e

File tree

4 files changed

+113
-93
lines changed

4 files changed

+113
-93
lines changed

src/engine/renderer/tr_bsp.cpp

Lines changed: 102 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,6 +4301,13 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
43014301

43024302
p = w->entityString;
43034303

4304+
bool hasMapOverBrightBits = false;
4305+
int mapOverBrightBits = 0;
4306+
4307+
bool hasSRGBtex = false;
4308+
bool hasSRGBcolor = false;
4309+
bool hasSRGBlight = false;
4310+
43044311
// only parse the world spawn
43054312
while ( true )
43064313
{
@@ -4403,7 +4410,8 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
44034410
// check for mapOverBrightBits override
44044411
if ( !Q_stricmp( keyname, "mapOverBrightBits" ) )
44054412
{
4406-
tr.mapOverBrightBits = Math::Clamp( atof( value ), 0.0, 3.0 );
4413+
hasMapOverBrightBits = true;
4414+
mapOverBrightBits = Math::Clamp( atof( value ), 0.0, 3.0 );
44074415
continue;
44084416
}
44094417

@@ -4438,71 +4446,52 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
44384446
tr.worldDeluxeMapping = glConfig2.deluxeMapping;
44394447
}
44404448

4441-
bool sRGBtex = false;
4442-
bool sRGBcolor = false;
4443-
bool sRGBlight = false;
4444-
44454449
s = strstr( value, "-sRGB" );
44464450

44474451
if ( s && ( s[5] == ' ' || s[5] == '\0' ) )
44484452
{
4449-
sRGBtex = true;
4450-
sRGBcolor = true;
4451-
sRGBlight = true;
4453+
hasSRGBtex = true;
4454+
hasSRGBcolor = true;
4455+
hasSRGBlight = true;
44524456
}
44534457

44544458
s = strstr( value, "-nosRGB" );
44554459

44564460
if ( s && ( s[5] == ' ' || s[5] == '\0' ) )
44574461
{
4458-
sRGBtex = false;
4459-
sRGBcolor = false;
4460-
sRGBlight = true;
4462+
hasSRGBtex = false;
4463+
hasSRGBcolor = false;
4464+
hasSRGBlight = true;
44614465
}
44624466

44634467
if ( strstr( value, "-sRGBlight" ) )
44644468
{
4465-
sRGBlight = true;
4469+
hasSRGBlight = true;
44664470
}
44674471

44684472
if ( strstr( value, "-nosRGBlight" ) )
44694473
{
4470-
sRGBlight = false;
4474+
hasSRGBlight = false;
44714475
}
44724476

44734477
if ( strstr( value, "-sRGBcolor" ) )
44744478
{
4475-
sRGBcolor = true;
4479+
hasSRGBcolor = true;
44764480
}
44774481

44784482
if ( strstr( value, "-nosRGBcolor" ) )
44794483
{
4480-
sRGBcolor = false;
4484+
hasSRGBcolor = false;
44814485
}
44824486

44834487
if ( strstr( value, "-sRGBtex" ) )
44844488
{
4485-
sRGBtex = true;
4489+
hasSRGBtex = true;
44864490
}
44874491

44884492
if ( strstr( value, "-nosRGBtex" ) )
44894493
{
4490-
sRGBtex = false;
4491-
}
4492-
4493-
if ( sRGBlight )
4494-
{
4495-
Log::Debug("map features lights in sRGB colorspace" );
4496-
tr.worldLinearizeLightMap = true;
4497-
}
4498-
4499-
if ( sRGBcolor && sRGBtex )
4500-
{
4501-
Log::Debug("map features lights computed with linear colors and textures" );
4502-
tr.worldLinearizeTexture = true;
4503-
/* The forceLegacyMapOverBrightClamping is only compatible and purposed
4504-
with legacy maps without color linearization. */
4505-
tr. legacyOverBrightClamping= false;
4494+
hasSRGBtex = false;
45064495
}
45074496

45084497
continue;
@@ -4522,6 +4511,87 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
45224511
continue;
45234512
}
45244513
}
4514+
4515+
/* These are the values expected by the rest of the renderer
4516+
(esp. tr_bsp), used for "gamma correction of the map".
4517+
Both were set to 0 if we had neither COMPAT_ET nor COMPAT_Q3,
4518+
it may be interesting to remember.
4519+
4520+
Quake 3 and Tremulous values:
4521+
4522+
tr.overbrightBits = 1;
4523+
tr.mapOverBrightBits = 2;
4524+
tr.identityLight = 1.0f / ( 1 << tr.overbrightBits );
4525+
4526+
Wolfenstein: Enemy Territory values:
4527+
4528+
tr.overbrightBits = 0;
4529+
tr.mapOverBrightBits = 2;
4530+
tr.identityLight = 1.0f / ( 1 << tr.overbrightBits );
4531+
4532+
Games like Quake 3 and Tremulous require tr.mapOverBrightBits
4533+
to be set to 2. Because this engine is primarily maintained for
4534+
Unvanquished and needs to keep compatibility with legacy Tremulous
4535+
maps, this value is set to 2.
4536+
4537+
Games like True Combat: Elite (Wolf:ET mod) or Urban Terror 4
4538+
(Quake 3 mod) require tr.mapOverBrightBits to be set to 0.
4539+
4540+
The mapOverBrightBits value will be read as map entity key
4541+
by R_LoadEntities() in tr_bsp, making possible to override
4542+
the default value and properly render a map with another
4543+
value than the default one.
4544+
4545+
If this key is missing in map entity lump, there is no way
4546+
to know the required value for mapOverBrightBits when loading
4547+
a BSP, one may rely on arena files to do some guessing when
4548+
loading foreign maps and games ported to the Dæmon engine may
4549+
require to set a different default than what Unvanquished
4550+
requires.
4551+
4552+
Using a non-zero value for tr.mapOverBrightBits turns light
4553+
non-linear and makes deluxe mapping buggy though.
4554+
4555+
Mappers may port and fix maps by multiplying the lights by 2.5
4556+
and set the mapOverBrightBits key to 0 in map entities lump.
4557+
4558+
In legacy engines, tr.overbrightBits was non-zero when
4559+
hardware overbright bits were enabled, zero when disabled.
4560+
This engine do not implement hardware overbright bit, so
4561+
this is always zero, and we can remove it and simplify all
4562+
the computations making use of it.
4563+
4564+
Because tr.overbrightBits is always 0, tr.identityLight is
4565+
always 1.0f. We can entirely remove it. */
4566+
4567+
if ( hasSRGBlight )
4568+
{
4569+
Log::Debug("map features lights in sRGB colorspace" );
4570+
tr.worldLinearizeLightMap = true;
4571+
}
4572+
4573+
if ( hasSRGBcolor && hasSRGBtex )
4574+
{
4575+
Log::Debug("map features lights computed with linear colors and textures" );
4576+
tr.worldLinearizeTexture = true;
4577+
4578+
/* The forceLegacyMapOverBrightClamping is only compatible and purposed
4579+
for legacy maps without color linearization. */
4580+
tr.legacyOverBrightClamping = false;
4581+
4582+
tr.mapOverBrightBits = r_overbrightDefaultLinearExponent.Get();
4583+
}
4584+
else
4585+
{
4586+
tr.legacyOverBrightClamping = r_overbrightDefaultLegacyClamp.Get();
4587+
4588+
tr.mapOverBrightBits = r_overbrightDefaultLegacyExponent.Get();
4589+
}
4590+
4591+
if ( !r_overbrightIgnoreMapSettings.Get() && hasMapOverBrightBits )
4592+
{
4593+
tr.mapOverBrightBits = mapOverBrightBits;
4594+
}
45254595
}
45264596

45274597
/*

src/engine/renderer/tr_image.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,59 +3054,6 @@ void R_InitImages()
30543054
tr.lightmaps.reserve( 128 );
30553055
tr.deluxemaps.reserve( 128 );
30563056

3057-
/* These are the values expected by the rest of the renderer
3058-
(esp. tr_bsp), used for "gamma correction of the map".
3059-
Both were set to 0 if we had neither COMPAT_ET nor COMPAT_Q3,
3060-
it may be interesting to remember.
3061-
3062-
Quake 3 and Tremulous values:
3063-
3064-
tr.overbrightBits = 0; // Software implementation.
3065-
tr.mapOverBrightBits = 2; // Quake 3 default.
3066-
tr.identityLight = 1.0f / ( 1 << tr.overbrightBits );
3067-
3068-
Games like Quake 3 and Tremulous require tr.mapOverBrightBits
3069-
to be set to 2. Because this engine is primarily maintained for
3070-
Unvanquished and needs to keep compatibility with legacy Tremulous
3071-
maps, this value is set to 2.
3072-
3073-
Games like True Combat: Elite (Wolf:ET mod) or Urban Terror 4
3074-
(Quake 3 mod) require tr.mapOverBrightBits to be set to 0.
3075-
3076-
For some reasons the Wolf:ET engine sets this to 0 by default
3077-
but the game sets it to 2 (and requires it to be 2 for maps
3078-
looking as expected).
3079-
3080-
The mapOverBrightBits value will be read as map entity key
3081-
by R_LoadEntities() in tr_bsp, making possible to override
3082-
the default value and properly render a map with another
3083-
value than the default one.
3084-
3085-
If this key is missing in map entity lump, there is no way
3086-
to know the required value for mapOverBrightBits when loading
3087-
a BSP, one may rely on arena files to do some guessing when
3088-
loading foreign maps and games ported to the Dæmon engine may
3089-
require to set a different default than what Unvanquished
3090-
requires.
3091-
3092-
Using a non-zero value for tr.mapOverBrightBits turns light
3093-
non-linear and makes deluxe mapping buggy though.
3094-
3095-
Mappers may port and fix maps by multiplying the lights by 2.5
3096-
and set the mapOverBrightBits key to 0 in map entities lump.
3097-
3098-
In legacy engines, tr.overbrightBits was non-zero when
3099-
hardware overbright bits were enabled, zero when disabled.
3100-
This engine do not implement hardware overbright bit, so
3101-
this is always zero, and we can remove it and simplify all
3102-
the computations making use of it.
3103-
3104-
Because tr.overbrightBits is always 0, tr.identityLight is
3105-
always 1.0f. We can entirely remove it. */
3106-
3107-
tr.mapOverBrightBits = r_overbrightDefaultExponent.Get();
3108-
tr.legacyOverBrightClamping = r_overbrightDefaultClamp.Get();
3109-
31103057
// create default texture and white texture
31113058
R_CreateBuiltinImages();
31123059
}

src/engine/renderer/tr_init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9292
Cvar::NONE, 4, 1, MAX_REF_LIGHTS / 16 );
9393
cvar_t *r_realtimeLightingCastShadows;
9494
cvar_t *r_precomputedLighting;
95-
Cvar::Cvar<int> r_overbrightDefaultExponent("r_overbrightDefaultExponent", "default map light color shift (multiply by 2^x)", Cvar::NONE, 2);
96-
Cvar::Cvar<bool> r_overbrightDefaultClamp("r_overbrightDefaultClamp", "clamp lightmap colors to 1 (in absence of map worldspawn value)", Cvar::NONE, false);
97-
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false);
95+
Cvar::Cvar<int> r_overbrightDefaultLegacyExponent("r_overbrightDefaultLegacyExponent", "default map light color shift for legacy maps (multiply by 2^x)", Cvar::NONE, 2);
96+
Cvar::Cvar<int> r_overbrightDefaultLinearExponent("r_overbrightDefaultLinearExponent", "default map light color shift for maps with linear colorspace (multiply by 2^x)", Cvar::NONE, 1);
97+
Cvar::Cvar<bool> r_overbrightDefaultLegacyClamp("r_overbrightDefaultLegacyClamp", "clamp legacy lightmap colors to 1 (in absence of map worldspawn value)", Cvar::NONE, false);
98+
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultLegacyClamp / r_overbrightDefaultLegacyExponent / r_overbrightDefaultLinearExponent, ignoring worldspawn", Cvar::NONE, false);
9899
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));
99100
Cvar::Cvar<bool> r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true );
100101
Cvar::Cvar<bool> r_preferBindlessTextures( "r_preferBindlessTextures", "use bindless textures even when material system is off", Cvar::NONE, false );
@@ -1169,8 +1170,9 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11691170
r_subdivisions = Cvar_Get( "r_subdivisions", "4", CVAR_LATCH );
11701171
r_realtimeLightingCastShadows = Cvar_Get( "r_realtimeLightingCastShadows", "1", 0 );
11711172
r_precomputedLighting = Cvar_Get( "r_precomputedLighting", "1", CVAR_CHEAT | CVAR_LATCH );
1172-
Cvar::Latch( r_overbrightDefaultExponent );
1173-
Cvar::Latch( r_overbrightDefaultClamp );
1173+
Cvar::Latch( r_overbrightDefaultLegacyExponent );
1174+
Cvar::Latch( r_overbrightDefaultLinearExponent );
1175+
Cvar::Latch( r_overbrightDefaultLegacyClamp );
11741176
Cvar::Latch( r_overbrightIgnoreMapSettings );
11751177
Cvar::Latch( r_lightMode );
11761178
Cvar::Latch( r_colorGrading );

src/engine/renderer/tr_local.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ enum class shaderProfilerRenderSubGroupsMode {
28292829

28302830
viewParms_t viewParms;
28312831

2832-
// r_overbrightDefaultExponent, but can be overridden by mapper using the worldspawn
2832+
// r_overbrightDefault[Linear/Legacy]Exponent, but can be overridden by mapper using the worldspawn
28332833
int mapOverBrightBits;
28342834
// pow(2, mapOverbrightBits)
28352835
float mapLightFactor;
@@ -2959,8 +2959,9 @@ enum class shaderProfilerRenderSubGroupsMode {
29592959
extern Cvar::Range<Cvar::Cvar<int>> r_realtimeLightLayers;
29602960
extern cvar_t *r_realtimeLightingCastShadows;
29612961
extern cvar_t *r_precomputedLighting;
2962-
extern Cvar::Cvar<int> r_overbrightDefaultExponent;
2963-
extern Cvar::Cvar<bool> r_overbrightDefaultClamp;
2962+
extern Cvar::Cvar<int> r_overbrightDefaultLinearExponent;
2963+
extern Cvar::Cvar<int> r_overbrightDefaultLegacyExponent;
2964+
extern Cvar::Cvar<bool> r_overbrightDefaultLegacyClamp;
29642965
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
29652966
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
29662967
extern Cvar::Cvar<bool> r_colorGrading;

0 commit comments

Comments
 (0)