turned r_showtris and r_shownormals into bitmasks

This commit is contained in:
myT 2022-04-29 21:12:01 +02:00
parent a12cf70700
commit 866b93ef5e
6 changed files with 101 additions and 42 deletions

View file

@ -24,6 +24,13 @@ add: /waitms <milliseconds> to delay command executions by the specified number
add: r_alphaToCoverageMipBoost <0.0 to 0.5> (default: 0.125) boosts the alpha value of higher mip levels
with A2C enabled, it prevents alpha-tested surfaces from fading (too much) in the distance
chg: r_showtris/r_shownormals <bitmask> (default: 0) draws wireframe triangles/vertex normals
1 - enables the feature
2 - only draws for visible triangles
4 - draws for backfacing triangles
8 - uses the original vertex color
16 - uses the original vertex alpha as vertex color
chg: r_lightmap 1 now handles most alpha-tested surfaces
chg: printing warnings when there are excessive sound loads from disk during gameplay

View file

@ -189,3 +189,18 @@ S_COLOR_VAL " 2 " S_COLOR_HELP "= R16G16B16A16"
"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."
#define help_r_showtris_bitmask \
S_COLOR_VAL " 1 " S_COLOR_HELP "= Enables the feature\n" \
S_COLOR_VAL " 2 " S_COLOR_HELP "= Only draws for visible triangles\n" \
S_COLOR_VAL " 4 " S_COLOR_HELP "= Draws for backfacing triangles\n" \
S_COLOR_VAL " 8 " S_COLOR_HELP "= Uses the original vertex color\n" \
S_COLOR_VAL " 16 " S_COLOR_HELP "= Uses the original vertex alpha as vertex color"
#define help_r_showtris \
"draws wireframe triangles\n" \
help_r_showtris_bitmask
#define help_r_shownormals \
"draws vertex normals\n" \
help_r_showtris_bitmask

View file

@ -93,8 +93,8 @@ cvar_t *r_singleShader;
cvar_t *r_roundImagesDown;
cvar_t *r_colorMipLevels;
cvar_t *r_picmip;
cvar_t *r_showtris;
cvar_t *r_showsky;
cvar_t *r_showtris;
cvar_t *r_shownormals;
cvar_t *r_finish;
cvar_t *r_clear;
@ -440,9 +440,9 @@ static const cvarTableItem_t r_cvars[] =
{ &r_speeds, "r_speeds", "0", CVAR_TEMP, CVART_BOOL, NULL, NULL, "draws rendering performance counters" },
{ &r_verbose, "r_verbose", "0", CVAR_TEMP, CVART_BOOL, NULL, NULL, "prints additional information" },
{ &r_debugSurface, "r_debugSurface", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "draws collision models" },
{ &r_showtris, "r_showtris", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "draws wireframe triangles" },
{ &r_showsky, "r_showsky", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "forces sky in front of all surfaces" },
{ &r_shownormals, "r_shownormals", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "draws wireframe normals" },
{ &r_showtris, "r_showtris", "0", CVAR_CHEAT, CVART_BITMASK, "0", XSTRING(SHOWTRIS_MAX), help_r_showtris },
{ &r_shownormals, "r_shownormals", "0", CVAR_CHEAT, CVART_BITMASK, "0", XSTRING(SHOWTRIS_MAX), help_r_shownormals },
{ &r_clear, "r_clear", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "clears to violet instead of black" },
{ &r_lockpvs, "r_lockpvs", "0", CVAR_CHEAT, CVART_BOOL, NULL, NULL, "helps visualize the current PVS' limits" },
{ &r_maxpolys, "r_maxpolys", XSTRING(DEFAULT_MAX_POLYS), 0, CVART_INTEGER, XSTRING(DEFAULT_MAX_POLYS), NULL, "maximum polygon count per frame" },

View file

