precision mediump float;

uniform sampler2D uSampler;
uniform float uBlur;
uniform float uRadius;
varying vec2 vTextureCoord;
uniform vec3 iResolution;

void main() {
  float Pi = 6.28318530718;
  float Directions = 16.0;
  float Quality = 6.0;
  float Size = 4.0;
  vec2 Radius = Size/iResolution.xy;

  vec4 sum = vec4(.0);
  if (uBlur > 0.0) {
    for (float d=0.0; d<Directions; d++) {
      for (float i=1.0; i<=Quality; i++) {
        sum += texture2D(uSampler, vTextureCoord + vec2(cos(d), sin(d)) * Radius*i) ;
      }
    }
  } else {
    sum = texture2D(uSampler, vTextureCoord);
  }

  sum /= Quality * Directions - 15.0;
  gl_FragColor = vec4(sum.rgb + vec3(0.0), sum.w);

}