Trails using fbo and shaders

Currently I am writing an app that renders up to 50k triangles using an ofVboMes. I wish to add a trail effect such as in the FboTrails example, but run into trouble; it seems to be problematic to render the mesh into an fbo that is allocated as GL_RGBA32F.

This works well with the alfa channel above about 3, and using and fbo with GL_RGBA.

fbo.begin();
ofSetColor(0, 0, 0, 3);
ofRect(0, 0, 1280, 960);
ofSetColor(255);
shader.begin();
mesh.draw();
shader.end();
fbo.end();
fbo.draw(0, 0);

When setting the alfa channel lower, things don’t fade to black, which is as expected given that no floating points are used. However. when trying to use GL_RGBA32F, there is trouble, as only parts of the screen get rendered (also framerate goes down considerably). See image below; sometimes parts of the black areas are also rendered, but never all of it.

Is there another way to achieve this effect? I tried drawing the mesh to the fbo aside from drawing it to the screen, and then bind the fbo texture, to use it in the shader, but it has no effect (which may be due to me being rather new with shaders).

For anyone interested: meanwhile: the best results I got were with:

  • using a seperate shader to do the fading (shader uses a mesh with two triangles to draw a transparent square over the whole screen (actually works also with ofRect();))
  • That resolves the issue as addressed in the previous post; I can now use GL_RGBA32F_ARB, but fps will drop from 60 to 40; using GL_RGBA16F instead yields framerate of ~45 fps, but also gives errors, see below. Rendering the new frame to GL_RGBA, then drawing that to GL_RGBA_16F doesn’t improve things. I am ok with 45 fps though…but 60 would be nice :slight_smile: Maybe using floats in textures just slows down things a lot??
  • I tried using the pingpong technique as outlined in gpuParticleSystemExample; using a texture of the previous frame in a shader; however, multiplying the texture color value with a value below 1.0 resulted in nothing being drawn.

Errors from using GL_RGBA16F (or GL_RGBA16F_ARB):

[ error ] ofGLUtils: ofGetGlTypeFromInternal(): unknown internal format 34842, returning GL_UNSIGNED_BYTE
[ error ] ofGLUtils: ofGetGLFormatFromInternal(): unknown internal format 34842, returning GL_RGBA

An alternative technique is to use only GL_RGBA, and use higher fading values, but then apply it only once every x frames. Works well, very fast, but less elegant, and less acurate…