Depth fetch workaround.

This commit is contained in:
luboslenco 2016-10-26 13:50:17 +02:00
parent 186195089c
commit 8e21184c37
2 changed files with 7 additions and 3 deletions

View file

@ -134,7 +134,9 @@ void main() {
}
fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), mask_probe);
#else
fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), mask);
// fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), mask);
// TODO: Can not read and write to depth buffer at once, fetch depth from g0
fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), 1.0 - gl_FragCoord.z);
#endif
fragColor[1] = vec4(baseColor.rgb, occ);

View file

@ -99,10 +99,12 @@ void main() {
vec2 texCoord = screenPosition * 0.5 + 0.5;
// texCoord += vec2(0.5 / screenSize); // Half pixel offset
// 0 - 1 => -1 - 1
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, mask
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, occlusion
// 0 - 1 => -1 - 1
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// TODO: Can not read and write to depth buffer at once, fetch depth from g0
float depth = (1.0 - g0.a) * 2.0 - 1.0;
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);