Caustics in MentalRay for Maya

INTRODUCTION

Before we start with tutorial please download the scenes that we will use in our training.

DOWNLOAD THE SCENES

So we meet again (for those who passed through my GI tutorial ;) ). This time we will learn how to set the caustic effect in mentalray for maya. As you already know, the calculation of caustics is not integrated in maya default renderer, and since we have lot's bottles and liquids in our scene, we just need those little bright areas called caustics. ;)

So, let's go to work. For those of you who have not used mentalray for maya yet, please go to the alias wavefront web site and dl it. It is free. If you want to know how to install it, there is explanation in my first tutorial ... link!

In this tutorial we will explore the mentalray's world of caustics. For our test scenes we will use three type of scene. The first one will be well known caustics example ... glass with water in it. The second one is caustics produced by the sea surface and the third one is just a few simple objects with reflective surfaces. Since caustics take some time to render, except maya and mentalray you will need lot's of patience when going trough this tuto. I'm joking, it render very fast. ;)Yes, you can also fake the caustics and achieve faster renders times, but you will not get the real caustic effect, and it can be a little problematic when it comes to moving lights or objects that produces caustic effect in the scene.

Let's take a look at a few real time examples and say a few words about him. This was shoot with my new digital camera... yuppi! ;)

Real world examples:

 

Caustics are marked with red lines on both pictures. In our first example of this tutorial we will try to make the caustics similar to the one in first picture. These two examples show two different kind of caustic effect. On the first pic the caustic are produced by refraction of the glass and the water inside, and on the second one by the reflection of the cd. When the light ray passes trough the glass and the water it changes the direction, this is called refraction. Because of cylindrical shape of glass, the light rays are refracted in that way that they become accumulated together when they exit the glass, and after they hit the desk, the part of it gets brightly illuminated... that is called the caustics. On the second example, the reflection of the CD object is guilty for the caustic effect on the paper below it. In this example the light rays are reflected from the CD, and after they hit the paper it gives it an additional illumination, that's why the part of paper surface is brighter than other parts.

 

EXAMPLE 1 - Glass with water

Unzip the scenes from the zip file and load the scene01a.mb. When you open it, you'll see that there are few simple objects in the scene... the wall, the floor, and glass with water in it. There are also few shaders. The ones we are interested in are the Water1 and Glass1. If you go to the attribute editor of the first shader you'll see that it is highly transparent and that diffuse value is set to 0. This is because the glass or the water does not produce diffuse reflection of the light rays. So, if you create glass be sure to set the diffuse to 0 and increase transparency values. If you open raytrace option section of the Water1 shader you'll see that it has refractive index of 1.33, and the Glass1 shader has refractiov value set to 1.5. These are the values these materials have in real world, so if you create the glass be sure to set the refraction to 1.5, since it's default value it 1. Same goes to the water shaders, just set the refraction to 1.33. If you want to create crystal or diamond shaders you will have to use higher refraction values ... just the refraction values table on the internet.

As you already know, we will use the mentalray renderer to render caustics. To use it go to the Render menu> Render Using > mental ray. Now open the render window from Window> Rendering Editors > Render View. You can also set the mentalray as your renderer from RenderView ... click in the Render View toolbar where it says Maya Software and select mentalray. If you do a simple test render of the scen you just loaded it will look like this:

Oh my god, what is this? You won't believe it but this is the glass with water in it, and it doesn't have raytracing turned on. How to do this? As usually, in Render View go to the Options > Render Global's (mental ray). When mentalrayGlobals window pop up, go to the Quality section and press the box on the right side of RenderQuality option. The mentalrayOptions1 will open. As you see the raytracing on the top is turned on. Try to render the scene again. This is what you'll get.

Why this? Because when the ray hit the glass, with these options ray is only refracted once and it needs to be refracted at least 6 times (glass, glass, water, water, glass, glass). That's why we must increase the refracted ray depth to get the desirable effect. To do this go to the mentalrayOptions1 and in Rendering section set the Max Refraction rays and Max Ray Depth to 6. Render again and you'll get this:

