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

Pages: [1]
1
Graphics / Re: See through walls like effect
« on: May 12, 2023, 09:10:50 am »
Thank you for the clipping method!

I did it just like that and i got it working and it has no significant impact on the performance. The results are exactly what i was looking for.

This is the code if you want to see it: https://github.com/r-a-cristian-93/LastHero/blob/c8e5cd9b20e5c9ce83066f560a5b7781ab1e1e86/src/SystemDrawEntities.h

2
Graphics / Re: See through walls like effect
« on: May 10, 2023, 11:44:21 am »
Having a second texture for the outline can be easily done.

All the entities will be already drawn (player, trees, enemies) on a texture (call it ent_texture) before i will apply the overlay. The entities need to be drawn in a specific order, the most distant will be drawn first. If i use that ent_texture's alpha mask then the entire outline will be rendered because the outline's entity is already there. And this way i end up with the same result as before.

Maybe i could have another texture (call it rev_ent_texture) to draw on it the entities in reverse order, and when i encounter an entity that might require an outline i will use the rev_ent_texture's alpha mask to draw the outline texture on the ent_texture that will finally be displayed to the user. I don't know what impact it will have on the performance but it's worth giving it a shot.

Thx

3
Graphics / [SOLVED] See through walls like effect
« on: May 09, 2023, 01:46:11 pm »
Hi!

I am working on a 2d isometric game with SFML, nothing fancy or professional and i am looking for a way to draw outlines to entities that are behind tall objects (trees, walls) and only partially.

The game first draws the ground which is a tilemap, then it draws the entities, then it draws the outlines.
Currently i am using a shader to draw the outline on top of everything at all times which is pretty close to what i am looking for but not too great. If the texture has opacity on the outline pixels then it looks really bad.

You can see in the attached image the result i am looking for.

Is there any way i can draw the outline only on the overlapping areas? I suppose i will have to determine the overlapping areas in a shader, but i don't know if that's possible of how to do it.

4
Graphics / Re: setColor() and shader
« on: April 18, 2022, 12:27:25 pm »
Thank you! That fixed the problem, now it works just fine.

5
Graphics / [SOLVED] setColor() and shader
« on: April 17, 2022, 06:29:00 pm »
Having this simple program, when i use the shader the setColor() function does not take effect. Without using the shader the setColor() works just fine. I want to apply the color and the shader only after everything is drawn
Why does this happen and how can i fix it.


        sf::RenderWindow window;
        sf::RenderTexture screen_tex;
        sf::Sprite screen_sprite;
        sf::Shader shader;

        shader.loadFromFile("shader.vert", "shader.frag");

        window.create(sf::VideoMode(800, 600), "very-nice-window", 3);
        window.setFramerateLimit(60);
        window.setKeyRepeatEnabled(false);

        screen_tex.create(800, 600);
        screen_sprite = sf::Sprite(screen_tex.getTexture());

        screen_tex.clear();
        drowSomeStuff(screen_tex);
        screen_tex.display();
        screen_sprite.setColor({100,0,0});

        window.clear();
        window.draw(screen_sprite, shader);
        window.display();
 

6
Graphics / Re: Using shaders with sfml
« on: February 19, 2022, 02:09:54 pm »
I finally got it working! I had to separate the shader in two different files, one for the vertex shader and one for the fragment shader.

I also had to feed OutputSize, TextureSize, and InputSize uniform variables to the verex shader. Then in the main() function of the vertex shader i added these lines and delete their previous declarations.

        mat4 MVPMatrix = gl_ModelViewProjectionMatrix;
        vec4 VertexCoord = gl_Vertex;
        vec4 TexCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;


7
Graphics / Re: Using shaders with sfml
« on: February 18, 2022, 03:03:49 pm »
I made some progress. If i add this line the the shader file i get a green texture. I also dropped all the setUniform() calls from my program as they seem to do nothing.

#define FRAGMENT

8
Graphics / Re: Using shaders with sfml
« on: February 16, 2022, 12:44:50 pm »
I'm a complete ignorant in shaders, but have you tried anothe one, just for testing? I get this error:

Quote
Failed to compile vertex shader:
0:368(1): error: syntax error, unexpected end of file

I could use this simple shader which is not useful to me, it only paints some colors on top of everything. But other shaders that i downloaded do not seem to work.


uniform vec2 u_resolution;

void main() {
    vec2 st = gl_FragCoord.st/u_resolution;
    gl_FragColor = vec4(st.x, st.y, 0.0, 1);
}
 

        shader.loadFromFile("rainbow.glsl", sf::Shader::Fragment);
        shader.setUniform("u_resolution", sf::Glsl::Vec2{ 100, 100 });*/
 


9
Graphics / [SOLVED] Using shaders with sfml
« on: February 16, 2022, 10:49:40 am »
Hi!

I want to use this shader but all i get is a black image. I know the texture is loaded correctly because i can render it without the shader.

This is how i load and use the shader, which is probably not correct.

void init() {
        shader.loadFromFile("glsl-shaders-master/xbr/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.glsl", sf::Shader::Vertex);
        shader.loadFromFile("glsl-shaders-master/xbr/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.glsl", sf::Shader::Fragment);
        shader.setUniform("MVPmatrix", sf::Glsl::Mat4(bg_sprite.getTransform()));
        shader.setUniform("FrameDirection", 1);
        shader.setUniform("FrameCount", 100);
        shader.setUniform("OutputSize", sf::Vector2f(500, 500));
        shader.setUniform("TextureSize", sf::Vector2f(500, 500));
        shader.setUniform("InputSize", sf::Vector2f(500, 500));
        shader.setUniform("Texture", sf::Shader::CurrentTexture);

        //more code
}

void draw() {
        window.draw(bg_sprite, &shader);

        //more code
}

This are the errors i get:

Uniform "MVPmatrix" not found in shader
Uniform "FrameDirection" not found in shader
Uniform "FrameCount" not found in shader
Uniform "OutputSize" not found in shader
Uniform "TextureSize" not found in shader
Uniform "InputSize" not found in shader
Uniform "Texture" not found in shader

Pages: [1]