Specialized passes: Material ID, Object ID and UV Pass – Tutorial

When outputting to composite rendered passes, it can be very useful to have the ability to select your render components by types.
In this example, we are going to explore how to output render passes per material and per object.

ninja_masterbeauty.jpg

Material ID
The term “Material ID” is commonly used when the render passes output the render per material.
For example, in this scene we are using 5 shaders. The objective is to have 5 different color variables for easy selection/isolation in the compositing phase.

ninja_materials.jpg

Maya 2009 comes with a built-in ability to do so in the form of render pass. This pass is called “Diffuse Material Color”.  However, if you are using multiple objects that share the same color or one of your shaders has a texture node attached to the color, this approach may not be ideal. Thus, the need to use a custom color buffer.
We start by adding a custom color as a render pass.

cuscolorpass.jpg

Open the Hypershade and create multiple “writeToColorBuffer” nodes that match the same number of shaders you have in the scene.

colornode.jpg

In the Hypershade, middle-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”.

tocolor.jpg

Repeat the above step for each shader.
In the Attriubte Editor for each of the writeToColorBuffer nodes, choose customColor as the Custom Color Pass.  For each material give a unique color value thus making the material different even if they share the same color value or have a texture assigned to them.

writetocolorattr.jpg

This is the result:

material_id.jpg

Object ID
The same concept applies to the object ID (aka label ID).  That is, the need to be able to select part of the rendered image based on pre-defined “labels”.  Currently, Maya doe not have a direct solution for this pass, however it can be done by using multiple techniques.

Method A- Pre Maya 2009 render passes
Select all the objects that you wish to include in the pass, and execute the following MEL script:
addAttr -ln miLabel -at long -k 1;
This will add a new attribute (called “MI Label”) for all the objects in the Extra Attributes section:

milabel.jpg

In this example, we have 11 different objects in the scene. Once we create a different “MI Label” for each object, we will assign a different ID value, thus making each object unique during render time.
Select the render camera and under the mental ray section > Output Shaders,  select the Create button.  This will create a mentalrayOutputPass.

cam_shader.jpg

Change the Frame Buffer Type to “Label (Integer) 1×32 Bit”.  Note: you can change the image format and the name of the pass according to your needs.

campass.jpg

The result will be a separate rendered file in the format selected in the Image Format field.

obj_id.png

Method B – Custom Depth
In this approach we will use a custom depth pass to determine our object ID in the scene. This approach works best when the objects have a noticeable distance between each other.

render_color.jpg

We will start by adding a “Custom Depth” pass in our associated passes.

customdepth.jpg

In the Hypershade, we will add multiple “writeToDepthBuffer” nodes. These nodes can be found under the Miscellaneous section of the mental ray nodes.

depthnode.jpg

We will connect the “.outColor” attribute of the Shader to the writeToDepthBuffer’s “.evaluationPassThrough” attribute.
In the Attribute Editor of the writeToDepthBuffer, change Custom Depth Pass to the custom depth pass node that we added in the Render Settings.

hyper_pass.jpg

For each writeToDepthBuffer node we will give a different value for each Depth.

writetodepthattr.jpg

Once we render the result will be like this:

depthresult.jpg

UV Pass
This workflow will allow the user to select parts of the geometry based on their UV shells.
In this example, this geometry has multiple UV shells (11 in total) and all located in the 0-1 region.

uv_shell.jpg

We will start by creating a Custom Color Pass (same as above) and adding a “writeToColorBuffer” node in the Hypershade.
In the Hypershade, midde-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”.
In the Attriubte Editor for each of the writeToColor nodes, choose “Custom Color” as our Custom Color Pass.
In the Hypershade, under the mental ray Nodes > Textures section, create a mib_texture_vector node.  Then add it to the Color value of the writeToColorBuffer node.

uvconnection.jpg

In the mib_texture_vector node, change the “Project” to “uv”:

mib_tex.jpg

Now when you perform a render, you will get a color variation based on the UV shells of your mesh.

uv_shell_color.jpg

Recent Entries

19 Responses to “Specialized passes: Material ID, Object ID and UV Pass – Tutorial”

  1. fawad ahmed khan Says:

    well thats a great tutorial …i really appericiate it…
    though still i have a question …

    what if one had to render multiple renders..even its tga,tiff or what ever format other than exr …or if we are using mentalray,renderman ..scanline renderer or other renderers

    Question is …..is there any mel script or fast automated solution that can collect these custome passes/files and compile them in a single exr file(after rendering).so that we can use it in nuke or fusion…

  2. Ashraf Says:

    Unfortunately No , EXR is a special file format.
    I’m not aware of any MEL script that ill do what you are looking for

  3. omar Says:

    thanks for this great tutorial !!!!

  4. arnel Says:

    Thanks for the great maya tutorial

  5. marc Says:

    hi, thanks for tutorial. if using mia_material x passes material, what would be the out connection in connection editor to the write to color node? there is no outcolor as i can see..
    thanks!

  6. marc Says:

    ah! i found it…mia x passes works if use ‘message’ as the output.
    : )

  7. vishal3d Says:

    thankz in advance,
    can u show us, how we can use it in compositing package, i mean abt uv pass.

  8. omar Says:

    hey ash,
    it would be greatly appreciated if u create a tutorial on the uses of the uv pass in aftereffects.

  9. Ashraf Says:

    You would need a special plugin
    search for UV pass and after effects, you should get that page

  10. francoisgfx Says:

    ft-UVpass : http://aescripts.com/ft-uvpass/

    :)

  11. sep Says:

    Cool! THat was really helpful. These Mental ray writers always like to make things complicated. In Renderman it is just a click to add UV pass… Hope they make things simpler in future…

  12. swami Says:

    Thanks for the tutorial.
    Do you have a tutorial or website explaining how you use these passes in Nuke. Even if you show how to use the id matte pass. I only know to shuffle out RGBA and CMYK color using a shuffle node.

    Thank you

  13. hussein moussa Says:

    hey ashram i was just fiddling around with the uv pass when i was trying it out with the mental ray shaders i cant seem to find a “.outcolor” to connect to the “.evaluationpassthrough” , so what would be the work around to that. and i wanna thank you again for the cairo met workshop it was really great and hope to see you there next year :D ohh and also it would be great to tell me the nuke node you used to connect the uv pass with the new texture cause you passed through that fast in the conference and well shane had a problem with his file so we didn’t get it in depth. thanks a lot and hope to hear from you soon.

  14. Ashraf Says:

    Make sure that “show hidden” is enabled in your connection editor window
    for both left and right sides.
    hope this helps.

  15. hussein moussa Says:

    no still cant find it maybe theres an equivalent to the .outcolor in the mentally shaders like the one in the normal maya shaders?

  16. Chris Says:

    Hi Hussein, did you find out, how to connect a mia material so far? didn´t find the connection as well. it worked with any other typ of shader, but not with the mia material. anybody an idea?

    greetz chris

  17. Brandon Says:

    @Chris and Hussein, Make sure the “show hidden” is enabled in the connection editor and then connect the “RESULT” of the mia_material to the “EvaluationPassThrough” of the writeToColorBuffer. Hope that helps!

    Cheers

    :)

  18. waleed Says:

    that is so great..thnx 4 the tips

  19. daksh Says:

    thnx u for this helpful tutorials…
    ….

Leave a Reply