ofxBlurShader causing unwanted trailing

Hi there,

I’m experimenting with ofxBlurShader in combination with ofxWordPalette and I’m having a persistent problem where ofxBlurShader does not refresh and just blends on top of the previous frames. (image below)

The effect I’m trying to achieve is simply to blur the words from ofxWordPalette. I’m still learning how fbos and shaders work, so maybe I’m missing something obvious, but after a good amount of trial and error I seem to be getting nowhere with this. Any insight would be much appreciated. Thanks.

  
  
  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
  
	ofBackground(0);  
  
	ofSetFrameRate(30);  
	  
	blur.setup(ofGetWidth(), ofGetHeight());  
  
	ofEnableAlphaBlending();  
	  
	incr = 0;  
	  
	words.setup(2048, 1024, "verdana.ttf", 18);	  
	words.setWords("poe.txt");  
	  
	bool oddRow = false;  
	for(int y = 0; y < ofGetHeight(); y += 80){  
		for(int x = 0; x < ofGetWidth(); x += 80){  
			  
			ofVec2f position = ofVec2f();  
			position.x = x;  
			if(oddRow){  
				position.x += 10;  
			}  
			position.y = y;  
			points.push_back( position );  
		}  
		oddRow = !oddRow;  
	}  
	noiseVal = new ofxPerlin;  
	  
	for(int i = 0; i < points.size(); i++){ //go through all the points  
		//		ofVec2f mousePoint(ofGetMouseX() - incr, ofGetMouseY());  
	}  
	shortestWordLength = words.getShortestWord().box.width;  
	longestWordLength = words.getLongestWord().box.width;  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	incr += 2;  
  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	float deltaTime = ofGetElapsedTimeMillis()/100;  
    blur.begin();  
    blur.amount = ofMap(ofGetMouseX(),-55,ofGetWidth(),0,10,true);  
    blur.iterations = ofMap(ofGetMouseY(),0,ofGetHeight(),1,10,true);  
	  
	for(int i = 0; i < points.size(); i++){ //go through all the points  
		float px = points[i].x + incr;  
		float py = points[i].y;  
		float setNoise = noiseVal->noise(points[i].x,points[i].y,deltaTime*0.010);  
		setNoise = setNoise*2*PI;  
		float angleX = cos(setNoise);  
		float angleY = sin(setNoise);  
		px = px + (angleX*13.99);  
		py = py + (angleY*13.99);  
		if(int(px) % 1000 == 0){points[i].x -= 1000;};  
		ofVec2f trajectory = ofVec2f(px, py) - points[i];  
		ofVec2f direction = trajectory.normalized();   
		WordWithSize& w = words.getOrderedWord(i%100);   
		  
		ofPushMatrix();  
		ofTranslate(ofVec2f(px,py));  
		ofRotate( atan2(direction.y, direction.x) * RAD_TO_DEG);  
		words.drawWord(w, ofVec2f(0, 0) );  
		ofPopMatrix();  
  
	}  
	words.unbindPalette();  
	blur.end();  
  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y ){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::windowResized(int w, int h){  
  
}  
  
//--------------------------------------------------------------  
void testApp::gotMessage(ofMessage msg){  
  
}  
  
//--------------------------------------------------------------  
void testApp::dragEvent(ofDragInfo dragInfo){   
  
}  
  

//

  
  
  
  
#pragma once  
  
#include "ofMain.h"  
#include "ofxWordPalette.h"  
#include "ofxNoise.h"  
#include "ofxBlurShader.h"  
  
class testApp : public ofBaseApp{  
  
  public:  
	void setup();  
	void update();  
	void draw();  
  
	void keyPressed  (int key);  
	void keyReleased(int key);  
	void mouseMoved(int x, int y );  
	void mouseDragged(int x, int y, int button);  
	void mousePressed(int x, int y, int button);  
	void mouseReleased(int x, int y, int button);  
	void windowResized(int w, int h);  
	void dragEvent(ofDragInfo dragInfo);  
	void gotMessage(ofMessage msg);  
	  
	  
	float setNoise[320];  
	float noiseAngle;  
	ofxPerlin *noiseVal;  
	ofxWordPalette words;  
	float shortestWordLength;  
	float longestWordLength;  
	int incr;  
	ofVec2f trajectory;  
	ofVec2f direction;  
	ofVec2f mousePoint;  
	ofxBlurShader blur;  
	vector<ofVec2f> points;  
};  
  

after blur.begin(), try adding ofClear(0, 255).

this should reset your background in the fbo to opaque black before you start drawing.

FBOs are not auto-cleared like the screen.

That did the trick, thanks! I tried ofBackground but I guess that does something different…

memo introduced ofClear() with 007, and it’s created some confusion about what exactly ofBackground() is supposed to do. sorry about that, we’re still trying to figure it out :slight_smile: