#version 450 core

in vec2 vUv;

uniform sampler2D uDepthTex;
uniform float uMinDepth;
uniform float uMaxDepth;
uniform vec2 uUvMin;
uniform vec2 uUvMax;

out vec4 FragColor;

void main()
{
    vec2 uv = mix(uUvMin, uUvMax, vUv);
    float d = texture(uDepthTex, uv).r;

    // untouched / void area stays black
    if (d >= 0.999999)
    {
        FragColor = vec4(0.0, 0.0, 0.0, 1.0);
        return;
    }

    float denom = max(uMaxDepth - uMinDepth, 1e-6);
    float t = clamp((d - uMinDepth) / denom, 0.0, 1.0);

    // Nearer useful values become brighter
    float gray = 1.0 - t;
    FragColor = vec4(vec3(gray), 1.0);
}