Blog Archives

Using Framebuffers with the Layering Library (MILA)

You can take a brief look at the main structure of the MILA shaders inside Maya in the first post explaining their usage: The Layering Library (MILA)

One of the most important things to remember about MILA is how the framebuffer passes work.

The builtin framebuffers use the modern framebuffer mechanism in mentalray that uses a named framebuffer and type.

Your main framebuffers are additive; this means in compositing you simply add or plus the passes together to create your beauty. This avoids other operations that might cause problems like multiplication. Multiplying in compositing causes problems with edges and makes it impossible to recreate the beauty render. It also complicates compositing objects onto one another or plates.

Your main passes are (First given as a Light Path Expression (LPE)):

  • L<RD>E  or direct_diffuse
  • L.+<RD>E or indirect_diffuse
  • L<RG>E or direct_glossy
  • L.+<RG>E or indirect_glossy
  • L<RS>E or direct_specular
  • L.+<RS>E or indirect_specular
  • L.+<TD>E or diffuse_transmission
  • L.+<TG>E or glossy_transmission
  • L.+<TS>E or specular_transmission
  • LTVTE and/or front_scatter and back_scatter
  • emission (in LPE, emission is actually a light)

Direct effects are usually the result of the light source.

Indirect effects are usually the result of light from other objects.

Why include LPE? LPE makes specifying passes the same for all rendering solutions. This idea unifies the conventions used for getting the same data regardless of renderer used.

You also have the option to add custom shaders on top of this in the material root node. Keep in mind that what is added here may increase render time since they are run separately from the material and we typically reserve them for inexpensive utility passes like noise, fresnel, and ID mattes.

The Root node, the mila_material This includes the ability to create and attach custom framebuffers for output

The Root node, the mila_material This includes the ability to create and attach custom framebuffers for output

Getting these framebuffer passes from Maya requires a bit of a workaround using a legacy user pass system rediscovered by Brenton. I find it to be easier than using Custom Color with the exception you have to keep track of the names of your passes and spell them correctly to match up. MILA also makes it a universal solution since all shaders are set to automatically write to these buffers without more work. This is part of the idea behind LPE: the  light path stored is always the same for the LPE chosen regardless of renderer. Making this automatic is an easy decision in this case.

For the passes built into MILA you simply need to have the framebuffers ready with the correct name and MILA will write to them automatically. Keep in mind that Maya’s current system overwrites data written to their default passes like “diffuse” so you cannot use those or the same names if they are used in the scene.

Fist: Select the miDefaultOptions node

select miDefaultOptions;

Second create a framebuffer:

AEmrUserBuffersAppend miDefaultOptions.frameBufferList;

The above command creates a user framebuffer seen as default below.

A new user framebuffer

A new user framebuffer

You have two selections above: Data Type and whether or not to interpolate (filter) the result.

You typically want to interpolate results for color framebuffers like direct diffuse, ID mattes, fresnel passes, etc. You do NOT want to interpolate data buffers like z-depth, normals, world points, etc.

You can see the typical data types that should not be interpolated at the bottom of the list. These data types are not interpolated by mental ray because it is mathematically incorrect for compositing. They also require high precision so you will notice they default to Floating Point 32-bit data.

Framebuffer Data Types - Data Passes

Framebuffer Data Types – Data Passes

I have not used the LPE for direct diffuse because Maya does not allow angled brackets and other symbols in text fields for names at this point. After creating and naming your passes, you can then add them to the camera Output Shaders as the last step to render them.

mental ray tab, add an output pass

mental ray tab, add an output pass

When you create an entry you will see a Output Pass that looks like the default one below.

Default Output Shader

Default Output Shader

Since we have already created passes, you can select the “Use User Buffer” option, then in the dropdown “user Buffer” menu, select the pass you want. Below is the direct_diffuse example:

Direct Diffuse Output Shader

Direct Diffuse Output Shader

I then select the following options:

  • File Mode: I want to write to the rendered file
  • Image Format: OpenEXR, I have already specified 16-half float and EXR as my rendering format in the main Render Settings editor.
  • File Name Postfix: I leave this blank. This way all of the passes are written to the same EXR and packed together as layers.

You can follow this same method when adding user passes to the mila_material root. Be sure and name them the same as the pass you will create and then reference in the camera Output Shader

Added Color and Vector buffers

Added Color and Vector buffers

Keep in mind that the usual Maya Default passes for data will still work with MILA and you can select those as well instead of adding those default passes here. It’s useful here if you need different or additional data per shader. ID Mattes are very useful in this case. And in fact, this shader can detect and use the user_data shaders for you to assign ID groups and other data to objects. This means you can render complex scenes with fewer shaders and still organize the passes logically. This will be a future explanation since this introduces a new workflow/pipeline for getting information from Maya while avoiding the Render Layers system when possible.

In the example file below you’ll see I am driving some parameters of the shader with attached object data. This has a few benefits. One such benefit is the data follows the object rather than the shader and you can change the result of the shader by manipulating the object user_data. I also have a single sphere in one ID matte group but also included with another group of ID mattes, giving me different ways to handle the object in post.

You can find an example workflow in this Maya File [removed since MILA updates broke it, need to make a new one]. The scene has the default framebuffers and a couple ID mattes set up. You can play with the materials and quality to get other buffers to show a result (for example, emission is empty because I am not using that effect.) I also have single-layer materials. Try mixing and matching and seeing the resulting framebuffers. Be sure and attach your own HDRI to the Maya IBL Image.

(Maya 2013 SP2)

Additional layering/mixing is left to user experimentation.