Hello!
I've recently decided to update to 2.5 version and have small issue with shader I use.
That's original image:
that's blurred version in 2.4.2:
and that's blurred version in 2.5:
I've circled most visible change but as you keep looking you find more
Main code:
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
int main() {
sf::Sprite sprite;
sf::Texture texture;
if (!texture.loadFromFile("background.jpg")) {}
sprite.setTexture(texture);
sf::Shader blurShader;
if (!blurShader.loadFromFile("blur.frag", sf::Shader::Fragment)) {}
blurShader.setUniform("texture", sf::Shader::CurrentTexture);
blurShader.setUniform("blur_radius", 0.001f);
sf::RenderTexture rendertexture;
rendertexture.create(1280, 720);
rendertexture.clear();
for (int i = 100; i >= 0; i--) {
rendertexture.draw(sprite, &blurShader);
rendertexture.display();
sprite.setTexture(rendertexture.getTexture());
}
sprite.setPosition(0, 0);
sf::RenderWindow window(sf::VideoMode(1280, 720), "Peppa pig");
sf::Event event;
while (window.isOpen()) {
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
exit(0);
else if (event.key.code == sf::Keyboard::Escape)
exit(0);
}
window.clear();
window.draw(sprite);
window.display();
}
}
Code of 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);
}
Compiled using visual studio 2015.