added r_ignoreShaderSortKey as a work-around for broken maps

This commit is contained in:
myT 2022-04-24 22:44:25 +02:00
parent b8fd6e7c64
commit 4670a811c1
5 changed files with 38 additions and 7 deletions

View file

@ -4,6 +4,10 @@ See the end of this file for known issues.
DD Mmm 20 - 1.53
add: r_ignoreShaderSortKey <0|1> (default: 0) ignores the shader sort key of transparent surfaces
instead, it sorts by depth and original registration order only
this is a work-around for broken maps like bones_fkd_b4 (grates drawn in front of simple items)
add: r_mapGreyscale <0.0 to 1.0> (default: 0) controls the map's desaturation level
r_mapGreyscale 0 = full color (nothing done)
r_mapGreyscale 1 = completely monochrome

View file

@ -184,3 +184,8 @@ S_COLOR_VAL " 2 " S_COLOR_HELP "= R16G16B16A16"
#define help_r_mapGreyscaleCTF \
"how desaturated CTF map surfaces look\n" \
"It applies to the red/blue color-coded surfaces of popular CTF/NTF maps."
#define help_r_ignoreShaderSortKey \
"ignores the shader sort key of transparent surfaces\n" \
"Instead, it sorts by depth and original registration order only.\n" \
"You can use this as a work-around for broken maps like bones_fkd_b4."

View file

@ -83,6 +83,7 @@ cvar_t *r_ext_max_anisotropy;
cvar_t *r_msaa;
cvar_t *r_ignoreGLErrors;
cvar_t *r_ignoreShaderSortKey;
cvar_t *r_vertexLight;
cvar_t *r_uiFullScreen;
@ -403,6 +404,7 @@ static const cvarTableItem_t r_cvars[] =
//
{ &r_lodbias, "r_lodbias", "-2", CVAR_ARCHIVE, CVART_INTEGER, "-16", "16", help_r_lodbias },
{ &r_ignoreGLErrors, "r_ignoreGLErrors", "1", CVAR_ARCHIVE, CVART_BOOL, NULL, NULL, "if " S_COLOR_VAL "0" S_COLOR_HELP ", OpenGL errors are fatal" },
{ &r_ignoreShaderSortKey, "r_ignoreShaderSortKey", "0", CVAR_ARCHIVE, CVART_BOOL, NULL, NULL, help_r_ignoreShaderSortKey },
{ &r_fastsky, "r_fastsky", "0", CVAR_ARCHIVE, CVART_BOOL, NULL, NULL, help_r_fastsky },
{ &r_noportals, "r_noportals", "0", CVAR_ARCHIVE, CVART_BOOL, NULL, NULL, help_r_noportals },
{ &r_dynamiclight, "r_dynamiclight", "1", CVAR_ARCHIVE, CVART_BOOL, NULL, NULL, "enables dynamic lights" },

View file

@ -1060,6 +1060,7 @@ extern cvar_t *r_lodCurveError;
extern cvar_t *r_alphaToCoverageMipBoost; // increases the alpha value of higher mip levels
extern cvar_t *r_ignoreGLErrors;
extern cvar_t *r_ignoreShaderSortKey;
extern cvar_t *r_brightness;
extern cvar_t *r_mapBrightness;

View file

@ -1245,6 +1245,22 @@ static int R_CompareDrawSurf( const void* aPtr, const void* bPtr )
}
// same thing but ignoring the sort key since some maps get this so wrong
// example: a grate shader in bones_fkd_b4 has a sort key value of 16,
// so it will draw in front of pretty much everything else
static int R_CompareDrawSurfNoKey( const void* aPtr, const void* bPtr )
{
const drawSurf_t* a = ( const drawSurf_t* )aPtr;
const drawSurf_t* b = ( const drawSurf_t* )bPtr;
if ( a->depth > b->depth )
return -1;
if ( a->depth < b->depth )
return 1;
return a->index - b->index;
}
static void R_SortDrawSurfs( int firstDrawSurf, int firstLitSurf )
{
const int numDrawSurfs = tr.refdef.numDrawSurfs - firstDrawSurf;
@ -1303,15 +1319,18 @@ static void R_SortDrawSurfs( int firstDrawSurf, int firstLitSurf )
}
// sort transparent surfaces by depth
qsort( drawSurfs + numDrawSurfs - numTranspSurfs, numTranspSurfs, sizeof(drawSurf_t), &R_CompareDrawSurf );
typedef int (*sortFunc_t)( const void*, const void* );
const sortFunc_t transpSort = r_ignoreShaderSortKey->integer ? &R_CompareDrawSurfNoKey : &R_CompareDrawSurf;
qsort( drawSurfs + numDrawSurfs - numTranspSurfs, numTranspSurfs, sizeof(drawSurf_t), transpSort );
#if defined(_DEBUG)
float prevSort = -1.0f;
for ( int i = 0; i < numDrawSurfs; ++i )
{
R_DecomposeSort( (drawSurfs + i)->sort, &entityNum, &shader, &fogNum );
assert( shader->sort >= prevSort );
prevSort = shader->sort;
if ( r_ignoreShaderSortKey->integer == 0 ) {
float prevSort = -1.0f;
for ( int i = 0; i < numDrawSurfs; ++i ) {
R_DecomposeSort( (drawSurfs + i)->sort, &entityNum, &shader, &fogNum );
assert( shader->sort >= prevSort );
prevSort = shader->sort;
}
}
#endif