I made a particle trail effect in OpenGL.
The trick is to draw a semi transparent rectangle on the screen to gradually fade the previous frame:
ofSetColor(0,0,0,255*(1.0-persistence));
ofFill();
ofRect(0, 0, ofGetScreenWidth(), ofGetScreenHeight());
and then draw the particles (roughly):
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofEnablePointSprites();
vbo.draw(GL_POINTS, 0, (int)points.size());
ofDisablePointSprites();
The problem is that the trails do not fade until being pure black, but remain grayish.
I could threshold the dark gray values, or fade them progressively, but what is the best way to do it? OpenGL blending functions/operations or shader? Speed is a major concern.
You need to allocate your fbo with a floating point format.
There is an example in openFrameworks examples directory that shows the difference between floating point and non floating point format and it seems to be your problem ( examples/gl/fboTrailsExample
).
Allocation with a floating point format:
ofFbo rgbaFboFloat;
rgbaFboFloat.allocate(400, 400, GL_RGBA32F_ARB);
and then in the update method you can draw to the fbo between rgbaFboFloat.begin();
and rgbaFboFloat.end();
To finish, you draw your fbo in the draw method: rgbaFboFLoat.draw(0,0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.