precision highp float;
uniform sampler2D u_image;
uniform float u_scale;
uniform vec2 u_texSize;
varying vec2 v_texCoord;

vec4 AvgN(in sampler2D image, in vec2 texCoord, in vec2 pixelSize) {
  const int n = 1;
  float total = 0.0;
  vec4 avg = vec4(0,0,0,0);
  float base = 0.0;

  for(int i = -n; i <= n; i++) {
    float ii = float(i);
    for(int j = -n; j <= n; j++) {
      float jj = float(j);
      vec2 coord = texCoord + vec2(ii * pixelSize.x, jj * pixelSize.y);
      vec4 cc = texture2D(image, coord);
      total += 1.0;
      avg += cc;
    }
  }
  avg = avg / total;
  return avg;
}

void main() {
  gl_FragColor = AvgN(u_image, v_texCoord, u_texSize);
}