


in vec2 screenpos1;
in vec2 screenpos2;
in vec4 vpos;
in vec2 texCoord;

uniform sampler2D mbbuff1;
uniform sampler2D mbbuff1depth;
uniform sampler2D mbbuff2;

void main()
{

    
    
    
    
    vec4 col1=texture2D(mbbuff1,gl_FragCoord/vec2(1920.0,1080.0));
    

    vec4 coldepth=texture2D(mbbuff1depth,gl_FragCoord/vec2(1920.0,1080.0));
    float currdepth=vpos.z;
    float imagedepth=(coldepth.r*256*65536+coldepth.g*256*256+coldepth.b*256*1)/(65536.0*256.0)*200.0;
    if (currdepth>imagedepth) 
    {gl_FragColor = col1; return;}



    

    const float steps=10.0;
    float xoff=screenpos2.x-screenpos1.x;
    float yoff=screenpos2.y-screenpos1.y;
    float xstep=xoff/steps;
    float ystep=yoff/steps;

    vec2 blurxy=gl_FragCoord/vec2(1920.0,1080.0);
    vec4 blurcolor=vec4(0,0,0,1);
    for (float i=0.0;i<1.0;i+=1.0/steps){
       blurcolor+=texture2D(mbbuff1,blurxy)*(1.0-i)+texture2D(mbbuff2,blurxy)*(i);
       blurxy+=vec2(xstep,ystep);
    }
    blurcolor/=steps;
    gl_FragColor = blurcolor;
}
