qzdoom-gpl/wadsrc/static/shaders/glsl/lineardepth.fp

36 lines
1 KiB
Text
Raw Normal View History

2016-08-29 11:10:22 +00:00
in vec2 TexCoord;
out vec4 FragColor;
2016-09-03 02:12:00 +00:00
#if defined(MULTISAMPLE)
uniform sampler2DMS DepthTexture;
uniform int SampleCount;
#else
2016-08-29 11:10:22 +00:00
uniform sampler2D DepthTexture;
2016-09-03 02:12:00 +00:00
#endif
2016-08-29 11:10:22 +00:00
uniform float LinearizeDepthA;
uniform float LinearizeDepthB;
uniform float InverseDepthRangeA;
uniform float InverseDepthRangeB;
void main()
{
2016-09-03 02:12:00 +00:00
#if defined(MULTISAMPLE)
ivec2 texSize = textureSize(DepthTexture);
ivec2 ipos = ivec2(TexCoord * vec2(texSize));
float depth = 0.0;
for (int i = 0; i < SampleCount; i++)
depth += texelFetch(DepthTexture, ipos, i).x;
depth /= float(SampleCount);
#else
/*ivec2 texSize = textureSize(DepthTexture, 0);
ivec2 ipos = ivec2(TexCoord * vec2(texSize));
if (ipos.x < 0) ipos.x += texSize.x;
if (ipos.y < 0) ipos.y += texSize.y;
float depth = texelFetch(DepthTexture, ipos, 0).x;*/
2016-08-29 11:10:22 +00:00
float depth = texture(DepthTexture, TexCoord).x;
2016-09-03 02:12:00 +00:00
#endif
2016-08-29 11:10:22 +00:00
float normalizedDepth = clamp(InverseDepthRangeA * depth + InverseDepthRangeB, 0.0, 1.0);
FragColor = vec4(1.0 / (normalizedDepth * LinearizeDepthA + LinearizeDepthB), 0.0, 0.0, 1.0);
}