uniform sampler2D RTScene; // the texture with the scene you want to blur
uniform sampler2D Mask;    // Mask used to early-out the blur.
 
uniform float blurSize;
 
void main(void)
{
   vec4 sum = vec4(0.0);
   vec2 tex = gl_TexCoord[0].xy;
   
   vec4 m = texture2D(Mask, tex);
   
   // Early out if the mask is empty.
   if(m[3] < .001) {
     discard;
      // to debug the mask:
      // gl_FragColor = vec4(0,0,0,1);
   } else {
   
     float coefs[9];
     coefs[0] = 0.05;
     coefs[1] = 0.09;
     coefs[2] = 0.12;
     coefs[3] = 0.15;
     coefs[4] = 0.16;
     coefs[5] = 0.15;
     coefs[6] = 0.12;
     coefs[7] = 0.09;
     coefs[8] = 0.05;
     
     // blur in x (horizontal)
     // take nine samples, with the distance blurSize between them
     for(int i=0;i<9;++i) {
       vec2 p = vec2(tex.x - (float(i)-4.0)*blurSize, tex.y);
     
       sum += coefs[i] 
            * texture2D(RTScene, p);
     }
   
     gl_FragColor = sum;
     
  }
}