@ -194,7 +194,8 @@ typedef enum {
CGEN_WAVEFORM, // programmatically generated
CGEN_LIGHTING_DIFFUSE,
CGEN_FOG, // standard fog
CGEN_CONST // fixed color
CGEN_CONST, // fixed color
CGEN_DEBUG_ALPHA // debug only: replicate the alpha channel
} colorGen_t;
typedef enum {
@ -985,6 +986,14 @@ extern trGlobals_t tr;
#define DXGIPM_FLIPDISCARD 1
#define DXGIPM_MAX 1
// r_showtris + r_shownormals
#define SHOWTRIS_ENABLE_BIT 1
#define SHOWTRIS_OCCLUDE_BIT 2
#define SHOWTRIS_BACKFACE_BIT 4
#define SHOWTRIS_VERTEX_COLOR_BIT 8
#define SHOWTRIS_VERTEX_ALPHA_BIT 16
#define SHOWTRIS_MAX 31
extern cvar_t *r_backend;
extern cvar_t *r_verbose; // used for verbose debug spew
@ -1046,8 +1055,8 @@ extern cvar_t *r_textureMode;
extern cvar_t *r_vertexLight; // vertex lighting mode for better performance
extern cvar_t *r_uiFullScreen; // ui is running fullscreen
extern cvar_t *r_showtris; // enables wireframe rendering of the world
extern cvar_t *r_showsky; // forces sky in front of all surfaces
extern cvar_t *r_showtris; // draws wireframe triangles
extern cvar_t *r_shownormals; // draws wireframe normals
extern cvar_t *r_clear; // clear to violet instead of black for debugging

View file

@ -146,6 +146,53 @@ static void RB_DrawGeneric()
}
static void RB_DrawDebug( const shaderCommands_t* input, qbool drawNormals, int options )
{
if (drawNormals) {
// we only draw the normals for the first (SHADER_MAX_VERTEXES / 2 - 1) vertices
int nv = tess.numVertexes;
if (nv >= SHADER_MAX_VERTEXES / 2)
nv = SHADER_MAX_VERTEXES / 2 - 1;
for (int i = 0, j = nv; i < nv; ++i, ++j) {
VectorMA(input->xyz[i], 2, input->normal[i], tess.xyz[j]);
}
for (int i = 0, j = 0; i < nv; ++i, j += 3) {
tess.indexes[j + 0] = i;
tess.indexes[j + 1] = i;
tess.indexes[j + 2] = i + nv;
}
tess.numVertexes = nv * 2;
tess.numIndexes = nv * 3;
}
const cullType_t cull = (options & SHOWTRIS_BACKFACE_BIT) ? CT_BACK_SIDED : CT_FRONT_SIDED;
RB_PushSingleStageShader(GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE, cull);
shaderStage_t* const stage = tess.shader->stages[0];
if (options & SHOWTRIS_VERTEX_COLOR_BIT) {
stage->rgbGen = CGEN_EXACT_VERTEX;
} else if (options & SHOWTRIS_VERTEX_ALPHA_BIT) {
stage->rgbGen = CGEN_DEBUG_ALPHA;
} else {
stage->rgbGen = CGEN_CONST;
stage->constantColor[0] = drawNormals ? 0 : 255;
stage->constantColor[1] = drawNormals ? 0 : 255;
stage->constantColor[2] = 255;
stage->constantColor[3] = 255;
}
stage->alphaGen = AGEN_SKIP;
R_ComputeColors(tess.shader->stages[0], tess.svars[0], 0, tess.numVertexes);
if ((options & SHOWTRIS_OCCLUDE_BIT) == 0) {
gal.SetDepthRange(0, 0);
}
gal.Draw(DT_GENERIC);
gal.SetDepthRange(0, 1);
RB_PopShader();
}
void RB_EndSurface()
{
shaderCommands_t* input = &tess;
@ -184,46 +231,17 @@ void RB_EndSurface()
}
// draw debugging stuff
const qbool showTris = r_showtris->integer & SHOWTRIS_ENABLE_BIT;
const qbool showNormals = r_shownormals->integer & SHOWTRIS_ENABLE_BIT;
if (!backEnd.projection2D &&
(tess.pass == shaderCommands_t::TP_BASE) &&
tess.numIndexes > 0 &&
tess.numVertexes > 0) {
if (r_showtris->integer) {
RB_PushSingleStageShader(GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE, CT_FRONT_SIDED);
R_ComputeColors(tess.shader->stages[0], tess.svars[0], 0, tess.numVertexes);
gal.SetDepthRange(0, 0);
gal.Draw(DT_GENERIC);
gal.SetDepthRange(0, 1);
RB_PopShader();
}
if (r_shownormals->integer) {
// we only draw the normals for the first (SHADER_MAX_VERTEXES / 2 - 1) vertices
int nv = tess.numVertexes;
if (nv >= SHADER_MAX_VERTEXES / 2)
nv = SHADER_MAX_VERTEXES / 2 - 1;
for (int i = 0, j = nv; i < nv; ++i, ++j) {
VectorMA(input->xyz[i], 2, input->normal[i], tess.xyz[j]);
}
for (int i = 0, j = 0; i < nv; ++i, j += 3) {
tess.indexes[j + 0] = i;
tess.indexes[j + 1] = i;
tess.indexes[j + 2] = i + nv;
}
tess.numVertexes = nv * 2;
tess.numIndexes = nv * 3;
RB_PushSingleStageShader(GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE, CT_FRONT_SIDED);
shaderStage_t* const stage = tess.shader->stages[0];
stage->rgbGen = CGEN_CONST;
stage->constantColor[0] = 0;
stage->constantColor[1] = 0;
stage->constantColor[2] = 255;
stage->constantColor[3] = 255;
R_ComputeColors(tess.shader->stages[0], tess.svars[0], 0, tess.numVertexes);
gal.SetDepthRange(0, 0);
gal.Draw(DT_GENERIC);
gal.SetDepthRange(0, 1);
RB_PopShader();
}
tess.numVertexes > 0 &&
(showTris || showNormals)) {
if (showTris)
RB_DrawDebug(input, qfalse, r_showtris->integer);
if (showNormals)
RB_DrawDebug(input, qtrue, r_shownormals->integer);
}
// clear shader so we can tell we don't have any unclosed surfaces

View file

@ -1093,6 +1093,16 @@ void R_ComputeColors( const shaderStage_t* pStage, stageVars_t& svars, int first
case CGEN_ONE_MINUS_ENTITY:
RB_CalcColorFromOneMinusEntity( ( unsigned char * ) &svars.colors[firstVertex], numVertexes );
break;
case CGEN_DEBUG_ALPHA:
for ( int i = firstVertex; i < firstVertex + numVertexes; i++ )
{
const byte alpha = tess.vertexColors[i][3];
svars.colors[i][0] = alpha;
svars.colors[i][1] = alpha;
svars.colors[i][2] = alpha;
svars.colors[i][3] = 255;
}
break;
}
//