mia_material, transparency and alpha channel tip

david | mentalray,rendering,tutorials | Tuesday, May 22nd, 2007

maya 2008 users: See update at end of this post.

The mia_material makes most of the old maya shaders some what redundant. I'm sure it will take me some time to understand its full potential and some effort to learn how it works. So on my last two projects I forced myself to use mia for everything. That way I knew I would learn more quickly. And I have to say it gave great results. It is now my preferred shader for everything but sub-surface scattering.

Here is a problem I encountered, and the solution I found. It involves transparency and the alpha channel.

Mostly I render passes that are composited in after effects, so if I have transparant surfaces, the transparency must show correctly in the alpha channel.

This wireframe shows a test setup - the orange plane with the lump has a mia_material assigned. The blue spheres are there to demonstrate the shaders transparency.


I mapped a ramp texture to the transparency of the mia_material.shaderDiagram01.jpg

The render looks like this.


And the alpha channel, as you can see, shows the plane as having no transparancy.


I guess that this is technically correct because the mia_material is refracting the black background, but this is not what I need for compositing purposes.

The solution is to add a "helper" plane to the setup as shown in the following diagram.


The plane behind the spheres has a black surface shader assigned to it which has it's matte opacity set to zero. The plane is flagged to be visible in refraction, but has primary visibility and most of its other render stat flags disabled.



Now when I render the mia_material refracts the black plane instead of the background. Since the black plane has a matte opacity of zero it does not contribute to the alpha channel, and the mia_shader respects that in the refraction. Here is the result.


update 01 May 2008: In maya 2008 this trick is no longer required so long as you remember to turn on the mia_material Advanced Refraction Attribute called "Propagate Alpha". This is possibly how it was intended to work in maya 8.5 too - but it didnt...

ambient occlusion with miLabel

david | mentalray,rendering,tutorials | Saturday, May 12th, 2007

default occlusion

It has become fairly standard to create an ambient occlusion pass when rendering, or to include mib_amb_occlusion somewhere in your shader network. The first picture shows a very simple single shader, default ambient occlusion example with the max distance set to the diameter of the small sphere, no lights. The orthographic wireframe view shows the setup.

I often use this setup to render an object on a flat color. It gives me the occlusion of both surfaces - the object and the ground. But what if I dont want the horizon effect in the background? That's where the "miLabel" attribute comes into play.

mib_amb_occlusion_attributes.jpg Here is a snapshot of the mib_amb_occlusion attributes. The two attributes at the bottom - "Id_inclexcl" & "Id_nonself" - can be used to control what surfaces are used when doing the occlusion. To be able to use Id_inclexcl & Id_nonself, your surfaces need to have an extra attribute called "miLabel" added to their transform nodes. The label is simply a number that the shader can use to identify the surfaces.


You can add the miLabel attribute using "Add Attributes..." in the attribute editor, or using a simple mel command. In my example the flattened sphere acting as the background and floor is called nurbsSphere1 so I add an extra attributes using the following mel command:

addAttr -at short -longName miLabel -defaultValue 5 nurbsSphere1;


Preventing Self Occlusion: Set miLabel to something other than zero - in this example I set it to "5". Now if I return to the mib_amb_occlusion attributes and set Id_nonself=5 then objects with miLabel=5 will not occlude themselves.

Inclusive Occlusion: Set Id_nonself back to zero and set Id_inclexcl=5. This means that ONLY surfaces with miLabel=5 are considered in the occlusion. My background occludes its self and the small sphere, but the small sphere (which has no miLabel) does not occlude the background.

Exclusive Occlusion: Leave Id_nonself=0 and set Id_inclexcl= -5. (Note the negative sign.) This means that surfaces with miLabel=5 do NOT contribute to occlusion. So the background does not occlude the small sphere or its self. Only the small sphere contributes to occlusion. It occludes the ground and its self (although in this example, due to its shape, no self occlusion is visible).

With the miLabel, Id_inclexcl and Id_nonself attributes, you can specify exactly which surfaces receive and create occlusion .

bumpCombiner template modification

david | dj mod,mel script,mentalray,rendering | Tuesday, May 8th, 2007

hyperSwatch.jpgWhen I render from Maya I usually use Mentalray. It's a powerful renderer out of the box, but I have become reliant on some custom shaders written by francescaluce for Ctrl-studio. One of them is the bumpCombiner. It's primary function is to enable several bump textures to be combined in vector space. It's like a layered texture for bumps.

Layering bump textures can be done using the in built maya bump nodes by "daisy-chaining" them together. You connect the outNormal of one to the normalCamera of the next, and the last one to the shader's bump slot. But some mentalray shaders don't have a bump slot.

What the bumpCombiner gives you is a way to add bumps to shaders without a bump slot and a much better work flow for managing the bump layers. No more daisy-chains. There is a global bump control and you can modify the relative strengths of each bump layer as well as being able to mask each layer with another texture. You can even disable the bump for FG/GI rays, and for reflect/refract rays.

The shader can be found at highend3d.com or mymentalray.com.

One thing that I always missed was the ability to add a name to the bump layers in the bumpCombiner's attribute editor page. This would sometimes lead to confusion as I tried to remember which parameters were related to which bump node. So today I finally got around to fixing the template to allow a label to be entered for each layer. It's just a simple addition to two text files. You can get them here. Just replace the originals (after making a backup).


using custom mentalray shaders in maya 8.5

david | dj mod,mentalray,rendering,tutorials | Friday, May 4th, 2007

Here are a few tips for anybody using custom mentalray shaders with maya 8.5, especially people who have upgraded from previous versions of maya. If you are like me, you installed the upgrade and jumped right in to see if your favourite custom shaders still worked. You may have had your maya.rayrc file all set up just the way you liked it - I had declarations for over 50 shaders in mine. I keep the custom shader files in a different folder to the ones that came with maya, which made my maya.rayrc even more complicated. Well as of maya 8.5 this all got simpler.

With mentalray for maya 8.5 you nolonger need to customise that maya.rayrc file. You can put your custom shaders anywhere you like, including a shared network folder, so your entire render farm can get the shaders from a single central location. The only thing you need to do is add this line to your Maya.env file (default location is C:\Documents and Settings\david\My Documents\maya\8.5)...

MI_CUSTOM_SHADER_PATH = d:\mentalray\lib;d:\mentalray\include;

Notice how the environment variable is set to two file paths seperated by a semi-colon, which specify the location of the custom dll's AND the mi's. When you open maya you will have access to any shaders that it finds in those folders.

Powered by WordPress | Based on a theme by Roy Tanck