That looks nice. The next thing to do is to turn on the shadows on. So select the spotlight and go to it's attribute editor (Ctrl+A). Open the Shadows section. On the top of the Shadow section is the Depth Map Shadows section. We will not use this type of shadows since it is faked shadow and can not be used in situations where the transparent surface need to cast shadow on the other objects. That's why you must open the section below, the Raytrace Shadow Attributes, and turn on the Use Ray Trace Shadows option. Render again and this happens:

Ok, we have the refraction and shadow, now we need to get the caustic in the scene. To produce caustic effect, you must set the light as photon emitter and set the caustics on in mentalray rendering options. So select the light, go to the attribute editor (Ctrl+A) and go to the mentalray > caustics and global illumination section. Set on the Emit Photons option. The Energy and Exponent becomes available to adjust, but for now leave it as it is. We will use it later to increase od decrease the intensity of caustics. Now go to the RenderGlobals (mentalray) > mentalrayOptions1 > Caustics/Global Illumination and turn on Caustics option. If you render the scene at this moment you'll get caustics effect in your picture, similar to this one:

As you see, there are some caustics on the floor in the shadow area, but there is something wrong. What? If you look at the picture from beginning, from real situation, you'll see that we are missing the area pointed in the that pic. The problem in our renderer is similar to the one we met few moments ago when we turned on the refraction. Remember the ray depth? ;) To solve this, in the mentalrayOptions1 at the Caustics/Global Illumination section set the Max Refraction Photons and Max Photons Depth to 6. Render again:

Here it comes. :) But to intense. To decrease the intensity of it, go to the attribute section of the our spotlight, and go to the Caustics and Global Illumination section. If you remember, I mentioned before that we will use the Energy and Exponent value to decrease the intensity od caustics. We will make few pictures to show you what's happening when we change these two values:


Energy 500
Exponent 2


Energy 1500
Exponent 2

Energy 3000
Exponent 2

Energy 8000 (Default)
Exponent 2

Energy 8000
Exponent 2 (Default)

Energy 8000
Exponent 2.5

Energy 8000
Exponent 3

Energy 8000
Exponent 3.5

We can get similar effect when we increase the exponent or energy value. In my opinion the value somewhere between energy 1500 and 3000 will be the most appropriate. So set the Energy value to 2300 and leave exponent to it's default value (2) and do another test render.

The quality of the caustics are controlled by the few options in light attribute editor and in the mentalray render globals options. To set the number of caustic photons emitted from the light source, select the light and go to it's attribute editor. Then jump to mentalray > Caustic and Global Illumination section. Let's make a few examples with different kind of Caustic Photons:


Caustic Photons 3 000


Caustic Photons 10 000 (Default)

Caustic Photons 30 000

Caustic Photons 80 000

The first picture renders very fast but it doesn't have the quality that we want. The second one is much better that the first, and it can be used for the final render. The third and last one produced the best caustic effect but with increased render times. Let's make a little interpolation between the second and third picture, and set the photons to 20 000. This will be our final setup for this situation. There would be situations, like rendering the caustics from sea surface, when you'll need to increase the caustic photons to higher values to get desirable result.

There are still few options that we are interested in, when it comes to quality of caustics. You'll find it in RenderGlobals (mentalray) > mentalrayOptions1 > Caustics/Global Illumination section. With Caustic Radius you can control how big are the area that photons are collected from, and with Caustic Accuracy you can control how much photons are collected together when calculating caustics at point x of the scene. You will leave these two to their default values. Don't worry about 0 value at Caustic Radius option ... if it is set to 0, the renderer set the appropriate value of this option, and it does this very good in many situations. As for the other option, the accuracy, well you should probably leave it as it is, but if you increase the caustic photons to very high values you should also increase this option to higher value. Also, if you change the Caustic Filter Type from Box to Cone, it will produce a little bit sharper caustics effect.

So this is it... the end of our first session... let's get in to the sea :)

 

EXAMPLES 2 and 3 - Mirrors and Water caustics

Welcome to the second part of my caustic tutorial. Since you already learned how to setup the caustic in tutorial above, we will just make a few quick examples in this section. The first one is the caustics produced by the water surface and the second one will be caustics from reflective surfaces as mirrors or metal surfaces.

