Skip to content

Commit 2f4202d

Browse files
committed
Add cvar r_overbrightQ3 to simulate its overbright
The Quake 3 overbright implementation worked by scaling up the entire color buffer. For surfaces that were not lit by precomputed lighting you had to use cgen identityLighting to cancel out. This breaks a lot of stuff so this cvar is only for testing.
1 parent f27fdce commit 2f4202d

File tree

9 files changed

+45
-24
lines changed

9 files changed

+45
-24
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,7 @@ GLShader_cameraEffects::GLShader_cameraEffects( GLShaderManager *manager ) :
28972897
GLShader( "cameraEffects", ATTR_POSITION | ATTR_TEXCOORD, manager ),
28982898
u_ColorMap3D( this ),
28992899
u_CurrentMap( this ),
2900+
u_GlobalLightFactor( this ),
29002901
u_ColorModulate( this ),
29012902
u_TextureMatrix( this ),
29022903
u_ModelViewProjectionMatrix( this ),

src/engine/renderer/gl_shader.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,6 +3536,21 @@ class u_Time :
35363536
}
35373537
};
35383538

3539+
class u_GlobalLightFactor :
3540+
GLUniform1f
3541+
{
3542+
public:
3543+
u_GlobalLightFactor( GLShader *shader ) :
3544+
GLUniform1f( shader, "u_GlobalLightFactor" )
3545+
{
3546+
}
3547+
3548+
void SetUniform_GlobalLightFactor( float value )
3549+
{
3550+
this->SetValue( value );
3551+
}
3552+
};
3553+
35393554
class GLDeformStage :
35403555
public u_Time
35413556
{
@@ -4459,6 +4474,7 @@ class GLShader_cameraEffects :
44594474
public GLShader,
44604475
public u_ColorMap3D,
44614476
public u_CurrentMap,
4477+
public u_GlobalLightFactor,
44624478
public u_ColorModulate,
44634479
public u_TextureMatrix,
44644480
public u_ModelViewProjectionMatrix,

src/engine/renderer/glsl_source/cameraEffects_fp.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ uniform sampler3D u_ColorMap3D;
2929
#endif
3030

3131
uniform vec4 u_ColorModulate;
32+
uniform float u_GlobalLightFactor; // 1 / tr.identityLight
3233
uniform float u_InverseGamma;
3334

3435
IN(smooth) vec2 var_TexCoords;
@@ -55,6 +56,7 @@ void main()
5556
vec2 st = gl_FragCoord.st / r_FBufSize;
5657

5758
vec4 color = texture2D(u_CurrentMap, st);
59+
color *= u_GlobalLightFactor;
5860

5961
if( u_Tonemap ) {
6062
color.rgb = TonemapLottes( color.rgb * u_TonemapExposure );

src/engine/renderer/tr_backend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,7 @@ void RB_CameraPostFX()
33503350
// enable shader, set arrays
33513351
gl_cameraEffectsShader->BindProgram( 0 );
33523352

3353+
gl_cameraEffectsShader->SetUniform_GlobalLightFactor( 1.0f / tr.identityLight );
33533354
gl_cameraEffectsShader->SetUniform_ColorModulate( backEnd.viewParms.gradingWeights );
33543355

33553356
gl_cameraEffectsShader->SetUniform_InverseGamma( 1.0 / r_gamma->value );

src/engine/renderer/tr_bsp.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,14 +3883,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
38833883
out->fogParms = shader->fogParms;
38843884

38853885
out->color = Color::Adapt( shader->fogParms.color );
3886-
3887-
/* Historically it was done:
3888-
3889-
out->color *= tr.identityLight;
3890-
3891-
But tr.identityLight is always 1.0f in Dæmon engine
3892-
as the as the overbright bit implementation is fully
3893-
software. */
3886+
out->color *= tr.identityLight;
38943887

38953888
out->color.SetAlpha( 1 );
38963889

@@ -5138,6 +5131,7 @@ void RE_LoadWorldMap( const char *name )
51385131
tr.worldLight = tr.lightMode;
51395132
tr.modelLight = lightMode_t::FULLBRIGHT;
51405133
tr.modelDeluxe = deluxeMode_t::NONE;
5134+
tr.mapLightFactor = tr.identityLight = 1.0f;
51415135

51425136
// Use fullbright lighting for everything if the world is fullbright.
51435137
if ( tr.worldLight != lightMode_t::FULLBRIGHT )
@@ -5209,11 +5203,19 @@ void RE_LoadWorldMap( const char *name )
52095203
}
52105204
}
52115205

5212-
/* Set GLSL overbright parameters if the legacy clamped overbright isn't used
5213-
and the lighting mode is not fullbright. */
5206+
/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
52145207
if ( tr.lightMode != lightMode_t::FULLBRIGHT )
52155208
{
5216-
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5209+
if ( r_overbrightQ3.Get() )
5210+
{
5211+
// light factor is applied to entire color buffer; identityLight can be used to cancel it
5212+
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
5213+
}
5214+
else
5215+
{
5216+
// light factor is applied wherever a precomputed light is sampled
5217+
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5218+
}
52175219
}
52185220

