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

Pages: [1] 2 3 ... 8
1
SFML wiki / Re: Rectangular Boundary Collision
« on: March 14, 2021, 09:00:15 pm »
This is really interesting.

I've been eyeballing this code for a few weeks as a means of solving my off-screen culling which isn't perfect due to scale and rotation combined with a zooming and rotating view. What I have is working alright based on a cull-radius, but this could help make it very accurate!

I'm supposing I could make one object a 'screen-rectangle' and the other one whichever entity instance I'm checking.

Thanks.


*EDIT
Worked as expected!
Increased CPU usage a bit more than I'd like, but I can filter-out a lot of that with a radius check, leaving only the outer entities to test with this code.

Thanks HAPAX!!  ;D

2
Graphics / Applying a blur shader gives black square
« on: June 21, 2020, 08:11:23 pm »
Hi.

This shader will work if I apply it to, for example, a full screen sf::RenderTexture, but sadly not on a small object such as a sf::Sprite.

Not sure if it's the shader or something else I'm doing incorrectly. It originates from https://www.shadertoy.com/view/XdfGDH

SHADER:
uniform sampler2D       texture;
uniform vec2            textureSize;
uniform float           blurFactor;

float normpdf(in float x, in float sigma)
{
        return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}

void main()
{
        vec3 c = texture2D(texture, gl_FragCoord.xy / textureSize.xy).rgb;
       
        //declare stuff
        const int mSize = 11;
        const int kSize = (mSize-1)/2;
        float kernel[mSize];
        vec3 final_colour = vec3(0.0);
       
        //create the 1-D kernel
        float sigma = blurFactor;
        float Z = 0.0;
        for (int j = 0; j <= kSize; ++j)
        {
                kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), sigma);
        }
               
        //get the normalization factor (as the gaussian has been clamped)
        for (int j = 0; j < mSize; ++j)
        {
                Z += kernel[j];
        }
               
        //read out the texels
        for (int i=-kSize; i <= kSize; ++i)
        {
                for (int j=-kSize; j <= kSize; ++j)
                {
                        final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(texture, (gl_FragCoord.xy+vec2(float(i),float(j))) / textureSize.xy).rgb;
                }
        }
               
        gl_FragColor = vec4(final_colour/(Z*Z), 1.0);
}
 


C++:
#include <SFML\Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(1920, 1080), "SFML Testing");
        window.setVerticalSyncEnabled(true);
        window.setKeyRepeatEnabled(false);

        sf::Texture texture;
        texture.loadFromFile("player.png");
        texture.setSmooth(true);
       
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setPosition(static_cast<float>(window.getSize().x / 2), static_cast<float>(window.getSize().y / 2));
       
        sf::Shader shader;
        shader.loadFromFile("blur.frag", sf::Shader::Fragment);
        shader.setUniform("texture", texture);
        shader.setUniform("textureSize", static_cast<sf::Glsl::Vec2>(texture.getSize()));
        shader.setUniform("blurFactor", 5.f);
       
        sf::RenderStates states;
        states.texture = &texture;
        states.shader = &shader;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                                window.close();
                }

                window.clear(sf::Color::Yellow);
                window.draw(sprite, states);
                window.display();
        }

        return EXIT_SUCCESS;
}

3
I came across this guy's solution that works and it has some additional flexibility.

http://kpulv.com/309/Dev_Log__Shader_Follow_Up/#

4
Graphics / Re: Problem with using a Shader from shadertoy.com
« on: July 10, 2015, 06:56:41 pm »
Texture size is 1920x1080 or whatever the screen resolution will be. I'll be passing it the scene RenderTexture.

*edit* Just noticed it's doing the same thing originally on ShaderToy so there's nothing really wrong with it, functionally.

5
I'm just getting more involved with shaders and SFML and really fell in love with this effect on shadertoy.com which is perfect for my explosions.

https://www.shadertoy.com/view/llj3Dz#

Now shader code is new to me but I took a stab at converting it. The effect runs alright, but the source texture is upside down, mirrored and only shows half the screen.

