## Friday, February 10, 2012

### Global Illumination methods in Vray

What is GI?

GI is short for Global Illumination. Renderers that use global illumination algorithms take into account not only the light coming directly from light sources (=direct light), but also the light that is bounced of from all surfaces and all of the following light bounces untill infinity (=indirect light). This results in much more natural and photoreal lighting compared to traditional non GI renderers.
Non GI rendering

On the right, a simple image with only one light, coming in fom the left. As you can see, the shadows are completely black and you hardly see the shape of the objects. Also note the shadow underneath the glass sphere, also black.
GI - primary bounce

In reality, light keeps on bouncing around untill infinity. Each time a bounce occurs, the light loses a bit of energy, depending on the properties of the surface it hits. So after an infinite amount of bounces, the lights energy reaches zero. To calculate an infinite amount of light bounces would be crazy, so Vray has some ways to compensate for this. Also, the loss of energy has an exponential curve, so in fact the light energy fades out pretty quickly. This means that the effect of the primary bounce on the final lighting will be far greater than for example the 63rd bounce.

This is why Vray divides the indirect illumination into two main parts: primary and secondary bounces.

On the right, the same image now with GI turned on, only primary bounces. Note the shadows and the interior part are not black anymore. There are still very dark places, this is where the primary light bounces almost don't reach.
GI - secondary bounces

To further mimic real world lighting, we must enable the secondary bounces too. Calculating primary and secondary bounces is not an easy task. You have to imagine that a light ray from the direct light hits a surface, and bounces back in all directions. Let's say it scatters into 50 new rays, which are then primary bounces. These 50 rays again hit some surface, and scatter again in 50 new rays. So after only two bounces there are already 50*50=2500 rays flying around. And this is only frome 1 ray of the direct light. Of course Vray has some ways to limit the number of rays, together with very clever ways of finding out which rays are more important than others etc...

The images on the right shows the effect of the secondary bounces. As you can see, the second bounce has a big effect, the third one already a lot less, and so on. Even the jump from 4 to 12 bounces is almost nothing.
Primary bounces - Brute force
The easiest engine is the 'brute force'. As the name already suggests, it requires brute force to calculate :-) This method computes the GI in every single shaded point. So even with very flat surfaces where lighting is very even, every point will be calculated. This is of course very slow, but also very exact.
The image on the right is lit with Vray's skylight. Think of this as a real sky illuminating the scene. There is no sun, so it's a bit like a cloudy day, casting light evenly from all directions. This skylight is treated as primary bounce GI, so in this scene, there is no direct light. All the light (and thus also shadows) are calculated by the GI engine, which make the skylight perfect for testing the quality and speed of the engines!
I rendered the image on the right with the default values for the engine. As you can see, this is 8 subdivs. The secondary bounces are greyed out, since we disabled these for the tests. The subdivs value is the quality of the brute force GI. So more subdivs is more accurate calculations, less noisy image and of course slower render speed. I included the render time in all the images, click on it to enlarge!
The second image is with brute force subdivs set to 16. You can clearly see the noise is a lot less now, but rendertimes went from 23 to 56 seconds. Note that the subdivs value of 8 actually means 8*8=64, and 16 means 16*16=256. So take care when you want to increase quality! (This is true for all subdivs values inside Vray by the way.)
The third image is with subdivs=32. Notice how it's especially the noise inside the box that get's better now. Also note how defined the shadows are under the teapots and also the sphere. Even caustics are showing up underneath the glass sphere! Caustics apppear when light gets bundled by reflected and/or refracted light rays. Like in the old days when you used to burn ants with a magnifying glass from the bundled sunlight :-)
To summarize, if you have a good pc and enough time to wait, brute force is an easy and very high qualiy GI engine. The downside is that when you start using secondary bounces, especially on interior scenes where there is usually a lot of secondary GI light, that the brute force method will become extremely slow.
The irradiance map is Vray's answer to efficiently speed up GI calculations. Not all surfaces and regions in a scene have the same GI detail, for example on a flat plane without any objects, lighting will be very even in every point. But when the surface is very bumpy, and lots of small objects rest on it, the GI will be much more detailed: small shadows and varying light intensities all over the place.
Basically, the irradiance map calculations can find out which parts of the scene need accurate GI and which parts don't. This is controlled by various parameters that you can see in the screenshot on the right.
The result of all this, is a collection of points on the surfaces in the scene. Each point now has a given value for it's color (=light). Areas that are flat without much detail, will have points spaced far away from each other. Since lighting doesn't vary much between two points close together. But in more detailed areas, points will be placed much closer, for example in our image underneath the teapots, where there is variation on lighting (=shadows).
The image on the right is rendered with IR map as primary bounce. The second image shows how the IR map points are placed. You can clearly see there are less points in the background than for example in between the wall and the cylinders.
Note the rendertimes of the first image, and also how clean (=no noise) it is compared to the brute force GI renders. But on the other hand, the very fine detail is lost a little bit (enlarge images to see this better). The last image I used very low settings to better see the 'blurring' or loss of detail in the shadows. Now all objects seem to be floating because of the lack of detailed shadowing underneath them.
Primary bounces - Light cache
Light cache is a very fast way of computing GI. It's a bit special as it computes all bounces always. So if we put it in the primary bounces, it's actually computing all bounces... The first image is with default settings, and as you can see, it is much lighter than all the previous images. This is due to the extra bounces it computes. For a better explanation of how the light cache works, please read the vray manual: http://www.spot3d.com/vray/help/150R1/render_params_lightmap.htm

