From 547a41ef2d2bf5cf8f90a782015cfeb2a466969e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 14 Jan 2024 15:53:20 +0300 Subject: [PATCH] ref: gl: mirror entities culling --- ref/gl/gl_beams.c | 4 ++++ ref/gl/gl_cull.c | 30 +++++++++++++++++++++++++++++- ref/gl/gl_local.h | 5 +++-- ref/gl/gl_rsurf.c | 3 +++ ref/gl/gl_sprite.c | 3 +++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ref/gl/gl_beams.c b/ref/gl/gl_beams.c index 01f91129..4c4084aa 100644 --- a/ref/gl/gl_beams.c +++ b/ref/gl/gl_beams.c @@ -119,6 +119,10 @@ qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ) vec3_t mins, maxs; int i; + // support for custom mirror management + if( RI.currentbeam && R_CullEntityInMirror( RI.currentbeam )) + return true; + for( i = 0; i < 3; i++ ) { if( start[i] < end[i] ) diff --git a/ref/gl/gl_cull.c b/ref/gl/gl_cull.c index d432b073..1a642227 100644 --- a/ref/gl/gl_cull.c +++ b/ref/gl/gl_cull.c @@ -35,6 +35,31 @@ qboolean R_CullBox( const vec3_t mins, const vec3_t maxs ) return GL_FrustumCullBox( &RI.frustum, mins, maxs, 0 ); } +/* +================= +R_CullEntityInMirror + +decide whether entity should be reflected in mirror +================= +*/ +qboolean R_CullEntityInMirror( cl_entity_t *e ) +{ + if( FBitSet( RI.params, RP_MIRRORVIEW )) + { + // cull this entity out of mirrors but not normal views + if( FBitSet( e->curstate.effects, EF_NOREFLECT )) + return true; + } + else + { + // cull this entity out of normal views but not mirrors + if( FBitSet( e->curstate.effects, EF_REFLECTONLY )) + return true; + } + + return false; +} + /* ============= R_CullModel @@ -53,6 +78,9 @@ int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ) return 1; } + if( R_CullEntityInMirror( e )) + return 1; + if( R_CullBox( absmin, absmax )) return 1; @@ -98,7 +126,7 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ) } else dist = PlaneDiff( tr.modelorg, surf->plane ); - if( glState.faceCull == GL_FRONT ) + if( glState.faceCull == GL_FRONT || FBitSet( RI.params, RP_MIRRORVIEW )) { if( FBitSet( surf->flags, SURF_PLANEBACK )) { diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index e276c322..f1ac35d5 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -84,8 +84,9 @@ extern poolhandle_t r_temppool; #define RP_ENVVIEW BIT( 0 ) // used for cubemapshot #define RP_OLDVIEWLEAF BIT( 1 ) #define RP_CLIPPLANE BIT( 2 ) +#define RP_MIRRORVIEW BIT( 3 ) // lock pvs at vieworg -#define RP_NONVIEWERREF (RP_ENVVIEW) +#define RP_NONVIEWERREF (RP_ENVVIEW|RP_MIRRORVIEW) #define R_ModelOpaque( rm ) ( rm == kRenderNormal ) #define R_StaticEntity( ent ) ( VectorIsNull( ent->origin ) && VectorIsNull( ent->angles )) #define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( gp_cl->playernum + 1 ) && e->player ) @@ -324,6 +325,7 @@ qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ); // int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ); qboolean R_CullBox( const vec3_t mins, const vec3_t maxs ); +qboolean R_CullEntityInMirror( cl_entity_t *e ); int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ); // @@ -541,7 +543,6 @@ void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, c void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum ); qboolean R_SpeedsMessage( char *out, size_t size ); void R_SetupSky( const char *skyboxname ); -qboolean R_CullBox( const vec3_t mins, const vec3_t maxs ); int R_WorldToScreen( const vec3_t point, vec3_t screen ); void R_ScreenToWorld( const vec3_t screen, vec3_t point ); qboolean R_AddEntity( struct cl_entity_s *pRefEntity, int entityType ); diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index e28f256a..3f258f13 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -1551,6 +1551,9 @@ void R_DrawBrushModel( cl_entity_t *e ) if( clmodel->surfaces != WORLDMODEL->surfaces ) allow_vbo = false; + if( R_CullEntityInMirror( e )) + return; + if( !VectorIsNull( e->angles )) { for( i = 0; i < 3; i++ ) diff --git a/ref/gl/gl_sprite.c b/ref/gl/gl_sprite.c index 9a1060a0..e26fdd62 100644 --- a/ref/gl/gl_sprite.c +++ b/ref/gl/gl_sprite.c @@ -701,6 +701,9 @@ static qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale ) float blend; vec3_t v; + if( R_CullEntityInMirror( e )) + return; + TriWorldToScreen( origin, v ); if( v[0] < RI.viewport[0] || v[0] > RI.viewport[0] + RI.viewport[2] )