Skip to content

Add translucent solid option for showing culling bbox #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/engine/renderer/tr_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static ListAnimationsCmd listAnimationsCmdRegistration;
R_CullMD5
=============
*/
static void R_CullMD5( trRefEntity_t *ent )
static cullResult_t R_CullMD5( trRefEntity_t *ent )
{
int i;

Expand Down Expand Up @@ -638,19 +638,16 @@ static void R_CullMD5( trRefEntity_t *ent )
{
case cullResult_t::CULL_IN:
tr.pc.c_box_cull_md5_in++;
ent->cull = cullResult_t::CULL_IN;
return;
return cullResult_t::CULL_IN;

case cullResult_t::CULL_CLIP:
tr.pc.c_box_cull_md5_clip++;
ent->cull = cullResult_t::CULL_CLIP;
return;
return cullResult_t::CULL_CLIP;

case cullResult_t::CULL_OUT:
default:
tr.pc.c_box_cull_md5_out++;
ent->cull = cullResult_t::CULL_OUT;
return;
return cullResult_t::CULL_OUT;
}
}

Expand All @@ -674,9 +671,7 @@ void R_AddMD5Surfaces( trRefEntity_t *ent )

// cull the entire model if merged bounding box of both frames
// is outside the view frustum
R_CullMD5( ent );

if ( ent->cull == cullResult_t::CULL_OUT )
if ( R_CullMD5( ent ) == cullResult_t::CULL_OUT )
{
return;
}
Expand Down
37 changes: 28 additions & 9 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ backEndState_t backEnd;

static Cvar::Cvar<bool> r_clear( "r_clear", "Clear screen before painting over it on every frame", Cvar::NONE, false );
Cvar::Cvar<bool> r_drawSky( "r_drawSky", "Draw the sky (clear the sky if disabled)", Cvar::NONE, true );
static Cvar::Cvar<int> r_showEntityBounds(
"r_showEntityBounds", "show bboxes used for culling (1: wireframe; 2: translucent solid)", Cvar::CHEAT, 0);

