Part 2: Installation and Use of the lm_2DMV Mental Ray Shader to Create a Motion Vector Sequence

This segment will cover the installation and use of lm_2DMV, a Mental Ray shader created just for this purpose. lm_2DMV stands for la maison 2D Motion Vectors. For a long time, lm_2DMV has been the standard way to render out a motion vector pass for ReelSmart Motion Blur. It can also work with a ReelSmart product called SmoothKit, which interpolates between frames in case you need to fake slow motion. With the release of Maya 2009, it became unnecessary to use lm_2DMV because Mental Ray can now export a native render pass that produces the same data. For those of you who don’t have 2009 or just want to use the tried-and-true method, read on. If you want the newer render pass method, then you can move on to Part 3 (see link below).

Part 3: Rendering a 2D Motion Vector Sequence Using Maya 2009’s Built-in Render Pass>>

Step 1. Get the Motion Vector Shader File for Your OS

First go to the site of the shader’s original author, la maison lm_2DMV. You need to get a version that is correct for your OS. If you have Windows 32 bit, then your download is in the “download” section. If you have Mac or Windows 64, then you don’t need anything from the “download” section. Look instead under the “other software and other OS” section for your download. Whatever you choose, you will probably end up with the following three files:

  • lm2DMV_v2.dll
  • lm2DMV_v2.so
  • lm2DMV_v2.spdl

If you are on Windows, then all you need is the .DLL.

I believe that Mac/Linux users need to use the .SO file instead of the .dll.

The reason for the .SPDL (Softimage Plug-in Definition Language) file is that this shader was originally made with SoftImage XSI in mind. Throw away this file and keep the .dll or .so, depending on your OS flavor.

Step 2. Get the Maya-Specific Files

Horvatth Szabolcs created the Maya-specific version. You’ll need the files from this page.

  • AElm2DMV_v2Template.MEL
    This script tells Maya how to display the shader’s attributes in the attribute editor.
  • lm2DMV_v2.MI
    This is the node that will actually show up in your hypershade. If this node could talk, it would say, “When you assign me to  geometry, the render color of that geometry will be decided by what the shader file (your .dll or .so from step 1) dictates.” It also provides the shader’s default numerical values.
  • render_lm2DMV_v2.XPM
    You don’t really need this at all, but it will give your shader a nice icon if you choose to install it.

Step 3. Put Your Four Shiny New Files in The Right Places

lm2DMV_v2.MI goes into ‘Maya app folder/mentalray/include/’

PC path: Program files > Autodesk > Maya(2009) > mentalray > include > lm2DMV_v2.MI

Mac path: Applications > Autodesk > Maya(2009) > Maya > (right click > show package contents) > Contents > mentalray > include > lm2DMV_v2.MI

lm2DMV_v2.dll (or .so) goes into ‘Maya app folder > mentalray > lib/’

PC path: Program files > Autodesk > Maya(2009) > mentalray > lib > lm2DMV_v2.dll

Mac path: Applications > Autodesk > Maya(2009) > Maya > (right click > show package contents) > Contents > mentalray > lib > lm2DMV_v2.so

AElm2DMV_v2Template.MEL goes into ‘Maya app folder > scripts > AETemplates

PC path: Program files > Autodesk > Maya(2009) > scripts > AETemplates (Attribute Editor Templates) > AElm2DMV_v2Template.MEL

Mac path: Applications > Autodesk > Maya(2009) > Maya > (right click > show package contents) > Contents > scripts > AETemplates (Attribute Editor Templates) > AElm2DMV_v2Template.MEL

You can also use one of the other Maya scripts directories for this file, such as the one in your documents folder.

render_lm2DMV_v2.XPM goes into ‘Maya app folder > icons

PC path: Program files > Autodesk > Maya(2009) > icons > render_lm2DMV_v2.XPM

Mac path: Applications > Autodesk > Maya(2009) > Maya > (right click > show package contents) > Contents > icons > render_lm2DMV_v2.XPM

Step 4. Modify the maya.rayrc File

Open maya.rayrc with a text editor. The file is located in ‘Maya app folder > mentalray’

PC path: Program files > Autodesk > Maya(2009) > mentalray > maya.rayrc

Mac path: Applications > Autodesk > Maya(2009) > Maya > (right click > show package contents) > Contents > mentalray > maya.rayrc

If your file doesn’t have any other custom additions, then the file should just contain text with comment # symbols before each line. You can just leave them alone and paste these two lines at the end of the file:

link "{MAYABASE}/lib/lm2DMV_v2.{DSO}"
mi "{MAYABASE}/include/lm2DMV_v2.mi"

Save the file, and then you’re done with this step.

This file will tell Maya to load the lm_2DMV shader when the program starts. After you do this, you can load or unload the shader from within Maya by going to:

Window > Rendering Editors > Mental Ray > Shader Manager

Step 5. Using the Shader in Maya

Okay! That was tedious, but now it’s all done. Let’s get down to the business of usage.

