#version 130
/**
 Apply as a full-screen post-process
 */

uniform sampler2D   depthBuffer;
uniform float       threshold;

out vec3            color;

void main() {
    ivec2 pos = ivec2(gl_FragCoord.xy);

    // Compare this pixel to its neighbors
    float depth0 = texelFetch(depthBuffer, pos, 0).r;

    bool edge = false;
    ivec2 delta;
    for (delta.y = -1; delta.y <= +1; ++delta.y) {
        for (delta.x = -1; delta.x <= +1; ++delta.x) {
            edge = edge || (abs(texelFetch(depthBuffer, pos + delta, 0).r - depth0) > threshold);
        }
    }

    color = edge ? vec3(0.0) : vec3(1.0);
}
