mib_continue and mip_rayswitch

david | mentalray,rendering,tutorials | Thursday, September 11th, 2008

I read a thread on cgTalk, which was started by Filip Orrby, in which he asked "How to make object not block FG rays?". He went on to answer his own question and since it is similar to a technique I use, I decided to elaborate.

I'm going to write about a shader and lighting setup I use a fair bit for product shots, where the background is very simple, often white and the product is to be brightly lit. For my final renders I usually break things into render layers, but I like to be able to quickly render everything in one pass to evaluate my animation and to show my progress to the client.

Here is a typical example of the end result.

mib_continue_YES.jpg

To see a step-by-step breakdown of the setup, click here

My lighting is physical sun/sky using final gather. My background is a simple fileTexture of a cloudy sky above a white ground which I have mapped onto a flattened sphere. You can download my scene file here.

Here is a snapshot of the wireframe.

wireframe.jpg

and this is a small version of the sky map

sky_spherical_small.jpg

The problem is that the flattened sphere blocks the final-gather rays from the physical sky. I could just live with it and use the sphere surface with its file texture as a final-gather radiator. And I would get somthing like this

mib_continue_NO.jpg

As you can see the result is still good and is not drastically different to the first image. But my background image is mostly white with a bit of blue and this drives the look of the FG giving it a neutral feel. Compare this with the first image where, due to the low angle of the sun, there is a noticeable warm look to the FG.

So, how do we stop the sphere blocking the FG? The answer is, by using mib_continue and mip_rayswitch.

mip_rayswitch enables different shaders to be used depending on the type of ray that is being calculated. Have a look at the attributes here to see the different type of rays that can be singled out.

attributes_mip_rayswitch.jpg

I'll just mention two of them in this example. The eye rays are the ones you actually see in the rendered image, so that is where I connect the shader that I want for my background color. The finalgather rays are obviously used in the FG calculations and it is here I connect the mib_continue shader.

mib_continue is a shader that takes any incomming ray and simply lets it continue on through the surface as if the surface was not even there. So in my example it lets the FG rays from the physical sky continue through the flattened sphere. In this case I'm just using the mib_continue with it's default attributes.

So that is the basis of my setup, but to make it work there are a few more things to consider.

Firstly, I am using mia_exposure_photographic tone mapper as a lens shader with gamma=2.2 for a linear workflow. This means I need to increase the brightness of my background texture map to boost it into the same dynamic range as the physical sky. If I dont, then the background will be black! And I need to de-gamma the fileTexture since the gamma will be added by the tone mapper.

Secondly, I am using the mip_matteshadow shader with my own spin on it for coloring the flattened sphere. I'll do my best to explain: mip_matteshadow is a more powerful version of maya's native useBackground shader. It is normally used to catch shadows, occlusion, reflections and indirect lighting for compositing later and supports multiple outputs. But I am using it as a way of doing that compositing within the render. Reason 1: it makes it easy to get shadows on a surface that is not otherwise illuminated by any lights. Reason 2: it makes it easy to get reflections on very light colored (or white) surfaces, because it can do subtractive reflections. (I didnt use reflections in my example though.) Reason 3: When I get to my final renders phase, I can easily break out the components I need into different renderlayers without having to change too many things.

Thirdly, I am using mib_amb_occlusion instead of using mip_matteshadow's occlusion feature. The reason is that I often add nurbs-planes to act as final-gather casters, much like you would use diffuse lights or reflector cards in a real photo shoot. These planes will have primary visibility off, but I do not what them to  occlude the ground in any way. mib_amb_occlusion has an idNonself attribute that can be used to prevent objects from being considered for ambient occlusion.

attributes_mib_amb_occlusion.jpg

Notice how I have set idNonself=5 . If I add an extra attribute called miLabel to an object's transform node and set its value to the same number, in this case 5, then it will be ignored by the ambient occlusion. Here is how it looks on the bgndSphere transform node

attributes_bgndSphereTransform.jpg

So now, to bring all this together, I just need to show you the hypershader network (click image for a larger version that you can actually read).

hypershade_network_small.jpg

I'll explain the connections from left to right.

The fileTexture connects to the gammaCorrect node with a value of 0.455 (1/2.2)

attributes_gamma.jpg

mib_amb_occlusion is combined with the background color using a mib_color_mix node, where the occlusion layer is multiplied over the background color.

attributes_mib_color_mix.jpg

The combined result is then multiplied by 20000 to bring it into roughly the same dynamic range as the physical sky and counter the effect of the exposure node lens shader. This number, 20000,  was determined through trial-and-error (but after doing this for I while, I've got fairly good at guessing).

attributes_mult.jpg

The very bright background color is then connected to the eye ray of the mip_rayswitch where it is combined with finalgather ray from the mib_continue node (shown earlier).

The output of mip_rayswitch is fed into the mip_matteshadow background color. And mip_matteshadow is connected to the SG node as the miMaterialShader. (The lambert shown has no effect on the render, but is useful for being able to select assigned objects from the hypershade rmb-menu)

Have a look at the mip_matteshadow attributes

attributes_mip_matteshadow.jpg

It is not obvious but the Ambient color is set to 20000, 20000, 20000 (just like the multiply value I used before). This setting is required so that the Shadows color will work properly.

Ok. Thats it. Longer than I expected.

I use this set up quite a bit so some of it's wierdness has disappeared and it feels quite comfortable. It doesnt replace the use of render layers and good compositing, but it is great for those early work-in-progress renders. Hopefully you saw some ideas here that you could use in your own work.

mib_continue_YES.jpg

Download example maya2008 scene including fileTexture.

4 Comments »

  1. Great post, David. A lot new techniques to me and I love the detailed explanation of the shading network.

    Comment by jasonhuang1115 — September 16, 2008 @ 12:38 pm

  2. Your setup is pretty cool but you can't get the reflection from the backgroung.
    I just tested you scene by replacind the sky by an hdri, changed materials to chrome, and this didn't worked.
    Any idea?

    great tut between !

    Comment by David — February 2, 2009 @ 1:51 am

  3. Actually, I can get the reflection from the background.
    Just connect bgndColorMult.output to mip_rayswitch1.reflection.

    If you wanted to you could even connect a different texture here (say a blurred one or something completely different - its up to you)

    If you also want the bgnd to catch the object reflections then you need to check catchReflections in mip_matteshadow.

    Comment by david — February 2, 2009 @ 11:07 pm

  4. thx a million
    It worked !

    Comment by David — February 8, 2009 @ 3:01 am

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