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 - AveryBibeau

Pages: [1]
1
Graphics / Re: GLSL Fragment Shader artifacts
« on: August 01, 2013, 06:29:55 am »
After updating my drivers (Intel HD4000), a few issues seem to be fixed. The radial shadow is no longer blue and the noise is less noticeable (but still prominent in dark areas). I haven't had access to an nVidia/AMD setup yet to test if it's just a problem with Intel drivers, but I can't see anything in my setup that is weird enough to cause this much trouble between specs.

2
Graphics / GLSL Fragment Shader artifacts
« on: July 30, 2013, 02:33:19 am »
I'm having trouble with eliminating artifacts from this fragment shader. I'm trying to simulate a radial blur/crepuscular rays effect and it works, except for the artifacts. I've found that when the RenderWindow's antialiasing is 0, they are most prominent, and they are still prominent until antialiasing is set to 8. In sf::Style::Fullscreen mode they are more prominent. Also, when the number of samples is higher than 65 (64 loop iterations), the shader goes haywire and displays nonsensical graphics. Finally, the artifacts have a slight blue tint to them even though the entire scene is just white with a black circle.

Here's the code for my fragment shader:
uniform float exposure;

uniform float decay;

uniform float density;

uniform float weight;

uniform vec2 lightPositionOnScreen;

uniform sampler2D firstPass;

const int NUM_SAMPLES = 65;

out vec4 color;

void main()
{      
        vec2 pixel = gl_FragCoord.xy;
       
        pixel.x /= 1920.0;
        pixel.y /= 1080.0;
       
        vec2 lpos = lightPositionOnScreen;
        lpos.x /= 1920.0;
        lpos.y /= 1080.0;

        vec2 deltaTextCoord = vec2( lpos.xy - pixel.xy );

        deltaTextCoord *= density / float(NUM_SAMPLES);

        float illuminationDecay = 1.0;

        for(int i=0; i < NUM_SAMPLES ; i++)
        {
                pixel += deltaTextCoord;

                vec4 sample = texture2D(firstPass, pixel);
                       
                sample *= illuminationDecay * weight;

                color += sample;
                       
                illuminationDecay *= decay;
        }
        color *= exposure;
}

And here is the code for the project:
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        sf::ContextSettings cs;
        cs.antialiasingLevel = 0;
        int scrHeight = sf::VideoMode::getDesktopMode().height;
        int scrWidth = sf::VideoMode::getDesktopMode().width;
        sf::RenderWindow Window(sf::VideoMode( scrWidth, scrHeight ), "SFML", sf::Style::Default, cs );
        Window.setVerticalSyncEnabled(true);

        sf::Clock clock;

        srand( time(NULL) );

        sf::Shader rayShader;

        rayShader.loadFromFile("data\\shaders\\radial.FRAG", sf::Shader::Fragment);
        rayShader.setParameter("exposure", 0.5f);
        rayShader.setParameter("decay", 0.97f);
        rayShader.setParameter("density", 0.97f);
        rayShader.setParameter("weight", 0.5f);

        sf::RenderTexture buffer1;
        sf::Sprite buffer1Sprite;
        buffer1.create( 1920, 1080 );
        buffer1.setSmooth( true );
        buffer1Sprite = sf::Sprite( buffer1.getTexture() );

        sf::RenderTexture buffer2;
        sf::Sprite buffer2Sprite;
        buffer2.create( 1920, 1080 );
        buffer2.setSmooth( true );
        buffer2Sprite = sf::Sprite( buffer2.getTexture() );

        sf::CircleShape test;
        test.setRadius( 40 );
        test.setOrigin( 40, 40 );
        test.setFillColor( sf::Color::Black );
        test.setPosition( 400, 400 );

        sf::RenderStates states;

        while( Window.isOpen() )
        {
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::LControl ) && sf::Keyboard::isKeyPressed( sf::Keyboard::Q ) )
                        Window.close();
                sf::Time dt = clock.restart();

                sf::Event Event;
                while( Window.pollEvent( Event ) )
                {
                        if( Event.type == sf::Event::Closed )
                                Window.close();

                        if( Event.type == sf::Event::Resized )
                        {
                                sf::FloatRect visibleArea( 0, 0, Event.size.width, Event.size.height );
                                Window.setView( sf::View( visibleArea ) );
                        }
                }

                float x = sf::Mouse::getPosition(Window).x;
                float y = sf::Mouse::getPosition(Window).y;

                rayShader.setParameter("lightPositionOnScreen", sf::Vector2f(960.0, 540.0 ));
                rayShader.setParameter("firstPass", sf::Shader::CurrentTexture );
                rayShader.setParameter("exposure", 0.25f);
                rayShader.setParameter("decay", 0.97f);
                rayShader.setParameter("density", 0.97f);
                rayShader.setParameter("weight", 0.5f);
               
                states.shader = &rayShader;
                test.setPosition( x, y );
                bg.setColor( sf::Color::Black );
                buffer1.clear( sf::Color::Transparent );
                buffer1.draw( test );
                buffer1.display();

                buffer2.clear( sf::Color::Transparent );
                buffer2.draw( buffer1Sprite );
                buffer2.draw( buffer1Sprite, states );
                buffer2.display();
                Window.clear( sf::Color::White );

                Window.draw( buffer2Sprite );

                Window.display();
        }
}

