Motion blur: how to save/reload PrevModelViewProjectionMat?

Hello,

I’m trying to implement motion blur filter.

Note: I already know how to make multiple pixel/fragment shader.

First, I need to generate the velocity buffer. As the author explains: we render the geometry, transforming every vertex by both the current model-view-projection matrix as well as the previous model-view-projection matrix. In the vertex shader we do the following.

The problem is: I don’t know how to save the previous matrix. Jmonkey passed automatically the “global” variable:

uniform mat4 g_WorldViewProjectionMatrix;

So my question is: Could you tell me how I can save the previous matrix, please?

   uniform mat4 uModelViewProjectionMat;
   uniform mat4 uPrevModelViewProjectionMat;

   smooth out vec4 vPosition;
   smooth out vec4 vPrevPosition;

   void main(void) {
      vPosition = uModelViewProjectionMat * gl_Vertex;
      vPrevPosition = uPrevModelViewProjectionMat * gl_Vertex;

      gl_Position = vPosition;
   }

Thank you in advance :slight_smile:

1 Like

The WorldViewProjection matrix is actually 3 matrices multiplied together, the world matrix, the view matrix, and the projection matrix.
The world matrix comes from the geometry (scene graph object). The view and projection matrices come from the camera from which the scene is rendered. So to determine the previous WorldViewProjectionMatrix you will need to get the previous values for all 3. It is actually quite tricky to write a motion blur filter for this reason. Ideally you could piggy back on jME3 already calculating those values and then store them somewhere for the next frame …

In any case, I would like to leave some exercise for the reader, so here you may find the source code for UniformBindingManager where the WorldViewProjectionMatrix is actually calculated: