Indirect Illumination with Mental Ray

Global Illumination, Final Gather and Caustics, these are the three individual elements that we commonly use as 3D artists to simulate the effects of bounced and focused light. We will explore each of these in the following sections with theory and practice.

Global Illumination

The underlying principle of Global Illumination is that light, in the real world, can exhibit the ability to reflect off of any surface. The more luminous the surface (the whiter the surface), the more light will be reflected. Since light is reflected off of all materials along the properties of Diffuse-Gloss-Specularity-Reflectivity, we should assume that when multiple objects of a luminance greater than pure black (everything except for black holes) are present in our scene, that light will reflect back into the shadow areas on nearby objects from that surface. This principle is used in Hollywood, in photographers' studios and on television sets by having stagehands hold up brightly coloured reflectors or use bright backdrops when filming with directional light to lessen the shadows on actors or items.

It can also be observed in everyday situations, such as when light enters through a window, hits a wall and reflects off to the ceiling. This is called a diffuse reflection, since the walls have no reflectivity/specularity to them and it is merely their albedo (or overall tonal value) that controls how much light bounces. A white wall will of course bounce more light than a darkly painted wall. You can see in Fig.01 that the colour of the light (in this case orange from the morning sun) will also be transferred.

Fig. 01

Fig. 01

As we set up global illumination, we need to observe how the light bounce will affect the shadow areas. In the simple demo image below, the light rays emitted from our source (spot light) will bounce off of the ground plane and onto the shadow side of ball, thus lightening the shadow as we see in Fig.02.

Fig. 02

Fig. 02

To Render Global Illumination with Mental Ray

First, let's build a simple room to test everything out. Here I have a cube-shaped room with one window. Inside the room I have two big orange and purple - let's call them "abstract minimalist paintings" - propped against the walls. In the centre of the room there is a cube-shaped "table", on top of which there is another "abstract minimalist sculpture" - a sphere. And hey, I've even put a chair in the room to make it interesting. All told, this scene has 1401 quads, so that's a pretty small polygon count. For the purposes of this demo, I will be using Maya 2009 with Mental Ray 3.7, rendering on a Quad Core Intel Xeon 2x3Ghz Mac Pro, running OS 10.5.5 with 4GB of 667 DDR2 RAM. All of my test renders were done at 1280x720, at Production quality Anti-Aliasing Settings. That is mentioned so that you can calibrate your render times to my own.

I have also used the Distance tool to determine that the upper far corner of the room is roughly 24 units away from the lower near corner. Notice how I am measuring my scene diagonally in 3D space (Fig.03). This measurement will be important in future steps (see: Determining Accurate Global Illumination Scale below).

Fig. 03

Fig. 03

Additionally, I have decided to test the scene using Maya's Physical Sun and Sky simulator, which is an easy way to create some realistic direct day lighting effects. Setting this up and altering the values will not really be covered in detail in the course of this tutorial, however. Below you can see an image of where to create this Simulator. What it does is create a directional light in the scene. The angle that you point the directional light colours and changes the intensity of the daylight to mimic the position of the sun. On this light I have enabled Raytrace Shadows, and Raytracing is on in my scene by default (allowing those shadows to be diagnosed) (Fig.04).

Fig. 04

Fig. 04

Created along with the Physical Sun and Sky simulator is a lens shader which gets attached to each of the cameras in your scene automatically. Below are the settings in this Lens Shader that I have altered to set up the scene (red dots indicate values that I have changed). I have changed these exposure settings to be more physically correct to my scene than the default values would otherwise give me (Fig.05).

Fig. 05

Fig. 05

Before I set up any Global Illumination settings, let's see what would happen if I rendered this scene out right now. The scene looks incredibly dark because the only light that we pick up is what is coming from outside of the window (the direct light only), and since there is only that one light in the scene, everything falls in shadow. Well, time to fix this with the Global Illumination (Fig.06 - render time = 0m 05s).

Fig. 06

Fig. 06



So, to set up Global Illumination, open the Render Settings window and enable Global Illumination. Don't alter any settings yet, we will get to that in a bit (Fig.07).

Fig. 07

Fig. 07

Next, select your light and make sure that it emits photons. Again, I have left the default settings for now (Fig.08).

Fig. 08

Fig. 08