Load the second scene from the zip file, the scene02a.mb. The scene has two object, the transparent water surface and the floor which will receive the caustics. There is also one directional light that will be used to produce caustic. Material of the water surface has the idex of refraction set to 1.33 so that it refract the light rays when they hit the water surface. To see the effect of caustics I added some bump on it ... remember that this must be set if you want the caustic effect to apear like on the bottom od the sea. So let's start...

If you render the scene at this moment it will look like this.

As ordinary it does'nt have raytracing and caustics turned on . So let's turn both of these on. First select the light and jump to it's attribute editor (Ctrl+A). Then go to the Shadow > Raytrace Shadow Attriubtes and set the Use Ray Trace Shadow on. Since we need to set the light as photon emiter, go to the mentalray > Caustic and Global Illumination section and turn on Emit Photons. If you render the scene at this moment you'll get the same picture as one above. To correct this we have to turn on the raytracing and set the caustics on. Open the Render View > Options > RenderGlobals (mentalray) > Quality > press the box on the right of RenderQuality > when mentalrayOptions1 window opens, go to the Caustics/Global Illumination section and set the Caustics to on. Render again...

Why is the surface so white? Because of to bright caustics effect. To decrease the intensity of the caustics select the light and jump to it's attribute editor (Ctrl+A) then go to the mentalray > caustics and global illumination section. As you already know from the first part of tutorial, we can control the intensity with the exponent and energy values. This time we will experiment with both parameters. For this situation I'v set the energy value to 2000 and exponent value to 3.6. Let's make one quick test render:

Ok, now that we have satisfying intensity level of caustics we will continue to fine tune it to get the better quality of it. The next value with which we will play a little bit is Caustics Photons. I suppose you already know where is it. ;) Since the surface on which the photons are casted is pretty big, we must increase this value to very high levels. So let's make a few example images with different caustics photons values...


Caustic Photons 10 000 (Default)


Caustic Photons 30 000

Caustic Photons 60 000

Caustic Photons 100 000

It easier to decide which fits our need when we have few pictures like the ones above. The rendering of all four pictures is relatively fast so we dont have to worry about that. As for the quality, yes the last one is the best one, but the third is also fine, so we will pick the value between these two. Let there be 80 000 photons. ;)

There are still few values we have to play with to get the better result. They are in Render Globals (mentalray) > mentalrayOptions1 > section Caustics/Global Illumination. Since we have very high Caustic Photons value we will increase the Caustics Accuracy to 100. This will average more photons when calculating accuracy and the effect of this is that the result is a little bit smoother. I also found out that if you set Caustic Filter Type to Cone you'll get rid of the noise and get much better result than box filter. Let's show these effects on next pictures:


Caustics Accuracy 64
Caustics Filter Type Box


Caustics Accuracy 100
Caustics Filter Type Box

Caustics Accuracy 100
Caustics Filter Type Cone

And that's it. The end our water caustics.

Now we will just show you one simple example of how caustics can be used with reflective objects. Just load our last scene (scene03a)...

In this scene I already set the light to cast shadow and to emit the caustic photons. I didn't set the caustics on in mentalrayOption1 ... you will do that, just after we do one qick render of the scene:

From the picture above you can see that we have three object in the scene, the sphere the wall and the floor. I'v set the wall and sphere to be reflective object. I suppose you already know how to do that... ;) Because they are reflective they will reflect the photons emitted from the light source and cast it on to the floor. Let's turn on caustics: Render View > RenderGlobals (mentalray) > Quality section > click on the box near RenderQuality > then when mentalrayOptions1 opens go to the Caustics/Global Illumination and turn on Caustics. Render again:

As you can see, since the wall has red color it reflects the photons and illuminates a floor a little bit. This is also happening with the sphere and the floor. The intensity of the caustics is driven by the few parameters of the objects material. These are the color of the object, the specular color and reflectivity. By increasing the specular color and reflectivity you'll get the brighter caustic effect, and by changing the color of the object you are changing the color of casustics. The picture below is one example of this ... I'v changed the specular to be brighter than before and as you can see it emits more red color on the floor.

That's it. The end of our caustics tutorial. I hope that I helped a little bit with these examples. I know that they are as simple as they can be, but it can be the great examples for beginners to start learning how to use mentalray for maya.

Happy rendering, and bye till next tutorial. ;)