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

Author Topic: Fading without artifacts  (Read 17988 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fading without artifacts
« Reply #30 on: October 03, 2012, 07:34:32 am »
Quote
Would that work?
I'm sorry, I don't have the time to investigate and find a good solution to your problem, so you'd better try your ideas directly and see if they work :-\
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Fading without artifacts
« Reply #31 on: October 03, 2012, 01:07:41 pm »
Well it was more a general question to everybody. I not an expert in GLSL so I was wondering if someone could tell me if my idea is even possible, before I waist my time with trying something that won't work. Main question is how can I pass the Rendertexture to the shader. (so that I can retrieve the color using texture2D())
Or is there another way to apply a global shader to a rendertexture?

What about the other questions in my previous post?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fading without artifacts
« Reply #32 on: October 03, 2012, 01:32:21 pm »
Quote
Main question is how can I pass the Rendertexture to the shader
sf::Shader has a setParameter(name, sf::Texture) function.

Quote
Or is there another way to apply a global shader to a rendertexture?
Other than what?
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Fading without artifacts
« Reply #33 on: October 03, 2012, 03:39:19 pm »
Other than what?
Other than drawing a rectangle over the texture after everything else is drawn with blendmode set to None and apply a shader to the rectangle. The rendertextures texture is passed to the shader so you can modify it there.

I get a error saying "parameter "texture" not found in shader" when I call shader.setParameter("texture", rendertexture.getTexture()); although I declared uniform sampler2D texture; in the shader.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fading without artifacts
« Reply #34 on: October 03, 2012, 03:52:09 pm »
Quote
Other than drawing a rectangle over the texture after everything else is drawn with blendmode set to None and apply a shader to the rectangle. The rendertextures texture is passed to the shader so you can modify it there.
So you want to draw the render-texture on the render-texture? It doesn't work, you can't have the render-texture as both the source and the destination.

Quote
I get a error saying "parameter "texture" not found in shader" when I call shader.setParameter("texture", rendertexture.getTexture()); although I declared uniform sampler2D texture; in the shader.
The GLSL compiler optimizes out unused variables (unused = not part of the code that produces the final pixel), so make sure that you use it in your shader.
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Fading without artifacts
« Reply #35 on: October 03, 2012, 04:13:17 pm »
Ah thanks for the explanation. I was wondering what the problem was.

So if I can't use a render-texture as the source and the destination, is there any other way to apply a "global" shader to a render-texture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fading without artifacts
« Reply #36 on: October 03, 2012, 04:26:20 pm »
If you want to draw a texture on itself, you have to use two render-textures: one is the source, one is the destination, and you swap them every frame so that the previous destination becomes the new source etc.
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Fading without artifacts
« Reply #37 on: October 03, 2012, 06:11:43 pm »
So that is the only way how i can fade out a render-texture? Using two textures and a shader. There is no way the problem with the artifacts will be resolved?

By the way: what exactly do you me by a render-texture can't be source and destination. If I apply the shader to the rectangle and draw it onto the render-texture, the rectangle is the source and the render-texture the destination. the shader simply uses information from the render-texture to compute it's color.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fading without artifacts
« Reply #38 on: October 03, 2012, 06:20:54 pm »
Quote
So that is the only way how i can fade out a render-texture? Using two textures and a shader
Nobody said that, this is just your idea. But since nobody seems to have the time to investigate this issue, you're on your own ;)

Quote
By the way: what exactly do you me by a render-texture can't be source and destination. If I apply the shader to the rectangle and draw it onto the render-texture, the rectangle is the source and the render-texture the destination. the shader simply uses information from the render-texture to compute it's color.
If you use the texture in your shader, it is a source. You can't read and write to the same texture at the same time.
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Fading without artifacts
« Reply #39 on: October 07, 2012, 09:57:18 pm »
Alright I found this article: http://www.pixelnerve.com/v/2010/07/20/pingpong-technique/ I think the technique described is what I need. Or does anybody else know a different technique on how I could achieve this effect?

@Laurent: Are still convinced that adding a subtract blendmode is still not an option? I think it would be really helpful. Especially with this issue or issues like this. You could simply use the subtract blendmode instead of solving it with two textures and a shader that subtracts the colors :)