FramebufferOutput Mental Ray shader


The FramebufferOutput shader creates framebuffer definitions to allow rendering of multiple passes with a single render within Maya or standalone MR. Enabling user framebuffers was already possible in Maya 6 and 6.5 by adding custom text to a camera but it required the standalone version of Mental Ray and did not work at all with the Mental Ray for Maya plugin. With Maya 7 a simple solution for defining user framebuffers appeared (as file ouput passes on the camera nodes) but it is not really realiable and lacks a few important settings.

Enabling framebuffers is accomplished by adding a Mental Ray geometry shader to a "dummy" object in the Maya scene (geometry type does not matter, it is not exported anyway). When the geometry shader gets initialized it adds the user framebuffer data to the Mental Ray state as if the framebuffers were set up by Maya. You can control all framebuffer attributes by opening the attribute editor and editing the user interface for the FramebufferOutput shader, don't have to set anything else in Maya.

Shader parameters:

Mode: Controls the rendering of all framebuffers.
- Disable: No framebuffers are rendered.
- Enable: All defined framebuffers are rendered.
- Enable for full resolution renders: Framebuffers are only rendered for full frames and not used when rendering just a region of the image.

Use image name prefix: When enabled the image prefix is added before the framebuffer image name: prefix_imageName. Image Prefix is useful when you'd like to have a similar naming convention for all of the framebuffers.

Custom render directory: The directory where the images will be rendered. By default the path of the primary rendered image is used and it is compatible with all command line settings of maya and MR standalone too.

The full image name is assembled from these components:


These framebuffers are used automatically by Mental Ray, using them does not require any additional computation.

- Depth: Z-depth
- Normal: Normal-vectors in world space.
- Motion: Motion vectors (when something animates).
- Label: Label (or Tag) information. Requires user labels to be defined using the miLabel integer extra attribute on the transform or shape node of the objects in Maya.
- Coverage: The coverage buffer stores how much objects - with different labels - occlude each other. The coverage buffer requires the minimum sampling of min -1 max 0 to work.

Interpolate: Averaging color information. When disabled each pixel stores the value for the frontmost object and not the weighted average.


Add new: Creates a new framebuffer using the parameters set below. Maya 6.0 (MR3.3) can only use 8 user framebuffers but newer versions (Maya 6.5, MR3.4 and above) support unlimited number of buffers.

Edit selected: Modifies the currently selected framebuffer line with the settings set using the menus. Values are only updated when the user presses this edit button or the enter on the numerical keyboard when modifying the image name.

Delete selected: Removes the selected framebuffer from the list. Delete can also be done by pressing the delete key on the keyboard.

Channels: The channel type and dynamic range the framebuffer uses. See details in the "Texture Mapping and Texture Files" section of the MR documentation. The "+" sign is for interpolated colors and "-" uses the frontmost object.

File format: The file format the buffer uses. Most of the file formats can only store a limited type of channels.

Image name: The name of the rendered image.

User framebuffers: The list of all framebuffer settings.

Enable / disable selected: The selected framebuffer can be disabled. This means that the framebuffer is not rendered although it remains in the list. Disabled framebuffers have a comment mark "#" at the beginning of the line to show the disabled state.




- Copy DSO file into "alias/maya/mentalray/lib" (DLL for Windows / SO for linux and OSX)
- Copy MI file into "alias/maya/mentalray/include"
- Copy the Icon file into a standard maya icon directory.
- Copy the MEL file into a standard maya mel script directory.

- Modify "alias/maya/mentalray/maya.rayrc" with the two following lines, both of them comes after the standard link and mi lines:

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


To get FramebufferOutput working create an object, select its transform node and open the mental ray options to turn on the "Enable Geometry Shader" attribute. Click on the checker icon to attach a shader and select FramebufferOutput from the "Geometry" shader section of the "Create Render Node" dialog. (As an alternate method you can drag or connect the shader directly in the hyperShade.)

The creation of this setup can be easily done by copying the script called sz_CreateFramebufferOutput.mel to a maya script directory and using the command: sz_CreateFramebufferOutput; This command hooks up the shader to a hidden polygonal cube where you can easily change the settings.


- By default Maya uses the first (0) user framebuffer to store shader glow values, even when there is no glow enabled in the scene. In Maya 6.0 it can not be turned off, in Maya 6.5 and above you can turn off the RenderGlobals/MentalRay/Translation/Export Post Effects switch to disable it and make the framebuffer usable.

- The object that has the FramebufferOutput shader must be visible for the geometry shader to work but you can turn off the LOD visibility parameter of the object's transform node to hide it in the viewport. (Thats what the sz_CreateFramebufferOutput script does.) Hiding the object by turning off the normal visibility is like disabling the framebuffer output since this way the shader is not exported at all.

- Multiple FramebufferOutput shaders can be created and used and by showing/hiding you can easily switch between them.

- The geometry shader can be exported and imported to quickly transfer render pass setups from scene to scene. (Of course you still need to manually setup the writing to framebuffers with the shaders.)

Side note:

Quite some time ago when I just finished the writing of the prototype of this shader I found a similar shader by called "ctrl_buffers". Since the design of the shaders (both GUI and code) looks quite different and I needed some specific functionality I though that it does make sense to complete it. Take a look at ctrl_buffers and use the one you prefer!