layering shaders with mentalray

david | mentalray, rendering, tutorials | Friday, February 1st, 2008

This is a mini tutorial where I will show one method of layering shaders using mentalray for maya 2008. To make it slightly more interesting one of the shaders will be the misss_fast_simple.

Maya comes with its own layered shader node and you can hook it up with mentalray shaders, but it doesnt always work, and I'm not a big fan of the interface so I dont use it. For several years I have been using the mix8layers shader (from ctrl.studio). It is a reliable shader and texture layering node with lots of features. But today my layering example will use a phenomenon I created called dj_mix_colors which is built upon the mib_color_mix node.

I am going to layer a rusty metalic looking blinn over misss_fast_simple to get the result you can see in this picture.

layeringShadersInMR_DJ001.jpg

I created a sphere on a plane with a couple of area lights as shown in the next picture

perspView.jpg

Then I created a blinn shader with its color coming from a crater texture and bump from a noise texture.

Next I created a misss_fast_simple. When you do this in maya 2008 a few extra nodes are automatically created at the same time. The extra nodes are a lightmap node and a mentalrayTexture and they are used to generate and store the sub surface scattering calculations. The important thing to realize is that the misss_fast_lmap_maya node (the light map) connects to the shading group node rather than to the material node. This connection to the shading group node must be taken into consideration when I do the shader layering.

Before getting into any layering I simply assigned the blinn to my sphere and adjusted the material attributes to make the rusty metalic appearance. Then I assigned the misss_fast_skin and adjusted the lighting to show off the subsurface scattering.

Next I created a dj_mix_colors node. This node can either be used as a texture or as a material in mentalray shader networks. For reasons which I will not explain here, if you are trying this example, you may not be able to assign dj_mix_colors to a surface using the hypershade Assign Material To Selection menu. However it can be easily done by assigning another shader (say a lambert) to create a shading group node, and then you can drag-and-drop the dj_mix_colors into the mentalray Material Shader slot in the shading group node. The lambert will be ignored (and can be deleted).

In this example I just reused the shading group node that was created along with the misss_fast_simple material. I connected my dj_mix_colors node so that it replaced the misss_fast_simple material. This saved me creating that temporary lambert material, but much more importantly it means the lightmap connection is already set up.

So here is what the shading group attribute editor looks like now (I have renamed it to be more meaningful)

layeringShadersSG_attr.jpg

dj_mix_colors can mix upto 8 different inputs in a variety of ways. In this case I started by setting color0 to black. I then enabled 2 additional colors and set the mode for each of these to add. I dragged the blinn to color1 and dragged the misss_fast_simple to color2.

If I do a render now then both materials are added together. In dj_mix_colors weight1 and weight2 controls the relative strength of the 2 layers. But I want to use a mask to cut out one material, and in this example I am using a simple checker texture with the repeatU set to 0.5 so I get horizontal stripes.

First I connect the checker to the dj_mix_colors weight2. Now the misss_fast_simple will only effect the areas defined by the white parts of the checker. I need to also connect to weight1 but this needs to go via a reverse node so that the blinn will be seen only in the areas where the checker is black.

The dj_mix_colors attribute editor looks like this

dj_mix_colors_attr.jpg

Rending now shows that the materials colors are masked correctly, but the bump continues to cover the sphere. This is due to the way maya handles bump maps. Even though the bump node is connected to the material, that is not how the renderer sees it. To correct the bump I just have to connect the reversed checker to the alphaGain of the noise texture to cancel out the noise.

Thats it!

Here is a snapshot of the hypershade network with the connections highlighted. Click the image for the full sized image

layersHyperGraphSmall.jpg

And here is the render again

layeringShadersInMR_DJ001.jpg

You can download my scene file here.

To use this example you will also need to get dj_mix_colors but the technique could also be used with the standard mib_color_mix.

6 Comments »

  1. David,

    Thanks for all your hard work writing code, tutorials and sharing them for free!

    I tried to use dj_mix_colors for blending displacement maps in Maya 2008 and had some unexpected results. The renders worked fine if I rendered as current frame but batch renders didn't work. They came up blank. The displacement maps were driven by blendshapes. I had to resort to using the original mr mix color utility. Have you experienced anything like this?

    Thanks again!
    MrT

    Comment by MrT — May 14, 2008 @ 11:26 am

  2. When you say "current frame", do you mean in the renderview window? Or do you mean the first frame of the batch render? I've head of people having problems with batching animation driven shaders, but never had those problems myself, and often wondered if thats becauise my render farm manager always does one frame at a time.

    I havent used dj_mix_color as an input to displacements before though. I'll give it a try. (I've used it extensively in just about everything else, without a problem). Maybe its a phenomenon/displacement limitation.

    Thanks for the comment.

    Comment by david — May 14, 2008 @ 11:42 pm

  3. MrT,
    I did some testing with dj_mix_colors blending displacement maps. The mix weight was animated using a set-driven-key, where the driver was the output of a blendshape slider that was animated. I used ctrl_multid_single (from ctrl.studio) as the mentalray displacement shader (so not using the maya displacement slot). I'm using a subdivision approximation on my polySphere (no displacement approximation).
    I found that the set-driven-key is ignored in the batch render (I think this is a known limitation), but the displacement works as expected - but no animated blend. The animated blend of the displacement works correctly if it is keyed directly, rather than via set-driven-key.

    So dj_mix_colors seems to be ok with displacements (at least in this simple test).

    Comment by david — May 16, 2008 @ 1:13 am

  4. Hi,
    Is there a way to use mia_material_x with the dj_color_mix. I want to use some bump on the mia_material_x.
    I tried to the best of my ability, but I couldn't figure it out. Sorry. I'm new to maya.
    Any help will be much appreciated.

    Thanks

    Comment by poorawaste — June 28, 2009 @ 10:01 pm

  5. mia_material_x can be layered like other shaders, but unfortunately the connection will not get made via drag-and-drop. You have to use the connection editor, and hook up mia_material_x.result to the color slot of the dj_mix_color (or mib_color_mix, or what ever layer method you choose).

    mia_material_x has a bump slot (actually 2) so you do not need any layering if all you want to do is add a bump. If you want to layer AND have a bump just on one of the layers, then you need to mask the bump map correctly (as shown in the example in this post). If you don't mask it, the renderer will ignore the layers when it computes the bump and render it in all layers.

    If you are new to maya and learning how to construct shader networks, then make some time to get familiar with the connection editor. Once you get the hang of it you will find it a very powerful tool.

    Comment by david — June 29, 2009 @ 11:01 pm

  6. hi david
    thank you for your help. i really appreciate it. Your tip worked. i was trying to blend two mia_material_x materials. i am fairly new to maya and I can do some very basic connection editor stuff. But i cannot do advanced stuff with it. Your advice makes absolute sense. i can see how it can be a very powerful tool.

    thanks again

    Comment by poorawaste — June 30, 2009 @ 5:14 pm

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress | Based on a theme by Roy Tanck