Fix manual depth test hole cutting

This commit is contained in:
Malin E
2023-03-03 08:44:13 +01:00
parent fedbf9a31e
commit 98836e5393
4 changed files with 46 additions and 12 deletions
+22 -2
View File
@@ -25,7 +25,6 @@
#include "fragment.glsl"
in vec2 vs_st;
in vec2 vs_viewportPixelCoord;
in vec3 vs_normalViewSpace;
in vec4 vs_positionCameraSpace;
in float vs_screenSpaceDepth;
@@ -51,6 +50,9 @@ uniform float lightIntensities[8];
uniform bool performManualDepthTest = false;
uniform sampler2D gBufferDepthTexture;
uniform vec4 viewport;
uniform vec2 resolution;
Fragment getFragment() {
Fragment frag;
frag.depth = vs_screenSpaceDepth;
@@ -60,9 +62,27 @@ Fragment getFragment() {
frag.color.a = 1.0;
if (performManualDepthTest) {
// gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to
// resolution.y, need to normalize it
vec2 texCoord = gl_FragCoord.xy;
texCoord.x = texCoord.x / resolution.x;
texCoord.y = texCoord.y / resolution.y;
// Modify the texCoord based on the Viewport and Resolution. This modification is
// necessary in case of side-by-side stereo as we only want to access the part of the
// feeding texture that we are currently responsible for. Otherwise we would map the
// entire feeding texture into our half of the result texture, leading to a doubling
// of the "missing" half. If you don't believe me, load a configuration file with the
// side_by_side stereo mode enabled, disable FXAA, and remove this modification.
// The same calculation is done in the FXAA shader, the HDR resolving and the
// atmosphere shader
vec2 st = texCoord;
st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x);
st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y);
// Manual depth test
float gBufferDepth =
denormalizeFloat(texture(gBufferDepthTexture, vs_viewportPixelCoord).x);
denormalizeFloat(texture(gBufferDepthTexture, st).x);
if (vs_screenSpaceDepth > gBufferDepth) {
frag.color = vec4(0.0);
frag.depth = gBufferDepth;