uniform sampler2D t_color;
uniform vec2 direction;
uniform int radius;
uniform float distort;

void main(void) {
  vec2 texcoord = gl_TexCoord[0].xy;
  vec4 col = vec4(0.0, 0.0, 0.0, 0.0);
  vec4 col2 = vec4(0.0, 0.0, 0.0, 0.0);
  float br = 0.0;

  float pier=1.0/float(radius);

  for (int i=-radius; i<=radius; i++) {
	col += texture2D(t_color, texcoord+i*direction)*(1.0-abs(float(i))/float(radius));
  }

  br = (col.r + col.g + col.b) / 3.0;
  
  col2.r = ( col.r*(1-br) ) + br*br;
  col2.g = ( col.g*(1-br) ) + br*br;
  col2.b = ( col.b*(1-br) ) + br*br;

  gl_FragColor = (1-distort)*col*pier+distort*clamp(col2*pier*2, 0.0, 0.5);
//  gl_FragColor = col*pier;
  
//  gl_FragColor = gl_FragColor*gl_FragColor;
  
}
