david | mel script,mentalray,rendering | Wednesday, March 4th, 2009

About 6 months ago I wrote about using mib_continue and mip_rayswitch to stop a surface blocking final gather rays. I used this technique regularly yet often wished there was an easier way to do the same thing - and there is!

Alessandro Prodan posted a solution on cgtalk that uses a new attribute called miFinalGatherHide to control whether a surface should block final gather rays.

You need to add the new attribute to the object's shapeNode. For example if we have an object called pTorus1 then we can add a new Boolean attribute by entering the following line in the script editor

addAttr -ln "miFinalGatherHide"  -at bool  pTorusShape1;

If you prefer, you can use the attribute editor to do the same thing.

Either way the result should look like this in the channel box

Being able to selectively hide objects from final gather without using complicated shader networks can really help lighting a scene. Here is a simple example. The scene is illuminated using only final gather. There are no real lights. In the first image notice how the area between the torus and the cube is darkened. Even though I have set my secondary diffuse bounces to 3, not much illumination finds its way in.

In the second image I have added the miFinalGatherHide attribute to the torus and set its value to 1 (on). Since the torus no longer blocks the final gather rays both the torus and the cube get better illumination.

To simplify the task of adding the miFinalGatherHide attribute I wrote a couple of mel scripts.

djFinalGatherHide.mel enables you to select a number of objects or groups and add the attribute to all surfaces found in the hierarchy in one go.

djFinalGatherUnhide.mel sets miFinalGatherHide to 0 (off) for all surfaces in the selected hierarchy .

These scripts are available on my downloads page.


  1. wow cheers been waiting a while for ya next gem.... one more essential to add to the mix :P

    Comment by matt999 — March 4, 2009 @ 3:15 am

  2. awesome

    Comment by David — March 26, 2009 @ 9:23 pm

  3. Hi David,

    Long time reader, second time poster. Excellent read as usual. I'm noticing in your scene that your illumination is slightly purple, a feat that i have been trying to achieve for quite some time using ONLY physical sun and sky. If you are using only sun and sky for the illumination coming in, could you possibly post your settings, or even the scene itself?

    Any help would be greatly appreciated!

    Thanks in advance

    Comment by loganai — April 18, 2009 @ 7:53 am

  4. Hi again,

    Just read the post through... and realized your not using sun and sky. Sorry please ignore my previous post

    Comment by loganai — April 18, 2009 @ 11:32 am

  5. As you noticed, I used only final gather to illuminate this scene. The main illuminators are some poly planes with mia_light_surface as a mi material shader. You can see one of these in the upper right of the picture, the other, bigger one is off camera to the left. Each of these has a mib_blackbody connected to the mia_light_surface color. The mib_blackbody on the right is set to temperature=4000 (more red) and the one on the left to 10000 (more blue). It's the interplay between the two colors creating those purplish hues.

    With the mia_physicalsky you have the "red/blue shift" attribute. Setting this to approx -0.15 will give a similar blue as the mib_blackbody temperature=10000. But this will shift both the sun and the sky color together. If you just want to shift the sun, then you need to make a few modifications in the hypershade window.

    Create a multiplyDivide and set the Input2 values to 0.318, 0.318, 0.318 (or whatever values you have in the physicalSky "RGB Unit Conversion"). Create a mib_blackbody and connect it to Input1 of the multiplyDivide. And connect the multiplyDivide to the physicalSun "RGB Unit Conversion". (This replaces the connection between the sky and the sun.) Now the sun color can be independently controlled by the mib_blackbody temperature.

    mib_blackbody temperature=6500 is neutral, higher is more blue, lower is more red.

    Of course you don't need to limit yourself to the mib_blackbody color range. Instead you could just use a surfaceShader with its outColor connected to the multiplyDivide Input1 and set any color you choose.

    Comment by david — April 19, 2009 @ 11:19 am

  6. Hi David, I've got some problem with your script: I select one or more poly objects, load the scripts, execute but nothing happens. I tried also to save the script to shelf but still not working.
    Adding the attribute via AttributeEditor everything goes fine but I've got some scenes with many objects so i would like to use your simple script. What's wrong?
    Thanks for your contribution to the community.

    Comment by fabergambis — May 1, 2009 @ 1:24 am

  7. fabergambis, I'm not sure why its not working for you. The script is attempting to find the shapeNodes in your selection. I guess it might get confused if you have surfaces parented to other surfaces, or several shapeNodes sharing a common transform. Are you getting an error message?

    Try selecting just the surfaces, instead of the heirarchy and see if that works.

    Comment by david — May 1, 2009 @ 1:54 am

  8. No luck, David. I tried on new scene with a single object but didn't worked for me.
    I select the new created object, execute the script and on the script editor I get a long message that ends with:
    warning("djFinalGatherHide: Selected heirarchy contained no poly, nurb or subDs, so nothing was done.");
    Don't know what to do.

    Comment by fabergambis — May 1, 2009 @ 3:50 am

  9. I'm not sure, but I use the script often so I know it works.
    The way you have written the error message with the () and "" and ; suggests that the script is not actually being executed and failing due to a syntax error, because that message would normally look like this:

    Warning: djFinalGatherHide: Selected heirarchy contained no poly, nurb or subDs, so nothing was done.

    What is the very first line of the long message that you are seeing?

    Comment by david — May 1, 2009 @ 10:19 am

  10. David,

    Wonderful blog!

    I'm wondering if a similar technique was used for these...


    I'm guessing he either used a sphere with a background texture mapped onto it and told it not to block final gather rays from the physical sun or used a camera_map and matte_shadow to comp in the car while still using the physical sun.

    I downloaded your mib_continue demo file but I noticed that the objects don't seem to reflect the background image, just each other.

    Any idea on how this image was achieved?

    Wonderful tutorials!

    Comment by Dangertaz — June 18, 2009 @ 11:59 am

  11. Dangertaz, thanks for the compliment - always appreciated.

    First the mib_continue demo. Reflection of the background is possible. Check out my reply to a similar question in the comments on that post.

    The images in the link that you posted look to me like they may have been illuminated with HDR images for reflections and diffuse lighting (final gather) and physical sun to get the directional illumination and shadowing. Hard to tell for sure, but I don't think there is any final gather from physical sky.

    Possibly something like the method shown here... http://www.hdrlabs.com/sibl/index.html

    Comment by david — June 19, 2009 @ 12:45 am

  12. Ack! I should have read the comments again!

    Thanks for the link!

    Are you a fan of SIBL? Ever try Spatial Image Based Lighting?

    Comment by Dangertaz — June 20, 2009 @ 8:13 am

  13. Ok, so my link was to something called "smart ibl" which confusingly bears the same acronym as Spacial Image Based Lighting.

    I have never used Spacial Image Based Lighting, but it seems like a step up from simple IBL approximations. Is anyone using this in production? I'd love to hear your experiences. Is it difficult to capture the light field data?

    I don't use IBL very often, but it does come in handy when I need a quick lighting setup, since I've collected a whole bunch of HDR light proble and panoramic images. A technique borrowed from the Smart IBL setup involves using a low resolution blurry version of the reflection map as the final gather source. I do use this method from time to time.

    Comment by david — June 21, 2009 @ 1:05 am

  14. Is this possible with fluids? I want to get shadows from fluids in my beauty, but i don't want them to be exposed to fg calculaitons...any ideas?

    Comment by markserena — April 2, 2013 @ 4:35 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