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

Author Topic: Off Screen Rendering Antialiasing  (Read 2851 times)

0 Members and 1 Guest are viewing this topic.

Elro444

  • Newbie
  • *
  • Posts: 5
    • View Profile
Off Screen Rendering Antialiasing
« on: October 13, 2017, 04:13:37 pm »
I am working on a small Top-down perspective game, where there is a 'vision' system, with shadows hiding stuff the player souldn't be able to see (like behind walls, or behind his back).
I use a sf::RenderTexture as a canvas, where i manage all the shadows for a player's screen(ConvexShapes drawn to it, then i convert it to an sf::Image, to use the createMaskFromColor function, to eliminate the non-shadow background. It will matter mostly for multiplayer, where i want to create a 'shared' vision for the entire team).
My problem is that when i draw my RenderTexture to the game window (sf::RenderWindow) it's pixelated. I'm new to SFML, and quite new to graphics in general, so if what I'm looking for is not antialiasing please forgive me.
Also,
I looked around a little and checked on the forum for this, and I saw that binary1248 said that RenderTexture "wastes a considerable amount of GPU resources both in terms of processing time and memory usage." (on this post: https://en.sfml-dev.org/forums/index.php?topic=22147.0 )
So is it really that bad to use RenderTexture?
If so, what should i use for off-screen rendering? (I saw the potential use of views, but I still can't see a way of replacing the Image::createMaskFromColor)
Is there any other way to supposingly 'erase' something drawn? (right now i am redrawing white to the temporary canvas, and then i set the alpha of white to 0, as mentioned above, to erase shadows before i draw them)
And last, if RenderTexture is still what i need to use, how do I make the shadows drawn from the RenderTexture smoother?
Sorry for the long post  ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Off Screen Rendering Antialiasing
« Reply #1 on: October 13, 2017, 04:46:55 pm »
See and test this pull request.
Also read this discussion.

Masking colors should be possible with a shader and should perform a lot better, as you're not transferring image data between CPU and GPU.

Keep in mind, that AA only works for vertex data, so if you already have image data (e.g. when loading image data from an sf::Image), then AA does not apply. I mean it's the same thing as drawing your RT onto the window, AA doesn't get magically applied on the image data.

If you want to smooth something image data, you may just want to write a shader for it.

After reading binary1248's comments and seeing the people that requested the mentioned PR notice that it's not actually what they expected to get, it makes me wonder myself on the usefulness of AA on RT.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Elro444

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Off Screen Rendering Antialiasing
« Reply #2 on: October 14, 2017, 08:44:59 pm »
See and test this pull request.
Thanks :D
But it seems that a shader can do that anyway, so i'd rather not use a non 'public release' (if thats the term) build, if possible, as I am just getting to know SFML.
To be honest I just didn't think of using shaders for some reason.

Quote
...as you're not transferring image data between CPU and GPU.
I was not aware of the difference between sf::RenderTexture and sf::Image (as described on this post).

So to conclude, is using sf::RenderTexture for off screen rendering not bad, but rather just the data tranferring between sf::RenderTexture and sf::Image, despite binary1248's asnwer?

Anyways, thanks a lot, it really helps ;D
Elro

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Off Screen Rendering Antialiasing
« Reply #3 on: October 15, 2017, 11:34:23 pm »
I was not aware of the difference between sf::RenderTexture and sf::Image
It's actually the difference between sf::Texture and sf::Image.

Textures are in vram, Images are in system ram.