Skip to content

Commit 9a75a4d

Browse files
committed
tr_image: create two fog images for naive and sRGB pipelines
1 parent 041e0f1 commit 9a75a4d

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/engine/renderer/tr_bsp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,6 +3954,8 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities )
39543954
tr.convertColorFromSRGB = convertColorFromSRGB_cheap;
39553955
}
39563956
}
3957+
3958+
tr.fogImage = tr.worldLinearizeTexture ? tr.fogImageLinear : tr.fogImageNaive;
39573959
}
39583960

39593961
/*

src/engine/renderer/tr_image.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,26 +2405,27 @@ static void R_CreateFogImage()
24052405
{
24062406
// Fog image is always created because disabling fog is cheat.
24072407

2408-
int x, y;
2409-
byte *data, *ptr;
2410-
float d;
2411-
float borderColor[ 4 ];
2412-
24132408
constexpr int FOG_S = 256;
24142409
constexpr int FOG_T = 32;
24152410

2416-
ptr = data = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * 4 );
2411+
byte *dataNaive, *ptrNaive;
2412+
byte *dataLinear, *ptrLinear;
2413+
ptrNaive = dataNaive = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * 4 );
2414+
ptrLinear = dataLinear = (byte*) ri.Hunk_AllocateTempMemory( FOG_S * FOG_T * 4 );
24172415

24182416
// S is distance, T is depth
2419-
for ( y = 0; y < FOG_T; y++ )
2417+
for ( int y = 0; y < FOG_T; y++ )
24202418
{
2421-
for ( x = 0; x < FOG_S; x++ )
2419+
for ( int x = 0; x < FOG_S; x++ )
24222420
{
2423-
d = R_FogFactor( ( x + 0.5f ) / FOG_S, ( y + 0.5f ) / FOG_T );
2421+
float d = R_FogFactor( ( x + 0.5f ) / FOG_S, ( y + 0.5f ) / FOG_T );
24242422

2425-
ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 255;
2426-
ptr[ 3 ] = 255 * d;
2427-
ptr += 4;
2423+
ptrNaive[ 0 ] = ptrNaive[ 1 ] = ptrNaive[ 2 ] = 255;
2424+
ptrLinear[ 0 ] = ptrLinear[ 1 ] = ptrLinear[ 2 ] = 255;
2425+
ptrNaive[ 3 ] = 255 * d;
2426+
ptrLinear[ 3 ] = 255 * convertFromSRGB( d );
2427+
ptrNaive += 4;
2428+
ptrLinear += 4;
24282429
}
24292430
}
24302431

@@ -2436,13 +2437,18 @@ static void R_CreateFogImage()
24362437
imageParams.filterType = filterType_t::FT_DEFAULT;
24372438
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24382439

2439-
tr.fogImage = R_CreateImage( "_fog", ( const byte ** ) &data, FOG_S, FOG_T, 1, imageParams );
2440-
ri.Hunk_FreeTempMemory( data );
2440+
tr.fogImageNaive = R_CreateImage( "_fogNaive", ( const byte ** ) &dataNaive, FOG_S, FOG_T, 1, imageParams );
2441+
tr.fogImageLinear = R_CreateImage( "_fogLinear", ( const byte ** ) &dataLinear, FOG_S, FOG_T, 1, imageParams );
2442+
2443+
ri.Hunk_FreeTempMemory( dataNaive );
2444+
ri.Hunk_FreeTempMemory( dataLinear );
2445+
2446+
/* Just to be safe and not leave a null pointer in the wild.
2447+
This is modified when a map is loaded. */
2448+
tr.fogImage = tr.fogImageNaive;
24412449

2442-
borderColor[ 0 ] = 1.0;
2443-
borderColor[ 1 ] = 1.0;
2444-
borderColor[ 2 ] = 1.0;
2445-
borderColor[ 3 ] = 1;
2450+
vec4_t borderColor;
2451+
Vector4Set( borderColor, 1.0f, 1.0f, 1.0f, 1.0f );
24462452

24472453
glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor );
24482454
}

src/engine/renderer/tr_local.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,9 @@ enum
24492449

24502450
image_t *defaultImage;
24512451
image_t *cinematicImage[ MAX_IN_GAME_VIDEOS ];
2452-
image_t *fogImage;
2452+
image_t *fogImage; // Will be set to either fogImageNaive or fogImageSrgb.
2453+
image_t *fogImageNaive;
2454+
image_t *fogImageLinear;
24532455
image_t *whiteImage; // full of 0xff
24542456
image_t *blackImage; // full of 0x0
24552457
image_t *redImage;

0 commit comments

Comments
 (0)