SFML community forums
Help => Graphics => Topic started by: dbiton on May 29, 2020, 11:46:30 pm
-
Is there a way to draw to a RenderTexture and apply a blend using a coefficient?
i.e:
out.rgb = new.rgb * c + old.rgb * (1-c)
I have looked into BlendMode, but it seems like only predefined multipliers are defined (I might be missing something).
I know this can be solved by looping over every pixel in the texture and doing it manually, but this is obviously more suited for the GPU.
I can probably use a shader, but I'm very inexperienced with them so I figured I would ask you guys before delving into that.
If it's relevant, I'm trying to achieve an effect where the previous frames linger on and slowly decay away.
Thanks in advance!
Edit: I've also tried to clear the texture with a color whose alpha is not 255 to "partially clear" it, but it didn't work.
-
I think that a shader is going to be the most effective solution for this problem. Try not to worry about experience, the SFML shaders are incredibly easy to use. See the Fragment Shader heading in this tutorial which is similar to the logic you would need:
https://www.sfml-dev.org/tutorials/2.5/graphics-shader.php
When multiplying the color of the texture, you can do something like:
gl_FragColor = gl_Color * vec4(pixel.r, pixel.g, pixel.b, myCustomAlphaValue);
You can bind multiple textures simultaneously for access in the shader code so you can combine the pixel data however you see fit.
-
I think that a shader is going to be the most effective solution for this problem. Try not to worry about experience, the SFML shaders are incredibly easy to use.
You were right, it wasn't hard at all. thanks for the help! :)