Skip to content

Commit

Permalink
Add a toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
VReaperV committed May 18, 2024
1 parent 3ad229d commit b4fbd11
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@ void MaterialSystem::CullSurfaces() {
uint globalWorkGroupX = totalDrawSurfs % MAX_COMMAND_COUNTERS == 0 ?
totalDrawSurfs / MAX_COMMAND_COUNTERS : totalDrawSurfs / MAX_COMMAND_COUNTERS + 1;
gl_cullShader->SetUniform_TotalDrawSurfs( totalDrawSurfs );
gl_cullShader->SetUniform_UseFrustumCulling( r_gpuFrustumCulling->integer );
gl_cullShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );

if ( PVSLocked ) {
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,7 @@ GLShader_cull::GLShader_cull( GLShaderManager* manager ) :
GLShader( "cull", ATTR_POSITION, manager, false, false, true ),
u_TotalDrawSurfs( this ),
u_SurfaceCommandsOffset( this ),
u_UseFrustumCulling( this ),
u_Frustum( this ) {
}

Expand Down
13 changes: 13 additions & 0 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,18 @@ class u_TotalDrawSurfs :
}
};

class u_UseFrustumCulling :
GLUniform1Bool {
public:
u_UseFrustumCulling( GLShader* shader ) :
GLUniform1Bool( shader, "u_UseFrustumCulling" ) {
}

void SetUniform_UseFrustumCulling( const int useFrustumCulling ) {
this->SetValue( useFrustumCulling );
}
};

class u_Frustum :
GLUniform4fv {
public:
Expand Down Expand Up @@ -4598,6 +4610,7 @@ class GLShader_cull :
public GLShader,
public u_TotalDrawSurfs,
public u_SurfaceCommandsOffset,
public u_UseFrustumCulling,
public u_Frustum {
public:
GLShader_cull( GLShaderManager* manager );
Expand Down
3 changes: 2 additions & 1 deletion src/engine/renderer/glsl_source/cull_cp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ struct Plane {

uniform uint u_TotalDrawSurfs;
uniform uint u_SurfaceCommandsOffset;
uniform bool u_UseFrustumCulling;
uniform vec4 u_Frustum[6]; // xyz - normal, w - distance

bool CullSurface( in BoundingSphere boundingSphere ) {
for( int i = 0; i < 5; i++ ) { // Skip far plane for now because we always have it set to { 0, 0, 0, 0 } for some reason
const float distance = dot( u_Frustum[i].xyz, boundingSphere.center ) - u_Frustum[i].w;

if( distance < -boundingSphere.radius ) {
return true;
return true && u_UseFrustumCulling;
}
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_lazyShaders;

cvar_t *r_useMaterialSystem;
cvar_t *r_gpuFrustumCulling;

cvar_t *r_ext_occlusion_query;
cvar_t *r_ext_draw_buffers;
Expand Down Expand Up @@ -1132,6 +1133,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_noMarksOnTrisurfs = Cvar_Get( "r_noMarksOnTrisurfs", "1", CVAR_CHEAT );

r_useMaterialSystem = Cvar_Get( "r_useMaterialSystem", "0", CVAR_LATCH );
r_gpuFrustumCulling = Cvar_Get( "r_gpuFrustumCulling", "1", CVAR_CHEAT );

/* 1: Delay GLSL shader build until first map load.
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,7 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
extern cvar_t *r_lazyShaders; // 0: build all shaders on program start 1: delay shader build until first map load 2: delay shader build until needed

extern cvar_t *r_useMaterialSystem;
extern cvar_t *r_gpuFrustumCulling;

extern cvar_t *r_norefresh; // bypasses the ref rendering
extern cvar_t *r_drawentities; // disable/enable entity rendering
Expand Down

0 comments on commit b4fbd11

Please sign in to comment.