In the examples folder there is an ofApp that creates a trailing effect by blending several ofFbo renders without calling ofClear. It uses ofDrawRectangle with a given color and a fadeAmount as alpha.
Is it possible to make the same but with a completely transparent background? Any openGL hack that allows this?
One solution I’ve thought is having
vector<ofFbo> fbos( fadeAmount );
Then at every loop of my application iterate over one of those FBOs and do:
// Main OF loop begin
//
fbos[current].begin();
ofClear(0); // Completely clear
... // Draw stuff for trailing effect
fbos[current].end();
// Draw all fbos on top of each other
screenFbo.begin();
for(ofFbo& fbo : fbos)
{
fbo.draw(...);
}
screenFbo.end();
screenFbo.draw(...); // Final result from all fbos
if(current++ == fbos.size()) current = 0;
//
// Main OF loop end
I haven’t tested this but I believe it should work using the correct blend mode, however it is extremely costly regarding the amount of FBOs required. Something tells me there must be a better way…Might not?
Maybe I could use ofClear with a known color, and then check for that color in a shader and discard it. Still hacky though… I might be overthinking this
Thanks! However, I want to draw some trails on a fully transparent fbo, because I’m using that texture as overlay for a video stream. If I use a semitransparent rect (like the fboTrails example) then the video will also be faded away.
Not entirely sure how it’s all supposed to blend together in the end, but if I wanted fading trails on top of a video and the trails can be one colour I would:
Setup:
Allocate an FBO
Clear it to black
Draw:
Bind this FBO
Draw semitransparent black rect, (this gives you the fade)
Draw your particle in white
Unbind
Draw the video
Use additive blend (and colorize it with whatever colour you have set with ofSetColor) or a shader to blend the trails FBO on top.
There’ll be a way to do it with alpha as well, but the caffeine hasn’t really hit yet so it’s escaping me.
How do I prevent the semitransparent black rect to tint the video? Also it won’t be semitransparent as the lack of ofClear for the trailing fbo will make it pitch black after some frames.
If that’s what you mean by additive blend please elaborate a bit.
So you’ll end up with a black and white FBO with your trails, if you draw that on top of your video with additive blending the black will become transparent like so:
(Just nicked this from the Internets, it shows individual particles being drawn so it’s not the same, but you can see the additive blending in effect )
If you have a color other than white set (via ofSetColor) when your draw your trail FBO on top of the video, the trail FBO will use that color instead of white.