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

Author Topic: 1.6 Shaders  (Read 4847 times)

0 Members and 1 Guest are viewing this topic.

Wurstinator

  • Newbie
  • *
  • Posts: 33
    • View Profile
1.6 Shaders
« on: August 23, 2010, 04:19:18 pm »
Hi,
this probably has been requested before but I didn't found something while flipping through this subforum.

In SFML 1.6 you can use App.Draw(Shader) also corresponding to a single Sprite/Shape/String. But as I read once in another topic, in 2.0 you can only use App.Draw(Drawable, Shader). So applying a Shader to the full screen or two or more shaders at once would be a big problem. You would have to create a new image each time which would cause in lag.

So my request (well, more a question) is: Is it possible to bring this feature back?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
1.6 Shaders
« Reply #1 on: August 23, 2010, 06:41:32 pm »
Look at this topic, it explains two ways of replacing sf::PostFx with sf::Shader:
http://www.sfml-dev.org/forum/viewtopic.php?t=1791
Laurent Gomila - SFML developer

Wurstinator

  • Newbie
  • *
  • Posts: 33
    • View Profile
1.6 Shaders
« Reply #2 on: August 29, 2010, 06:34:04 pm »
I only see one way: creating a RenderImage and drawing everything onto it.
But as I said, this needs some time, doesn't it?

For example, if you have an action RPG you may want to do something like this:

-Draw Map
-Draw Player, Enemies and other NPCs
-Apply a sepia shader, because this scene is set in the past
-Apply a blur shader, because you are nearly dead and this effect shall simulate that
-Draw HUD

You would have to do this, to reach your goal:

-Create RenderImage
-Draw Map, Player, Enemies ...
-Create another RenderImage
-Draw the first RenderImage onto the second
-Draw the second RenderImage onto the window
-Draw HUD

I don't know much about OpenGL but doesn't it take time to create (FPS = 60, Resolution = 800x600) 120 800x600 textures each second?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
1.6 Shaders
« Reply #3 on: August 29, 2010, 06:43:13 pm »
The second one is there:
http://www.sfml-dev.org/forum/viewtopic.php?p=11699#11699

This is exactly what sf::PostFx did, by the way. It's more convenient because you can easily insert post-effects without changing your rendering structure, but it's slightly slower.

Using render images is ok, you just draw to a different target (the render image instead of the screen). You don't create them 120 times per second, you do it once and then only use them. And you don't even have to create 120 of them, you can apply as many effects as you want with only two render images.
Laurent Gomila - SFML developer

Wurstinator

  • Newbie
  • *
  • Posts: 33
    • View Profile
1.6 Shaders
« Reply #4 on: September 01, 2010, 05:36:06 pm »
Okay.
But when this is, what PostFx did, why did you remove PostFx? It would be easier to use and it would probide better downward compatibility. Just a suggestion ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
1.6 Shaders
« Reply #5 on: September 01, 2010, 05:49:02 pm »
Quote
But when this is, what PostFx did, why did you remove PostFx? It would be easier to use and it would probide better downward compatibility

I didn't remove PostFx, I renamed it to Shader and made it more flexible. This is the same class except that its scope is wider and as a consequence it takes 2 more lines of code to get the same behaviour as before, with PostFx.
And I don't care about compatiblity between SFML 2.0 and SFML 1.6 (otherwise it would have been SFML 1.7).
Laurent Gomila - SFML developer

 

anything