Here are the artifacts in question:

3
Graphics / Re: Trouble with multiple shaders/buffers
« on: July 26, 2013, 11:02:01 pm »
Ah thank you, on top of that, I forgot to use additive rendering for the lights to each buffer, I was only doing it on the final output and my shader didn't have alpha decay. Thanks for the help!

4
Graphics / Trouble with multiple shaders/buffers
« on: July 25, 2013, 08:55:08 am »
I'm having trouble with using multiple buffers to use multiple shaders. I understand that I render to buffer1, draw it to buffer2, then continue drawing to buffer2, but I'm having trouble with the implementation. This is what I have so far and all it does is render the second light (at (100, 100)).

        void draw( sf::RenderWindow& target )
        {
                lightShader.setParameter("lightpos", sf::Vector2f( 960.f, 640.f ) );

                buffer1.clear( sf::Color::Transparent );
                buffer1.draw( buffer1Sprite, &lightShader );
                buffer1.display();

                lightShader.setParameter("lightpos", sf::Vector2f( 100.f, 100.f ) );

                buffer2.clear( sf::Color::Transparent );
                buffer2.draw( buffer1Sprite );
                buffer2.draw( buffer2Sprite, &lightShader );
                buffer2.display();

                target.draw( buffer2Sprite );
        }
 

5
General / Can't build documentation with Doxygen
« on: July 13, 2013, 05:57:07 pm »
I'm trying to build the offline documentation for SFML but can't get Doxygen and CMake working. The CMake output says that it successfully found Doxygen.exe 1.8.4 in my Program Files but under the DOXYGEN_HHC_PROGRAM it says DOXYGEN_HHC_PROGRAM-NOTFOUND. The Build/doc/html folder only contains the doxygen.css file from the SFML source and nothing else. What should I be doing to get it to properly build?

6
General / Re: SFML Separating Axis Theorem testing
« on: July 01, 2013, 04:57:44 am »
I found a big problem with this being used with sf::Transformable classes, it doesn't work with them. I'm not sure if there's a way to apply transformations relatively to a VertexArray automatically but I tried implementing this code:

bool sat( Object& shape1, Object& shape2 )
{
        sf::Vector2f vectorOffset( shape1.getPosition().x - shape2.getPosition().x, shape1.getPosition().y - shape2.getPosition().y );

        sf::VertexArray newshape1( sf::TrianglesFan, shape1.getShape().getVertexCount() );

        for( int i = 0; i < shape1.getShape().getVertexCount(); i++ )
        {
                float length = sqrt( shape1.getShape()[i].position.x*shape1.getShape()[i].position.x + shape1.getShape()[i].position.y*shape1.getShape()[i].position.y );
                newshape1[i].position.x = length*cos( (shape1.getRotation()*(PI/180) ) + atan2( shape1.getShape()[i].position.y, shape1.getShape()[i].position.x ) );
                newshape1[i].position.y = length*sin( (shape1.getRotation()*(PI/180) ) + atan2( shape1.getShape()[i].position.y, shape1.getShape()[i].position.x ) );
                //std::cout << newshape1[i].position.x << " " << newshape1[i].position.y << std::endl;
        }
        //std::cout << std::endl;

        for( int i = 0; i < shape1.getShape().getVertexCount(); i++ )
        {
                sf::Vector2f axis = getNormalAxis( newshape1, i );

                float min1 = dotProduct( axis, newshape1[0].position );
                float max1 = min1;

                for( int j = 1; j < shape1.getShape().getVertexCount(); j++ )
                {
                        float testNum = dotProduct( axis, newshape1[j].position );
                        if( testNum < min1 )
                                min1 = testNum;
                        if( testNum > max1 )
                                max1 = testNum;
                }

                float min2 = dotProduct( axis, shape2.getShape()[0].position );
                float max2 = min2;

                for( int j = 1; j < shape2.getShape().getVertexCount(); j++ )
                {
                        float testNum = dotProduct( axis, shape2.getShape()[j].position );
                        if( testNum < min2 )
                                min2 = testNum;
                        if( testNum > max2 )
                                max2 = testNum;
                }

                float offset = dotProduct( axis, vectorOffset );
                min1 += offset;
                max1 += offset;

                float test1 = min1 - max2;
                float test2 = min2 - max1;

                if( test1 > 0 || test2 > 0 )
                        return 0;

                //std::cout << i << std::endl;
        }
        return 1;
}
 

