Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Blur Shader not showing up  (Read 1818 times)

0 Members and 1 Guest are viewing this topic.

s1k3s

  • Newbie
  • *
  • Posts: 1
    • View Profile
Blur Shader not showing up
« on: July 11, 2014, 06:34:22 pm »
I'm trying to implement a SFML Shader following their example and it doesn't show up.

GameObject is a class that inherits and implements sf::Drawable. Inside GameObject I have a sf::Texture and a sf::Sprite objects, responsible for the image of the game object. I'm trying to apply a blur effect on it. Here's the .cpp where I load the image and shader:

x = new GameObject("Images/apple.png", 100, 100, 1, 1);
mshade.loadFromFile("Shaders/blur.frag", sf::Shader::Fragment);
mshade.setParameter("texture", *(x)->objectTexture);
mshade.setParameter("blur_radius", 200);

And this is how I draw it:

gameWindow->draw(*x, &mshade);

And this is the GLSL code to create the blur shader:

uniform sampler2D texture;
uniform float blur_radius;

void main()
{
    vec2 offx = vec2(blur_radius, 0.0);
    vec2 offy = vec2(0.0, blur_radius);

    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy)               * 4.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx)        * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx)        * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offy)        * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offy)        * 2.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
                 texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;

    gl_FragColor =  gl_Color * (pixel / 16.0);
}

But for some reason the image is displayed just as normally, without any effect. I also don't get any error. Does anyone know why the blur effect doesn't show up?

 

anything