@@ -1210,6 +1210,25 @@ void RB_RunVisTests( )
12101210 }
12111211}
12121212
1213+ void RB_PrepareForSamplingDepthMap ()
1214+ {
1215+ if ( !glConfig.textureBarrierAvailable )
1216+ {
1217+ return ;
1218+ }
1219+
1220+ if ( !backEnd.dirtyDepthBuffer )
1221+ {
1222+ return ;
1223+ }
1224+
1225+ // Flush depth buffer to make sure it is available for reading in the depth fade
1226+ // GLSL - prevents https://github.com/DaemonEngine/Daemon/issues/1676
1227+ glTextureBarrier ();
1228+
1229+ backEnd.dirtyDepthBuffer = false ;
1230+ }
1231+
12131232static void RenderDepthTiles ()
12141233{
12151234 GL_State ( GLS_DEPTHTEST_DISABLE );
@@ -1227,6 +1246,11 @@ static void RenderDepthTiles()
12271246 return ;
12281247 }
12291248
1249+ if ( glConfig.usingBindlessTextures )
1250+ {
1251+ RB_PrepareForSamplingDepthMap ();
1252+ }
1253+
12301254 // 1st step
12311255 R_BindFBO ( tr.depthtile1FBO );
12321256 GL_Viewport ( 0 , 0 , tr.depthtile1FBO ->width , tr.depthtile1FBO ->height );
@@ -1363,6 +1387,8 @@ void RB_RenderGlobalFog()
13631387
13641388 GLIMP_LOGCOMMENT ( " --- RB_RenderGlobalFog ---" );
13651389
1390+ RB_PrepareForSamplingDepthMap ();
1391+
13661392 GL_Cull ( cullType_t::CT_TWO_SIDED );
13671393
13681394 gl_fogGlobalShader->BindProgram ( 0 );
@@ -1377,20 +1403,8 @@ void RB_RenderGlobalFog()
13771403
13781404 GL_State ( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
13791405
1380- // all fogging distance is based on world Z units
1381- vec4_t fogDistanceVector;
1382- vec3_t local;
1383- VectorSubtract ( backEnd.orientation .origin , backEnd.viewParms .orientation .origin , local );
1384- fogDistanceVector[ 0 ] = -backEnd.orientation .modelViewMatrix [ 2 ];
1385- fogDistanceVector[ 1 ] = -backEnd.orientation .modelViewMatrix [ 6 ];
1386- fogDistanceVector[ 2 ] = -backEnd.orientation .modelViewMatrix [ 10 ];
1387- fogDistanceVector[ 3 ] = DotProduct ( local, backEnd.viewParms .orientation .axis [ 0 ] );
1388-
1389- // scale the fog vectors based on the fog's thickness
1390- VectorScale ( fogDistanceVector, fog->tcScale , fogDistanceVector );
1391- fogDistanceVector[ 3 ] *= fog->tcScale ;
1392-
1393- gl_fogGlobalShader->SetUniform_FogDistanceVector ( fogDistanceVector );
1406+ gl_fogGlobalShader->SetUniform_FogDensity ( fog->tcScale );
1407+ gl_fogGlobalShader->SetUniform_ViewOrigin ( backEnd.viewParms .orientation .origin );
13941408 SetUniform_Color ( gl_fogGlobalShader, fog->color );
13951409 }
13961410
@@ -1508,6 +1522,8 @@ void RB_RenderMotionBlur()
15081522
15091523 GLIMP_LOGCOMMENT ( " --- RB_RenderMotionBlur ---" );
15101524
1525+ RB_PrepareForSamplingDepthMap ();
1526+
15111527 GL_State ( GLS_DEPTHTEST_DISABLE );
15121528 GL_Cull ( cullType_t::CT_TWO_SIDED );
15131529
@@ -1546,12 +1562,7 @@ void RB_RenderSSAO()
15461562
15471563 GLIMP_LOGCOMMENT ( " --- RB_RenderSSAO ---" );
15481564
1549- // Assume depth is dirty since we just rendered depth pass and everything opaque
1550- if ( glConfig.textureBarrierAvailable )
1551- {
1552- glTextureBarrier ();
1553- backEnd.dirtyDepthBuffer = false ;
1554- }
1565+ RB_PrepareForSamplingDepthMap ();
15551566
15561567 GL_State ( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO );
15571568 GL_Cull ( cullType_t::CT_TWO_SIDED );
@@ -2718,9 +2729,6 @@ static void RB_RenderView( bool depthPass )
27182729 // draw everything that is translucent
27192730 if ( glConfig.usingMaterialSystem ) {
27202731 materialSystem.RenderMaterials ( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, backEnd.viewParms .viewID );
2721-
2722- // HACK: assume surfaces with depth fade don't use the material system
2723- backEnd.dirtyDepthBuffer = true ;
27242732 }
27252733 RB_RenderDrawSurfaces ( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, DRAWSURFACES_ALL );
27262734
0 commit comments