PDA

View Full Version : Creating a fading object trail in Modern OpenGL?



eratic-magician
03-20-2017, 05:33 PM
Hi, I'm looking to possibly create a trail behind a moving object that fades away over time. Right now, I'm moving bullets through a scene by setting their position equal to their moving rigid body's position. How can I create a basic trail (like a simple thick red line) that follows the object, can only be a certain length and fades away over time? I've tried looking this up can't find a good solution in modern OpenGL (rendering objects with a model * view * projection matrix).

Are GLlines still used? Or would another approach be better?

Thanks for any input.

john_connor
03-21-2017, 11:07 AM
Hi, I'm looking to possibly create a trail behind a moving object that fades away over time. Right now, I'm moving bullets through a scene by setting their position equal to their moving rigid body's position. How can I create a basic trail (like a simple thick red line) that follows the object, can only be a certain length and fades away over time?

use blending
https://www.khronos.org/opengl/wiki/Blending

use 2 framebuffers, "currentframe" and "previousframe", each frame you render your scene as you'd normally do into "currentframe". in addition to that, render a small portion of the "bullet trail" behind the bullet (how you do that is not important). next frame, previousframe becomes currentframe and currentframe will contain the scene again, but now you blend the 2 framebuffers together, using (lets say) 99% RGBA of previousframe and 1% RGBA of currentframe, the result will be displayed onto the screen

you can change the "speed" at which the trails are fading by playing with the 99% / 1% ratio

eratic-magician
03-21-2017, 02:15 PM
Great, I'll look into that, thanks.

Is this the standard way of doing this? I thought that using GLlines would be, but maybe that's outdated.