motion trails with fbo

Hi

I basically want to draw a circle into an fbo, next frame the circle moves and i want to leave the previous drawing but faded out, so that the circle creates a motion train as it moves, if that makes sense.

whats the best / easiest way to do this?

should i just be doing it using glsl?

thanks
chris

[quote author=“chrisoshea”]Hi

I basically want to draw a circle into an fbo, next frame the circle moves and i want to leave the previous drawing but faded out, so that the circle creates a motion train as it moves, if that makes sense.

thanks
chris[/quote]

One way is:

  1. disable the clearing of the color-buffer, clear only the depth buffer for the FBO once per frame
  2. draw a rect the same size as your FBO with your clearcolor and a transparency of 0.9 (try some values)
  3. draw your geometry

It’s easy and fast, but maybe not the (visually) nicest solution, for fast moving objects you’ll get a stroboscope-effect. Perhaps adding a Blur via GLSL helps here.

cheers,
Stephan

Hey Chris, this is the basics of what I do to retain and blur a little (without using a shader, just by downscaling).

this is using Zach Gage’s addon which I added some minor things to
http://code.google.com/p/ofxmsaof/sourc-…-OTexture.h

  
#include "testApp.h"  
#include "ofFBOTexture.h"  
  
  
ofFBOTexture fboNew;  
ofFBOTexture fboBlur;  
ofFBOTexture fboComp;  
  
//--------------------------------------------------------------  
void testApp::setup(){	  
	ofBackground(255, 255, 255);  
	ofPoint size;  
	size.set(ofGetWidth(), ofGetHeight());  
	  
	fboNew.allocate(size.x, size.y, true);  
	fboComp.allocate(size.x, size.y, true);  
	fboBlur.allocate(size.x/2, size.y/2, true);  
	  
	// set clear colors to white  
	fboNew.clear(1, 1, 1, 0);  
	fboComp.clear(1, 1, 1, 1);  
	fboBlur.clear(1, 1, 1, 0);  
	  
	ofSetFrameRate(30);  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
}  
  
void testApp::drawNew() {  
	ofSetColor(rand() % 0xFFFFFF);  
	ofCircle(mouseX, mouseY, 10);  
}  
  
//--------------------------------------------------------------  
void testApp::draw() {  
	// draw new stuff to FBO  
	fboNew.begin();  
	{  
		drawNew();  
	}  
	fboNew.end();  
	  
	// composite old and new  
	ofEnableAlphaBlending();  
	fboComp.begin();  
	{	  
		glColor4f(1, 1, 1, 1);  
		fboBlur.draw(0, 0, fboComp.getWidth (), fboComp.getHeight());  
		  
		glColor4f(1, 1, 1, 1);  
		fboNew.draw(0, 0, fboComp.getWidth(), fboComp.getHeight());  
	}  
	fboComp.end();  
	  
	  
	fboBlur.begin();  
	{  
		glColor4f(1, 1, 1, 1);  
		fboComp.draw(0, 0, fboBlur.getWidth(), fboBlur.getHeight());  
	}  
	fboBlur.end();  
	  
	// draw to screen  
	fboComp.draw(0, 0);  
}