Skip to content

Commit f49cbfe

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 d9b3615 commit f49cbfe

File tree

9 files changed

+45
-25
lines changed

9 files changed

+45
-25
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,7 @@ GLShader_cameraEffects::GLShader_cameraEffects( GLShaderManager *manager ) :
28932893
GLShader( "cameraEffects", ATTR_POSITION | ATTR_TEXCOORD, manager ),
28942894
u_ColorMap3D( this ),
28952895
u_CurrentMap( this ),
2896+
u_GlobalLightFactor( this ),
28962897
u_ColorModulate( this ),
28972898
u_TextureMatrix( this ),
28982899
u_ModelViewProjectionMatrix( this ),

src/engine/renderer/gl_shader.h

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

3540+
class u_GlobalLightFactor :
3541+
GLUniform1f
3542+
{
3543+
public:
3544+
u_GlobalLightFactor( GLShader *shader ) :
3545+
GLUniform1f( shader, "u_GlobalLightFactor" )
3546+
{
3547+
}
3548+
3549+
void SetUniform_GlobalLightFactor( float value )
3550+
{
3551+
this->SetValue( value );
3552+
}
3553+
};
3554+
35403555
class GLDeformStage :
35413556
public u_Time
35423557
{
@@ -4424,6 +4439,7 @@ class GLShader_cameraEffects :
44244439
public GLShader,
44254440
public u_ColorMap3D,
44264441
public u_CurrentMap,
4442+
public u_GlobalLightFactor,
44274443
public u_ColorModulate,
44284444
public u_TextureMatrix,
44294445
public u_ModelViewProjectionMatrix,

src/engine/renderer/glsl_source/cameraEffects_fp.glsl

Lines changed: 2 additions & 1 deletion
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;
@@ -41,7 +42,7 @@ void main()
4142
vec2 st = gl_FragCoord.st / r_FBufSize;
4243

4344
vec4 color = texture2D(u_CurrentMap, st);
44-
45+
color *= u_GlobalLightFactor;
4546
color = clamp(color, 0.0, 1.0);
4647

4748
#if defined(r_colorGrading)

src/engine/renderer/tr_backend.cpp

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

3331+
gl_cameraEffectsShader->SetUniform_GlobalLightFactor( 1.0f / tr.identityLight );
33313332
gl_cameraEffectsShader->SetUniform_ColorModulate( backEnd.viewParms.gradingWeights );
33323333

33333334
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
@@ -3910,14 +3910,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
39103910
out->fogParms = shader->fogParms;
39113911

39123912
out->color = Color::Adapt( shader->fogParms.color );
3913-
3914-
/* Historically it was done:
3915-
3916-
out->color *= tr.identityLight;
3917-
3918-
But tr.identityLight is always 1.0f in Dæmon engine
3919-
as the as the overbright bit implementation is fully
3920-
software. */
3913+
out->color *= tr.identityLight;
39213914

39223915
out->color.SetAlpha( 1 );
39233916

@@ -5159,6 +5152,7 @@ void RE_LoadWorldMap( const char *name )
51595152
tr.worldLight = tr.lightMode;
51605153
tr.modelLight = lightMode_t::FULLBRIGHT;
51615154
tr.modelDeluxe = deluxeMode_t::NONE;
5155+
tr.mapLightFactor = tr.identityLight = 1.0f;
51625156

51635157
// Use fullbright lighting for everything if the world is fullbright.
51645158
if ( tr.worldLight != lightMode_t::FULLBRIGHT )
@@ -5230,11 +5224,19 @@ void RE_LoadWorldMap( const char *name )
52305224
}
52315225
}
52325226

5233-
/* Set GLSL overbright parameters if the legacy clamped overbright isn't used
5234-
and the lighting mode is not fullbright. */
5227+
/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
52355228
if ( tr.lightMode != lightMode_t::FULLBRIGHT )
52365229
{
5237-
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5230+
if ( r_overbrightQ3.Get() )
5231+
{
5232+
// light factor is applied to entire color buffer; identityLight can be used to cancel it
5233+
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
5234+
}
5235+
else
5236+
{
5237+
// light factor is applied wherever a precomputed light is sampled
5238+
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5239+
}
52385240
}
52395241

