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

Author Topic: Shaders and RenderTextures  (Read 3697 times)

0 Members and 2 Guests are viewing this topic.

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Shaders and RenderTextures
« on: January 29, 2015, 09:06:23 am »
Hi.

I don't know if I'm doing something wrong or if there's a problem with how SFML shaders and render-textures work, but here's what I got.

I'm using latest SFML master from github on Win7 x64 in a 32-bit-build.

======= Sample 1 =======
I'm rending a rect to a RenderTexture and then rendering this texture via shader to the window.

(click to show/hide)
The first rendered frame looks like this (green rect on red ground) and it is wrong - its basically the result without use of the shader at all:

All consecutive rendered frames look like this (green rect on blue ground), which is correct use of the shader:

« Last Edit: January 29, 2015, 09:38:22 am by BlueCobold »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Shaders and RenderTextures
« Reply #1 on: January 29, 2015, 10:08:05 am »
With the provided code, I'm experiencing the same issue, however by using the "SFML way" it seems to work fine. I've no idea about OpenGL, so I'll leave the interpretation to others. ;D

(click to show/hide)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Shaders and RenderTextures
« Reply #2 on: January 29, 2015, 10:20:52 am »
Well, the "draw(drawable, &shader)" is not a solution I could use, because I'd have to pass down the shader to all draw-calls which is inacceptable. Independently binding the shader once should be enough.
If that's indeed the only correct way to use a shader, I'll have to find a way around it. The Shader::bind method shouldn't be publicly accessible then though.
The performance of this is horrible, because she shader will get bound and enabled for each drawable, the parameters set again and again.
« Last Edit: January 29, 2015, 10:32:51 am by BlueCobold »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Shaders and RenderTextures
« Reply #3 on: January 29, 2015, 10:50:05 am »
If that's indeed the only correct way to use a shader, I'll have to find a way around it. The Shader::bind method shouldn't be publicly accessible then though.
You make it sound like it's the worst issue ever. ;D
I mean sure we want it fixed, but one malformed first frame isn't going to harm anyone. If you don't pause at that point, you won't even notice it. :P
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Shaders and RenderTextures
« Reply #4 on: January 29, 2015, 10:54:23 am »
One does notice, because it flickers.
Anyway, the draw(drawable, &shader) solution is really horrible for performance. I guess I'll have to make a hack in my app and use this for the first frame and afterwards use the sf::Shader::bind myself. That looks to be working, but it just can't be a preferred solution.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Shaders and RenderTextures
« Reply #5 on: January 29, 2015, 05:43:27 pm »
Call window.resetGLStates() right after you create your window. It will initialize the internal GL state and make sure your shader doesn't get unbound the first time it is drawn to. You should be able to manually bind/unbind all the shaders you want after that, SFML doesn't cache the currently bound shader.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Shaders and RenderTextures
« Reply #6 on: February 03, 2015, 09:03:49 am »
Works like charm, perfect. Thanks a lot.
(plus: the solution actually makes sense by looking at the SFML source)

 

anything