52195221
tr.worldLoaded = true;

src/engine/renderer/tr_init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9393
cvar_t *r_precomputedLighting;
9494
Cvar::Cvar<int> r_overbrightDefaultExponent("r_overbrightDefaultExponent", "default map light color shift (multiply by 2^x)", Cvar::NONE, 2);
9595
Cvar::Range<Cvar::Cvar<int>> r_overbrightBits("r_overbrightBits", "clamp lightmap colors to 2^x", Cvar::NONE, 1, 0, 3);
96+
Cvar::Cvar<bool> r_overbrightQ3("r_overbrightQ3", "brighten entire color buffer like Quake 3 (incompatible with newer assets)", Cvar::NONE, false);
9697
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false);
9798
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));
9899
Cvar::Cvar<bool> r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true );
@@ -1186,6 +1187,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11861187
r_precomputedLighting = Cvar_Get( "r_precomputedLighting", "1", CVAR_CHEAT | CVAR_LATCH );
11871188
Cvar::Latch( r_overbrightDefaultExponent );
11881189
Cvar::Latch( r_overbrightBits );
1190+
Cvar::Latch( r_overbrightQ3 );
11891191
Cvar::Latch( r_overbrightIgnoreMapSettings );
11901192
Cvar::Latch( r_lightMode );
11911193
Cvar::Latch( r_colorGrading );

src/engine/renderer/tr_local.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ enum class shaderProfilerRenderSubGroupsMode {
825825
enum class colorGen_t
826826
{
827827
CGEN_BAD,
828-
CGEN_IDENTITY_LIGHTING, // Always (1,1,1,1) in Dæmon engine as the overbright bit implementation is fully software.
828+
CGEN_IDENTITY_LIGHTING, // Always (1,1,1,1) in Dæmon engine, unless you set r_overbrightQ3.
829829
CGEN_IDENTITY, // always (1,1,1,1)
830830
CGEN_ENTITY, // grabbed from entity's modulate field
831831
CGEN_ONE_MINUS_ENTITY, // grabbed from 1 - entity.modulate
@@ -2815,8 +2815,10 @@ enum class shaderProfilerRenderSubGroupsMode {
28152815
int mapOverBrightBits;
28162816
// min(r_overbrightBits.Get(), mapOverBrightBits)
28172817
int overbrightBits;
2818-
// pow(2, overbrightBits)
2818+
// pow(2, overbrightBits), unless r_overbrightQ3 is on
28192819
float mapLightFactor;
2820+
// 1/pow(2, overbrightBits) if r_overbrightQ3 is on
2821+
float identityLight;
28202822

28212823
orientationr_t orientation; // for current entity
28222824

@@ -2941,6 +2943,7 @@ enum class shaderProfilerRenderSubGroupsMode {
29412943
extern cvar_t *r_precomputedLighting;
29422944
extern Cvar::Cvar<int> r_overbrightDefaultExponent;
29432945
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
2946+
extern Cvar::Cvar<bool> r_overbrightQ3;
29442947
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
29452948
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
29462949
extern Cvar::Cvar<bool> r_colorGrading;

src/engine/renderer/tr_shade.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,21 +2321,15 @@ void Tess_ComputeColor( shaderStage_t *pStage )
23212321
// rgbGen
23222322
switch ( pStage->rgbGen )
23232323
{
2324+
case colorGen_t::CGEN_IDENTITY_LIGHTING:
2325+
tess.svars.color = Color::Color(tr.identityLight, tr.identityLight, tr.identityLight);
2326+
break;
2327+
23242328
case colorGen_t::CGEN_IDENTITY:
23252329
case colorGen_t::CGEN_ONE_MINUS_VERTEX:
23262330
default:
2327-
case colorGen_t::CGEN_IDENTITY_LIGHTING:
2328-
/* Historically CGEN_IDENTITY_LIGHTING was done this way:
2329-
2330-
tess.svars.color = Color::White * tr.identityLight;
2331-
2332-
But tr.identityLight is always 1.0f in Dæmon engine
2333-
as the as the overbright bit implementation is fully
2334-
software. */
2335-
{
23362331
tess.svars.color = Color::White;
23372332
break;
2338-
}
23392333

23402334
case colorGen_t::CGEN_VERTEX:
23412335
{

src/engine/renderer/tr_shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4836,7 +4836,7 @@ static void CollapseStages()
48364836

48374837
bool rgbGen_identity =
48384838
stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY
4839-
|| stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY_LIGHTING;
4839+
|| ( stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY_LIGHTING && !r_overbrightQ3.Get() );
48404840

48414841
bool alphaGen_identity =
48424842
stages[ i ].alphaGen == alphaGen_t::AGEN_IDENTITY;

0 commit comments

Comments
 (0)