uniform sampler2D 	tex;
uniform sampler2D 	depthTex;
varying vec2		t0,t1,t2;

void main()
{
	vec4 	c0,c1,c2;
	float 	d0,d1,d2,
			o0,o1;
	float 	count=1.0;
	vec4 	finalcolor;
	
	d0=-texture2D(depthTex,t0).z;
	c0=texture2D(tex, t0);
	
	finalcolor=c0;
	
//	if(d0<10000000.0)
//	{
		d1=-texture2D(depthTex,t1).z;
		d2=-texture2D(depthTex,t2).z;
//		if(d1<10000000.0 && d2<10000000.0)
//		{
			o0=clamp(20.0-abs(d0-d1),0.0,1.0);
			o1=clamp(20.0-abs(d0-d2),0.0,1.0);

			c1=texture2D(tex,t1)*o0;		
			c2=texture2D(tex,t2)*o1;

			count+=o0;
			count+=o1;
			
			finalcolor=(c0+c1+c2)/count;
//		}
//	}
	gl_FragColor =  finalcolor;
}