Motion Blur on Particles

Troy Corbin Developer Updates Leave a Comment

Hey gang! Haven’t had much to report this week as I’ve been crushing bugs introduced with the AI update. However, I have added one cool new feature to the rendering engine: motion blur on particles!

Motion Blur for Particles

Explosion particles as well as slugs now have a motion blur effect.

So how does it work?

First, we set up a Frame Buffer Object with the same dimensions as the window buffer. Be sure to bind a Texture Image for the color buffer, not a Render Buffer! We’ll need to be able to bind the texture later on.

Next, you’ll need a way to distinguish those particles that get motion blur vs those who do not. I just use a simple boolean on each particle type to tell me if it is blured or not.

Next, you’ll need a routine to draw to the motion blur FBO. Make sure it is early in your render loop. This routine should draw each blurred particle just like your normal render with one exception: We will not clear the color or depth buffers. Doing so would would erase the blur effect from the buffer. Instead, we want to slowly fade the alpha out with each call to this draw routine. Here is how I did it:

setOrtho();
glDisable(GL_TEXTURE_2D);
glBlendEquation( GL_FUNC_REVERSE_SUBTRACT );
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ONE);
glColor4f(1.0f,1.0f,1.0f,0.02f);
drawQuad(0,0,GlowBuffer.getWidth(),GlowBuffer.getHeight());
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBlendEquation( GL_FUNC_ADD );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glClear(GL_DEPTH_BUFFER_BIT);
setFrustum();

The setOrtho() functions to set the camera and perspective ready for an orthogonal view. drawQuad draws a primitive OpenGL quad. In this case, it covers the entire motion blur buffer. The glBlendEquation, glBlendFuncSeperate, and glColor4f all ensure that the quad we draw does not change any color data. Instead, we simply fade the alpha to transparent by 0.02 per pass. Everything after the drawQuad is just returning us to our normal render environment.

After running the above code and then rendering your motion blur particles, return to your normal draw buffer and render your entire scene. The point at which you will want to add the motion blur should be after you have rendered the scene but before you draw any GUI elements. Simply set up an orthogonal view and draw a quad across the entire buffer.

That’s it!

Troy CorbinMotion Blur on Particles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.