uniform sampler2D Color0; // this should hold the texture rendered by the horizontal blur pass
/*
//const float blurSize = 1.0/384.0;
 
void main(void)
{
   vec4 sum = vec4(0.0);
 
   // blur in y (vertical)
   // take nine samples, with the distance blurSize between them
   //sum += texture2D(Color0, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - 4.0*blurSize)) * 0.054670;
   sum += texture2D(Color0, gl_TexCoord[1].st ) * 0.015625; //0.004432;
   sum += texture2D(Color0, gl_TexCoord[2].st ) * 0.09375;  //0.053991;
   sum += texture2D(Color0, gl_TexCoord[3].st ) * 0.234375; //0.241971;
   sum += texture2D(Color0, gl_TexCoord[0].st ) * 0.3125;   //0.398942;
   sum += texture2D(Color0, gl_TexCoord[4].st ) * 0.234375; //0.241971;
   sum += texture2D(Color0, gl_TexCoord[5].st ) * 0.09375;  //0.053991;
   sum += texture2D(Color0, gl_TexCoord[6].st ) * 0.015625; //0.004432;
   //sum += texture2D(Color0, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + 4.0*blurSize)) * 0.054670;
 
   gl_FragColor = sum;//1.00027 * sum;
}
*/

const float c = -30.0;
const vec3 weights = vec3(0.3125, 0.234375, 0.09375);

// gaussian blur by importance sampling, see shaderX7, p.262
void main(void)
{
  //gl_FragColor = 0.2 * ( texture2D(Color0, gl_TexCoord[0].st) +
  //                       texture2D(Color0, gl_TexCoord[1].st) +
  //                       texture2D(Color0, gl_TexCoord[2].st) +
  //                       texture2D(Color0, gl_TexCoord[3].st) +
  //                       texture2D(Color0, gl_TexCoord[4].st) );

  vec4 dm2 = texture2D(Color0, gl_TexCoord[0].st);
  vec4 dm1 = texture2D(Color0, gl_TexCoord[1].st);
  vec4 d   = texture2D(Color0, gl_TexCoord[2].st);
  vec4 dp1 = texture2D(Color0, gl_TexCoord[3].st);
  vec4 dp2 = texture2D(Color0, gl_TexCoord[4].st);

  dm2 = weights.z * exp(c * (dm2 - d));
  dm1 = weights.y * exp(c * (dm1 - d));
  dp1 = weights.y * exp(c * (dp1 - d));
  dp2 = weights.z * exp(c * (dp2 - d));

  vec4 sum = weights.x + (dm2 + dm1 + dp1 + dp2);
  ///sum = log(sum);
  sum = exp(c * d) * sum;
  
  gl_FragColor = sum;//log(sum);
}