When rendered the image looks a whole lot brighter, but four noticeable issues have arisen (Fig.09 - render time = 0m 07s; Fig.10 - render time = 0m 06s, only a photon intensity of 1000 in this image for comparison):

  1. It's still not bright enough for me
  2. The scene looks way too splotchy
  3. I don't have enough colour bounce for my taste yet
  4. The render time went up by 2 seconds

We are going to have to take several steps to make this render look prettier. Let's tackle these 4 questions in order:

  1. It's still not bright enough for me (photon emission)
  2. The scene looks splotchy as all get-out (accurate scale)
  3. I don't have enough colour bounce for my taste yet (final gather)
  4. The render time went up by 2 second (tweaks made at the end)

To make the scene brighter, we have a few tricks up our sleeves. Sure we could just add more lights, or up the direct light intensity, but those are time-consuming solutions that will not be physically accurate. Instead, let's adjust the settings for Photon Emission:

Fig. 09

Fig. 09

Fig. 10

Fig. 10

Photon Emission: Photons are just like colourful super-bouncing balls tumbling from a big bucket at the top of a hill. They carry colour and light as tiny packets riding on a wave of energy. Everywhere they hit, they "bleed off" some of their colour onto where they hit, and then "pick up" some of the colour from that surface, bouncing and ricocheting until they come to a stop. At every hit, the photon is either absorbed based on the diffuseness of the surface, reflected based on the reflectance of the surface (the two combine to describe Albedo), or transmitted as through a transparent object. The bouncing process stops when the number of bounces equals the max photon depth as set in the Render Settings window or based on the exponent settings in the light. This bounce is akin to the end of the road for our super-bouncing balls, where they might gather in a big pile at the bottom of the hill. However, every place those balls (photons) hit as they went down the hill, they illuminated and spread colour, brightening the scene.

The Three values shown (Fig.11), in addition to the Max Photon Depth, give you all the variables you need to start controlling the 'splotchiness'.

Fig. 11

Fig. 11

Photon Intensity - This value is effectively the "elasticity" of the rubber balls (photons) in the analogy. A higher number makes for super-bouncy balls which have a lot of energy, thus will hit a lot of places and make the scene brighter. A low number will yield bowling balls, photons which die very quickly and leave the scene very dark.

Exponent - This is essentially a decay-rate value. Leave at 2.000 to simulate the natural effects of how light decays in a Nitrogen-Oxygen based atmosphere such as our own. In the analogy, changing values for the exponent to a higher number is like dumping the balls into water or maybe even jelly. The extra friction from the medium as opposed to air will slow their speed down.

GI Photons - This is the number of "balls" (photons) being dumped into the scene. The more you have, obviously, the brighter a scene is going to get. I do not suggest changing this value until you are done with the process of tweaking the scene and wish to make it brighter. This keeps the number of variables lower for now, and thus the scene easier to tweak.

Let's up my Photon Intensity from 8,000 to 40,000. And, let's also up the Max Photon Depth from 5 to 10 and render again. This will make the scene even brighter since we are allowing each photon double the amount of bounces, and more initial energy (Fig.12 - render time = 0m 07s).

Fig. 12

Fig. 12

Notice that the scene is now much brighter. If my scene was too bright here, I would turn my Photon Intensity values back down. Notice as well that my render time is still 7 seconds. Also notice how the scene looks like it is missing contact shadows, such as underneath the chair and along the wall. This will be fixed with final gather.

Well, now that the scene is brighter, its looks even more awful/splotchy because of the intensity of these photons doing some serious "disco effects" on the walls. The first way to fight this is to take an inventory of the scene size.

Determining Accurate Global Illumination Scale (Fig.13)
While GI can often be determined using a "guess and check" method, better understanding, the Accuracy and Radius values will allow us to accurately determine the amount of sampling needed to correctly light a scene indirectly. The Accuracy Value sets the maximum number of photon hits allowed in any scene, and while higher values will significantly increase render time, they will create much more accurate renders.

Fig. 13

Fig. 13

The Radius Value is very important. This controls the max. distanced from a photon hit that the energy will be calculated. Leaving this at 0 will allow Mental Ray to calculate what it thinks is the "best" size, but will take longer to compute, and in most cases isn't the best. To determine an accurate number for this radius, I suggest employing the Distance tool under Create > Measure Tools > Distance Tool (Fig.14).

Fig. 14

Fig. 14

The scene size here in my simple scene is 6.77 units. In my demo scene (if you remember from earlier), my scene size is roughly 24 units. What we do is take the scene size value, and use it as our Radius Value.

