#version 430 compatibility

uniform sampler2D tex0;			// texture 
uniform sampler2D tex1;			// blurmap
uniform float t;				// from timer

void main()
{

 vec4 col0 = texture2D(tex0,gl_TexCoord[0].st);
 vec4 col1 = texture2D(tex1,gl_TexCoord[1].st);
 vec4 col = texture2D(tex0,gl_TexCoord[0].st); 

 int pass = int((1.0-col1.r)*(6.0+t));

 int k=1;

 for(int i=-int(pass/2.0); i<int(pass/2.0); i++)
 for(int j=-int(pass/2.0); j<int(pass/2.0); j++)
 if(sqrt(i*i+j*j) <= pass*pass )
 {
	  vec2 w = vec2(i,j) / vec2(1280.0,720.0);  //float(720.0);
	  k++;
	  col +=	texture2D(tex0, gl_TexCoord[0].st + w); 
 }
 col = (col/float(k));
 gl_FragColor = col;
}
