Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualic0de

Posted 17 September 2012 - 06:26 PM

In order to accomplish a bilateral blur you will need to use FBOs (Frame Buffer Objects). You essentially render your scene to an FBO and then blur that in one direction. You then render the first FBO to either another FBO or to the screen then you blur that in the other direction.

Your Shaders are going to look something like this, you will have two of them, each in a different direction.

uniform sampler2D color_texture;
varying vec2 vTexCoord;

const float blurSize = 1.0/512.0;

void main(void)
{
vec4 sum = vec4(0.0);
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 4.0*blursize)) * 0.05;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 4.0*blursize)) * 0.05;
gl_FragColor = sum;
}

#2ic0de

Posted 17 September 2012 - 06:26 PM

In order to accomplish a bilateral blur you will need to use FBOs (Frame Buffer Objects). You essentially render your scene to an FBO and then blur that in one direction. You then render the first FBO to either another FBO or to the screen then you blur that in the other direction.

Your Shaders are going to look something like this, you will have two of them, each in a different direction.

uniform sampler2D color_texture;
varying vec2 vTexCoord;

const float blurSize = 1.0/512.0;

void main(void)
{
vec4 sum = vec4(0.0);
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 4.0*blursize)) * 0.05;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 4.0*blursize)) * 0.05;
gl_FragColor = sum;
}

You simply cannot do bilateral blur without FBOs

#1ic0de

Posted 17 September 2012 - 06:25 PM

In order to accomplish a bilateral blur you will need to use FBOs (Frame Buffer Objects). You essentially render your scene to an FBO and then blur that in one direction. You then render the first FBO to either another FBO or to the screen then you blur that in the other direction.

Your Shaders are going to look something like this, you will have two of them, each in a different direction.

uniform sampler2D color_texture;
varying vec2 vTexCoord;

const float blurSize = 1.0/512.0;

void main(void)
{
vec4 sum = vec4(0.0);
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 4.0*blursize)) * 0.05;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y - blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + blursize)) * 0.15;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 2.0*blursize)) * 0.12;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 3.0*blursize)) * 0.09;
sum += texture2D(color_texture, vec2(vTexCoord.x, vTexCoord.y + 4.0*blursize)) * 0.05;
gl_FragColor = sum;
}

PARTNERS