The Merge Distance is essentially a bubble; any photon inside that bubble gets blended with other photons in that bubble, creating a smoother result. For best results, set this at 01% of the scene size (in other words 01% of your radius value).

So, for my scene, my Radius is 24, my Merge Distance is 0.24. And here's what I get (Fig.15 - render time = 0m 13s).

Fig. 15

Fig. 15

The render time has gone up here (almost double), but the results are much cleaner. However, we still aren't even close yet. GI has done about all we can ask of it. Let's see what adding Final Gather to the mix will do.

Let's enable Final Gather in the Render Settings window (Fig.16).

Fig. 16

Fig. 16

Final Gather

Final gather is method of simulating indirect illumination. When used in combination with global illumination, Final Gather lets you create the most realistic, physically accurate lighting conditions for a scene (using Global Illumination alone can sometimes give splotchy results, as we have seen).

When Final Gather is enabled, every object effectively becomes a source of ray-emitting light, mimicking the natural world in which objects influence the colour of their surroundings. When one light ray strikes an object, a series of secondary rays are diverted at random angles around it to calculate the light energy contribution from the surrounding objects. The light energy is then evaluated during the ray tracing process to add the effect of the bounced light. Unlike Global Illumination, Final Gather does not use photon maps for the calculation of light at a given point in scene. Instead, Mental Ray for Maya samples the surrounding area above every point in the scene. The illumination at those points is then computed as direct illumination. (If Global Illumination is also being used at the same time, Final Gather calculates the total incoming illumination in the scene (called irradiance).)

Final Gather rays are emitted in many directions from a sample point and stop according to the settings in the Final Gather section of the Render Globals Setting window. Because Final Gather rays do not bounce, secondary surfaces are not taken into consideration. (However, when rays hit geometry, material shaders may cast secondary reflection, refraction, or transparency rays, as long as those secondary rays are specular or glossy, not diffuse.)
Final gathering eliminates the low-frequency variation in the global illumination that often results if too few photons are used. (Performance is optimized because Mental Ray for Maya reuses and interpolates nearby final gathers.)

Final Gather and Global Illumination
You can combine Final Gather and Global Illumination techniques to:

a. Achieve realistic lighting and shadows more cost effectively
b. Reduce flicker in animations
c. Effectively illuminate interiors (global Illumination on its own can sometimes render splotchy results)
d. You can reduce the number of Global Illum. Photons, the Global Illum. Energy levels and the number of Final Gather Rays, resulting in less rendering time but more realistic lighting

Hemispherical Sampling
Final Gather works by collecting the photons emitted into a scene and samples them back together with the goal of smoothing the look of many "rubber balls", to extend the metaphor, into a more cohesive, smoothly lit scene. Final Gather samples hemispherical areas, which can be thought of as baskets for these photons to reside in at the end of their emission. Final Gather works best in diffusely lit scenes to collect brightness in dark corners, and while similar to GI (and often used in conjunction with it), FG uses its hemispherical sampling form of raytracing to collect and smooth the bounces which are already calculated by the GI.

Final Gather Settings: Final Gather settings should be tweaked in the order shown in Fig.17. These are listed in order of importance.

Fig. 17

Fig. 17

1. Final Gather Accuracy. This value sets the number of rays fired from each primary ray. The default value is 100. 200 usually work for test renders. Go up to 500-1,000 at most for final renders.
2. Primary and Secondary Diffuse Scale. Can be used to multiply all computed FG values, and can be tinted any colour.
3. Max Radius (Fig.18). This value controls the size of the hemispherical sampling area. This number should be no larger than 1000% of the size (width) of the scene. This can be determined in the same way that was discussed a few paragraphs above. While I normally start at 1000% of the scene size; you can certainly experiment with other lower values such as 100%, or maybe even as low as 10% if you don't want as much colour bounce.

Fig. 18

Fig. 18

4. Min Radius. This value controls the minimum size of the hemispherical sampling area. Usually 100% of the Max radius value is best, but you can go down to 10 or even 1% for less colour bounce. If both Max and Min are left at 0, which can be done by leaving off the "Use Radius Quality Control" checkbox, Mental Ray will try to determine the "best" values for the scene. This may take longer to render.With settings 1-4 in place, here's how my render now looks. It's pretty good, right? Splotchiness is gone; great colour bounces off that orange thingy; nice soft shadows where objects contact one-another. It's perhaps still a little too dull for me, though. Notice as well that our render time has now had a whole minute tacked on to it (Fig.19 - render time = 1m 11s). Yikes!

