@@ -74,10 +74,7 @@ static void R_ColorShiftLightingBytes( byte bytes[ 4 ] )
7474 backward compatible with this bug for diagnostic purpose and fair comparison with
7575 other buggy engines. */
7676
77- if ( tr.mapOverBrightBits == 0 )
78- {
79- return ;
80- }
77+ ASSERT_LT ( tr.overbrightBits , tr.mapOverBrightBits );
8178
8279 /* Shift the color data based on overbright range.
8380
@@ -94,7 +91,7 @@ static void R_ColorShiftLightingBytes( byte bytes[ 4 ] )
9491 what hardware overbright bit feature was not doing, but
9592 this implementation is entirely software. */
9693
97- int shift = tr.mapOverBrightBits ;
94+ int shift = tr.mapOverBrightBits - tr. overbrightBits ;
9895
9996 // shift the data based on overbright range
10097 int r = bytes[ 0 ] << shift;
@@ -120,10 +117,7 @@ static void R_ColorShiftLightingBytes( byte bytes[ 4 ] )
120117
121118static void R_ColorShiftLightingBytesCompressed ( byte bytes[ 8 ] )
122119{
123- if ( tr.mapOverBrightBits == 0 )
124- {
125- return ;
126- }
120+ ASSERT_LT ( tr.overbrightBits , tr.mapOverBrightBits );
127121
128122 // color shift the endpoint colors in the dxt block
129123 unsigned short rgb565 = bytes[1 ] << 8 | bytes[0 ];
@@ -164,7 +158,7 @@ R_ProcessLightmap
164158*/
165159void R_ProcessLightmap ( byte *bytes, int width, int height, int bits )
166160{
167- if ( tr.mapOverBrightBits == 0 )
161+ if ( tr.overbrightBits >= tr. mapOverBrightBits )
168162 {
169163 return ;
170164 }
@@ -668,7 +662,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
668662 lightMapBuffer[( index * 4 ) + 2 ] = buf_p[( ( x + ( y * internalLightMapSize ) ) * 3 ) + 2 ];
669663 lightMapBuffer[( index * 4 ) + 3 ] = 255 ;
670664
671- if ( tr.legacyOverBrightClamping )
665+ if ( tr.overbrightBits < tr. mapOverBrightBits )
672666 {
673667 R_ColorShiftLightingBytes ( &lightMapBuffer[( index * 4 ) + 0 ] );
674668 }
@@ -1029,7 +1023,7 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf, in
10291023 cv->verts [ i ].lightColor = Color::Adapt ( verts[ i ].color );
10301024
10311025
1032- if ( tr.legacyOverBrightClamping )
1026+ if ( tr.overbrightBits < tr. mapOverBrightBits )
10331027 {
10341028 R_ColorShiftLightingBytes ( cv->verts [ i ].lightColor .ToArray () );
10351029 }
@@ -1239,7 +1233,7 @@ static void ParseMesh( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf )
12391233
12401234 points[ i ].lightColor = Color::Adapt ( verts[ i ].color );
12411235
1242- if ( tr.legacyOverBrightClamping )
1236+ if ( tr.overbrightBits < tr. mapOverBrightBits )
12431237 {
12441238 R_ColorShiftLightingBytes ( points[ i ].lightColor .ToArray () );
12451239 }
@@ -1366,7 +1360,7 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, bspSurface_t *surf,
13661360
13671361 cv->verts [ i ].lightColor = Color::Adapt ( verts[ i ].color );
13681362
1369- if ( tr.legacyOverBrightClamping )
1363+ if ( tr.overbrightBits < tr. mapOverBrightBits )
13701364 {
13711365 R_ColorShiftLightingBytes ( cv->verts [ i ].lightColor .ToArray () );
13721366 }
@@ -3889,14 +3883,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
38893883 out->fogParms = shader->fogParms ;
38903884
38913885 out->color = Color::Adapt ( shader->fogParms .color );
3892-
3893- /* Historically it was done:
3894-
3895- out->color *= tr.identityLight;
3896-
3897- But tr.identityLight is always 1.0f in Dæmon engine
3898- as the as the overbright bit implementation is fully
3899- software. */
3886+ out->color *= tr.identityLight ;
39003887
39013888 out->color .SetAlpha ( 1 );
39023889
@@ -4112,7 +4099,7 @@ void R_LoadLightGrid( lump_t *l )
41124099 tmpDirected[ 2 ] = in->directed [ 2 ];
41134100 tmpDirected[ 3 ] = 255 ;
41144101
4115- if ( tr.legacyOverBrightClamping )
4102+ if ( tr.overbrightBits < tr. mapOverBrightBits )
41164103 {
41174104 R_ColorShiftLightingBytes ( tmpAmbient );
41184105 R_ColorShiftLightingBytes ( tmpDirected );
@@ -4372,24 +4359,6 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
43724359 tr.mapOverBrightBits = Math::Clamp ( atof ( value ), 0.0 , 3.0 );
43734360 continue ;
43744361 }
4375-
4376- if ( !Q_stricmp ( keyname, " overbrightClamping" ) )
4377- {
4378- if ( !Q_stricmp ( value, " 0" ) )
4379- {
4380- tr.legacyOverBrightClamping = false ;
4381- }
4382- else if ( !Q_stricmp ( value, " 1" ) )
4383- {
4384- tr.legacyOverBrightClamping = true ;
4385- }
4386- else
4387- {
4388- Log::Warn ( " invalid value for worldspawn key overbrightClamping" );
4389- }
4390-
4391- continue ;
4392- }
43934362 }
43944363
43954364 // check for deluxe mapping provided by NetRadiant's q3map2
@@ -5070,11 +5039,15 @@ void RE_LoadWorldMap( const char *name )
50705039 // try will not look at the partially loaded version
50715040 tr.world = nullptr ;
50725041
5073- // tr.worldDeluxeMapping will be set by R_LoadLightmaps()
5074- tr.worldLightMapping = false ;
5075- // tr.worldDeluxeMapping will be set by R_LoadEntities()
5076- tr.worldDeluxeMapping = false ;
5077- tr.worldHDR_RGBE = false ;
5042+ // It's probably a mistake if any of these lighting parameters are actually
5043+ // used before a map is loaded.
5044+ tr.worldLightMapping = false ; // set by R_LoadLightmaps
5045+ tr.worldDeluxeMapping = false ; // set by R_LoadEntities
5046+ tr.worldHDR_RGBE = false ; // set by R_LoadEntities
5047+ tr.mapOverBrightBits = r_overbrightDefaultExponent.Get (); // maybe set by R_LoadEntities
5048+ tr.overbrightBits = std::min ( tr.mapOverBrightBits , r_overbrightBits.Get () ); // set by RE_LoadWorldMap
5049+ tr.mapLightFactor = 1 .0f ; // set by RE_LoadWorldMap
5050+ tr.identityLight = 1 .0f ; // set by RE_LoadWorldMap
50785051
50795052 s_worldData = {};
50805053 Q_strncpyz ( s_worldData.name , name, sizeof ( s_worldData.name ) );
@@ -5122,6 +5095,9 @@ void RE_LoadWorldMap( const char *name )
51225095 }
51235096 R_LoadEntities ( &header->lumps [ LUMP_ENTITIES ], externalEntities );
51245097
5098+ // Now we can set this after checking a possible worldspawn value for mapOverbrightBits
5099+ tr.overbrightBits = std::min ( tr.mapOverBrightBits , r_overbrightBits.Get () );
5100+
51255101 R_LoadShaders ( &header->lumps [ LUMP_SHADERS ] );
51265102
51275103 R_LoadLightmaps ( &header->lumps [ LUMP_LIGHTMAPS ], name );
@@ -5159,7 +5135,6 @@ void RE_LoadWorldMap( const char *name )
51595135 tr.worldLight = tr.lightMode ;
51605136 tr.modelLight = lightMode_t::FULLBRIGHT;
51615137 tr.modelDeluxe = deluxeMode_t::NONE;
5162- tr.mapLightFactor = 1 .0f ;
51635138
51645139 // Use fullbright lighting for everything if the world is fullbright.
51655140 if ( tr.worldLight != lightMode_t::FULLBRIGHT )
@@ -5231,11 +5206,19 @@ void RE_LoadWorldMap( const char *name )
52315206 }
52325207 }
52335208
5234- /* Set GLSL overbright parameters if the legacy clamped overbright isn't used
5235- and the lighting mode is not fullbright. */
5236- if ( !tr.legacyOverBrightClamping && tr.lightMode != lightMode_t::FULLBRIGHT )
5209+ /* Set GLSL overbright parameters if the lighting mode is not fullbright. */
5210+ if ( tr.lightMode != lightMode_t::FULLBRIGHT )
52375211 {
5238- tr.mapLightFactor = pow ( 2 , tr.mapOverBrightBits );
5212+ if ( r_overbrightQ3.Get () )
5213+ {
5214+ // light factor is applied to entire color buffer; identityLight can be used to cancel it
5215+ tr.identityLight = 1 .0f / float ( 1 << tr.overbrightBits );
5216+ }
5217+ else
5218+ {
5219+ // light factor is applied wherever a precomputed light is sampled
5220+ tr.mapLightFactor = float ( 1 << tr.overbrightBits );
5221+ }
52395222 }
52405223
52415224 tr.worldLoaded = true ;
0 commit comments