/**
 *
 * Diplomova prace
 * Stinove techniky na dnesnim hardware a jejich porovnani
 *
 * Michal Toth
 *
 * Fakulta informacnich technologii
 * Vysoke uceni technicke v Brne
 *
 * 2013/2014
 *
 */

/*
 * Druhy pruchod GBufferem s vyuzitim depth peelingu
 * vytvari dalsi vrstvu hloubky
 */

#version 420

uniform float w;
uniform float h;
uniform float range;
uniform sampler2D depthTex;
uniform mat4 imvp;

void main() {
    vec2 tc = vec2(gl_FragCoord.x/w,gl_FragCoord.y/h);

    float depth = gl_FragCoord.z;
    vec4 pos = imvp*vec4(tc*2-1,depth*2-1,1);
    pos/=pos.w;

    float depth2 = texture(depthTex,tc);
    vec4 pos2 = imvp*vec4(tc*2-1,depth2*2-1,1);
    pos2/=pos2.w;

    if(length(pos2-pos)<range)
    discard;
}
