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

Author Topic: [SFML 2] Shaders  (Read 3042 times)

0 Members and 1 Guest are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
[SFML 2] Shaders
« on: June 11, 2010, 05:49:43 pm »
Well I have a few questions about Shaders on SFML 2

1 - PostFX was applied to the screen, now Shaders are applied to drawables when drawn on a RenderTarget. This is great, but is it still possible to apply shaders to the current state of the screen as before?
This may be explained somewhere but I didn't find it.

2 - I can only apply one shader to a drawable, right? Shaders can't be applied one after another on the same drawable (on 1.x it was possible to apply several PostFX on the screen).
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML 2] Shaders
« Reply #1 on: June 11, 2010, 06:22:49 pm »
1- You can, this is explained in the class documentation. Just capture the current contents of the window in a sf::Image, and draw it with a sprite and the shader.

2- Like with PostFx, you have to repeat the procedure explained above to produce the desired result. There's technically no way to apply N shaders in one pass, you must do N passes.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
[SFML 2] Shaders
« Reply #2 on: June 11, 2010, 07:30:31 pm »
Ah, thanks. I was searching on the Shader documentation, I found now that there is a reference to it on the RenderImage  :)

Quote
Just capture the current contents of the window in a sf::Image, and draw it with a sprite and the shader.

You mean by using the Image::CopyScreen function? I think I'd better to render everything in a RenderImage and then draw with the shader on the screen.

Edit: Ok I understand now that to apply a shader between draws I need an additional image in witch to render the current content with the shader, and replace the original content with that.
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML 2] Shaders
« Reply #3 on: June 11, 2010, 08:19:16 pm »
Quote
Ah, thanks. I was searching on the Shader documentation, I found now that there is a reference to it on the RenderImage

Sorry, I thought this was explained in the class headern but it is not :)
It's explained in this thread, and it should probably be added to the class documentation.

Quote
You mean by using the Image::CopyScreen function? I think I'd better to render everything in a RenderImage and then draw with the shader on the screen.

Both solutions work. Using Copy::Screen is a little more expensive, but has the advantage of not impacting the rendering flow, you can use it exactly like you used sf::PostFx.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
[SFML 2] Shaders
« Reply #4 on: June 11, 2010, 10:04:11 pm »
Quote from: "Laurent"

It's explained in this thread

Ah, I knew this thread exists! I haven't searched well enough (it wasn't on the first, let's say, 20 results of a search for "Shader" :P)
Thank you
Pluma - Plug-in Management Framework

 

anything