Global Illumination in Maya 8 - Indoor INTRODUCTION Today, nearly all respectable 3D programs have some sort of GI (global illumination) algorithm integrated, and basically every new renderer that appears on market has been engineered from the start to support GI as better as it can. Unfortunately for Maya users, the default integrated renderer doesn't support any kind of GI, and I suppose there are no artist today who doesn't need a touch of GI. So, from the Maya 5, Alias decided to integrate one of the best renderer on the market today, the MentalRay. If someone of you have used XSI before, you know how powerful MRay is. One of the most interesting features in MRay for Maya is capability to compute additional light distribution in the scene which is usually known as global illumination. This tutorial is targeted at the beginner/intermediate users and I will try to describe as best as I can how do I use MRay to add global illumination to my scenes. There are a lot of pictures in this tutorial, so be patient if you don't have fast connection. Or if you like you can download complete tutorial in one zip file and read it offline. Well, let's start with a little introduction to MentalRays global illumination algorithms. The renderer has two solutions for computing additional light distribution in the scene. One is Global Illumination, and other is Final Gather. In some situations, you can get satisfying results with use of only one of this solutions, but the most powerful use is to combine these two together. Global Illumination algorithm shoots photons from light and tracks their path through the scene, and every time the photon hit some object in the scene it leaves the part of his energy on it. It is fast solution, and produces nice additional lighting of the scene, but it just isn't as accurate as you will want in most situations. But, that's why you would use second method which combined with GI would produce some stunning results. This second method is called Final Gather. The goal of final gather is same as global illumination, but approach is very different. Final gather is computed from point of view, and not from the light source like global illumination. After primary ray hits the intersection point on objects under the pixel, final gather is activated and shoots additional rays in the scene collecting color information's around the point for which we are computing color. In real world, the light is bouncing around unlimited times distributing light energy all over the scene. In computer computer situation this is impossible, and because of that many optimizations were needed. Because of that, no mater how high you set the parameters that controls quality of GI, you will never get the perfect solution, and your rendering times will bump up drastically. So our goal in next tutorials will be to balance between quality and speed. Through this tutorial, we will use two types of scenes for which we will create Global Illumination and Final Gather solutions. First scene is indoor type of scene and the second are outdoor. For the indoor scene, we will go throughout process step by step and for the outdoor scene I will show how FinalGather can be used along with HDRI to light up the scene. Because the mentalray comes with fresh installation of Maya, check if it is started, so run Maya and go to Window > Setting/Preferences >Plug-in Manager to check if Mayatomr is loaded. If it isn't, click on the box near option loaded. If you want to use MRay everyday you can also check the auto load box. Just to check if it is loaded, go to the Windows > Rendering Editors > Render View and in Options > Render Using check MentalRay.
INDOOR SCENES Introduction to Global Illumination Algorithm Before we start, open the maya scene called interior_01.mb. Once you open it you would see that this is a simple scene with some geometry, spotlight and a camera which we will use to render our tests. Just for information, if there is no light in the scene, maya tend to create the default light if you try to render. To turn this off go to the Render Options and under Common section go to the bottom and turn of Default Light. I tend to turn this off every time since there can be a situation where you won't have usual lights in the scene, but geometry that serves as the light and maya will understand the situation as "o, there are no lights in the scene, why don't I help my user and set one simple point light just for him" ... and of course, this produced very confused reaction from the viewer. So, turn this off for now. If you want you can delete my spotlight and create one of your own or maybe add some more geometry. It's up to you to redefine the scene as you want, or in case you are satisfied with what you have, be free to continue further... The scene, once you open it should look like this: You can change the angle at which the spotlight shines through the hole, but it must be pointed so that part of the light pass through the hole, or you won't get any light shining through it. For the start, go to the Attribute editor of the light (select light and press CTRL+A) to change some options. First of all, switch the Decay Rate to Quadratic. I use the quadratic decay rate in many cases to get realistic light behavior. This way the lights intensity drops as the distance from the source gets bigger. All available options in decay rate do some type of fade with distance except no decay which has equal intensity all through infinity. Also, if you have used the Quadratic Decay Rate, increase intensity to something like 2000. In Shadow > Raytrace Shadow Attributes check the Use Raytrace Shadows. This will produce the sharp raytraced shadows. Later you can use the area light to get more realistic shadow. Also if you check my scene you will see that I assigned the lambert shader to the object with some sky blue color set in color channel. Now, let's go and setup the global illumination... There are two menus that we are interested in. The first one is in light attribute editor and other is in MentalRay Render Settings. First thing we have do to is to change few options in light attributes, so that our light emits photons. To do this, select the one and only spotlight in the scene and press CTRL+A. After attribute editor pop's up, go to the MentalRay options > Caustic and Global Illumination and turn on the Emit Photons button. After you do this, few options below Emit Photons will unfade. As you would see, there are three options: Color, Intensity, Exponent. The Intensity is, as the name says the intensity of the photons shoot at the scene, and the exponent is the similar options as the Decay rate of the light or how much the photon fades with the distance. The Exponent is dependant on the scale of the scene ... the bigger the scene the light and photons will fade more than in small scale scenes. You can control the overall brightness of global illumination effect in the scene with both of these options but it is recommended to leave the exponent at 2 if you use quadratic scale. If you render the scene at this point, you will get the same result as if there was no global illumination. Why? Because we have to turn on the global illumination in the MentalRay Render Settings. To do this open the render window Window > Rendering Editors > Render View. After the Rendering View opens, go to the Options > Render Settings (mentalray). After the Render Settings opens, go to the Caustics and Global Illumination section, and in it turn on the Global Illumination to use prepass calculation of GI in the scene. But, before we render the image with the Global Illumination, select the light and in attribute editor of the light increase the Photon Intensity to 500 000 since the initial value will be to low to see any indirect illumination produced by GI. The first picture shows the picture without GI, and second with GI.
As you see, there is a lot of additional lighting in the scene, the scene look rich and full of details and indirect light variations, although, the quality of secondary illumination (GI) is not at the highest level. Remember that after we make a setup for the global illumination we have to use the final gather to get the best possible illumination that we can. For that reason, we have to fine tune the global illumination so that it serves the final gather pass when the time comes. So how can we tune the global illumination? As you remember there are some options in attribute editor of the light and in MentalRay Render Settings. Options in the light attribute are used to control the amount of photons in the scene and the brightness of the global illumination effect, and the options in MentalRay Globals are used to fine tune the global illumination, for example how many photons will be collected and mixed at point x when renderer calculates the illumination, or how big will be the area in which the photons would be collected. To see all the effects we can produce by tuning the global illumination option I will use a lot of pictures with different setting, since I think this is the best and the most intuitive way to show you the meaning of all this options. For the start we will first change some option in attribute editor of the light. So, select the light and jump to attribute editor. Go to the Caustic and Global Illumination options. As you see, by turning on the GI in the Mentalray Render Settings the Global Illum Photons has become available (not faded any more). This option is used to tell renderer how much GI photons will be shoot in the scene. The more photons you use, the more quality you get, but it slows down the renderer, althought the GI pass is in most situations very quick compared to FinalGather. But, just to experiment a little bit, we will try to to make the satisfying-fast solution for GI, so we will not use too much photons and loose precious time. The intensity of the GI in the scene above is right if you use only GI to produce secondary illumination, but if you use it in combination with FinalGather the solution, sometimes, it could be exaggerated and too bright. To change the overall brightness that GI has on the scene we will play a little bit with the Photon Intensity value. As I already said, the effect of the changed are best visible through the pictures, so...
As you can see, the images above show very clear a kind of effect the Photon Intensity have. It is recommended to do 3-4 images with different intensity values, like the ones above, and chose the right brightness for your situation. In this case, I am in need for the GI solution that is bright all over the scene, but fades in the tunnel on the left side of the image. The right one would for this case would be the 3rd solution with 300 000 photons, although I could still play with intensities varying from 100 000 to 300 000, depending on what you want to get. I think this options is pretty straight forward, so there is no need for further explanation ... just make a few test on your own. You will probably ask yourself, what would be the effect of we increasing the Global Illum Photons option. As before, the pictures are the best teacher...
At the first picture from above we can see what happens it the GI solution doesn't have enough photons, the secondary illumination is pretty undefined and produces visible artifacts all around the picture. The second and third one have more photons and produces satisfying results without too much impact on time. Last one has the best quality but it takes some time to calculate compared to others, but indirect illumination is more defined, specially in the corners where it fades to a darker colors. As usual, the value I would chose is something between the third and the forth, although you can try with the values around 100 000 which were quite nice in this situation. I will set the number of photons to around 500 000 and get the result as the one below..
The two options that we explored above were the only one that you will need to set up in the attribute editor of the light node. The exponent value should, in most cases match the decay value of the light that you set, although you can set it separately from the decay rate of the light. So for example, if you use quadratic just leave it at 2, and for linear set to 1. The other options essential for GI setup that we will explore in this tutorial are found Mentalray Render Settings (Render View). The options that were of some interest to us are the: Again the pictures for the options I mentioned above... first the accuracy setting...
The accuracy setting in first picture collects only 10 photons around point of sample, and that's why it looks so grainy. But, if you want to analyze all the photons in the scene try to set the Accuracy to 1 and you will get all of them visible. ;-) . The third picture shows much smoother results, although in my opinion not enough smooth, which is why we will use the result somewhere around 200 which is the somewhere around the best value where we don't loose the detail at corners like in 4th picture where the accuracy was set to 350. Now we would leave the Accuracy to 300 and play a little bit with the Global Illum Radius settings. The default value, which is set to 0 tells mentalray that he tries to approximate the best value for the scene, which in some situation can work and in others won't .... and that's why it is nice to see the effect of the radius value. The images...
In the first image Mentalray tries to collect the 300 points in the radius of 0.1 and as you can see it doesn't succeed in that. The second image still has some problems with the collection of the photons within 0.5 radius but the third one does this pretty fine and 4th one is also a nice. Something in between would probably be the best choice. The next important value is Max Photon Depth, and the pictures...
It is very easy to perceive the effect Depth value from the pictures above. The higher you set the depth the photons will bounce more and the scene would be brighter since the photons will reach a part of the image that is well hidden from light, like the tunnel in this example. In many cases a value around 5-10 would be enough, and in this situation we will stick to 6. The last value that doesn't have effect on the quality of the GI solution is the Global Illum Scale which is multiplier to the final GI solution of the image. So for example if you set it to green or red color you will get a kind of effect like in pictures below.
That would be all about GI setup. For the final values I chose the Photon Intensity 300 000 and Global Illumination Photons set to 300 000 in light attribute editor and in Mentalray Render Settings I picked the GI Accuracy 200, GI Radius 4 and Max Photon Depth 6. Now let's explore the Final Gather phase.
Introduction to Final Gather Algorithm As I said in the introduction before, the FinalGather is another way of calculating indirect illumination in the scene. Compared to GI method it is different in way that it is computed from the point of camera while GI is computed from point of the light source. You could say that FinalGather method is more detailed one, it gives a better results, but it is slower, and it can be used with the GI turned on. If you combine both algorithms then the FinalGather will be used for the first bounce of the light and GI for the other bounces depending on how much Photon Depth did you used in GI. This is the first way, and in old versions of maya it was the only way to get multi bounces of the light into the scene. From mentalray 3.4 above (Maya 7+) it is possible to do multi bounces using only FinalGather, but at the moment we will only explore the way with GI turned on and later we will mention the way to do only FG indirect illumination with multi bounces. Ok, let's begin ... we will continue from the scene above, with GI already set. Now, to turn on the Final Gather, go to the Mentalray Render Settings. Open the section Final Gather and turn on the Final Gather option. There are many options in FinalGather section but we will mention only three at this moment, the Final Gather Rays, Min Radius and Max Radius. Initially these options have default values of 100 0 0. All three options have a great impact on the rendering speed. FG Rays is number of rays shoot, from the point where FinalGather sample is calculated, at the scene to estimate the indirect illumination at that point. The more rays you have the more quality you get, but rendering speed drops dramatically. The Max and Min radius tell the renderer at which radius from shading point will FG collect information about surrounding indirect light. If these values are set to 0 0 then the renderer estimates the value of these two automatically. But, in this case we will set it manually. Let's see few pictures produced by changing these three values. First the FG Rays value...
First thing that you will probably notice is the time it takes to calculate FinalGather if we increase the rays value. Yes, the last one is the best one from ones above, but 1000 FinalGather rays is too much in many situations. But, if you are using versions of Maya below 7 be sure to bump up the rays a little bit higher since from Maya 7.0 above, the new version of Mentalray was implemented with Adaptive FG sampling which usually needs 10 times less samples than before. Also it is recommended not to use too small values like 10, and the reason why you shouldn't do that is because of that little indirect illumination shadows at the edges all around the scene. If you check the images above closely you will se the differences between them. Lets' check the image closely.... ;-)
As you can see, closer look reveals some loose of details in first image and the details you get by raising the Rays value. The other thing that you will se is how good the new Adaptive FG in mentalray is ... it produces quite good results even with 50 samples. Most of the times, in animations or final renderers you will need far less samples than expected, like 100-250, which is what I am using all the time, specially when you have a lot of textures with details in them which can hide the artifacts FG make. There are other situations, specially in architecture where you will have walls with flat paint where every artifact that FG can produce is visible, and in that situations you can raise the FG Rays to something like 500 or so... The other value that affects the time and smoothness of FG calculation is the Min and Max Radius which is used to define the min/max area in which MentalRay will try to collect final gather samples when rendering FG solution. I usually set the Min radius to be the 1/10 of max radius, and that is somehow rule which most of us obey, so we will use it through next images. I will use FG 50 Rays for this situation...
The good balance between Rays and Radius values are crucial one to get detailed FG solution and at the same time a quick one. As you can see, the first image takes too long to render and it look so noisy... the reason for that is that Mentalray just can't find enough FG points in the 0.01-0.1 area and the noise appears. The other ones are far better specially the second one. The third and the fourth are smooth but compared to second they have less defined shadows produced by indirect illumination. Now to get the good feeling of how big the min and max radius in second image is, use the Create > Measure Tools > Distance Tool and create distance of 1 unit and compare it to the scene size. This is also a good work habit for FG setup ... to use measure tool to create distance of 1 unit and then compare it to the scale of the scene and try to make an approximation of what should be min and max radius. At the end decision is yours. Make few tests for every scene you do, look at them, analyze analyze analyze and try to find the best possible values. In this situation, after a few test I did, I chose a quality/speed balanced solution as in the next image.
With these last image we conclude the first two parts of this tutorial. I showed you the usual and simplest way to setup Global Illumination and Final Gather in Mentalray. But this is not finished, there are still some tricks to learn before you are 100% ready to go in battle. ;-) So let's explore some other areas also...
BEYOND LESSON Saving Final Gather Solution In every test we made above, the GI and FG solutions were recalculated every time we pressed render. But, it doesn't have to be that way. Once you have created a suitable setup of Global Illumination, for example, you can save that solution to disk and reuse it. So, the usual workflow would be this ... get a nice GI ... ok this is it, I am satisfied ... now in Render Setting of Mentalray go to the Caustics and Global Illumination section and in the "Photon map file" set the name of the file in which GI would be saved. The next time you click render, GI will be calculated and stored to the file with the given name, and after that every time you render it will reuse it. This will save a lot of time and patience when setting up FG pass. The same technique can be applied to the Final Gather pass. Once you are satisfied with the FG solution, go to the Final Gather section in Render Settings and in Final Gather File set the name which you want to use to save solution. But, there is also one other crucial option in FG that isn't available in GI save. That is the Rebuild Final Gather which is by default set to On. If it is set to on, FG will erase all old point it calculated in the previous render and store the new points in the file. Now, this is nice if you are in process of tuning up FG, but once you are satisfied with the setup set the Rebuild Final Gather to Rebuild or Freeze. The Rebuild option will store point from the last render, and if you render the scene again it will eventually add a new point if needed somewhere. So, for example if you calculated FG samples and Mentalray stored that solution to the FG file you specified, and you changed the view of the camera to look at some other part of the scene ... press render ... with rebuild set to on, mentalray will add FG point at the parts of the scene that wasn't visible in last camera view. Last option is freeze, which freezes the last disk saved FG solution and does not add new FG points to it. With freeze some problems could arise if you move the camera to look at the part of the scene which doesn't have FG point already calculated. The Freeze mode is usually used when FG prepass was done for entire camera path, and then the solution was locked... Visualizing FG Points There is one nice way for analyzing the distribution of the FG points through the scene, and that is Map Visualize option. There are two ways to use this. The first one is to enable Enable Map Visualize in FinalGather section at Render Settings. When you turn it on, and render the scene, the FG points that were calculated in FG pass will be loaded and showed in viewport as tiny dot's. The dot's would be visible in wireframe and in shaded mode, although in shaded mode they will also have a FG color. To use Map Visualiser you would have to have some solution saved to disk which it can load. This means that you must have some kind of the name at Final Gather file, even if you have Rebuild set to On. The additional options that can be useful when visualizing FG points in viewport are to be found in Window > Rendering Editors > mentalray > Map Visualizer. If you already turned on Enable map visualiser in Render Settings, the name of the FG solution will be available at "Map file name". If not, you can load it directly from here. Just click at that little folder on the right side of "Map file name" ... go to the project you are working in, and you will find your FG solution at "project_name\renderData\mentalRay\finalgMap\solution_name". Once you loaded it it will appear in viewport, and you can play a little bit with Point Size value. Same technique can also be used with GI save solution ... just point it to the GI solution when loading it, or check Enable Map Visualizer in Global Illumination section at RenderSettings. As an example I captured my viewport with visualization turned on and I also played a little bit with scale of points in visualization options.
FG Multi bounces Let's get back to beauty of Final Gather. What would you say if I tell you now that there isn't any need for GI setup, when you can archive all that multi bounced indirect light with only FinalGather. Ok, if you take a blue pill, we won't continue further, and if you take a red pill, well... let's start... :-) The maya/mentalray users didn't have any other way of getting indirect illumination with multi bounces for a long time, and the only way to get it was to use Global Illumination for it and use Final Gather only for first bounce. Remember the Max Photon Depth option in Global Illumination section? Well, the time passed by, and Mentalray development went far away, so here we are ... with the ability to use two ways to do multi bounced indirect illumination. The multi bounced FG doesn't need any GI solution as in tutorial above, so once you turn on this option the Global Illumination should be turned off or the FG secondary bounces will be ignored. So first go to the Caustics and Global Illumination section at Render Settings and turn the GI of, then turn on the Secondary Diffuse Bounces in the Final Gather section on. Above Secondary Diffuse Bounces are few options that are important to us... these are Trace Reflection , Trace Refraction and Trace Depth. The Trace depth is usually the sum of the Refraction and Reflection values, so if they are set to 1 1, set the Depth to 2. The sum of Reflection and Rafraction values is tell Mentalray how much indirect light will bounce around the scene ... so for example if they are set to 1 1 you will get two light bounces, if set to 2 2 you will get four bounces and so on. The more bounces you set, the longer it would take to render but the scene will receive more indirect light and it would look more real. Before we look at the images and how this options affect the image, we must set few more parameters. First, if you are using default maya lights, the FG with secondary bounces would not work as it should if you don't change the default options of the light. So, select light, go to the attribute editor and in the Raytrace Shadow Attributes section set Ray Depth Limit to the sum of the Trace Reflection and Trace Refraction values that you have set in Final Gather section of Render Settings. For example if they are set to 2 2, set the Shadow Depth value to 2. The similar procedure must be done in Mentalray Render Settings, at Raytracing section ... set the Shadow Trace Depth to the same value as in light, and Max trace depth to the same or higher value. In next few test I scaled the FinalGather with the FinalGather Scale color in FinalGather section at RenderGlobals ... just to make secondary bounces effect more visible. Ok enough of this, let's see few pictures...
So you can see that the same multi bounce effect can be achieved with only Final Gather without any need for GI. Although, by looking at the pictures above, the 150 FG points is not enough, so we can use some higher value when secondary bounces are used. At the ends it's up to you to decide which one suits you the best. Play with both techniques, test them at your scenes and chose one ... you will have enough knowledge now that you passed this tutorial to decide where to go further... There is no need for Real Light source- (check indoor01_object_as_light.mb) I know this sound a little bit strange, specially if you use Mentalray for a short period, but every object in the scene can radiate energy to the scene and light objects that surround it. The next image is rendered without any light source in the scene:
Now, the time it takes to render this is about 10 minutes, which is pretty high. But, in these situation where you don't have any light in the scene except the sphere (example above) you will need some higher settings for final gather than in situations where you have some light sources. The main trick to get these kind of effect is in the material which is attached to the object that you will use as very bright source. Usually, I tend to apply the Surface Shader material to the object and in surface shader material options click the color and when color menu jumps out set the Value to something from 1 above. In example above I used the Value set to 10 which radiates nice amount of energy to objects around it. If, you don't want the object that lights the scene to appear in final Render, select him and go to his attribute editor when under Render Stats section you will find primary visibility, which should be turned off. By using this, the energy will be sent to the scene in FinalGather pass but in final render the object will be hidden. One thing to remember when using this method is not to turn check if the Filter value at FinalGather section is set to 0, because if it is set to 1 you can loose a lot of light energy at the scene and it can appear much darker. Try to make few tests using this method, and also try to combine this example with the ones which uses light as another source. The combinations are endless. Photon Map and light leaking through walls A big problem with photon mapping in some situation could be the weakness of this technique to leak the light in some parts where it should not be visible. This example is illustrated in next pictures.
Now, the problem can not be eliminated by setting up some GI settings or clicking just one option. This is something that needs to be considered in the process of modeling scene. The usual rule would be to always create walls that have some thickness. If you will be inside a room, don't create walls that will be flat polygon when looking from side view, it has to be real wall. In my example, I used one little trick and that is to model a little blocker outside a window where the light comes in. If you check the scene you will find the object that I am mentioning. This problem, however, doesn't appear if you are using FinalGather secondary bounces ability since MentalRay can handle FG points a little better. So remember, only GI is suffering from this. Area Light's at windows - (check indoor01_area_light.mb) Some artists when lighting up the interior scenes tend to use area lights placed at the windows. This gives a little more defined direct shadows and some additional illumination but render times jumps quite a bit since soft shadows from area lights must be sampled very high. A simple example of this is given with next images...
This renders are without any kind of indirect illumination, but it is already visible how more primary light produced by the Area Light is distributed around the scene. This additional light will for sure help when using turning on Final Gather. The Area light is created at Create>Light menu and it must be placed so that line perpendicular to area light is pointing inside through the hole or window. If you loaded the scene with this example, select the area light at the window and go to his attribute editor (Ctrl+A). First thing to notice is that I used the default settings in the Area Light Attributes section. If you want you can also play a little bit with Decay Rate ... try to set this to Linear or Quadratic to get some different results, but remember to bump up the Intensity value if you are using quadratic falloff. Under the Raytrace Shadow I turned on Use Raytrace Shadows and Set the Ray Depth Limit to 4 because I will use FinalGather and Secondary bounces with Depth 4. I didn't set the Shadow Rays to value greater than 1 because I will use Mentalray area shadow which produces much better and faster area shadows than Maya one. To set the Mentalray attributes, in light attribute editor under the mentalray > Area Light section set the Use Light Shape to on and for the type select Rectangle. As for the samples I used High Samples set to 32 which is not to much since MR samples area light in adaptive way which is much faster than usual way used in previous versions of maya. That's all I done here, but you can check all this in the example scene. At last you need the Final Gather with some usual settings like FG Rays 150, Min 0.1 and Max 1 + Secondary Bounces turned on with its default values and you will get the results similar to the next ones ...
The right image is far better than the left one but it renders a few times slower. So, for the still images this would be acceptable but for animations it could produce to high rendering times and you will probably stick to some other, faster solutions. Using IBL to add more Environment Light - (check indoor01_ibl_light.mb) The IBL node is one of the utility nodes that are great companion to FinalGather and Global Illumination. It is a environment shader which is very easy to setup and can be of great help in many situation, specially when doing HDRI lighting. In this example I will only mention it, and how to use it to set a simple color of environment to give more light from outside. Let's compare the two images below ... first one without IBL node and second with.
IBL can be activated if you go to the Render Settings of Mentalray, and at Image Base Lighting section click Create. This will create the IBL node for which attribute editor would be opened instantly. If not, you can always find it in Hypershade at Lights section with name mentalrayIBLShape. Now, in attribute editor of IBL node set the Type to Texture and when Texture option un fade click at color box and set the color to value you want ... in my example I set HSV to 0 0 5 (white with high value settings). The same situation which we used before on Surface Shader applied to object that light up the scene uses the same rules here, so to give a more energy to the scene increase the value settings when you are choosing color. If you want to hide the IBL node in the final render, you will find Render Section in attribute editor of IBL node which is where you should turn of Primary Visibility. More about IBL in next section and with this chapter we will conclude this first part of tutorial.
|