Really starting to see the power of shaders now and thought this would be a good intro to learning more. Any pointers on what I've done wrong would be great.

Here's the test image:




and the result from my testing code:




Here's the .cpp

#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window                 (sf::VideoMode(1920, 1080), "SFML window");
        window.setVerticalSyncEnabled   (true);
        window.setKeyRepeatEnabled              (false);

        sf::Texture bgt;
        bgt.loadFromFile("testcard.jpg");
       
        sf::Sprite bgs(bgt);

        sf::Shader shader;
        shader.loadFromFile("shockwave.frag", sf::Shader::Type::Fragment);

        sf::RenderStates states;
        states.shader = &shader;

        sf::Clock clock;

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                                window.close();
                }

                shader.setParameter("source",           sf::Shader::CurrentTexture);
        shader.setParameter("sourceSize",       sf::Vector2f(1920.f, 1080.f));
        shader.setParameter("time",                     clock.getElapsedTime().asSeconds());

                window          .clear  ();
                window          .draw   (bgs, states);
                window          .display();
        }

        return EXIT_SUCCESS;
}


...and my attempt to change the fragment shader from shadertoy format.

uniform sampler2D       source;
uniform vec2            sourceSize;
uniform float           time;


void main( void )
{
        //Sawtooth function to pulse from centre.
       
        float offset = (time- floor(time)) / time;
        float CurrentTime = (time)*(offset);
   
        vec3 WaveParams = vec3(10.0, 0.8, 0.1 );
   
        float ratio = sourceSize.y / sourceSize.x;
   
vec2 WaveCentre = vec2(0.5, 0.5);
        WaveCentre.y *= ratio;
   
        vec2 texCoord = gl_FragCoord.xy / sourceSize.xy;      
        texCoord.y *= ratio;
        float Dist = distance(texCoord, WaveCentre);
       
        vec4 Color = texture2D(source, texCoord);
   
        //Only distort the pixels within the parameter distance from the centre
        if (    (Dist <= ((CurrentTime) + (WaveParams.z))) &&
                (Dist >= ((CurrentTime) - (WaveParams.z))))
        {
        //The pixel offset distance based on the input parameters
        float Diff = (Dist - CurrentTime);
        float ScaleDiff = (1.0 - pow(abs(Diff * WaveParams.x), WaveParams.y));
        float DiffTime = (Diff  * ScaleDiff);
       
        //The direction of the distortion
        vec2 DiffTexCoord = normalize(texCoord - WaveCentre);        
       
        //Perform the distortion and reduce the effect over time
        texCoord += ((DiffTexCoord * DiffTime) / (CurrentTime * Dist * 40.0));
        Color = texture2D(source, texCoord);
       
        //Blow out the color and reduce the effect over time
        Color += (Color * ScaleDiff) / (CurrentTime * Dist * 40.0);
        }
   
        gl_FragColor = Color;
}

6
SFML wiki / Re: Simple Collision Detection for SFML 2
« on: August 05, 2014, 08:08:03 pm »
Today in VS2013 after installing Update 3, I discovered that Code Analysis is now working for me. Gave it a try and was returned only one error which originated from the pixel-perfect test in the wiki code.

Error:

collision.cpp(49): warning C6386: Buffer overrun while writing to 'mask':  the writable size is '*tex-

>public: class sf::Vector2<unsigned int> __thiscall sf::Texture::getSize(void)const ().y**tex->public: class

sf::Vector2<unsigned int> __thiscall sf::Texture::getSize(void)const ().x*1'
bytes, but '2' bytes might be

written.

sf::Uint8* CreateMask(const sf::Texture* tex, const sf::Image& img)
                {
                        sf::Uint8* mask = new sf::Uint8[tex->getSize().y*tex->getSize().x];

                        for (unsigned int y = 0; y < tex->getSize().y; y++)
                        {
                                for (unsigned int x = 0; x < tex->getSize().x; x++)
this line--->           mask[x + y*tex->getSize().x] = img.getPixel(x, y).a;
                        }

                        Bitmasks.insert(std::pair<const sf::Texture*, sf::Uint8*>(tex, mask));

                        return mask;
                }