Fig. 19

Fig. 19

5. Direct Illumination Shadow Effects (Fig.20). Does not change speed of render, should always be set to on. If off, will not be able to compute coloured or semi-transparent shadows well.

Fig. 20

Fig. 20

6. Filter (Fig.21). Softens the render and reduces artefacts. Set to 0 by default. Values between 1 and 4 will soften the render.

Fig. 21

Fig. 21

7. Falloff Start. This one is similar to the Min Radius (above). Here, values of around 10% of the scene work to show where you start ignoring elements around the current texel being illuminated, and start sampling the environment colour. Lower values often make for a brighter scene, since your environment (outside) is normally brighter than inside.

8. Falloff Stop. This one is similar to the Max Radius (above). Here, values of around 100% of the scene work to show where you ignoring all elements around the current texel being illuminated, and just sample the environment colour. Lower values often make for a brighter scene, since your environment (outside) is normally brighter than inside.If your Falloff Stop is a smaller number than your scene size, you start letting outside light pour in. Here I have set my Falloff Start and Stop to Values that are too low (Fig.22 - render time = 1m 11s).

Fig. 22

Fig. 22

Here I have turned them back down to the settings shown above (the proper settings) (Fig.23 - render time = 1m 11s).

Fig. 23

Fig. 23

For all intents and purposes, we can now call this scene done. But let's look at some ways to push it even further!

The Mental Ray Portal Light
This is highly suggested in your workflow. The problem is, by default we aren't using all of our Final Gather Rays. Some of these rays aren't getting into the room, but they are being calculated anyway. New since Maya 2008 is the Portal Light. Essentially an Area Light with a special Mental Ray shader mapped through it, this light, placed over the opening of the window, can dramatically aid the scene.

Mental Ray Portal Light (new to Maya 2008):

"A classic problem in computer graphics is lighting a scene solely through indirect light, like from a sky, or other "environment" light from an acquired HDRI or similar. This is accomplished in mental ray using Final Gathering (henceforth abbreviated as FG), and is done by tracing a large number of "FG rays" to see which hit the environment (or other lit surfaces). Since this is a large number of rays, the results are cached (for performance) at FG points and the result is interpolated, "smoothing" the result. To solve all these issues the concept of a portal light is introduced. The portal light is a (rectangular) area light which is placed in the window, which obtains it's proper intensity and color from the sky outside the window (i.e. an environment shader, like mia_physicalsky or similar) and how much of that sky that is "seen".

Practically, this makes the portal light behave as a "FG concentrator" so instead of having to send thousands of FG rays around the scene to "find" the window, the portal light actually blocks FG rays, and instead converts light from beyond the window to direct light, with high-quality area shadows with no interpolation related issues possible.

FG will now see a well lit room rather than a black room, and can be performed at much lower FG ray counts. Furthermore, since the light from the window is now direct, we gain one extra light bounce "for free"."

"The mia_portal_light shader should be applied both as light- and photon emitter shader on a rectangular area light. The mental ray light instance must be set to be visible (this is a technical requirement for the portal light to be able to "block" final gather rays. If the light actually is visible or not in the rendering is instead handled by the shader).
Furthermore, the mental ray light instance must be set up such that the rectangular area light is extended in the X/Y plane of the lights own coordinate space, and any transformation of the light must be handled with the light instance's transform"
-- From the Maya Help Documentation

Make sure that the Light Portal is connected to the Area Light as both a Photon Emitter and a Light Shader (Fig.24). Also, under the Area Light's "Mental Ray-Area Light" rollout, make sure that Visible is checked; otherwise the effects will not be calculated.

Fig. 24

Fig. 24

You can even use the light portal to make the scene brighter using the Intensity Multiplier feature. Or you can deepen the shadows by turning on both Shadows and Emit Direct Photons (Fig.25).

Fig. 25

Fig. 25

Remember, with Final Gather, changing any of the following settings can have a dramatic effect on the render:

  1. The camera background colour
  2. The object's materials coloured Incandescence or Ambient colour attributes
  3. Irradiance contributions from shaders
  4. Irradiance colour mapping contributions from shaders
  5. The number and location of lights in the scene

