Skip to content

Commit 0682adf

Browse files
committed
tr_image: store the fog alpha channel in red one so we can apply colorspace conversions on it
1 parent bb467ea commit 0682adf

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void main()
5353
// st.s = vertexDistanceToCamera;
5454
st.t = 1.0;
5555

56-
vec4 color = texture2D(u_ColorMap, st);
56+
vec4 color = vec4( vec3( 1.0 ), texture2D( u_ColorMap, st ).r );
5757

5858
outputColor = UnpackColor( u_Color ) * color;
5959
}

src/engine/renderer/glsl_source/fogQuake3_fp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void main()
3636
{
3737
#insert material_fp
3838

39-
vec4 color = texture2D(u_FogMap, var_TexCoords);
39+
vec4 color = vec4( vec3( 1.0 ), texture2D( u_FogMap, var_TexCoords ).r );
4040

4141
color *= var_Color;
4242

src/engine/renderer/tr_image.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,26 +2407,21 @@ static void R_CreateFogImage()
24072407

24082408
constexpr size_t FOG_S = 256;
24092409
constexpr size_t FOG_T = 32;
2410-
constexpr channels = 4;
2410+
constexpr size_t channels = 4;
24112411

2412-
byte *dataNaive, *ptrNaive;
2413-
byte *dataLinear, *ptrLinear;
2414-
ptrNaive = dataNaive = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * channels );
2415-
ptrLinear = dataLinear = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * channels );
2412+
byte *data, *ptr;
2413+
ptr = data = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * channels );
24162414

24172415
// S is distance, T is depth
2418-
for ( int y = 0; y < FOG_T; y++ )
2416+
for ( size_t y = 0; y < FOG_T; y++ )
24192417
{
2420-
for ( int x = 0; x < FOG_S; x++ )
2418+
for ( size_t x = 0; x < FOG_S; x++ )
24212419
{
24222420
float d = R_FogFactor( ( x + 0.5f ) / FOG_S, ( y + 0.5f ) / FOG_T );
24232421

2424-
ptrNaive[ 0 ] = ptrNaive[ 1 ] = ptrNaive[ 2 ] = 255;
2425-
ptrLinear[ 0 ] = ptrLinear[ 1 ] = ptrLinear[ 2 ] = 255;
2426-
ptrNaive[ 3 ] = 255 * d;
2427-
ptrLinear[ 3 ] = 255 * convertFromSRGB( d );
2428-
ptrNaive += channels;
2429-
ptrLinear += channels;
2422+
ptr[ 0 ] = 255 * d;
2423+
ptr[ 1 ] = ptr[ 2 ] = ptr[ 3 ] = 255;
2424+
ptr += channels;
24302425
}
24312426
}
24322427

@@ -2438,11 +2433,12 @@ static void R_CreateFogImage()
24382433
imageParams.filterType = filterType_t::FT_DEFAULT;
24392434
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24402435

2441-
tr.fogImageNaive = R_CreateImage( "_fogNaive", ( const byte ** ) &dataNaive, FOG_S, FOG_T, 1, imageParams );
2442-
tr.fogImageLinear = R_CreateImage( "_fogLinear", ( const byte ** ) &dataLinear, FOG_S, FOG_T, 1, imageParams );
2436+
tr.fogImageNaive = R_CreateImage( "_fogNaive", ( const byte ** ) &data, FOG_S, FOG_T, 1, imageParams );
2437+
2438+
imageParams.bits |= IF_SRGB;
2439+
tr.fogImageLinear = R_CreateImage( "_fogLinear", ( const byte ** ) &data, FOG_S, FOG_T, 1, imageParams );
24432440

2444-
ri.Hunk_FreeTempMemory( dataNaive );
2445-
ri.Hunk_FreeTempMemory( dataLinear );
2441+
ri.Hunk_FreeTempMemory( data );
24462442

24472443
/* Just to be safe and not leave a null pointer in the wild.
24482444
This is modified when a map is loaded. */

0 commit comments

Comments
 (0)