Skip to content

Commit 6ed75ce

Browse files
committed
Don't lose precision while linearizing light grid
In one step of light grid processing, values were converted from sRGB to linear and stored in bytes. This unnecessarily loses precision during the calculation.
1 parent c143244 commit 6ed75ce

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/common/Color.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ inline void convertFromSRGB( float* v, bool accurate = true )
5555
v[ 2 ] = convertFromSRGB( v[ 2 ], accurate );
5656
}
5757

58+
// Beware: this instantly loses precision, there are less than 256 possible outputs!
5859
inline void convertFromSRGB( byte* bytes, bool accurate = true )
5960
{
6061
vec3_t v;

src/engine/renderer/tr_bsp.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,9 +3590,6 @@ void R_LoadLightGrid( lump_t *l )
35903590
tmpDirected[ 2 ] = in->directed[ 2 ];
35913591
tmpDirected[ 3 ] = 255;
35923592

3593-
R_LinearizeLightingColorBytes( tmpAmbient );
3594-
R_LinearizeLightingColorBytes( tmpDirected );
3595-
35963593
R_ColorShiftLightingBytes( tmpAmbient );
35973594
R_ColorShiftLightingBytes( tmpDirected );
35983595

@@ -3602,6 +3599,12 @@ void R_LoadLightGrid( lump_t *l )
36023599
directedColor[ j ] = tmpDirected[ j ] * ( 1.0f / 255.0f );
36033600
}
36043601

3602+
if ( tr.worldLinearizeTexture )
3603+
{
3604+
convertFromSRGB( ambientColor );
3605+
convertFromSRGB( directedColor );
3606+
}
3607+
36053608
const float forceAmbient = r_forceAmbient.Get();
36063609
if ( ambientColor[0] < forceAmbient &&
36073610
ambientColor[1] < forceAmbient &&

0 commit comments

Comments
 (0)