Self Illumination
If Final Gather is turned on in a scene, an object may illuminate the scene (without even any lights present) as long as it has values set for it's Ambient Colour, Incandescence, or Irradiance that are higher than black (0).

Ambient Colour and Incandescence
I have now decided to turn the sphere on the table into a globe-lamp. Instead of making a volume light, I can simply adjust the Ambient Colour and Incandescence values (Fig.26).

Fig. 26

Fig. 26

Ambient Colour Channels, as well as Incandescence Channels, are present on all Maya materials. Ambient Colour serves to often brighten or soften the look of a material, complementing diffuse values. Incandesce is often used to make an object look like it is the source of light. If Mental Ray is used, all standard Maya materials also have Irradiance attributes which can be upped or mapped to multiply the already existing irradiant light. Also, if your saturation values for ambient colour and incandescence can go beyond 1, you can cause a more "powerful" light source from your material. Here, while the Incandescence looks to be red, I have set its value to that of 3, making it extra bright.

Here we see a self-illuminated object added to the scene (Fig.27). Notice how it lights the surrounding parts of the room too. There are no extra lights in this scene, other than the physical sun and sky, and the light portal.

Fig. 27

Fig. 27

When testing certain settings, it can be helpful to freeze your Final Gather and Global Illumination Maps from rebuilding each time. This can save dramatic amounts of render time. However, here are some warnings when doing this, as follows:

For Global Illumination (Fig.28):
The Photon Map Rebuild (on/off) option for Global Illumination defines if a photon map should be regenerated for your new render or if a new photon map should be created. When you render a scene for the first time, photons are generated. For later renders, you can turn this off and continue tweaking the camera, direct light intensity, light colour, and the GI radius, accuracy and scale settings without having to make a new map. However, changing texture or material values, camera position or object position, or any photon settings will have peculiar (incorrect) results. (See the following renders for examples.)

Fig. 28

Fig. 28

For Final Gather (Fig.29):
If rebuild is switched from on to Freeze, then new data will not be written in the FG file. Can be used to reduce light flicker in an animation, and VERY useful when not changing any of the FG settings and you are trying to tweak a still image.

Fig. 29

Fig. 29

In the following two images, both of the GI and FG Rebuild features have been turned off, forcing Mental Ray to re-use existing maps. Notice that when I move objects or the camera, things don't quite look right. However, in both renders, the render time was an amazingly fast 8 Seconds! This is because I am not rebuilding anything at all, and thus the render takes just as long as if FG and GI were turned off (Fig.30 - 31).

Fig. 30

Fig. 30

Fig. 31

Fig. 31

Rendering Caustic Effects: Caustics are light patterns that are created when light from a light source illuminates a diffuse surface via one or more specular reflections or transmissions. Examples are the light patterns found on the bottom of a swimming pool as light is refracted by the water surface; light being focused by the refractive value of glass onto a diffuse table; light emanating from the headlights of a car as light is refracted from the bulb off the back parabolic mirror; light being refracted inward by gold, a precious metal. Notice the common theme here. Refraction is the key to seeing caustic effects. In the following image, the red dots show several occurrences of caustic light (Fig.32).

Fig. 32

Fig. 32

To Enable Caustics, let's go into the Render Settings window and turn on Caustics (Fig.33).

Fig. 33

Fig. 33

We are also going to need to tweak our settings. Usually, I will make my Caustics Radius the same value as my GI radius (Fig.34).

Fig. 34

Fig. 34

Next we are going to need to make a refractive/transparent material to let light through. It's not enough to just set up refractivity. If you are using a Maya Material (Blinn, Anisotropic, Phong, etc.), you will need to add a photon shader to your material so that it can focus the photons into a caustic highlight. If you are using a Mental Ray material (DGS, Dialectric, MIA), these already have built in photon shaders so you won't have to do any extra work. Here is a look at the differences between the Shading Groups for a Maya Blinn, and a Mental Ray MIA material (Fig.35).

Fig. 35

Fig. 35

If you are using a Maya material, you can input the photon shader like this (Fig.36). And Render!

Fig. 36

Fig. 36

Notice how we now have a beautiful green tinted highlight in the middle of the shadow for the green crystal ball (Fig.37).

Fig. 37

Fig. 37

That's it for Caustics, and for this tutorial. I hope you were able to find it useful. Now get out there and render something pretty!

Fetching comments...

Post a comment