Compared to the IR map, it is a bit easier to setup. The most important value here is the again the subdivs. Don't compare it to the brute force subdivs, for the lightcache, you need much higher values. The second image is rendered with 2000 subdivs (instead of 1000). You can already see a big improvement in the GI detail.

If you turn on "show calc. phase" you will see the LC process being updated over time. This is a very effective way for evaluating lighting without having to wait for the render to complete.

The last render has 5000 subdivs, resulting in very good quality. Although it is possible to achieve good quality with LC only, it is mainly used for secondary bounces while you use IR map or brute force GI for the primary bounce.
Primary bounces - Photon map
Photon map is yet another way of computing a GI solution. However I never had the need to use this method. The other engines are in fact much easier to set up and to understand, so I wonder why this is still implemented.
http://www.spot3d.com/vray/help/150R1/render_params_photonmap.htm
GI engines - combinations
Although you can use any combination of engines for primary and secondary bounces, there are some really usefull ones. I will render some examples with the 3 most used combinations:
- primary = IR map and secondary = brute force
- primary = IR map and secondary = light cache
- primary = brute force and secondary = light cache
IR map and brute force
This combination is used a lot for scenes without too much secondary light. For example product renderings are usually made in some kind of studio setup, where an object is placed on a flat plane, lit by some large area lights and/or a skylight. Since most bounces fly off into the sky and therefore don't need further calculation, there are not much secondary bounces present. Most of the GI lighting is done by the primary bounces. The little secondary bounces are calculated by the exact brute force method. So with some good IR map settings, this results in high quality images with fast rendertimes. The biggest lighting effect even comes from direct lights, so even with some lower IR map settings the image is still very good, as the effect from the primary bounces isn't even that huge.

This method will however be slower for interior scenes, then you will be better off with the next combination.
IR map and Light cache
When the amount of bounced light gets more prominent in your scene, the brute force method can become quite slow, especially when used for secondary bounces. The lightcache is ideal as a secondary bounces engine, since it's so fast. On top of that, when you use this combo, the LC is calculated first, and all the info from the LC is used for the calculation of the IR map. As a result, the IR map will be computed faster too.

When you're after extreme detail in your GI light, you're better off using the next combo, instead of increasing the IR map settings to extremes. Because then the IR map will become very slow too. So the IR map + LC is a good combo for relatively flat interior scenes.
Brute force and Light cache
For very good quality images, this is the way to go. Of course a lot slower than the other combo's, but still not as slow as brute force + brute force would be. This can be a very good combo for high quality interiors, but also for exteriors, product scenes and last but not least, animations wih moving objects.

The IR map has many problems with moving objects, since it is an approximate method, so each frame will have a slightly varying lighting solution. This results in 'flickering' of the GI light in your animation. By using an exact method like brute force, you can remove the flickering. Usually animations are outdoor, and when indoor, it is rendered in two passes so it's not really an interior render. So then you're again in the situation like product renders, where there is not that much secondary bounces and the brute force + LC will be quite fast.

As you can see in the image on the right, the rendertime becomes very high. But note the shadows that the teapots are casting. It shows detail that is completely lost in the other renderings.
Conclusion
GI is great to produce realistic images, but it is always a struggle between image quality and detail versus rendertimes. Each engine has it's advantages, so it's important to try them all so you know when to use which engine. Especially the IR map has many settings to control, which can increase rendertimes a lot if you don't know what you're doing.

#### 1 comment:

1. I can't view the images. It says that I do not have permission to view it.