# shave and render passes

**URL:** <https://forums.chaos.com/t/shave-and-render-passes/38995>\
**Category:** General\
**Created:** [October 11, 2011, 6:13am UTC](https://forums.chaos.com/t/shave-and-render-passes/38995 "2011-10-11T06:13:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharktacos](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sharktacos](https://forums.chaos.com/u/sharktacos)\
**Post date:** [October 11, 2011, 6:13am UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/1 "2011-10-11T06:13:59Z")

</div>

What would be the recommended way to work with Shave and a Haircut and Vray’s render passes system?  
Is there a way to put the hair into a render element of some sort?

Here are some specific difficulties I bumped up against:

**occlusion** :  
I do know that the passes themselves work with shave. For example you can generate a spec pass that will work on the shave hair along with everything else. Occlusion is a big problem though because it takes (understandably) a really long time to render occlusion on hair. So simply having render passes on a scene with shave hair is problematic since it will take a huge hit on render times. So it there a way to exclude the hair from the occlusion calculation in the extra-tex pass?

**mattes** :  
Last time I checked there was not a way to get the hair into multi-matte because there was no way to assign the shave hair and object ID. Has this changed in 2.0? Would there be a way to set it up with a material ID? That would not work with the native Shave shader, but maybe we could assign a vray hair shader to it?

Any insights appreciated.😁

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [October 11, 2011, 6:29am UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/2 "2011-10-11T06:29:35Z")

</div>

> [@FlareVisuals | Matus Nedecky](https://forums.chaos.com/t/flarevisuals-matus-nedecky/36388/22):
>
> I do know that the passes themselves work with shave. For example you can generate a spec pass that will work on the shave hair along with everything else. Occlusion is a big problem though because it takes (understandably) a really long time to render occlusion on hair. So simply having render passes on a scene with shave hair is problematic since it will take a huge hit on render times. So it there a way to exclude the hair from the occlusion calculation in the extra-tex pass?

Hm, while you can exclude objects from occlusion in the V-Ray dirt texture, the shave geometry is created at render time, so there is no way to link it to the dirt texture. You might be able to do this from the post-translate Python callback. However I’m somewhat doubtful that it will speed things up - the hair would be still in the scene, and it will still need to be processed for any rays that pass through it. I’m afraid in that case it would be best to compute the occlusion in a separate render without the hair.

> Last time I checked there was not a way to get the hair into multi-matte because there was no way to assign the shave hair and object ID. Has this changed in 2.0? Would there be a way to set it up with a material ID? That would not work with the native Shave shader, but maybe we could assign a vray hair shader to it?You could be able to do it from said post-translate Python callback - you will need to set the “objectID” of the shave Node object in the V-Ray scene.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![sharktacos](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sharktacos](https://forums.chaos.com/u/sharktacos)\
**Post date:** [October 11, 2011, 7:02am UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/3 "2011-10-11T07:02:53Z")

</div>

> [@On another topic](https://forums.chaos.com/t/36575/16):
>
> Hm, while you can exclude objects from occlusion in the V-Ray dirt texture, the shave geometry is created at render time, so there is no way to link it to the dirt texture. You might be able to do this from the post-translate Python callback. However I’m somewhat doubtful that it will speed things up - the hair would be still in the scene, and it will still need to be processed for any rays that pass through it. I’m afraid in that case it would be best to compute the occlusion in a separate render without the hair.

One solution would be to make a render layer for the occlusion (instead of a render pass), and have everything but the hair in that render layer. The only problem with this is that Shave seems to be automatically included into render layers. I know there was a way to exclude it from a render layer with mental ray. Is there a way to do that with v-ray?

**EDIT:** The above _does_ seem to work with a layer override applied to the shave globals “hide hair” toggle. So that seems like a viable solution. Oddly, the same does not work with the shave “active” toggle in the shave node attributes. This works in Maya Software and Mental Ray, but with Vray it causes Maya to hang.

---

<div class="post-metadata">

**Author:** ![sharktacos](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sharktacos](https://forums.chaos.com/u/sharktacos)\
**Post date:** [October 12, 2011, 6:13pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/4 "2011-10-12T18:13:39Z")

</div>

> [@On another topic](https://forums.chaos.com/t/36575/16):
>
> You could be able to do it from said post-translate Python callback - you will need to set the “objectID” of the shave Node object in the V-Ray scene.

I think I understand what you mean, but being a non-programmer, I can’t imagine what the python code in the post-translate Python callback would need to be to connect the shave hair node object ID to a multi-matte. Do you know off-hand what the code would be, or can you point me to a recipe?

---

<div class="post-metadata">

**Author:** ![thekraken](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@thekraken](https://forums.chaos.com/u/thekraken)\
**Post date:** [March 16, 2012, 3:46pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/5 "2012-03-16T15:46:17Z")

</div>

Hi there,

Sorry for re-opening an old post, and for the following code … just testing things around 😉

According to Vlado’s advices I tried to set up a basic post-translate process to get shave masks, here is the current function :

```auto

import maya.cmds as cmds
import maya.mel	as mel

def postTranslate():
    with open("/tmp/vrpost.log", "w") as f:
        base_id = 1
	nodes = cmds.ls("shaveVrayShader*")
        nodes.sort()
        for n in nodes:
            mel.eval("vrayAddAttr " + n + " vrayColorId")
            mel.eval("vrayAddAttr " + n + " vrayMaterialId")
            cmds.setAttr(n + "." + "vrayMaterialId", base_id)
            col_id = float(base_id) / float(len(nodes))
            cmds.setAttr(n + "." + "vrayColorId", col_id, col_id, col_id, type="double3")
            f.write(n + " -> matte " + str(base_id) + ", color " + str(col_id) + "\n")
            base_id += 1

	base_id = 1
	nodes = cmds.ls("pSolidShape*")
	nodes.sort()
	for n in nodes:
            mel.eval("vrayAddAttr " + n + " vrayObjectID")
            cmds.setAttr(n + ".vrayObjectID", base_id)
            f.write(n + " -> object " + str(base_id) + "\n")
            base_id += 1

	nodes = cmds.ls("shaveHair*")
	nodes.sort()
	for n in nodes:
            mel.eval("vrayAddAttr " + n + " vrayObjectID")
            cmds.setAttr(n + ".vrayObjectID", base_id)
            f.write(n + " -> object " + str(base_id) + "\n")
            base_id += 1

```

With two hairy balls, here’s the resulting debug log, so everything seem workin as intended :

```auto

shaveVrayShader1 -> matte 1, color 0.5
shaveVrayShader2 -> matte 2, color 1.0
pSolidShape1 -> object 1
pSolidShape2 -> object 2
shaveHair1 -> object 1
shaveHair2 -> object 2
shaveHairShape1 -> object 3
shaveHairShape1_growth -> object 4
shaveHairShape2 -> object 5
shaveHairShape2_growth -> object 6

```

We are still stuck, the object, matte and material ids remain desperately black. The only working way (but not production ready) is to assign a standard material to shaveHair\* nodes and uncheck “Override Geom Shader” so we can extract some material masks.

Any tip or trick would be greatly appreciated !

Tonio

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [March 16, 2012, 5:24pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/6 "2012-03-16T17:24:03Z")

</div>

From what I see, in the post-translate function you are changing the Maya scene, which is no use; you should be modifying the V-Ray scene instead. I’m attaching an example here: [Chaos: Industry-leading design and visualization software](http://www.spot3d.com/vray/scenes/shave%5C_matte.zip)

If you export a .vrscene file for the scene, you will see two plugins in it with type “hairVRayShader” - one has name “pSolidShape2@mesh4” and the other - “pSolidShape1@mesh3”; look for the respective “Node” plugins which reference those hair shaders as geometry. In this particular scene, they are “pSolidShape1@node” and “pSolidShape2@node” (you could walk the V-Ray scene to find the Node plugin that corresponds to a particular hairVRayShader plugin). Then you need to set the “objectID” parameter of the respective Node plugins, and voila - you get your mattes.

This is my post-translate callback:```  
from vray.utils import \*

p=findByName(“pSolidShape2@node”)  
p[0].set(“objectID”, 1)

q=findByName(“pSolidShape1@node”)  
q[0].set(“objectID”, 2)

```auto

It might be a bit of a hassle to figure out the correct names though - the nodes just get some default names which are not immediately related to the Shave objects.

Best regards,
Vlado
![multimatte.jpg|640x480](upload://1fzsbmyda7gwGkcEBlMMmOACfRC.jpeg)
![rgba.jpg|640x480](upload://dEHRKBg79IEkh6CtPSXqUT0xApP.jpeg)
```

---

<div class="post-metadata">

**Author:** ![thekraken](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@thekraken](https://forums.chaos.com/u/thekraken)\
**Post date:** [March 16, 2012, 6:38pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/7 "2012-03-16T18:38:39Z")

</div>

Thanks a lot Vlado !

Sorry I didn’t read the documentation before spreading code … basically it works, here is my “pseudo” smart version, should be sufficient for our purpose (only four shave nodes, always on screen) :

```auto

rom vray.utils import findByName
import re

def postTranslate():
    nodes = findByName("pSolidShape*@*")
    nodes.sort()
    for n in nodes:
        if n.has("objectID"):
            match = re.match("pSolidShape([0-9]+)@.*", n.name())
            if match:
                object_id = int(match.groups()[0])
                n.set("objectID", object_id)

```

I’ll study your scene since I only get unmultipled objectid output rather than a clean multimatte result like yours (my matte aov remains black), should be trivial from now.

Thanks again, have a good weekend !

Tonio

 ![Capture d’écran 2012-03-16 à 19.25.54.png](https://europe1.discourse-cdn.com/chaosprd/original/3X/2/3/2386095da9b6f6faa873733b0c68d115d1b6ecaf.png)

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [March 18, 2012, 10:47am UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/8 "2012-03-18T10:47:48Z")

</div>

> [@2012 1.5SP1 version? (32bit)](https://forums.chaos.com/t/2012-1-5sp1-version-32bit/37646/2):
>
> I’ll study your scene since I only get unmultipled objectid output rather than a clean multimatte result like yours (my matte aov remains black), should be trivial from now.

For this you need one (or more) multimatte element with the correct object IDs set for the red/green/blue components, like I have set it up in my scene.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![thekraken](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@thekraken](https://forums.chaos.com/u/thekraken)\
**Post date:** [March 19, 2012, 2:35pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/9 "2012-03-19T14:35:14Z")

</div>

Really nice, it’s now working like a charm.

I tried to find an “artist compliant” workflow, not sure it’s the best way to control things but here’s our method now : assign a material to a shave display group (fortunately it’s the only way to get shave and render layers happy together), set a material id, create a matte RE and set ids accordingly.

The post-translate code will then transfer the material id to the associated shaveHairShader objectid, and we’ve come full cycle :

```auto

from vray.utils import findByName

def postTranslate():
    nodes = findByName("pSolidShape*@node")
    for node in nodes:
        if node.has("material") and node.has("objectID"):
            mat = node.get("material")
            if mat.has("material_id_number"):
                node.set("objectID", int(mat.get("material_id_number")))

```

Thanks again for your kind help Vlado !

Tonio

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [March 19, 2012, 3:02pm UTC](https://forums.chaos.com/t/shave-and-render-passes/38995/10 "2012-03-19T15:02:42Z")

</div>

Glad that you got it working 🙂

Best regards,  
Vlado
