Friday, May 31, 2013

Luminance depth layer with mental ray

This is the first post in quite a long time that's not related to my master's research project (well it is, kinda), but I felt like I had to share this, because it resolves a pretty long standing issue that has bothered me. Hopefully it is of use to a couple other people as well.

First off, credit for this goes to this member of creative cow (all of six years ago): http://forums.creativecow.net/thread/61/857907#857910

Rendering a luminance depth (or z-depth) layer in mental ray so that it respects smooth mesh preview:

There are a number of ways to get a depth pass out of maya that I won't get into. I much prefer to use a separate render layer because it is so fast to (re-)render and you have much more control over the details, than if you use a render pass on a beauty layer. But the problem with using the luminance depth preset on a render layer is that it forces you to use Maya software, which doesn't respect smooth mesh preview, so your depth pass doesn't line up with your other passes (I'm referring to layers and passes interchangeably here). And if you switch to mental ray, the pre-built shader setup doesn't work when you batch render.

So, here is the shading network that will give you the exact same information as the luminance depth preset, but in mental ray.

1) Create each of these nodes and link them as follows:


a) samplerInfo.pointCamera > distanceBetween.point1
b) distanceBetween.distance > setRange.valueX
c) setRange.outValueX > Ramp.vCoord
d) Ramp.outColor > SurfaceShader.outColor

2) It doesn't look like it in the thumbnail, but the ramp should look like this (white on bottom, black on top)


3) And the final things are to change the Max value in the setRange to 1 (I think this might have been missed in the original thread). And change the Old min and Old max to the range you want the transition to be over. Use the distance tool to check the distance you want. You can key this as well, but it might be easier to do that in post, depending on the scene.
Update (28/08/2014): I have noticed that in some instances large world distance values don't work. Instead I have to divide the values by 10 or 100 to get a proper range. I suspect this has something to with camera coordinate space, which is what the samplerInfo is using, but I don't really understand it. Comments are welcome on this point.


4) And the actually real final thing is to put all your geo into a new render layer and give it a material override with this new surface shader.

5) And render.

And this is the difference between maya software and mental ray.


There is still faceting in the mental ray, but in that case you have the control, instead of being limited to maya software render. Let me know in the comments if it works for you, or if I've missed something.

And my render is done, so I'll jump back to maya now.

Later,
Stuart

PS Okay, one last tip I'm experimenting with. nHair doesn't seem to work with this custom surface shader (there might be a way). The hair I want to be in the depth pass is darkish grey, so I've just added a directional light and increased the intensity until the hair renders at about the value I want. Nothing else is affected of course. Not super precise, but better than not including the hair in the depth pass. We'll see how it turns out.

5 comments:

  1. hello,
    I am using this technique in a scene i am working on at the moment. its great thanks. just one little issue.. i am getting banding on the surface shader. do you have any suggestions on how to solve this problem?

    thanks

    ReplyDelete
  2. Hmm, I haven't encountered this issue. Try increasing the dynamic range (make sure it's black to white, not just a few middle values of grey). Also check the bit depth of your image format (try a higher bit depth). Finally, try asking this at simplymaya.com and you might get more info or replies.

    ReplyDelete
  3. ok perfect thanks, il give those suggestions a go

    ReplyDelete
  4. Thanks so much for this Stuart! Worked perfectly for what I needed.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete