openEXR - any way to create a matte channel of selected items?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  10 October 2012
openEXR - any way to create a matte channel of selected items?

hi guys
I'm working with openEXR file formats. Overall i'm getting some good layers coming out that i can quickly composite together. However i wondered - is it possible to setup a render pass for openEXR that mattes out various bits..

ie in the image below i wanted to separate the hands and arm meshes from the remaining elements around him (car interior). Ideally i'd like the arms to be red, the meshes he's putting his hands in to be blue and the surrounding elements of car interior green. This way i can key them off and use each colour channel separately for a matte?

I guess it wouldn't be too tough to render out a hardware render of the image by just setting up a renderlayer and assigning 3 different surface shaders but just wondered if its possible to set it up as a renderpass at all and include that for openEXR format?

any openEXR guru's around here ?

  10 October 2012
I would say its not about EXR, but about render. Which render do you use?
3D animation blog
  10 October 2012
You can create a new pass in the render global pass (custom color pass) and then use the writeToColorBuffer utility node to write a color to the buffer.
I have attached a simple scene for you to check but the workflow would be

#1 create the new pass (let's call it myRGBpass)
#2 assign the pass to the scene
#3 create a writeToColorBuffer and set it to write to myRGBpass (add)
#4 set the writeToColorBuffer color to RED
#5 connect your arm shader to the evaluationPassThrough on the writeToColorBuffer

repeat #3, #4, #5 for GREEN and BLUE

I don't know if you have to do this for every shader or if you can "group" them and use a single writeToColorBuffer for more than one shader, maybe someone could help you with that
Attached Files
File Type: zip (31.0 KB, 15 views)
  10 October 2012
@nookie - absolute legend thankyou good sir - works a treat and openEXR see's it as just another layer - brilliant
  10 October 2012
Here is a mel script that I wrote that does this very thing. It adds a matte-channel of whatever you currently have selected (a single alpha, not RGB) which will render along with your current render layer.

roughly speaking, this is what it does:

  1. create a pass contribution map of the selected object
  2. create a render pass of type "matte"
  3. assign the pass contribution map to the render pass
Using the PCM method, you maintain transparency on objects, as well.

 global proc createMatte(){
 	string $promptResult = `promptDialog -title "matte name" -message "name of matte"`;
 	string $matteName = `promptDialog -query -text`;
 	string $curLayer = `editRenderLayerGlobals -q -currentRenderLayer`;
 	string $pcmNode_def = `createNode -skipSelect passContributionMap`;
 	string $pcmNewName = $matteName + "_pcm";
 	string $rpName = $matteName + "_mat";
 	string $pcmNode = `rename $pcmNode_def $pcmNewName`;
 	renderLayerEditorAssocContMap("RenderLayerTab", {$curLayer}, $pcmNode);
 	string $listSel[] = `ls -sl -fl`;
 	for($thisGeo in $listSel) {
 		alterNodeContMapConnection($thisGeo, $pcmNode, "dagObjects", 1);
 	string $rpNode = `createNode -name $rpName renderPass`;
 	setRenderPassType -type "MATTE" -numChannels 1 $rpNode;	 
 	setAttr ($rpNode + ".frameBufferType") 256;
 	setAttr ($rpNode + ".numChannels") 1;
 	string $owners[] = `listConnections -d off -s on -plugs 1 ($rpNode + ".owner")`;
 	if(!stringArrayContains(($curLayer + ".renderPass"), $owners))
 	connectAttr -nextAvailable ($curLayer + ".renderPass") ($rpNode + ".owner");
 	$owners = `listConnections -d off -s on -plugs 1 ($pcmNode + ".renderPass")`;
 	if(!stringArrayContains(($rpNode + ".message"), $owners)){
 		connectAttr -nextAvailable ($rpNode + ".message") ($pcmNode + ".renderPass");

This is the fastest, easiest, and most efficient way to make multiple mattes from selections in Maya.

Last edited by EdtheHobbit : 10 October 2012 at 07:01 PM. Reason: legibility
  10 October 2012
Let me know how this works for you, I wrote it for myself and haven't tested much "in the wild"
  10 October 2012
hi Ed I will try it out over the weekend - I quickly copy/pasted it at work and did a quick test scene and it seemed to work a treat tho hopefully it'll work with my more complex scene at home - i'll post pics to show you what i get

  10 October 2012
my two cents....

One show I was attending used assets which were not bound shaders per geometry so I was afraid, that I need to go through the hell of mixing layers with new shaders which then would trigger the evaluation of the custom color passes and yadda yadda...until I realized that one can bind ( or layer with add/whatever nodes and then bind ) geometry directly to the custom write node.

Try connecting your shape node's message - attribute to the writeToXXXXXbuffer and see for yourself.

It seems that one can create all kinds of bizarre node networks which float ie. are not bound to any geometry, and then just decide from where, geo or shading node, you trigger your custom pass evaluation.

- Oh no, it's me -
  11 November 2012
Hello EdTheHobbit,
I tried your script today to make a matte pass of some particular flowers which are buggin' me, to isolate them in Photoshop. It didn't seem to do anything, nor did it cough up an error. I'm not sure what I'm doing wrong?

I selected the objects, then ran the script. No contribution maps or render passes were created, however. I'm using Maya 2012 still though, is this a Maya 2013 thing, perhaps?
Commodore 64 @ 1MHz
1541 Floppy Drive

"Like stone we battle the wind... Beat down and strangle the rains..."
  11 November 2012
I wrote a utility to create matte passes from selected objects. It creates each matte as a single channel within the EXR. Probably a bit late to the party, but it might help in the future.


Last edited by faultymoose : 11 November 2012 at 12:57 AM.
  11 November 2012
Hey Infernal -- it shouuuuuld work... did you run the createMatte procedure after copy/pasting/running the script?
  11 November 2012
No, I just ran the script on my selected objects. I'm new to pass contribution maps. What I'm trying to do is have my main render, my z-depth pass, and a mask pass for one set of flowers render out. I'm using .tif files (.exrs don't work great in Photoshop, last I tried), and the z-depth pass works fine. I'll admit I don't know what I'm doing.

After trying your script, I manually set the flowers to a matte pass contribution map, and so I have two associated passes : depth and matte. I also associated the PCM (with only the flowers) with the matte pass, but upon rendering, the PCM didn't actually affect anything. Everything rendered in both the z-depth and the matte pass.

Am I doing this all wrong? How would I add or remove objects from the PCM? I can't find anywhere that will list this connection... Didn't find anything in Hypergraph either. I feel stupid.

@Faultymoose: looks pretty cool! Would it only work with .exr files, though? I need to learn what I'm doing manually first, methinks, before trying something more automated.
Commodore 64 @ 1MHz
1541 Floppy Drive

"Like stone we battle the wind... Beat down and strangle the rains..."
  11 November 2012
Yes I believe my script will only work with OpenEXR, unless there is another native format which supports arbitrary channels? I'm not sure, I'm afraid.

What my script is doing is more or less the same as what you're doing now: You select some objects, click a button, and it adds those objects to a pass contribution map (either an existing map, a new one, or multiple new maps depending on the options you've selected) and creates a matte pass for the render layer.

You can do it manually, but it's fiddly, for the reasons you've mentioned. Finding the objects associated to a PCM is not all that intuitive (I think you can right-click > select members and right-click > Add / Remove just like you can with render layers).

But you're right, learning to do it manually is important!

  11 November 2012
Infernal -- run the script, then type


in the MEL bar. The script above only builds the procedure, you still need to run it.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 03:30 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.