Tutorial 4 - Global Illumination and Caustics

This tutorial assumes that you have a basic understanding of "4D Blue" functions, especially that you know how to move, adjust and rename objects. In this tutorial we will start from existing simple scenes and set them up for global illumination rendering. We will start with simple caustics, move to a complete GI simulation in a simple box scene, and eventually set up and render fairly complex swimming pool scene.

Step 1 - Adjusting Gamma Correction.

Picture

For the first time in this tutorial, we need to pay special attention to the brightness of the rendered objects. When an image is rendered the color intensity is directly proportional to the light intensity of the virtual lights used in the scene and that is clearly what we want. However, there is a problem with that setup, because most display devices like the CRT monitor that myself and a lot of people use are not linear in the color intensity. For example, a color of value (0.5, 0.5, 0.5) will not be displayed as perfect gray - 50% white and 50% black. To compensate for this problem "Gamma Correction" is often used. The left half of the image in the picture shown is without gamma correction, and the right half is with gamma correction of 1.5. Depending on your display device, you might find that a different gamma value works the best for you. I usually try to use between 1.5 and 1.8, although some people even recommend 2.2

Picture

"4D Blue" supports gamma correction. You can adjust it in the "Render Setup" -"Resolution and Anti-Aliasing" tab. All the images in this tutorial use gamma correction of 1.5

Step 2 - Caustics.

Picture

We will start this tutorial simple, with only caustics. You can now download the caustics scene: Download "Tutorial 4" Caustics Scene. The scene should look like the image on the left. The floor is a procedural textur, and it is a bit slow during rendering - if you want replace it now with a bitmap or other simple texture - it will speed up things for the whole step.

Picture

If you render this scene right now, it should look like the image on the left. The cup rendered without GI. You quickly notice that the shaded area is very dark, unnaturally dark...

Picture

In the "Render Setup" in the "GI Global" tab, disable Global GI by deselecting the "Enable" flag.

Picture

Staying in the Render Setup, enable "Global Illumination" in the "Render Options" tab.

Picture

Select the "Glass" object and using the context menu in the "Nodes Toolbar", select "Parameters...". Enable "Generate Caustics" under "Global Illumination Parameters".

Picture

Now it is probably time to explain how Global Illumination works in "4D Blue". "4D Blue" uses a technique called "photon mapping" where every light source emits a number of photons to the scene and traces them. When the photons hit the surface they are stored on it, and then they can be either absorbed, or reflected. If reflected, they can be reflected diffusely or secularly or something in between based on the BRDF of the material used. This also explains the mysterious "fKGIAbsorb" coefficient for most of the shaders which controls the probability of the photon being absorbed on that material in a range of 0.0 to 1.0, with 0.0 being 0% and 1.0 being 100%. The photons can bounce like that until they are finally absorbed or until the maximum numbers of reflections have been reached. Then the light intensity is based on the density of the photons at any given point. The more photons around that point, the better the approximation is. The number of photons emitted by each light is controlled by the lights in the "GI, Sky" tab. 100000 is usually too little for most situations, but it is a very good starting value. So for now we are going to keep it.

Picture

Rendering the scene, and we have the following image. We can see a bit of light passing through, but it is patchy and noise. Clearly, we need to improve on that.

Picture

As you rendered the image, you probably noticed that there is only few hundred photons for the caustics. That is not many, but exactly where are they located? There is a tool especially designed to quickly preview the photon locations.  In the "Rendering" menu select "View Photon Maps". You should see an image like the one on the left, showing the exact locations of the photons.

Picture

For most early stages of the GI simulation, it is handy to see only the photon map and disable the direct illumination. In the "Render Setup" under the "Final Gather" tab, switch to "Preview Radiance Estimate".

Picture

Rendering the scene now, we can see only the caustics contribution; that is good. So we can focus on perfecting it without being distracted by the direct lighting.

Picture

Few hundred photons are clearly not enough to get an accurate illumination estimate. Let's increase the number of emitted photons 10 times and see what we get. Set the new caustics count to 1000000.

Picture

Render the scene, we clearly see an improvement. There are no more dark patches and the illumination is continuous. That is usually the first goal when setting up the caustics photon map. But we also notice the caustics are very smooth you could almost say blurry.

Picture

Looking at the previous image, we notice we need to do two things: further increase the number of photons and try to make the caustics sharper. To make the caustics sharper, we reduce the "Max Search Radius" to 0.05. Since we reduced the search radius, it is also a good idea to reduce the "Density Control Radius" to 0.002. From experience, I found out that keeping the density control radius at 1/20 of the search radius produces good results. We still are going to use only 64 photons as the "Max Search Size". The less photons we use, the sharper the end result will be (but also more noisy, so be careful) and that is desirable for caustics.

Picture

Increase the number of photons to 50 million. It is going to take a while to compute this map, but we already know it is probably also the last time we need to do so as it should produce a very good map.

