Friday, April 13, 2012

How to use Maya's 2d motion vector pass for Nuke's vectorBlur. (1of2)

We all know that motion blur is one of the essential effects to accomplish better realism but it generally requires a long rendering time, especially when using full 3d motion blur of Mental ray renderer.
As an alternative,  2d motion vector methods are widely used since it is a cheaper and still very effective and flexible solution.
There are some good articles and tutorials that you can find in the internet about 2d motion vector methods but I will focus on a more specific issue in this article which is a sync problem.  
First, let's take a look at what really happens when motion blur is on, in terms of moving objects' position.

Here's a very simple five-frame animation.

Pic 1. Master beauty

Click the image to see the moving stick.
The animated stick moves by one notch at a time so the moving stick is perfectly aligned with the sticks at the bottom at each frame.

Now you turn on 3d motion blur in Render Settings and you'll get this motion-blurred animation.

Pic 2. Master beauty 3d motion-blurred

The stick has the blur streaks on each side.But notice that the position of the moving stick is not aligned with the bottom sticks any more.

This is naturally what happens with motion blur on. Since the camera's shutter is open for a period of time, there will be some amount of offset in the position of the objects that are in motion.

This is perfectly fine if you use 3d motion blur for all the objects in the scene. But if you try to mix 2d motion -blurred elements and 3d motion-blurred elements, for example, mixing 3d motion-blurred BG pass and 2d motion-blurred character pass, this might cause a sync problem.

Anyhow, let's exclude full 3d motion blur for now because it is not our focus here.
When it comes to 2d motion vector method,  in Mental ray, there are a few options. Reel Smart Motion Blur is one good choice but it's not free and it requires an extra shader-lm2dmv shader. Not only that this method has its own sync issue so let's skip it for now.
Mental ray also provides the mip_motionblur shader and the mip_motion_vector shader as an output shader and unfortunately these are not easy to set up and inconvenient to use. 
I finally come down to using 2d motion vector which is given as a native Maya render pass almost for free.
What's great about it is  it doesn't require any tricky setups. All you have to do is just to take out the pass. Well, it does also has its own sync issue but I'll show how to solve it.
So, unlike other 2d motion vector methods, there's nothing really difficult about it at least on Maya's side.( How you handle it in Nuke is another story though. )

Now, let's go grab the right render pass. We will find 2D Motion Vector in the Render Pass List but that's not what you want. You need to pick Normalized 2D Motion Vector.

Pic3. Render Pass List

Associate the pass with the render layer.

Pic 4. mv2DNormRemap Associated

Now double click the name of the pass to open its attribute editor.

Pic 5. Max Pixel Disp

Make sure you keep this default value of 256. You will use this value in Nuke to calculate 'add uv' value for VectorBlur node but if you stick to a fixed value like 256 at all times, you don't have to calculate it every time.

Now, with no motion blur on, l render the previous animation again.

Pic 6. Master beauty with 2d Motion Vector pass associated

Now you can see that the master beauty pass  which is non motion-blurred is no longer the same as the original one. Of course the stick is not motion-blurred but it's no longer aligned with the bottom sticks. It's shifted to the left from the second frame. In another words, while the stick is in motion it has the shift. The motion blur was not even on. The only difference is that I included 2d motion vector pass in this render task.

Here's the 2d motion vector pass that's been rendered together with the master beauty pass.

Pic 7. 2d motion vector pass

You can see it has the same amount of shift.
So, as long as you use this 2d motion blur render pass for its master beauty pass in this case, you will not have any 'out of sync' problem. But what if you have already rendered out a master beauty pass  and plan to render a 2d motion vector pass separately afterwards? They will not match obviously. But you wouldn't want to render the master beauty pass again, would you?
So, the question is, can you compensate that shift when rendering out 2d motion vector pass?
the answer is, yes! you can.

Go to Render Settings and turn on Full 3d motion blur first to have an access to Motion Offsets section.
Turn on Custom Motion Offsets and adjust the Motion Back Offset to 0.
And make sure to turn back off the full 3d Motion Blur. ( If you turn this on, the 2d motion vector pass will not have the right values to it and eventually become unusable in Nuke.)

Pic 8. Motion Back Offset

Now, render again.

Pic 9. 2d motion vector in sync

Finally, this 2d motion vector looks right. It will match perfectly the master beauty that was rendered without a 2d motion vector pass together.  Ok, so far, so good. The next is how you can handle this 2d motion vector pass in Nuke to apply motion blur.

No comments:

Post a Comment