[osg-users] Dynamically change the "persistence" of the motion blur example

5 views
Skip to first unread message

William Hart

unread,
May 16, 2013, 6:15:13 PM5/16/13
to osg-...@lists.openscenegraph.org
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

Robert Osfield

unread,
May 17, 2013, 4:46:17 AM5/17/13
to OpenSceneGraph Users
Hi Bill,

Is there any reason why you could retain a ref_ptr<> to the Operation and modify it in your frame loop, or get the list of operations and use a dynamic_cast<MotionBlurOperation*>() to determine which one is the one you need to modify?

Robert.

William Hart

unread,
May 17, 2013, 6:54:16 AM5/17/13
to OpenSceneGraph Users
Hi Robert,

Sorry I'm not much of a C++ programmer, I do most of what I can in python and only wrap the bits I need to.  This sounds like what I want to do, is there somethings similar amongst the example s?

thanks

-Bill
Reply all
Reply to author
Forward
0 new messages