djx blog » ambient occlusion with miLabel


: 2

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 .