Tip: Make sure that raytracing is turned off when you render your lm_2DMV render layer. If your camera is moving in space, then the shader may not register the translation if raytracing is on.

Open Maya and your test scene and make sure that the lm_2DMV shader is showing up in the hypershade -> create mental ray nodes tab.

Step 6. Set Motion Blur Render Settings

The five steps below will show you how to turn on motion blur, but to set it to have no blurring effect. You must follow these steps so that Mental Ray will be forced to calculate the motion vectors internally. If you do not do follow these steps, then the shader output will be solid yellow with no variance.

Motion Blur Settings

  1. Make sure you have your masterLayer selected in Render Layers so that the changes happen globally on all render layers (not as a layer override).
  2. Go into the render settings dialogue and find the Motion Blur attributes.
  3. Change the setting to Motion Blur -> Full.
  4. Change Shutter Open and Shutter Close to 0.5.
  5. Again, these changes needs to happen on every render layer, not just on the vector layer. The reason every layer has to change is this: The shutter settings tell Mental Ray to render the temporal position halfway between one frame and the next (for example, instead of rendering frames 1, 2, and 3, the result you will see is 1.5, 2.5, and 3.5).

Step 7. Create a lm_2DMV Render Layer

Render Layers

Select the foreground geometry that you wish to blur and isolate it to its own render layer (by clicking the yellow button shown at right). Name your layer and then assign the lm_2DMV shader as a material override by doing the following:

right click on the render layer -> Overrides -> Create New Material Override -> lm 2dMV_v 2

Step 8. Set Shader Attributes

Now go into your hypershade, find the lm_2DMV node, and open its attribute editor. You will see two options: Target Plugin and Normalize. You will need to adjust Normalize. Basically, what this node is asking is, “In pixels, what is the most that the object will move between one frame and another?” Then the node takes the internal motion vector data and clamps it down to a range based on this setting. As long as you are rendering as a 16-bit image then you can just set this value to 512 (the highest it supports). You will still get plenty of detail in the image without needing to clamp it down further. Whatever you set this value to, you need to also enter that number into the Max Displace field later on in the RSMB plugin.

The RSMB plugin's Max Displace field needs to match the lm2DMV Shader's Normalize field

The RSMB plugin's Max Displace field needs to match the lm_2DMV Shader's Normalize field

With your vector render layer still active, open the render settings dialogue again. You will need to create some layer overrides here, so do the following:

  1. Make sure your motion vector render layer is still the active layer.
  2. Find the option box for raytracing, right click on it, and pick Create Layer Override.
  3. The text should turn orange, indicating that this setting will be changed on this render layer only (otherwise, it would use whatever setting you chose when you had the masterLayer selected).
  4. Turn off raytracing.
  5. Do the same thing to turn off shadows.
  6. If you want to optimize render time further you can experiment with overrides such as lowering the anti-aliasing samples.

Step 9. Make Background and Foreground Beauty Layers

Make two more render layers that contain everything in your scene. You can do this by duplicating the masterLayer twice.

backgroundOn the background layer, you need to turn off primary visibility of all foreground geometry.

  1. Make sure that the background render layer is the active layer.
  2. Select the foreground geometry (what will be blurred).
  3. Go to Window -> General Editors -> Attribute Spreadsheet-> Render tab.
  4. Pick every field under Primary Visibility.
  5. Type 0 (zero) and press Enter.
  6. This should change every field to “off.”

workerNow activate the other render layer that will be your foreground beauty pass.

On this layer, turn off Primary Visibility on all the background geometry to isolate the foreground instead.

The reason that the primary visibility attribute is better than simply hiding or not adding certain geometry to a layer is that, with this method, all the hidden objects are still casting indirect light from final gather, as well as their shadows and reflections (if you want), onto your visible geometry.

Step 10. Make a Second Matte Layer (If Needed)

In many situations, you will use the built-in alphas from your vector or foreground layers and will not need to do anything extra. What I’ve created in this example shows the yellow railing in front of my foreground character layer. This requires an extra step. I had to generate a second matte layer. Using material overrides, I made the railing geometry white (and anything else that obstructed my motion blurred geometry) and everything else black. Remember to apply the same motion blur render settings to this layer as in step 6 (shutter open/close set to 0.5). This layer should be applied in the compositor last. The foreground character and its alpha and blur need to be precomped, and then this railing luma matte needs to be applied to that in order to cut a hole through the foreground character to let the railing show. If this matte was added at the same time as the other alpha(s), then the motion blur plugin would try to use the railing obstruction in its blur calculations, which we definitely don’t want.

railing matte

Step 11. Render It!

Once you have the foreground, background, matte, and vector sequences rendered out, you are ready to move on to the compositing stage. If you are following along with the tutorial and are curious about ReelSmart vs. built-in Maya motion blur, then you can render out your masterLayer with the motion blur shutter overrides set back to 0 and 1 so that you get the default composite beauty with blur sequence for comparison.