Skip to content
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
5 changes: 5 additions & 0 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 29 additions & 9 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -1363,6 +1387,8 @@ void RB_RenderGlobalFog()

GLIMP_LOGCOMMENT( "--- RB_RenderGlobalFog ---" );

RB_PrepareForSamplingDepthMap();

GL_Cull( cullType_t::CT_TWO_SIDED );

gl_fogGlobalShader->BindProgram( 0 );
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

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 @@ -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();

/*
====================================================================
Expand Down
9 changes: 4 additions & 5 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------
Expand Down Expand Up @@ -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 ) );

Expand Down