I want to create a "blur rect" that blurs everything underneath it. I have a rectangle (sf::RectangleShape) that's black and half transparent and I want to apply an additional blur effect to it by using a pixel shader.
The blur.frag is from the shader example (can't find the URL right now):
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);
}
And this is the code:
sf::Shader shader_blur_;
shader_blur_.loadFromFile("./data/blur.frag", sf::Shader::Type::Fragment);
shader_blur_.setParameter("blur_radius", 0.05);
and the draw code:
...
renderTarget.draw(someText);
renderTarget.draw(someButton);
renderTarget.draw(blurRect, &shader_blur_); // has no effect
...
It has no effect. When I apply the shader to the other stuff, for example the
someText, it properly blurs the text, but that's not what I want. I want to apply it to the
blurRect so everything underneath it (in this case:
someText and
someButton) gets blurred!
I also tried
renderStates.shader = &shader_blur_;
renderTarget.draw(blurRect, renderStates);
but it doesn't work either.
Could you please help me?