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!
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:
glBlendEquation( GL_FUNC_REVERSE_SUBTRACT );
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ONE);
glBlendEquation( GL_FUNC_ADD );
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.