title: OpenGl blurring
body: <p>I'm using libgdx and want to make a common Gaussian blur post-processing effect. Following <a href="https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson5" rel="nofollow noreferrer">this</a> guide I faced some issues with texture filtering. Here the images:</p>
  <p>actual image:</p>
  <p><img src="https://i.stack.imgur.com/Y5vlP.png" alt="actual image" /></p>
  <p>blurred with radius = 1:</p>
  <p><img src="https://i.stack.imgur.com/If94d.png" alt="blurred with radius = 1" /></p>
  <p>blurred with radius = 5:</p>
  <p><img src="https://i.stack.imgur.com/lwsud.png" alt="blurred with radius = 5" /></p>
  <p>In the simplest case, I just have a transparent frame buffer object with some objects rendered to it. Then I need to apply some shader effects to this, basically only blur and then render the result to the screen. I also want to adjust the blur radius, but if I set the radius to more than 1 it becomes looking very rough. Guess it should be used with some linear filtering, but it isn't here. So I just need the same effect applied with a soft blur and configurable radius, maybe some other shader-sided options. And  I've also tried to explicitly assign Linear filtering to FBO textures, which doesn't change anything.</p>
  <p>Fragment shader:</p>
  <pre><code>//&quot;in&quot; attributes from our vertex shader
  varying vec4 vColor;
  varying vec2 vTexCoord;
  
  //declare uniforms
  uniform sampler2D u_texture;
  uniform float resolution;
  uniform float radius;
  uniform vec2 dir;
  
  void main() {
      //this will be our RGBA sum
      vec4 sum = vec4(0.0);
      
      //our original texcoord for this fragment
      vec2 tc = vTexCoord;
      
      //the amount to blur, i.e. how far off center to sample from 
      //1.0 -&gt; blur by one pixel
      //2.0 -&gt; blur by two pixels, etc.
      float blur = radius/resolution; 
      
      //the direction of our blur
      //(1.0, 0.0) -&gt; x-axis blur
      //(0.0, 1.0) -&gt; y-axis blur
      float hstep = dir.x;
      float vstep = dir.y;
      
      //apply blurring, using a 9-tap filter with predefined gaussian weights
      
      sum += texture2D(u_texture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
      sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
      sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
      sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
      
      sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270;
      
      sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
      sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
      sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
      sum += texture2D(u_texture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
  
      gl_FragColor = vColor * sum;
  }
  </code></pre>
  <p>The full <a href="https://gist.github.com/dudusaw/f400ebda2438b5bf5872be05df1be6da" rel="nofollow noreferrer">class</a></p>