It sort of works, the rotation is somewhat detected but there are sometimes it detects collisions when one hasn't occurred and I'm not sure if it's a decimal error (unlikely?) or something else

7
General / SFML Separating Axis Theorem testing
« on: July 01, 2013, 12:29:49 am »
I've put together a small implementation of the Separate Axis Theorem in SFML with VertexArrays but wanted to see if anyone could look it over. I'm pretty good with C++ but by no means a master so I'd love to know how I could improve this. It is an implementation of the ActionScript3 version found here :
http://rocketmandevelopment.com/2010/05/19/separation-of-axis-theorem-for-collision-detection/

My code:

Object.h
class Object : public sf::Drawable, public sf::Transformable
{
public:
        Object() : shape( sf::TrianglesStrip, 6 ), verts( 4 )
        {
                shape[0].position = sf::Vector2f( 0, 0 );
                shape[1].position = sf::Vector2f( 100, 0 );
                shape[2].position = sf::Vector2f( 0, 50 );
                shape[3].position = sf::Vector2f( -50, 0 );
                shape[4].position = sf::Vector2f( 0, -50 );
                shape[5].position = sf::Vector2f( 100, 0 );

                for( int i = 0; i < 4; i++ )
                {
                        verts[i].setRadius( 4 );
                        verts[i].setFillColor( sf::Color::Red );
                        verts[i].setOrigin( verts[i].getGlobalBounds().width/2, verts[i].getGlobalBounds().height/2 );
                        verts[i].setPosition( shape[i+1].position );
                }
        }
        sf::VertexArray& getShape()
        {return shape;}
private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
                states.transform *= getTransform();
                target.draw( shape, states);
                for( int i = 0; i < verts.size(); i++ )
                {
                        target.draw( verts[i], states);
                }
    }
        sf::VertexArray shape;
        std::vector<sf::CircleShape> verts;
};

Functions.h
sf::Vector2f normalize( sf::Vector2f& input )
{
        if( sqrt(input.x*input.x + input.y*input.y) == 0 )
        {
                input.x = 1;
                return input;
        }
        float length = sqrt(input.x*input.x + input.y*input.y);

        input.x /= length;
        input.y /= length;
        return input;
}

sf::Vector2f getNormalAxis( sf::VertexArray& shape, int index )
{
        sf::Vector2f vector1 = shape[index].position;
        sf::Vector2f vector2;
        if( index >= shape.getVertexCount() - 1 )
                vector2 = shape[0].position;
        else
                vector2 = shape[index+1].position;

        sf::Vector2f normalAxis( -(vector2.y - vector1.y), vector2.x - vector1.x );
        normalAxis = normalize( normalAxis );
        return normalAxis;
}

float dotProduct( sf::Vector2f& vector1, sf::Vector2f& vector2 )
{
        return vector1.x*vector2.x + vector1.y*vector2.y;
}

bool sat( Object& shape1, Object& shape2 )
{
        sf::Vector2f vectorOffset( shape1.getPosition().x - shape2.getPosition().x, shape1.getPosition().y - shape2.getPosition().y );

        for( int i = 0; i < shape1.getShape().getVertexCount(); i++ )
        {
                sf::Vector2f axis = getNormalAxis( shape1.getShape(), i );

                float min1 = dotProduct( axis, shape1.getShape()[0].position );
                float max1 = min1;

                for( int j = 1; j < shape1.getShape().getVertexCount(); j++ )
                {
                        float testNum = dotProduct( axis, shape1.getShape()[j].position );
                        if( testNum < min1 )
                                min1 = testNum;
                        if( testNum > max1 )
                                max1 = testNum;
                }

                float min2 = dotProduct( axis, shape2.getShape()[0].position );
                float max2 = min2;

                for( int j = 1; j < shape2.getShape().getVertexCount(); j++ )
                {
                        float testNum = dotProduct( axis, shape2.getShape()[j].position );
                        if( testNum < min2 )
                                min2 = testNum;
                        if( testNum > max2 )
                                max2 = testNum;
                }

                float offset = dotProduct( axis, vectorOffset );
                min1 += offset;
                max1 += offset;

                float test1 = min1 - max2;
                float test2 = min2 - max1;

                if( test1 > 0 || test2 > 0 )
                        return 0;
        }
        return 1;
}

My basic implementation just uses two shapes that are the same, one of which is controlled by the mouse. It seems to work fine so far; I haven't tested it extensively with more complex objects/numbers. So I wanted to see if anyone with experience in this area can provide some tips in terms of improving this. My next step is to of course calculate resultant vectors and implement this with freely moving objects.

Edit: On an unrelated note, does anyone have an argument for using TriangleStrips over TriangleFans or vice versa?

Pages: [1]