52405242
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 );
@@ -1169,6 +1170,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11691170
r_precomputedLighting = Cvar_Get( "r_precomputedLighting", "1", CVAR_CHEAT | CVAR_LATCH );
11701171
Cvar::Latch( r_overbrightDefaultExponent );
11711172
Cvar::Latch( r_overbrightBits );
1173+
Cvar::Latch( r_overbrightQ3 );
11721174
Cvar::Latch( r_overbrightIgnoreMapSettings );
11731175
Cvar::Latch( r_lightMode );
11741176
Cvar::Latch( r_colorGrading );

src/engine/renderer/tr_local.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ enum class shaderProfilerRenderSubGroupsMode {
826826
enum class colorGen_t
827827
{
828828
CGEN_BAD,
829-
CGEN_IDENTITY_LIGHTING, // Always (1,1,1,1) in Dæmon engine as the overbright bit implementation is fully software.
829+
CGEN_IDENTITY_LIGHTING, // Always (1,1,1,1) in Dæmon engine, unless you set r_overbrightQ3.
830830
CGEN_IDENTITY, // always (1,1,1,1)
831831
CGEN_ENTITY, // grabbed from entity's modulate field
832832
CGEN_ONE_MINUS_ENTITY, // grabbed from 1 - entity.modulate
@@ -2831,8 +2831,10 @@ enum class shaderProfilerRenderSubGroupsMode {
28312831
int mapOverBrightBits;
28322832
// min(r_overbrightBits.Get(), mapOverBrightBits)
28332833
int overbrightBits;
2834-
// pow(2, overbrightBits)
2834+
// pow(2, overbrightBits), unless r_overbrightQ3 is on
28352835
float mapLightFactor;
2836+
// 1/pow(2, overbrightBits) if r_overbrightQ3 is on
2837+
float identityLight;
28362838

28372839
orientationr_t orientation; // for current entity
28382840

@@ -2957,6 +2959,7 @@ enum class shaderProfilerRenderSubGroupsMode {
29572959
extern cvar_t *r_precomputedLighting;
29582960
extern Cvar::Cvar<int> r_overbrightDefaultExponent;
29592961
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
2962+
extern Cvar::Cvar<bool> r_overbrightQ3;
29602963
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
29612964
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
29622965
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
@@ -2323,21 +2323,15 @@ void Tess_ComputeColor( shaderStage_t *pStage )
23232323
// rgbGen
23242324
switch ( pStage->rgbGen )
23252325
{
2326+
case colorGen_t::CGEN_IDENTITY_LIGHTING:
2327+
tess.svars.color = Color::Color(tr.identityLight, tr.identityLight, tr.identityLight);
2328+
break;
2329+
23262330
case colorGen_t::CGEN_IDENTITY:
23272331
case colorGen_t::CGEN_ONE_MINUS_VERTEX:
23282332
default:
2329-
case colorGen_t::CGEN_IDENTITY_LIGHTING:
2330-
/* Historically CGEN_IDENTITY_LIGHTING was done this way:
2331-
2332-
tess.svars.color = Color::White * tr.identityLight;
2333-
2334-
But tr.identityLight is always 1.0f in Dæmon engine
2335-
as the as the overbright bit implementation is fully
2336-
software. */
2337-
{
23382333
tess.svars.color = Color::White;
23392334
break;
2340-
}
23412335

23422336
case colorGen_t::CGEN_VERTEX:
23432337
{

src/engine/renderer/tr_shader.cpp

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

48484848
bool rgbGen_identity =
48494849
stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY
4850-
|| stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY_LIGHTING;
4850+
|| ( stages[ i ].rgbGen == colorGen_t::CGEN_IDENTITY_LIGHTING && !r_overbrightQ3.Get() );
48514851

48524852
bool alphaGen_identity =
48534853
stages[ i ].alphaGen == alphaGen_t::AGEN_IDENTITY;

0 commit comments

Comments
 (0)