Skip to content

Commit fe30922

Browse files
committed
r_forceBlendRegime
1 parent 83cc4b3 commit fe30922

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

src/engine/renderer/gl_shader.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,11 +2861,8 @@ class u_ColorModulateColorGen_Uint :
28612861
ALPHA_MINUS_ONE = 3,
28622862
ALPHA_ADD_ONE = 4,
28632863
// <-- Insert new bits there.
2864-
IS_LIGHT_STYLE = 27,
2865-
LIGHTFACTOR_BIT0 = 28,
2866-
LIGHTFACTOR_BIT1 = 29,
2867-
LIGHTFACTOR_BIT2 = 30,
2868-
LIGHTFACTOR_BIT3 = 31,
2864+
IS_LIGHT_STYLE = 10,
2865+
LIGHTFACTOR_BIT0 = 11,
28692866
// There should be not bit higher than the light factor.
28702867
};
28712868

@@ -2883,8 +2880,11 @@ class u_ColorModulateColorGen_Uint :
28832880
<< Util::ordinal( ColorModulate_Bit::ALPHA_ADD_ONE );
28842881
colorModulate_Uint |= colorModulation.useVertexLightFactor
28852882
<< Util::ordinal( ColorModulate_Bit::IS_LIGHT_STYLE );
2886-
colorModulate_Uint |= uint32_t( colorModulation.lightFactor )
2887-
<< Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );
2883+
2884+
// Light factor unit is 128 / ( 1 << 21 )
2885+
// needs to go up to pow( 8, 2.2 ) = 97.006
2886+
uint32_t lightFactorBits = lrintf( colorModulation.lightFactor * 16384.0f );
2887+
colorModulate_Uint |= lightFactorBits << Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );
28882888

28892889
this->SetValue( colorModulate_Uint );
28902890
}

src/engine/renderer/glsl_source/common.glsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ colorMod << 1: color * ( -1 )
6969
colorMod << 2: alpha * 1
7070
colorMod << 3: alpha * ( -1 )
7171
colorMod << 4: alpha = 1
72-
colorMod << 5-26: available for future usage
73-
colorMod << 27: color += lightFactor
74-
colorMod << 28-31: lightFactor
72+
colorMod << 5-9: available for future usage
73+
colorMod << 10: color += lightFactor
74+
colorMod << 11-31: lightFactor
7575
7676
colorMod float format:
7777
@@ -123,7 +123,7 @@ ModBits_t ColorModulateToBits( const in colorModulatePack colorMod )
123123
float ColorModulateToLightFactor( const in colorModulatePack colorMod )
124124
{
125125
#if defined(HAVE_EXT_gpu_shader4)
126-
return float( colorMod >> 28u );
126+
return float( colorMod >> 11u ) * ( 1.0 / 16384 );
127127
#else
128128
return abs( colorMod.g );
129129
#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
}
@@ -3917,15 +3917,18 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
39173917
tr.worldLinearizeLightMap = true;
39183918
}
39193919

3920-
if ( sRGBcolor && sRGBtex )
3921-
{
3922-
Log::Debug( "Map features lights computed with linear colors and textures." );
3923-
tr.worldLinearizeTexture = true;
3924-
}
3925-
else if ( sRGBcolor != sRGBtex )
3920+
if ( !r_forceBlendRegime.Get() )
39263921
{
3927-
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." );
3928-
tr.worldLinearizeTexture = true;
3922+
if ( sRGBcolor && sRGBtex )
3923+
{
3924+
Log::Debug( "Map features lights computed with linear colors and textures." );
3925+
tr.worldLinearizeTexture = true;
3926+
}
3927+
else if ( sRGBcolor != sRGBtex )
3928+
{
3929+
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." );
3930+
tr.worldLinearizeTexture = true;
3931+
}
39293932
}
39303933

39313934
continue;
@@ -4631,12 +4634,23 @@ static void SetWorldLight() {
46314634

46324635
/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
46334636
if ( tr.lightMode != lightMode_t::FULLBRIGHT ) {
4637+
float factor = float( 1 << tr.overbrightBits );
4638+
4639+
if ( tr.worldLinearizeLightMap && !tr.worldLinearizeTexture )
4640+
{
4641+
factor = powf( factor, 1.0f / 2.2f );
4642+
}
4643+
else if ( !tr.worldLinearizeLightMap && tr.worldLinearizeTexture )
4644+
{
4645+
factor = powf( factor, 2.2f );
4646+
}
4647+
46344648
if ( r_overbrightQ3.Get() ) {
46354649
// light factor is applied to entire color buffer; identityLight can be used to cancel it
4636-
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
4650+
tr.identityLight = 1.0f / factor;
46374651
} else {
46384652
// light factor is applied wherever a precomputed light is sampled
4639-
tr.mapLightFactor = float( 1 << tr.overbrightBits );
4653+
tr.mapLightFactor = factor;
46404654
}
46414655
}
46424656
}
@@ -4693,7 +4707,6 @@ void RE_LoadWorldMap( const char *name )
46934707
tr.overbrightBits = std::min( tr.mapOverBrightBits, r_overbrightBits.Get() ); // set by RE_LoadWorldMap
46944708
tr.mapLightFactor = 1.0f; // set by RE_LoadWorldMap
46954709
tr.identityLight = 1.0f; // set by RE_LoadWorldMap
4696-
tr.worldLinearizeTexture = false;
46974710
tr.worldLinearizeLightMap = false;
46984711

46994712
s_worldData = {};

src/engine/renderer/tr_init.cpp

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

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

1348+
Cvar::Latch( r_forceBlendRegime );
1349+
tr.worldLinearizeTexture = r_forceBlendRegime.Get() == 2;
1350+
13461351
tr.lightMode = lightMode_t( r_lightMode.Get() );
13471352

13481353
if ( !Com_AreCheatsAllowed() )

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ enum
24302430
bool worldLightMapping;
24312431
bool worldDeluxeMapping;
24322432
bool worldHDR_RGBE;
2433-
bool worldLinearizeTexture;
2433+
bool worldLinearizeTexture; // this determines whether linear or naive blending is used
24342434
bool worldLinearizeLightMap;
24352435

24362436
floatProcessor_t convertFloatFromSRGB;
@@ -2646,6 +2646,7 @@ enum
26462646
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
26472647
extern Cvar::Cvar<bool> r_overbrightQ3;
26482648
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
2649+
extern Cvar::Range<Cvar::Cvar<int>> r_forceBlendRegime;
26492650
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
26502651
extern Cvar::Cvar<bool> r_colorGrading;
26512652
extern Cvar::Cvar<bool> r_preferBindlessTextures;

0 commit comments

Comments
 (0)