Skip to content

Commit e93becb

Browse files
committed
r_forceBlendRegime
1 parent 3f0cd52 commit e93becb

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

src/engine/renderer/gl_shader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,10 +2630,7 @@ class u_ColorModulateColorGen_Uint :
26302630
ALPHA_ONE = 2,
26312631
ALPHA_MINUS_ONE = 3,
26322632
// <-- Insert new bits there.
2633-
LIGHTFACTOR_BIT0 = 28,
2634-
LIGHTFACTOR_BIT1 = 29,
2635-
LIGHTFACTOR_BIT2 = 30,
2636-
LIGHTFACTOR_BIT3 = 31,
2633+
LIGHTFACTOR_BIT0 = 11,
26372634
// There should be not bit higher than the light factor.
26382635
};
26392636

@@ -2647,8 +2644,11 @@ class u_ColorModulateColorGen_Uint :
26472644
<< Util::ordinal( ColorModulate_Bit::ALPHA_ONE );
26482645
colorModulate_Uint |= ( colorModulation.alphaGen == -1.0f )
26492646
<< Util::ordinal( ColorModulate_Bit::ALPHA_MINUS_ONE );
2650-
colorModulate_Uint |= uint32_t( colorModulation.lightFactor )
2651-
<< Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );
2647+
2648+
// Light factor unit is 128 / ( 1 << 21 )
2649+
// needs to go up to pow( 8, 2.2 ) = 97.006
2650+
uint32_t lightFactorBits = lrintf( colorModulation.lightFactor * 16384.0f );
2651+
colorModulate_Uint |= lightFactorBits << Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );
26522652

26532653
this->SetValue( colorModulate_Uint );
26542654
}

src/engine/renderer/glsl_source/common.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ colorMod << 0: color * 1
6868
colorMod << 1: color * ( -1 )
6969
colorMod << 2: alpha * 1
7070
colorMod << 3: alpha * ( -1 )
71-
colorMod << 4-27: available for future usage
72-
colorMod << 28-31: lightFactor
71+
colorMod << 4-10: available for future usage
72+
colorMod << 11-31: lightFactor
7373
7474
colorMod float format:
7575
@@ -98,7 +98,7 @@ vec4 ColorModulateToColor( const in colorModulatePack colorMod )
9898
float ColorModulateToLightFactor( const in colorModulatePack colorMod )
9999
{
100100
#if defined(HAVE_EXT_gpu_shader4)
101-
return float( colorMod >> 28u );
101+
return float( colorMod >> 11u ) * ( 1.0 / 16384 );
102102
#else
103103
return colorMod.g;
104104
#endif

src/engine/renderer/tr_bsp.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
486486
int lightMapBits = IF_LIGHTMAP | IF_NOPICMIP;
487487
int deluxeMapBits = IF_NORMALMAP | IF_NOPICMIP;
488488

489-
if ( tr.worldLinearizeLightMap )
489+
if ( tr.worldLinearizeTexture )
490490
{
491491
lightMapBits |= IF_SRGB;
492492
}
@@ -3969,15 +3969,18 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
39693969
tr.worldLinearizeLightMap = true;
39703970
}
39713971

3972-
if ( sRGBcolor && sRGBtex )
3973-
{
3974-
Log::Debug( "Map features lights computed with linear colors and textures." );
3975-
tr.worldLinearizeTexture = true;
3976-
}
3977-
else if ( sRGBcolor != sRGBtex )
3972+
if ( !r_forceBlendRegime.Get() )
39783973
{
3979-
Log::Warn( "Map features lights computed with a mix of linear and non-linear colors or textures, acting like both colors and textures were linear when lights were computed." );
3980-
tr.worldLinearizeTexture = true;
3974+
if ( sRGBcolor && sRGBtex )
3975+
{
3976+
Log::Debug( "Map features lights computed with linear colors and textures." );
3977+
tr.worldLinearizeTexture = true;
3978+
}
3979+
else if ( sRGBcolor != sRGBtex )
3980+
{
3981+
Log::Warn( "Map features lights computed with a mix of linear and non-linear colors or textures, acting like both colors and textures were linear when lights were computed." );
3982+
tr.worldLinearizeTexture = true;
3983+
}
39813984
}
39823985