Picture

The image looks so much better. The caustics are clearly sharper. In fact they look so good that we are done.

Picture

It took so long to compute the map, we clearly don’t want to do it again especially since we are very happy with it, so we are going to lock it now. In the "GI Caustics" tab, under "Render Setup" enable the "Lock" flag. It will force the rendered to always use the existing map. If you make any changes to the lights or the scene or the setup, you will need to unlock it if you want the photon map to be recomputed. You can also save the photon map to a disk if you want, so you also don't need to recomputed the map when you reload the scene next time.

Picture

The "caustics only" renderings look very good. We are now ready to switch back to regular rendering mode. In the "Final Gather" tab, under the "Rendering Setup", switch back to "Final". Render!

Picture

This is the final rendering. Compare it with the first image in this step. It clearly looks much more realistic. Caustics when used right can quickly and drastically improve the photorealism of your scenes.

Step 3 - Simple Global Illumination Scene.

Picture

In this step, we are going to focus on global illumination using a simple box scene. You can now download the box scene: Download "Tutorial 4" Box Scene. The scene should look like the image on the left.

Picture

If you render it right now, it doesn't look too good. It is very dark and you can't even see what color the big box is. It is completely in the shadow. In "Render Setup", disable caustics in the "GI Caustics" tab as we will not use them in this step. Then in "Final Gather", switch "Preview Radiance Estimate". Eventually in "Render Options", enable "Global Illumination".

Picture

In the "GI Global" tab, disable "Precomputed Irradiance". Pre-computing irradiance speeds up things greatly later on, but for now it would only slow us down. We will come back to it later.

Picture

If you render the scene right now, you should see an image like the one on the left. It looks interesting with all the noisy patches and the dark spots on the sphere. In fact, it is not that bad but we can improve it.

Picture

Lock the global photon map, switch to "Fixed Area" in the "Density Estimation" and increase "Max Search Size" to 2048.

Picture

Even that we used the same photon map, the new image looks different. It seems a bit darker and smoother, and we can see darker edges around the corners. Different density-estimate techniques produce different results. In most situations for global illumination, the "Convex Hull Area Estimation" works the best. But there are situations when it fails badly, especially when the scene contains a lot of highly detailed objects. In such situations and in many others, the "Fixed Area" is superior. Usually a smooth image is better for global illumination.

Picture

We are going to increase the photon count and see what happens. Since we will need to recompute the photon map, unlock the map. Then adjust the "Search Radius" to 0.1 and reduce "Density Control Radius" to 0.005.

Picture

In the light constructor, increase the photon sample count to 500000. Render!

Picture

The new image looks better but too patchy. It seems the new search radius that we have chosen is, in fact, too small.

Picture

Again lock the map, and adjust the search radius to 0.2. You probably notice that the lock feature is very useful, especially for these kind of trials. In fact, the only parameters used during the photon map computation is the number of photon samples in the light constructors and the "Density Control Radius". You can adjust all the other parameters with the photon map locked as the map doesn't need to be recomputed.

Picture

The image looks much better now. It is clearly smoother.

Picture

Let’s see what the image would look like if we used "Convex Hull Area Estimation" method again.

Picture

It looks pretty good in fact. The edges are no longer dark. Only the sphere is giving us problems. The problem is that it is not very smooth - i.e. the angle at the edges is fairly high and it only appears smooth because we interpolate normals.

Picture

The "Irradiance Estimate" is not the best, but it is good enough for this tutorial. We are not ready to enable "Precompute Irradiance". This will force the render to precompute the radiance for about 25% of the photons. It will greatly speed up our next task which is the final gather.

Picture

The new image looks almost like the previous one and even a bit better. That's good. We clearly don't want the precomputed irradiance look worse than if we didn't use it.

Picture

It took a while to precompute irradiance as well. In some situations, it can also be a very expensive step, so we clearly want to lock it now.

Picture

We are ready now to setup the final step in the global illumination rendering - the "Final Gather". It is true that you could use the photon map itself, but as you can see the map would have to be very large to produce satisfying results. It is common to use a final gather instead, which will sample the map around the surface intersections point in order to evaluate the light intensity at that point. It clearly seems expensive, that is why an "Irradiance Cache" is used and only the irradiance is computed for few points in the whole image and then interpolated in between. The default minimum and required weight is usually good for most situations, don't change it. The "Max Cache Radius" should be approximately twice as large as max search radius used for the map itself. "Max Angle" specifies at which maximum angle that we can reuse the cached points, 30 degrees is usually good. The "Min Distance" controls at what minimum distance between surfaces we no longer store the cache points as they are not accurate enough. "View Cache" shows us the cached points during preview rendering. Eventually the "Gather Samples" specifies how many samples we are going to use to sample the scene for each irradiance point. The real value in fact PI * N * N, so if you enter 6 approximately, 110 samples will be used. Don't worry about the rest of the parameters. The initial rendering with final gather enabled is to make sure the cache point are distributed well, usually a small value of 6 is enough.

