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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Carbonedioxide

Pages: [1]
1
Graphics / Shader problem
« on: August 15, 2018, 05:33:18 am »
Hello!
I've recently decided to update to 2.5 version and have small issue with shader I use.

That's original image:
(click to show/hide)

that's blurred version in 2.4.2:
(click to show/hide)

and that's blurred version in 2.5:
(click to show/hide)
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.

Pages: [1]
anything