Skip to content
Draft
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
14 changes: 7 additions & 7 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2861,11 +2861,8 @@ class u_ColorModulateColorGen_Uint :
ALPHA_MINUS_ONE = 3,
ALPHA_ADD_ONE = 4,
// <-- Insert new bits there.
IS_LIGHT_STYLE = 27,
LIGHTFACTOR_BIT0 = 28,
LIGHTFACTOR_BIT1 = 29,
LIGHTFACTOR_BIT2 = 30,
LIGHTFACTOR_BIT3 = 31,
IS_LIGHT_STYLE = 10,
LIGHTFACTOR_BIT0 = 11,
// There should be not bit higher than the light factor.
};

Expand All @@ -2883,8 +2880,11 @@ class u_ColorModulateColorGen_Uint :
<< Util::ordinal( ColorModulate_Bit::ALPHA_ADD_ONE );
colorModulate_Uint |= colorModulation.useVertexLightFactor
<< Util::ordinal( ColorModulate_Bit::IS_LIGHT_STYLE );
colorModulate_Uint |= uint32_t( colorModulation.lightFactor )
<< Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );

// Light factor unit is 128 / ( 1 << 21 )
// needs to go up to pow( 8, 2.2 ) = 97.006
uint32_t lightFactorBits = lrintf( colorModulation.lightFactor * 16384.0f );
colorModulate_Uint |= lightFactorBits << Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 );

this->SetValue( colorModulate_Uint );
}
Expand Down
8 changes: 4 additions & 4 deletions src/engine/renderer/glsl_source/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ colorMod << 1: color * ( -1 )
colorMod << 2: alpha * 1
colorMod << 3: alpha * ( -1 )
colorMod << 4: alpha = 1
colorMod << 5-26: available for future usage
colorMod << 27: color += lightFactor
colorMod << 28-31: lightFactor
colorMod << 5-9: available for future usage
colorMod << 10: color += lightFactor
colorMod << 11-31: lightFactor

colorMod float format:

Expand Down Expand Up @@ -123,7 +123,7 @@ ModBits_t ColorModulateToBits( const in colorModulatePack colorMod )
float ColorModulateToLightFactor( const in colorModulatePack colorMod )
{
#if defined(HAVE_EXT_gpu_shader4)
return float( colorMod >> 28u );
return float( colorMod >> 11u ) * ( 1.0 / 16384 );
#else
return abs( colorMod.g );
#endif
Expand Down
37 changes: 25 additions & 12 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
int lightMapBits = IF_LIGHTMAP | IF_NOPICMIP;
int deluxeMapBits = IF_NORMALMAP | IF_NOPICMIP;

if ( tr.worldLinearizeLightMap )
if ( tr.worldLinearizeTexture )
{
lightMapBits |= IF_SRGB;
}
Expand Down Expand Up @@ -3917,15 +3917,18 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
tr.worldLinearizeLightMap = true;
}

if ( sRGBcolor && sRGBtex )
{
Log::Debug( "Map features lights computed with linear colors and textures." );
tr.worldLinearizeTexture = true;
}
else if ( sRGBcolor != sRGBtex )
if ( !r_forceBlendRegime.Get() )
{
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." );
tr.worldLinearizeTexture = true;
if ( sRGBcolor && sRGBtex )
{
Log::Debug( "Map features lights computed with linear colors and textures." );
tr.worldLinearizeTexture = true;
}
else if ( sRGBcolor != sRGBtex )
{
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." );
tr.worldLinearizeTexture = true;
}
}

continue;
Expand Down Expand Up @@ -4631,12 +4634,23 @@ static void SetWorldLight() {

/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
if ( tr.lightMode != lightMode_t::FULLBRIGHT ) {
float factor = float( 1 << tr.overbrightBits );

if ( tr.worldLinearizeLightMap && !tr.worldLinearizeTexture )
{
factor = powf( factor, 1.0f / 2.2f );
}
else if ( !tr.worldLinearizeLightMap && tr.worldLinearizeTexture )
{
factor = powf( factor, 2.2f );
}

if ( r_overbrightQ3.Get() ) {
// light factor is applied to entire color buffer; identityLight can be used to cancel it
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
tr.identityLight = 1.0f / factor;
} else {
// light factor is applied wherever a precomputed light is sampled
tr.mapLightFactor = float( 1 << tr.overbrightBits );
tr.mapLightFactor = factor;
}
}
}
Expand Down Expand Up @@ -4693,7 +4707,6 @@ void RE_LoadWorldMap( const char *name )
tr.overbrightBits = std::min( tr.mapOverBrightBits, r_overbrightBits.Get() ); // set by RE_LoadWorldMap
tr.mapLightFactor = 1.0f; // set by RE_LoadWorldMap
tr.identityLight = 1.0f; // set by RE_LoadWorldMap
tr.worldLinearizeTexture = false;
tr.worldLinearizeLightMap = false;

s_worldData = {};
Expand Down
5 changes: 5 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Cvar::Cvar<int> r_rendererAPI( "r_rendererAPI", "Renderer API: 0: OpenGL, 1: Vul
Cvar::Cvar<bool> r_overbrightQ3("r_overbrightQ3", "brighten entire color buffer like Quake 3 (incompatible with newer assets)", 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_forceBlendRegime(
"r_forceBlendRegime", "override map settings to use: 1 = naive blending, 2 = linear blending", Cvar::NONE, 0, 0, 2);
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 );
static Cvar::Range<Cvar::Cvar<int>> r_readonlyDepthBuffer(
Expand Down Expand Up @@ -1343,6 +1345,9 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
return false;
}

Cvar::Latch( r_forceBlendRegime );
tr.worldLinearizeTexture = r_forceBlendRegime.Get() == 2;

tr.lightMode = lightMode_t( r_lightMode.Get() );

if ( !Com_AreCheatsAllowed() )
Expand Down
3 changes: 2 additions & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ enum
bool worldLightMapping;
bool worldDeluxeMapping;
bool worldHDR_RGBE;
bool worldLinearizeTexture;
bool worldLinearizeTexture; // this determines whether linear or naive blending is used
bool worldLinearizeLightMap;

floatProcessor_t convertFloatFromSRGB;
Expand Down Expand Up @@ -2646,6 +2646,7 @@ enum
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
extern Cvar::Cvar<bool> r_overbrightQ3;
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
extern Cvar::Range<Cvar::Cvar<int>> r_forceBlendRegime;
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
extern Cvar::Cvar<bool> r_colorGrading;
extern Cvar::Cvar<bool> r_preferBindlessTextures;
Expand Down