void GL_Bind( image_t *image )
{
Expand Down Expand Up @@ -1563,7 +1565,7 @@ static void RB_RenderDebugUtils()
{
GLIMP_LOGCOMMENT( "--- RB_RenderDebugUtils ---" );

if ( r_showEntityTransforms->integer )
if ( r_showEntityBounds.Get() )
{
trRefEntity_t *ent;
int i;
Expand All @@ -1577,13 +1579,23 @@ static void RB_RenderDebugUtils()
gl_genericShader->SetDepthFade( false );
gl_genericShader->BindProgram( 0 );

GL_State( GLS_POLYMODE_LINE | GLS_DEPTHTEST_DISABLE );
if ( r_showEntityBounds.Get() == 2 )
{
GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
glEnable( GL_POLYGON_OFFSET_FILL );
GL_PolygonOffset( r_offsetFactor->value, r_offsetUnits->value );
}
else
{
GL_State( GLS_POLYMODE_LINE | GLS_DEPTHTEST_DISABLE );
}

GL_Cull( cullType_t::CT_TWO_SIDED );

// set uniforms
gl_genericShader->SetUniform_AlphaTest( GLS_ATEST_NONE );
SetUniform_ColorModulateColorGen( gl_genericShader, colorGen_t::CGEN_VERTEX, alphaGen_t::AGEN_VERTEX );
SetUniform_Color( gl_genericShader, Color::Black );
SetUniform_Color( gl_genericShader, Color::Color(0, 0, 0, 0) );

// bind u_ColorMap
gl_genericShader->SetUniform_ColorMapBindless(
Expand All @@ -1595,13 +1607,13 @@ static void RB_RenderDebugUtils()

for ( i = 0; i < backEnd.refdef.numEntities; i++, ent++ )
{
if ( ( ent->e.renderfx & RF_THIRD_PERSON ) &&
backEnd.viewParms.portalLevel == 0 )
if ( ent->e.reType != refEntityType_t::RT_MODEL )
{
continue;
}

if ( ent->cull == cullResult_t::CULL_OUT )
if ( ( ent->e.renderfx & RF_THIRD_PERSON ) &&
backEnd.viewParms.portalLevel == 0 )
{
continue;
}
Expand All @@ -1613,16 +1625,23 @@ static void RB_RenderDebugUtils()

Tess_Begin( Tess_StageIteratorDebug, nullptr, nullptr, true, -1, 0 );

Tess_AddCube( vec3_origin, ent->localBounds[ 0 ], ent->localBounds[ 1 ], Color::Blue );

Tess_AddCube( vec3_origin, mins, maxs,Color::White );
if ( r_showEntityBounds.Get() == 2)
{
Tess_AddCube( vec3_origin, ent->localBounds[ 0 ], ent->localBounds[ 1 ], Color::Color(0, 0, 0.5, 0.4) );
}
else
{
Tess_AddCube( vec3_origin, ent->localBounds[ 0 ], ent->localBounds[ 1 ], Color::Blue );
Tess_AddCube( vec3_origin, mins, maxs,Color::White );
}

Tess_End();
}

// go back to the world modelview matrix
backEnd.orientation = backEnd.viewParms.world;
GL_LoadModelViewMatrix( backEnd.viewParms.world.modelViewMatrix );
glDisable( GL_POLYGON_OFFSET_FILL );
}

if ( r_showSkeleton->integer )
Expand Down
2 changes: 0 additions & 2 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_showTris;
cvar_t *r_showSky;
cvar_t *r_showSkeleton;
cvar_t *r_showEntityTransforms;
cvar_t *r_showLightGrid;
cvar_t *r_showLightTiles;
cvar_t *r_showBatches;
Expand Down Expand Up @@ -1276,7 +1275,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_showTris = Cvar_Get( "r_showTris", "0", CVAR_CHEAT );
r_showSky = Cvar_Get( "r_showSky", "0", CVAR_CHEAT );
r_showSkeleton = Cvar_Get( "r_showSkeleton", "0", CVAR_CHEAT );
r_showEntityTransforms = Cvar_Get( "r_showEntityTransforms", "0", CVAR_CHEAT );
r_showLightGrid = Cvar_Get( "r_showLightGrid", "0", CVAR_CHEAT );
r_showLightTiles = Cvar_Get("r_showLightTiles", "0", CVAR_CHEAT | CVAR_LATCH );
r_showBatches = Cvar_Get( "r_showBatches", "0", CVAR_CHEAT );
Expand Down
2 changes: 0 additions & 2 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ enum class ssaoMode {
// local
float axisLength; // compensate for non-normalized axis

cullResult_t cull;
vec3_t localBounds[ 2 ];
vec3_t worldBounds[ 2 ];
};
Expand Down Expand Up @@ -2834,7 +2833,6 @@ enum class ssaoMode {
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_showSkeleton;
extern cvar_t *r_showEntityTransforms;
extern cvar_t *r_showLightGrid;
extern cvar_t *r_showLightTiles;
extern cvar_t *r_showBatches;
Expand Down
27 changes: 9 additions & 18 deletions src/engine/renderer/tr_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
R_CullMDV
=============
*/
static void R_CullMDV( mdvModel_t *model, trRefEntity_t *ent )
static cullResult_t R_CullMDV( mdvModel_t *model, trRefEntity_t *ent )
{
mdvFrame_t *oldFrame, *newFrame;
int i;
Expand Down Expand Up @@ -59,13 +59,11 @@ static void R_CullMDV( mdvModel_t *model, trRefEntity_t *ent )
{
case cullResult_t::CULL_OUT:
tr.pc.c_sphere_cull_mdv_out++;
ent->cull = cullResult_t::CULL_OUT;
return;
return cullResult_t::CULL_OUT;

case cullResult_t::CULL_IN:
tr.pc.c_sphere_cull_mdv_in++;
ent->cull = cullResult_t::CULL_IN;
return;
return cullResult_t::CULL_IN;

case cullResult_t::CULL_CLIP:
tr.pc.c_sphere_cull_mdv_clip++;
Expand All @@ -91,14 +89,12 @@ static void R_CullMDV( mdvModel_t *model, trRefEntity_t *ent )
if ( sphereCull == cullResult_t::CULL_OUT )
{
tr.pc.c_sphere_cull_mdv_out++;
ent->cull = cullResult_t::CULL_OUT;
return;
return cullResult_t::CULL_OUT;
}
else if ( sphereCull == cullResult_t::CULL_IN )
{
tr.pc.c_sphere_cull_mdv_in++;
ent->cull = cullResult_t::CULL_IN;
return;
return cullResult_t::CULL_IN;
}
else
{
Expand All @@ -112,19 +108,16 @@ static void R_CullMDV( mdvModel_t *model, trRefEntity_t *ent )
{
case cullResult_t::CULL_IN:
tr.pc.c_box_cull_mdv_in++;
ent->cull = cullResult_t::CULL_IN;
return;
return cullResult_t::CULL_IN;

case cullResult_t::CULL_CLIP:
tr.pc.c_box_cull_mdv_clip++;
ent->cull = cullResult_t::CULL_CLIP;
return;
return cullResult_t::CULL_CLIP;

case cullResult_t::CULL_OUT:
default:
tr.pc.c_box_cull_mdv_out++;
ent->cull = cullResult_t::CULL_OUT;
return;
return cullResult_t::CULL_OUT;
}
}

Expand Down Expand Up @@ -296,9 +289,7 @@ void R_AddMDVSurfaces( trRefEntity_t *ent )

// cull the entire model if merged bounding box of both frames
// is outside the view frustum.
R_CullMDV( model, ent );

if ( ent->cull == CULL_OUT )
if ( R_CullMDV( model, ent ) == CULL_OUT )
{
return;
}
Expand Down
18 changes: 5 additions & 13 deletions src/engine/renderer/tr_model_iqm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
R_CullIQM
=============
*/
static void R_CullIQM( trRefEntity_t *ent ) {
static cullResult_t R_CullIQM( trRefEntity_t *ent ) {
vec3_t localBounds[ 2 ];
float scale = ent->e.skeleton.scale;
IQModel_t *model = tr.currentModel->iqm;
Expand Down Expand Up @@ -962,17 +962,14 @@ static void R_CullIQM( trRefEntity_t *ent ) {
{
case cullResult_t::CULL_IN:
tr.pc.c_box_cull_md5_in++;
ent->cull = cullResult_t::CULL_IN;
return;
return cullResult_t::CULL_IN;
case cullResult_t::CULL_CLIP:
tr.pc.c_box_cull_md5_clip++;
ent->cull = cullResult_t::CULL_CLIP;
return;
return cullResult_t::CULL_CLIP;
case cullResult_t::CULL_OUT:
default:
tr.pc.c_box_cull_md5_out++;
ent->cull = cullResult_t::CULL_OUT;
return;
return cullResult_t::CULL_OUT;
}
}

Expand All @@ -999,14 +996,9 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) {
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) &&
tr.viewParms.portalLevel == 0;

// cull the entire model if merged bounding box of both frames
// is outside the view frustum.
R_CullIQM( ent );

// HACK: Never cull first-person models, due to issues with a certain model's bounds
// A first-person model not in the player's sight seems like something that should not happen in any case
// But R_CullIQM is always called because it sets some fields used by other code
if ( ent->cull == cullResult_t::CULL_OUT && !( ent->e.renderfx & RF_FIRST_PERSON ) )
if ( !( ent->e.renderfx & RF_FIRST_PERSON ) && R_CullIQM( ent ) == cullResult_t::CULL_OUT )
{
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/engine/renderer/tr_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ void R_AddBSPModelSurfaces( trRefEntity_t *ent )
VectorAdd( ent->worldBounds[ 0 ], ent->worldBounds[ 1 ], boundsCenter );
VectorScale( boundsCenter, 0.5f, boundsCenter );

ent->cull = R_CullBox( ent->worldBounds );

if ( ent->cull == CULL_OUT )
if ( R_CullBox( ent->worldBounds ) == CULL_OUT )
{
return;
}
Expand Down