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 .


  1. just want to thank you .. its very usefull no know how to use id_inclexcl & id_nonself :)

    i have question regarding miLabel, when i use label pass.. which is the relation between the miLablel number and the RGB output in label pass... i mean what the formula for the miLable->RGB solid.

    thanks again.

    Comment by firas3d — August 24, 2008 @ 6:38 pm

  2. Hi firas3d. I have never rendered a label pass, and I don't know what that formula would be. Can you see any pattern if you render an object where miLabel is animated so it increments by one each frame?
    Try asking at Somebody there should know.

    Comment by david — August 25, 2008 @ 12:14 am

  3. I'm having some trouble getting this working. I know, sounds simple enough, but for some reason setting an miLabel attribute and adjusting the mi_amb_occlusion's Id* attributes has no effect. Would you please post a simple scene file which does this? Thanks!!

    Comment by s4l4x — September 16, 2008 @ 12:44 pm

  4. Make sure you are putting the miLabel attribute on the object's transform node, not the shapeNode.
    Here is a link to an example (made very quickly)


    Comment by david — September 17, 2008 @ 12:04 am

  5. Perfect thanks!!! (I was using a float instead of an integer).

    Comment by s4l4x — September 17, 2008 @ 6:38 am

  6. Man, I was looking for a solution everywhere! It took a while to find it also, and came down to searching for the correct keyword "miLabel". I'd also tried id Inclexcl, Object label id, mib_amb, and god knows what else. The Maya documentation is a little less than clear on the subject of Ambient Occlusion.

    Thanks very much for valuable contribution to teh Internets!

    Comment by Nick — November 17, 2008 @ 2:39 am

  7. How do I get the third picture to render out all of the other objects in the scene. I need a true AO layer is a true matte for one object.
    I can not multiply or mix any of the three images above into a working matted AO pass.

    Can you please help?? I want exactly what I am seeing in your third picture - but with all of the other objects in the scene besides the sphere casting and excepting AO?

    Thanks in advance!

    Comment by patrickkrebs — January 21, 2009 @ 4:18 pm

  8. I don't think you can do what you want with miLabel and a single shader.
    But you could render a 2nd pass with the mask objects white and everything else black and then precomp that over the top of your occlusion render.

    Comment by david — January 21, 2009 @ 11:01 pm

  9. Hey Dave, I was wondering if this miLabel will solve my problem I am having or if there is another way around for what Im trying to accomplish when trying to setup a render layer using mib_fg_occlusion. When rendering out an AO layer my background is plain black. And yes I have changed the color to white, but still comes out black and also all my geometry is fairly grey. I am using an IBL node and cant figure out how I can override that so I can have my BG white. Any suggestions? Thanks

    Comment by smokedogg — December 22, 2009 @ 10:19 am

  10. Ignore that last post. Sorry about that, I just realized for some reason I had my settings all mixed up in my sIBL folder and now I think everything is fine. Thank you

    Comment by smokedogg — December 23, 2009 @ 5:35 pm

  11. smokedogg: I've been so busy finishing up for christmas that I did not get a chance to reply. Glad to hear you worked it out. Cheers.

    Comment by david — December 23, 2009 @ 8:55 pm

  12. Hello!
    Thanks you for this explanation.
    I'm wrote a simple mel script to set up an objects label, feel free to use it
    Thnx to all)!

    Comment by DQvsRA — June 1, 2010 @ 11:41 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