2016-08-29 11:10:22 +00:00
|
|
|
|
|
|
|
in vec2 TexCoord;
|
2018-06-12 21:52:33 +00:00
|
|
|
layout(location=0) out vec4 FragColor;
|
2016-08-29 11:10:22 +00:00
|
|
|
|
2016-09-03 02:12:00 +00:00
|
|
|
#if defined(MULTISAMPLE)
|
2018-06-13 13:53:56 +00:00
|
|
|
layout(binding=0) uniform sampler2DMS DepthTexture;
|
|
|
|
layout(binding=1) uniform sampler2DMS ColorTexture;
|
2016-09-03 02:12:00 +00:00
|
|
|
#else
|
2018-06-13 13:53:56 +00:00
|
|
|
layout(binding=0) uniform sampler2D DepthTexture;
|
|
|
|
layout(binding=1) uniform sampler2D ColorTexture;
|
2016-09-03 02:12:00 +00:00
|
|
|
#endif
|
2016-09-03 02:29:50 +00:00
|
|
|
|
2016-10-06 05:36:49 +00:00
|
|
|
float normalizeDepth(float depth)
|
|
|
|
{
|
|
|
|
float normalizedDepth = clamp(InverseDepthRangeA * depth + InverseDepthRangeB, 0.0, 1.0);
|
|
|
|
return 1.0 / (normalizedDepth * LinearizeDepthA + LinearizeDepthB);
|
|
|
|
}
|
|
|
|
|
2016-08-29 11:10:22 +00:00
|
|
|
void main()
|
|
|
|
{
|
2016-09-03 02:29:50 +00:00
|
|
|
vec2 uv = Offset + TexCoord * Scale;
|
|
|
|
|
2016-09-03 02:12:00 +00:00
|
|
|
#if defined(MULTISAMPLE)
|
|
|
|
ivec2 texSize = textureSize(DepthTexture);
|
2016-09-09 16:19:00 +00:00
|
|
|
#else
|
|
|
|
ivec2 texSize = textureSize(DepthTexture, 0);
|
|
|
|
#endif
|
|
|
|
|
2016-10-06 05:36:49 +00:00
|
|
|
ivec2 ipos = ivec2(max(uv * vec2(texSize), vec2(0.0)));
|
2016-09-09 16:19:00 +00:00
|
|
|
|
|
|
|
#if defined(MULTISAMPLE)
|
2016-10-09 04:17:48 +00:00
|
|
|
float depth = normalizeDepth(texelFetch(ColorTexture, ipos, SampleIndex).a != 0.0 ? texelFetch(DepthTexture, ipos, SampleIndex).x : 1.0);
|
2016-09-03 02:12:00 +00:00
|
|
|
#else
|
2016-10-06 05:36:49 +00:00
|
|
|
float depth = normalizeDepth(texelFetch(ColorTexture, ipos, 0).a != 0.0 ? texelFetch(DepthTexture, ipos, 0).x : 1.0);
|
2016-09-03 02:12:00 +00:00
|
|
|
#endif
|
2016-10-09 04:17:48 +00:00
|
|
|
|
|
|
|
FragColor = vec4(depth, 0.0, 0.0, 1.0);
|
2016-08-29 11:10:22 +00:00
|
|
|
}
|