diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index 01b9029628..be45db7452 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -2000,6 +2000,11 @@ void MaterialSystem::RenderMaterials( const shaderSort_t fromSort, const shaderS } } + // All material packs currently render depth-writing shaders. + // If we were to render depth fade or anything else sampling u_DepthMap with the material system, + // we would need to track this on a per-material basis. + backEnd.dirtyDepthBuffer = true; + GL_BindVAO( backEnd.defaultVAO ); // Draw the skybox here because we skipped R_AddWorldSurfaces() diff --git a/src/engine/renderer/tr_backend.cpp b/src/engine/renderer/tr_backend.cpp index b74d60c2b2..a7dffb05f6 100644 --- a/src/engine/renderer/tr_backend.cpp +++ b/src/engine/renderer/tr_backend.cpp @@ -1210,6 +1210,25 @@ void RB_RunVisTests( ) } } +void RB_PrepareForSamplingDepthMap() +{ + if ( !glConfig.textureBarrierAvailable ) + { + return; + } + + if ( !backEnd.dirtyDepthBuffer ) + { + return; + } + + // Flush depth buffer to make sure it is available for reading in the depth fade + // GLSL - prevents https://github.com/DaemonEngine/Daemon/issues/1676 + glTextureBarrier(); + + backEnd.dirtyDepthBuffer = false; +} + static void RenderDepthTiles() { GL_State( GLS_DEPTHTEST_DISABLE ); @@ -1227,6 +1246,11 @@ static void RenderDepthTiles() return; } + if ( glConfig.usingBindlessTextures ) + { + RB_PrepareForSamplingDepthMap(); + } + // 1st step R_BindFBO( tr.depthtile1FBO ); GL_Viewport( 0, 0, tr.depthtile1FBO->width, tr.depthtile1FBO->height ); @@ -1363,6 +1387,8 @@ void RB_RenderGlobalFog() GLIMP_LOGCOMMENT( "--- RB_RenderGlobalFog ---" ); + RB_PrepareForSamplingDepthMap(); + GL_Cull( cullType_t::CT_TWO_SIDED ); gl_fogGlobalShader->BindProgram( 0 ); @@ -1496,6 +1522,8 @@ void RB_RenderMotionBlur() GLIMP_LOGCOMMENT( "--- RB_RenderMotionBlur ---" ); + RB_PrepareForSamplingDepthMap(); + GL_State( GLS_DEPTHTEST_DISABLE ); GL_Cull( cullType_t::CT_TWO_SIDED ); @@ -1534,12 +1562,7 @@ void RB_RenderSSAO() GLIMP_LOGCOMMENT( "--- RB_RenderSSAO ---" ); - // Assume depth is dirty since we just rendered depth pass and everything opaque - if ( glConfig.textureBarrierAvailable ) - { - glTextureBarrier(); - backEnd.dirtyDepthBuffer = false; - } + RB_PrepareForSamplingDepthMap(); GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO ); GL_Cull( cullType_t::CT_TWO_SIDED ); @@ -2706,9 +2729,6 @@ static void RB_RenderView( bool depthPass ) // draw everything that is translucent if ( glConfig.usingMaterialSystem ) { materialSystem.RenderMaterials( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, backEnd.viewParms.viewID ); - - // HACK: assume surfaces with depth fade don't use the material system - backEnd.dirtyDepthBuffer = true; } RB_RenderDrawSurfaces( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, DRAWSURFACES_ALL ); diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 12820b2c05..827b1ba465 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2923,6 +2923,7 @@ void GL_TexImage3D( GLenum target, GLint level, GLint internalFormat, GLsizei wi void GL_CompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data, bool isSRGB ); void GL_CompressedTexSubImage3D( GLenum target, GLint level, GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLsizei size, const void *data, bool isSRGB ); void R_ShutdownBackend(); + void RB_PrepareForSamplingDepthMap(); /* ==================================================================== diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index b617fb3691..b1123524c3 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -874,12 +874,9 @@ void Render_generic3D( shaderStage_t *pStage ) bool hasDepthFade = pStage->hasDepthFade; bool needDepthMap = pStage->hasDepthFade; - if ( needDepthMap && backEnd.dirtyDepthBuffer && glConfig.textureBarrierAvailable ) + if ( needDepthMap ) { - // Flush depth buffer to make sure it is available for reading in the depth fade - // GLSL - prevents https://github.com/DaemonEngine/Daemon/issues/1676 - glTextureBarrier(); - backEnd.dirtyDepthBuffer = false; + RB_PrepareForSamplingDepthMap(); } // choose right shader program ---------------------------------- @@ -1497,6 +1494,8 @@ void Render_liquid( shaderStage_t *pStage ) GLIMP_LOGCOMMENT( "--- Render_liquid ---" ); + RB_PrepareForSamplingDepthMap(); + // Tr3B: don't allow blend effects GL_State( pStage->stateBits & ~( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS | GLS_DEPTHMASK_TRUE ) );