39833986
continue;
@@ -4659,12 +4662,23 @@ static void SetWorldLight() {
46594662

46604663
/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
46614664
if ( tr.lightMode != lightMode_t::FULLBRIGHT ) {
4665+
float factor = float( 1 << tr.overbrightBits );
4666+
4667+
if ( tr.worldLinearizeLightMap && !tr.worldLinearizeTexture )
4668+
{
4669+
factor = powf( factor, 1.0f / 2.2f );
4670+
}
4671+
else if ( !tr.worldLinearizeLightMap && tr.worldLinearizeTexture )
4672+
{
4673+
factor = powf( factor, 2.2f );
4674+
}
4675+
46624676
if ( r_overbrightQ3.Get() ) {
46634677
// light factor is applied to entire color buffer; identityLight can be used to cancel it
4664-
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
4678+
tr.identityLight = 1.0f / factor;
46654679
} else {
46664680
// light factor is applied wherever a precomputed light is sampled
4667-
tr.mapLightFactor = float( 1 << tr.overbrightBits );
4681+
tr.mapLightFactor = factor;
46684682
}
46694683
}
46704684
}
@@ -4779,7 +4793,6 @@ void RE_LoadWorldMap( const char *name )
47794793
tr.overbrightBits = std::min( tr.mapOverBrightBits, r_overbrightBits.Get() ); // set by RE_LoadWorldMap
47804794
tr.mapLightFactor = 1.0f; // set by RE_LoadWorldMap
47814795
tr.identityLight = 1.0f; // set by RE_LoadWorldMap
4782-
tr.worldLinearizeTexture = false;
47834796
tr.worldLinearizeLightMap = false;
47844797

47854798
s_worldData = {};

src/engine/renderer/tr_init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Cvar::Cvar<int> r_rendererAPI( "r_rendererAPI", "Renderer API: 0: OpenGL, 1: Vul
9797
Cvar::Cvar<bool> r_overbrightQ3("r_overbrightQ3", "brighten entire color buffer like Quake 3 (incompatible with newer assets)", Cvar::NONE, false);
9898

9999
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false);
100+
Cvar::Range<Cvar::Cvar<int>> r_forceBlendRegime(
101+
"r_forceBlendRegime", "override map settings to use: 1 = naive blending, 2 = linear blending", Cvar::NONE, 0, 0, 2);
100102
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));
101103
Cvar::Cvar<bool> r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true );
102104
static Cvar::Range<Cvar::Cvar<int>> r_readonlyDepthBuffer(
@@ -1374,6 +1376,9 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
13741376
return false;
13751377
}
13761378

1379+
Cvar::Latch( r_forceBlendRegime );
1380+
tr.worldLinearizeTexture = r_forceBlendRegime.Get() == 2;
1381+
13771382
tr.lightMode = lightMode_t( r_lightMode.Get() );
13781383

13791384
if ( !Com_AreCheatsAllowed() )

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ enum
24282428
bool worldLightMapping;
24292429
bool worldDeluxeMapping;
24302430
bool worldHDR_RGBE;
2431-
bool worldLinearizeTexture;
2431+
bool worldLinearizeTexture; // this determines whether linear or naive blending is used
24322432
bool worldLinearizeLightMap;
24332433

24342434
floatProcessor_t convertFloatFromSRGB;
@@ -2644,6 +2644,7 @@ enum
26442644
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
26452645
extern Cvar::Cvar<bool> r_overbrightQ3;
26462646
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
2647+
extern Cvar::Range<Cvar::Cvar<int>> r_forceBlendRegime;
26472648
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
26482649
extern Cvar::Cvar<bool> r_colorGrading;
26492650
extern Cvar::Cvar<bool> r_preferBindlessTextures;

0 commit comments

Comments
 (0)