forkkmuopengl/BaseGLProject/textureViewer.frag
2019-04-15 14:15:16 +09:00

29 lines
647 B
GLSL

#version 430
in vec2 uv;
out vec4 final_color;
uniform sampler2D tex;
uniform bool depth;
float LinearizeDepth(in vec2 uv)
{
float zNear = 0.1f; // zNear of your perspective projection
float zFar = 2000.0f; // zFar of your perspective projection
float depth = texture(tex, uv).x;
return (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
}
void main()
{
//rrra because depth textures are not usual textures, they have only one channel
final_color = (depth) ? texture(tex, uv).rrra : texture(tex, uv).rgba;
if (depth) {
float d;
d = LinearizeDepth(uv);
final_color = vec4(d,d,d,1.0);
}
}