Hi,
I've been using the Accumulation buffer to apply motion blur to point cloud animations, directly taken from the osgMotionBlur example, where the motion blur is applied to each window as an osg::Operation. What I'd like to be able to do is dynamically change the amount of blur by varying the persistence parameter. I've poked around the API and found that I can remove the motion blur operation with a removeAllOperations call then reapply the motion blur with a different persistence value, but this causes the accumulation buffer to be cleared. I can't see any other way to access the Operator once its been applied.
Below is the code,
#include <osgViewer/ViewerBase>
#include <osgViewer/Viewer>
#include <iostream>
class MotionBlurOperation: public osg::Operation
{
public:
MotionBlurOperation(double persistence):
osg::Operation("MotionBlur",true),
cleared_(false),
persistence_(persistence)
{
}
virtual void operator () (osg::Object* object)
{
osg::GraphicsContext* gc = dynamic_cast<osg::GraphicsContext*>(object);
if (!gc) return;
double t = gc->getState()->getFrameStamp()->getSimulationTime();
if (!cleared_)
{
// clear the accumulation buffer
glClearColor(0, 0, 0, 0);
glClear(GL_ACCUM_BUFFER_BIT);
cleared_ = true;
t0_ = t;
}
double dt = fabs(t - t0_);
t0_ = t;
// compute the blur factor
double s = powf(0.2, dt / persistence_);
// scale, accumulate and return
glAccum(GL_MULT, s);
glAccum(GL_ACCUM, 1 - s);
glAccum(GL_RETURN, 1.0f);
}
private:
bool cleared_;
double t0_;
double persistence_;
};
void motionblur(osgViewer::GraphicsWindow* w, double persistence) {
w->add(new MotionBlurOperation(persistence));
}
any ideas ?
thanks in advance
Bill
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org