Picture

The image looks clearly different. One, we now only see the indirect illumination; second, we see a lot of small dots. These dots show us the points at which the irradiance value has been cached. They should not be too close to each other, and not too far either. They should be closer, near object that are close to each other like the sphere and the ground. The distribution that we see here is a good one. The image is noisy, because we used too few samples for each irradiance cache point.

Picture

If we render the image with the "View Cache", disabled the image would look like the one on the left.

Picture

Lets increase the sample count and see what happens. Increase the count to 10.

Picture

The image clearly took longer to render, but it also looks much better.

Picture

Increase again the sample count to a value of 14 produces a satisfying result at least.

Picture

We are eventually ready o render the final image! Switch back to "Final" in the "Final Gather" tab.

Picture

And the final image! Compare it with the first image in this step and you will see why people are raving about the complete global illumination solutions!

Step 4 - Complete Global Illumination Simulation - The Swimming Pool.

Picture

In this step, we are going to use full global illumination simulation using a fairly complex swimming pool scene. It contains many objects, metallic ladders, reflective floor, water in the pool, and six spotlights. You can now download the swimming pool scene: Download "Tutorial 4" Swimming Pool Scene. Once you unzip the file please copy the image maps to the 4D Blue Image Maps directory. The scene should look like the image on the left.

Picture

If you render the scene right now the image looks ok, but the pool is dark and the walls are almost invisible, completely in shadow. Once again, in "Render Setup" in the "Final Gather", switch to "Preview Radiance Estimate". And then in "Render Options" enable "Global Illumination". Also disable global illumination in "GI Global" as we will start with caustics.

Picture

Enable "Generate Caustics" for the "Water", "Ladder1", and "Ladder2" objects in the "Properties..." section for each of the objects in the "Nodes Toolbar" context menu.

Picture

Make sure the caustics are setup properly like on the left image and we are ready for the first trial.

Picture

It is not bad, but we can't see much. It seems we need to extend the search radius; and, of course, increase the number of photons used.

Picture

Let's start with increasing the photon count. We can always increase the radius latter. In the previous rendering, we had about 12000 caustics photons. Assuming we want to have about 1M for a nice good map, we need to increase the counts 100 times. For each of the six spot lights, adjust the "Sample Photon" count for caustics to 10000000.

Picture

Wow, the image looks pretty good. I think we are ok with the current radius after all. Also notice that the final number of caustics photons is less than the expected 1.2 M photons - it is only about 960K photons. That is because of density control. Once the photons are being stored closely to each other, they are combined into one. This way we can have a very accurate map without using as much memory.

Picture

We are happy with the caustics map. Let's lock it, and also disable it since we don't need it for a while as we will be working on the global map, and caustics would only slow us down.

Picture

Let's move to the global map. Enable it, and setup as shown on the left image. These are good starting parameters.

Picture

After rendering, we get a very dark image. The left part uses 1.5 gamma correction, and the right half 2.5 gamma correction. The image is clearly too spotty as we can almost see individual photons. We clearly need more photons.

Picture

The global photon map has about 40K photons. Our goal again is about 1M of photons. Experimentally I found that because of density correction, we need to increase the number of emitted photons 50 times to get about 1M of global photons. For all six of the spotlights, increase the global "Sample Photons" count to 5000000.

Picture

We again have a very dark image and again the left part uses 1.5 gamma correction, and the right half 2.5 gamma correction. This time however the image is clearly much better. It looks almost good enough without final gather!

Picture

The images are too dark to go on with final gather. We are going to artificially increase their brightness by 3. In some situations that is necessary as the intensity computed by direct illumination and photon tracing at times differs, and sometimes you want the indirect illumination to be brighter on purpose. Adjust the intensity coefficient to 3.

Picture

The new image looks much better. It is bright enough for the final gather. At this time, you can precompute the irradiance just like in the previous step if you want. It will greatly speed up computing the final gather calculations.

Picture

In the "Final Gather" tab, adjust the samples number to 12. From previous step, we know that the rest of the values should be ok, so we are ready for the high quality try. Also switch to "Preview Global Illumination" in the "Rendering Output" group.

Picture

The indirect illumination result looks pretty good. We are now ready to combine it all together. Enable caustics and switch to "Final" in the "Rendering Output".

Picture

The final image is with direct illumination, indirect illumination and caustics. It clearly looks much better than just the plain direct illumination! I hope this tutorial gives you enough information to start using complete global illumination simulations in all your scenes. There is always few steps involved and a few parameters to adjust for each of it, but you will be able to quickly adjust all of them based on your need with experience and practice. Just remember, start with little and improve until you are satisfied.