Constructive criticsm on my linear sampling Gaussian blur

Posted by Aequitas on Game Development See other posts from Game Development or by Aequitas
Published on 2012-11-14T17:54:08Z Indexed on 2012/11/14 23:21 UTC
Read the original article Hit count: 337

Filed under:
|
|

I've been attempting to implement a gaussian blur utilising linear sampling, I've come across a few articles presented on the web and a question posed here which dealt with the topic. I've now attempted to implement my own Gaussian function and pixel shader drawing reference from these articles.

This is how I'm currently calculating my weights and offsets:

int support = int(sigma * 3.0)
weights.push_back(exp(-(0*0)/(2*sigma*sigma))/(sqrt(2*pi)*sigma));
total += weights.back();

offsets.push_back(0);
for (int i = 1; i <= support; i++)
{
  float w1 = exp(-(i*i)/(2*sigma*sigma))/(sqrt(2*pi)*sigma);
  float w2 = exp(-((i+1)*(i+1))/(2*sigma*sigma))/(sqrt(2*pi)*sigma);

  weights.push_back(w1 + w2);
  total += 2.0f * weights[i];

  offsets.push_back(w1 / weights[i]);
}

for (int i = 0; i < support; i++)
{
  weights[i] /= total;
}

Here is an example of my vertical pixel shader:

  vec3 acc = texture2D(tex_object, v_tex_coord.st).rgb*weights[0];
  vec2 pixel_size = vec2(1.0 / tex_size.x, 1.0 / tex_size.y);
  for (int i = 1; i < NUM_SAMPLES; i++)                                                     
  {
    acc += texture2D(tex_object, (v_tex_coord.st+(vec2(0.0, offsets[i])*pixel_size))).rgb*weights[i];
    acc += texture2D(tex_object, (v_tex_coord.st-(vec2(0.0, offsets[i])*pixel_size))).rgb*weights[i];
  }
  gl_FragColor = vec4(acc, 1.0);

Am I taking the correct route with this? Any criticism or potential tips to improving my method would be much appreciated.

© Game Development or respective owner

Related posts about c++

Related posts about glsl