Skip to content

Commit ef6d4c7

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 c393524 commit ef6d4c7

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
@@ -3877,14 +3877,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
38773877
out->fogParms = shader->fogParms;
38783878

38793879
out->color = Color::Adapt( shader->fogParms.color );
3880-
3881-
/* Historically it was done:
3882-
3883-
out->color *= tr.identityLight;
3884-
3885-
But tr.identityLight is always 1.0f in Dæmon engine
3886-
as the as the overbright bit implementation is fully
3887-
software. */
3880+
out->color *= tr.identityLight;
38883881

38893882
out->color.SetAlpha( 1 );
38903883

@@ -5126,6 +5119,7 @@ void RE_LoadWorldMap( const char *name )
51265119
tr.worldLight = tr.lightMode;
51275120
tr.modelLight = lightMode_t::FULLBRIGHT;
51285121
tr.modelDeluxe = deluxeMode_t::NONE;
5122+
tr.mapLightFactor = tr.identityLight = 1.0f;
51295123

51305124
// Use fullbright lighting for everything if the world is fullbright.
51315125
if ( tr.worldLight != lightMode_t::FULLBRIGHT )
@@ -5197,11 +5191,19 @@ void RE_LoadWorldMap( const char *name )
51975191
}
51985192
}
51995193

5200-
/* Set GLSL overbright parameters if the legacy clamped overbright isn't used
5201-
and the lighting mode is not fullbright. */
5194+
/* Set GLSL overbright parameters if the lighting mode is not fullbright. */
52025195
if ( tr.lightMode != lightMode_t::FULLBRIGHT )
52035196
{
5204-
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5197+
if ( r_overbrightQ3.Get() )
5198+
{
5199+
// light factor is applied to entire color buffer; identityLight can be used to cancel it
5200+
tr.identityLight = 1.0f / float( 1 << tr.overbrightBits );
5201+
}
5202+
else
5203+
{
5204+
// light factor is applied wherever a precomputed light is sampled
5205+
tr.mapLightFactor = float( 1 << tr.overbrightBits );
5206+
}
52055207
}
52065208

52075209
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
@@ -2817,8 +2817,10 @@ enum class shaderProfilerRenderSubGroupsMode {
28172817
int mapOverBrightBits;
28182818
// min(r_overbrightBits.Get(), mapOverBrightBits)
28192819
int overbrightBits;
2820-
// pow(2, overbrightBits)
2820+
// pow(2, overbrightBits), unless r_overbrightQ3 is on
28212821
float mapLightFactor;
2822+
// 1/pow(2, overbrightBits) if r_overbrightQ3 is on
2823+
float identityLight;
28222824

28232825
orientationr_t orientation; // for current entity
28242826

@@ -2943,6 +2945,7 @@ enum class shaderProfilerRenderSubGroupsMode {
29432945
extern cvar_t *r_precomputedLighting;
29442946
extern Cvar::Cvar<int> r_overbrightDefaultExponent;
29452947
extern Cvar::Range<Cvar::Cvar<int>> r_overbrightBits;
2948+
extern Cvar::Cvar<bool> r_overbrightQ3;
29462949
extern Cvar::Cvar<bool> r_overbrightIgnoreMapSettings;
29472950
extern Cvar::Range<Cvar::Cvar<int>> r_lightMode;
29482951
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
@@ -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)