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.


Messages - simps

Pages: [1]
1
Graphics / Re: Frag shader doesn't work as intended
« on: October 08, 2013, 05:19:04 pm »
Oh, mouse coords are in [0..1] range
Thank you Laurent
I was terribly inattentive  :-\

2
Graphics / Re: Frag shader doesn't work as intended
« on: October 08, 2013, 03:04:52 pm »
Thanks for detailed answer!
I haven't checked shader code myself because I've snatched it from \SFML-2.1-windows-vc9-32bits\SFML-2.1\examples\shader\resources\pixelate.frag
And it's a mystery how it works in the example.

simps

3
Graphics / Frag shader doesn't work as intended
« on: October 04, 2013, 05:01:04 pm »
Hello
Basically, I'm doing the following:
(SFML 2.1 statically linked)

void TestFunc ()
{
        sf::RenderWindow Window;
        Window.create(sf::VideoMode(800, 600), "TestFunc");

        //rect
        sf::RectangleShape Rect;
        Rect.setPosition(300.0f, 200.0f);
        Rect.setSize(sf::Vector2f(200.0f, 100.0f));
        Rect.setOutlineThickness(4);
        Rect.setFillColor(sf::Color(0, 0, 0, 0));
        Rect.setOutlineColor(sf::Color(0x00, 0x33, 0xff));//light blue

        //texture to render into
        sf::RenderTexture RenderTexture;
        bool bRes = RenderTexture.create(512, 512);
        if (bRes == false) return;

        //pixelate shader from examples
        sf::Shader ShaderPixelateF;
        bRes = ShaderPixelateF.loadFromFile("dat/shaders/pixelate_f.glsl", sf::Shader::Type::Fragment);
        if (bRes == false) return;
        ShaderPixelateF.setParameter("texture", sf::Shader::CurrentTexture);
        ShaderPixelateF.setParameter("pixel_threshold", 10.0f);

        //sprite to render shader with
        sf::Sprite Sprite;

        //main cycle
        while (Window.isOpen())
        {
                sf::Event Event;
                while (Window.pollEvent(Event))
                {
                        if (Event.type == sf::Event::Closed || (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Key::Escape))
                        {
                                Window.close();
                        }
                }

                RenderTexture.clear(sf::Color(0, 0, 0, 0));
                RenderTexture.draw(Rect);
                RenderTexture.display();

                Sprite.setTexture(RenderTexture.getTexture());

                Window.clear(sf::Color(0, 128, 0));//green

                Window.draw(Sprite, &ShaderPixelateF);

//              Window.draw(Sprite);

                Window.display();
        }
}
 

and pixelate_f.glsl is:

uniform sampler2D texture;
uniform float pixel_threshold;

void main()
{
    float factor = 1.0 / (pixel_threshold + 0.001);
        vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
        gl_FragColor = texture2D(texture, pos) * gl_Color;

//      gl_FragColor = vec4 (1.0, 1.0, 0.0, 1.0);//yellow
}
 

I'm seeing only green background.
Uncommenting line in cpp brings rect (rendering to texture works, sprite has texture properly set).
Uncommenting line in shader brings yellow box (shader works).
Where I'm doing wrong?

Thanks in advance
simps

Pages: [1]