@@ -4301,6 +4301,13 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
4301
4301
4302
4302
p = w->entityString ;
4303
4303
4304
+ bool hasMapOverBrightBits = false ;
4305
+ int mapOverBrightBits = 0 ;
4306
+
4307
+ bool hasSRGBtex = false ;
4308
+ bool hasSRGBcolor = false ;
4309
+ bool hasSRGBlight = false ;
4310
+
4304
4311
// only parse the world spawn
4305
4312
while ( true )
4306
4313
{
@@ -4403,7 +4410,8 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
4403
4410
// check for mapOverBrightBits override
4404
4411
if ( !Q_stricmp ( keyname, " mapOverBrightBits" ) )
4405
4412
{
4406
- tr.mapOverBrightBits = Math::Clamp ( atof ( value ), 0.0 , 3.0 );
4413
+ hasMapOverBrightBits = true ;
4414
+ mapOverBrightBits = Math::Clamp ( atof ( value ), 0.0 , 3.0 );
4407
4415
continue ;
4408
4416
}
4409
4417
@@ -4438,71 +4446,52 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
4438
4446
tr.worldDeluxeMapping = glConfig2.deluxeMapping ;
4439
4447
}
4440
4448
4441
- bool sRGBtex = false ;
4442
- bool sRGBcolor = false ;
4443
- bool sRGBlight = false ;
4444
-
4445
4449
s = strstr ( value, " -sRGB" );
4446
4450
4447
4451
if ( s && ( s[5 ] == ' ' || s[5 ] == ' \0 ' ) )
4448
4452
{
4449
- sRGBtex = true ;
4450
- sRGBcolor = true ;
4451
- sRGBlight = true ;
4453
+ hasSRGBtex = true ;
4454
+ hasSRGBcolor = true ;
4455
+ hasSRGBlight = true ;
4452
4456
}
4453
4457
4454
4458
s = strstr ( value, " -nosRGB" );
4455
4459
4456
4460
if ( s && ( s[5 ] == ' ' || s[5 ] == ' \0 ' ) )
4457
4461
{
4458
- sRGBtex = false ;
4459
- sRGBcolor = false ;
4460
- sRGBlight = true ;
4462
+ hasSRGBtex = false ;
4463
+ hasSRGBcolor = false ;
4464
+ hasSRGBlight = true ;
4461
4465
}
4462
4466
4463
4467
if ( strstr ( value, " -sRGBlight" ) )
4464
4468
{
4465
- sRGBlight = true ;
4469
+ hasSRGBlight = true ;
4466
4470
}
4467
4471
4468
4472
if ( strstr ( value, " -nosRGBlight" ) )
4469
4473
{
4470
- sRGBlight = false ;
4474
+ hasSRGBlight = false ;
4471
4475
}
4472
4476
4473
4477
if ( strstr ( value, " -sRGBcolor" ) )
4474
4478
{
4475
- sRGBcolor = true ;
4479
+ hasSRGBcolor = true ;
4476
4480
}
4477
4481
4478
4482
if ( strstr ( value, " -nosRGBcolor" ) )
4479
4483
{
4480
- sRGBcolor = false ;
4484
+ hasSRGBcolor = false ;
4481
4485
}
4482
4486
4483
4487
if ( strstr ( value, " -sRGBtex" ) )
4484
4488
{
4485
- sRGBtex = true ;
4489
+ hasSRGBtex = true ;
4486
4490
}
4487
4491
4488
4492
if ( strstr ( value, " -nosRGBtex" ) )
4489
4493
{
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 ;
4506
4495
}
4507
4496
4508
4497
continue ;
@@ -4522,6 +4511,87 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
4522
4511
continue ;
4523
4512
}
4524
4513
}
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
+ }
4525
4595
}
4526
4596
4527
4597
/*
0 commit comments