I don't personally use this part of the wiki code, but I thought it worth highlighting in case it causes other folks a problem.

7
SFML wiki / Re: Settings parser
« on: July 27, 2014, 10:36:43 am »
This is indeed useful, thanks for updating it.

I have however noticed that when I 'set' a value in the file and later the destructor calls write(), it adds a line to the file. These tend to build up after a while.

8
Graphics / Re: Repeating texture question
« on: July 21, 2014, 01:36:22 pm »
That's a different way of looking at it and just might work!

Thanks for the tip.

9
Graphics / Re: Repeating texture question
« on: July 20, 2014, 05:28:01 pm »
No, not map related as such.

The idea is to draw a moving starfield into a large RenderTexture, say 1024x1024, then use that texture to draw for example a 4x4 tiling of the texture using a sprite. When the view is zoomed out it looks like you're drawing thousands of them, but it's just a few hundred in reality.

I wonder if that would be a nice addition to SFML, a setting that makes anything drawn at the edge of a texture is auto-wrapped. So, if you did a 'setWrapped(true)' and drew a circle at 0,0 the 4 quarters of the circle would appear in each corner of the texture, thereby allowing the creation of seamless tiling textures.

10
Graphics / Repeating texture question
« on: July 20, 2014, 11:42:06 am »
For the purpose of explaining, I will use the simple example of a very small starfield.

I've tested rendering it into a RenderTexture set to Repeat. It would look something like this:

http://imgur.com/E9QtGaK

...which is then drawn with a sprite in tiled fashion multiple times to create a larger, seamless effect.

http://imgur.com/CRoR7Lx

Given that the stars that say, go off the top, are repositioned at the bottom, there is a moment where they are sliced in half which destroys the illusion.

My question : Is there a way of making things drawn to the texture 'wrap-around' (Pretty sure this isn't possible with my knowledge of the library).

Sure I could re-draw the ones that are partially off-screen to the opposite side in order to maintain the illusion, but my intention is to do this with considerably larger "stars" and there would be a lot of re-drawing going on!

Any good ideas would be appreciated.

11
General discussions / Re: SFML Game Development -- A book on SFML
« on: October 28, 2013, 12:16:08 am »
Latest CMake - check.
VS2010 up to date - check.
Cache cleared - check.

These were all checked prior to posting. Tried VS2013 (it has some nice things in it, I like! :) ). I'll leave it and SFML until they're officially married.

Still an odd thing though with VS2010 on my PC. Not sure why CMake is so upset.
No biggie, I'll play around with the source in a fresh project and see how it goes.

12
General discussions / Re: SFML Game Development -- A book on SFML
« on: October 27, 2013, 05:53:48 pm »
Just trying my first attempt at compiling the book files with Cmake and encountered this error...

The C compiler identification is MSVC 16.0.30319.1
The CXX compiler identification is MSVC 16.0.30319.1
Check for working C compiler using: Visual Studio 10
Check for working C compiler using: Visual Studio 10 -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
  10.0/VC/bin/cl.exe" is not able to compile a simple test program.

Is my compiler at fault here? I don't have much experience with CMake.

13
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 14, 2013, 02:15:05 pm »
That's fair comment. My world simulation is quite large with stuff interacting off-screen, so yeah.

14
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 13, 2013, 08:20:26 pm »
RE your quadtree implementation... Would it not be more effecient to add a 'remove' function rather than recreating the tree each frame? That way, any object that has moved is removed from the tree and re-added in the new position.

For myself I made a simple spacial partitioning system with a fixed-size grid that implemented the remove/add technique, it's only created once.

BTW, that car game would look awesome with a rotating view! :)

15
General / Re: Unhandled exception at 0x77AB22C2 (ntdll.dll)
« on: August 31, 2013, 01:03:53 am »
Pein95, out of interest are you using SFML 2.1?

Pages: [1] 2 3 ... 8