MoonWorksGraphicsTests/Common/Content/Shaders/Source/TexturedDepthQuad.frag

26 lines
581 B
GLSL
Raw Normal View History

#version 450
layout (location = 0) in vec2 TexCoord;
layout (location = 0) out vec4 FragColor;
2024-06-06 05:47:06 +00:00
layout(set = 2, binding = 0) uniform sampler2D Sampler;
2024-06-06 05:47:06 +00:00
layout (set = 3, binding = 0) uniform UniformBlock
{
float zNear;
float zFar;
};
// Calculation taken from http://www.geeks3d.com/20091216/geexlab-how-to-visualize-the-depth-buffer-in-glsl/
float linearizeDepth(float originalDepth)
{
return (2.0 * zNear) / (zFar + zNear - originalDepth * (zFar - zNear));
}
void main()
{
float d = texture(Sampler, TexCoord).r;
d = linearizeDepth(d);
FragColor = vec4(d, d, d, 1.0);
}