Remember 3December
Find out where to celebrate your 3D CG art...
Theme color:
  • 1/3
You are here: Homepage /  Blogs /  Captain Proton / Specialized passes: Material ID, Object ID and UV Pass
Specialized passes: Material ID, Object ID and UV Pass
Posted: Feb 17, 2009
Category:
Social Media:
Bookmark and Share

Material ID Pass, Object ID Pass and UV Pass (By Guest blogger: Ash Aiad for Maya Support team)

 
Important: The Ninja model was taken from CG Society Free 3D models. Please visit this link for more details.
http://features.cgsociety.org/story_custom.php?story_id=580

When outputting to render passes for compositing, 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.

Material ID Pass

 
The term “Material ID” is commonly used when the render passes output the render per material. For instance selecting all surfaces that are "metal" type.

In this scene we are using 5 shaders. The objective is to have 5 different color variables for easy selection/masking in the compositing phase.
Maya 2009 has built-in render pass capabilities. This pass is called “Diffuse Material Color”. However, if you are using multiple objects that share the same diffuse color or one of your shaders has a texture node attached to the color, this approach *IS* not ideal. Thus, the need to use a custom color buffer for creating Material ID pass.
We start by adding a custom color as a render pass, and assign it to the active render layer.

Image Description: We start by adding a custom color as a render pass, and assign it to the active render layer.

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

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

In the Hypershade, middle-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”. Repeat the above step for each shading network such each element in the scene

Image Description: In the Hypershade, middle-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”. Repeat the above step for each shading network such each element in the scene "contributes" to the custom color frame buffer. This approach can also be done on "per face" shading network, where we can use colorCustom Pass to extract a particular set of faces to ease selection and masking.

In the Attribute Editor for each of the writeToColorBuffer nodes, choose

Image Description: In the Attribute 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.

This is the result of a material ID pass using custom color pass.Obnj

Image Description: This is the result of a material ID pass using custom color pass.Obnj

Object ID Pass (Method A) - Valid for Maya 2009 and older versions.

 
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.

Select all the objects that you wish to include in the pass, and execute the following MEL script:
Image Attachment Code Example
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.

Image Description: This will add a new attribute (called “MI Label”) for all the objects in the Extra Attributes section.

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.

Image Description: Select the render camera and under the mental ray section > Output Shaders, select the Create button. This will create a mentalrayOutputPass.

Change the Frame Buffer Type to “Label (Integer) 1x32 Bit”. Note: you can change the image format and the name of the pass according to your needs. It would be important to provide a File Name Postfix (suffix) to ensure proper naming of rendered elements on disk.

Image Description: Change the Frame Buffer Type to “Label (Integer) 1x32 Bit”. Note: you can change the image format and the name of the pass according to your needs. It would be important to provide a File Name Postfix (suffix) to ensure proper naming of rendered elements on disk.

The result will be a separate rendered file in the format selected in the Image Format field. in this case we use imf_disp to view the file, since it will automatically color each labels to better visualize the result.

Image Description: The result will be a separate rendered file in the format selected in the Image Format field. in this case we use imf_disp to view the file, since it will automatically color each labels to better visualize the result.

Object ID Pass (Method B) - Valid for Maya 2009 only

 
In this approach we will use a custom depth pass to determine our object ID in the scene. We will assign a custom "depth" value for each objects (HDR values) which can then be used as selection mask during compositing.
Beauty Render

Image Description: Beauty Render

We will start by adding a “Custom Depth” pass in our associated passes, and then associate this pass to the active render layer

Image Description: We will start by adding a “Custom Depth” pass in our associated passes, and then associate this pass to the active render layer

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

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

We will connect the “.outColor” attribute of the Shader to the writeToDepthBuffer’s “.evaluationPassThrough” attribute.

Image Description: 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. For each writeToDepthBuffer node we will give a different value for each Depth.

Image Description: In the Attribute Editor of the writeToDepthBuffer, change Custom Depth Pass to the custom depth pass node that we added in the Render Settings. For each writeToDepthBuffer node we will give a different value for each Depth.

Once we render the result will be like this. Each depth value can be considered as

Image Description: Once we render the result will be like this. Each depth value can be considered as "ID" in this case. It is important to use a file format that can support HDR, like IFF and openEXR.

UV Pass

 
This workflow allows to re-texture surfaces during compositing stage.
In this example, this geometry has multiple UV shells (11 in total) and all located in the 0-1 region.

Image Description: In this example, this geometry has multiple UV shells (11 in total) and all located in the 0-1 region.

We will start by creating a Custom Color Pass (same as above) and then assign it to the active render layer.

Image Description: We will start by creating a Custom Color Pass (same as above) and then assign it to the active render layer.

Then add a “writeToColorBuffer” node in the Hypershade

Image Description: Then add a “writeToColorBuffer” node in the Hypershade

In the Hypershade, middle-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”. Again, in 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.

Image Description: In the Hypershade, middle-mouse drag the shader on top of the writeToColorBuffer node and choose “Evaluation Pass Through”. Again, in 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.

In the Attriubte Editor for each of the writeToColor nodes, choose “Custom Color” as our Custom Color Pass. For the Color input, it will be driven by another shader which

Image Description: In the Attriubte Editor for each of the writeToColor nodes, choose “Custom Color” as our Custom Color Pass. For the Color input, it will be driven by another shader which "extract" UVs

In the mib_texture_vector node, change the “Project” to “uv”. By default the shader will extract the first UV (0), if you have many UVs, you need to increase the

Image Description: In the mib_texture_vector node, change the “Project” to “uv”. By default the shader will extract the first UV (0), if you have many UVs, you need to increase the "select" attribute to 1, or 2, etc.

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

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

Thanks Ash Aiad for your contribution

 
In order to post any comments, you must be logged in!
Newest users comments View All 10 Comments
Posted by intaglio on Sep 03, 2009 at 06:10 PM
i think you left out to specify where i can see the result of a render pass because is not default when you preview render, for that you have to go (in the preview render window) to file / load render pass,
Posted by zeronev on Jun 15, 2009 at 12:30 PM
excellent,this tut is just what I want.
Posted by JuanBernardo on Apr 15, 2009 at 04:10 AM
awesome, simply awsome. Thanks, I can go to sleep now.
Posted by Ash-Man2 on Mar 03, 2009 at 06:17 PM
It worked on my side
try this file
rapidshare.com/files/204829456/custom_Pass.rar.html
Posted by vizije on Mar 03, 2009 at 01:31 PM
Hmm ever tried this with mia X shaders?
My renders keep crashing. I tried material ID and depth ID. I connected mias resault but no way to render in Maya 2009 (64bit).
Any idea?