A Lightning-Fast Presentation of Global Illumination in Unity 5

IronEqual
IronEqual
Published in
5 min readSep 16, 2017

Everything is in the title!

With Unity 5 comes Physically Based Rendering materials (PBR), but materials are only one part of the rendering. As we’ll see today, lighting is very important in order to make a scene more appealing to the eye. The goal of this article is not to dig deeply into lighting and Global Illumination but more to introduce the concept and quickly see the different options we have in Unity and their differences.

Direct and Indirect Lighting

When shading an object, the shader calculates the interaction between the object and the light received at a specified point.
When the light is coming directly from its emission point, we call that “direct lighting”.
When the light is coming after bouncing on surfaces (from 1 to infinity) we call that “indirect lighting”.

Direct lighting is pretty simple in unity: take a light (point, directional or spot) and what you’ll get by default is direct lighting.

Default Unity 5 lighting

As you can see, the result it not very appealing. Dark areas are black and it doesn’t seems so real. It’s because there isn’t any indirect lighting! Therefore it seems that indirect lighting is a key element to physically-based lighting. Indirect lighting is more complicated than a direct one because the light bounces depend not only on the emission source but also on the scene geometry! Calculating it entirely in realtime is still a challenge only a few technology have achieved (while still having limitations in some way). Unfortunately, there is no such technology built-in in Unity 5.

Let’s see what alternatives we have at our disposition to get that indirect lighting:

Ambient Lights and Skyboxes

The concept behind an Ambient Light is to lit every object with an omnidirectional light.

We added an ambiant light

While it’s better than before (with the right Ambient light we can notice some detail in the shadows), it’s still seems fake.
One way to increase the fidelity is to use a skybox as ambient source. A skybox, is an omnidirectional texture : for every direction you can sample a color. This way the ambient light is different according to the normal of the object.

With a skybox

Static and Dynamic Objects

Before going further, I need to present the very simple concept of dynamic and static objects in Unity.
Static object can’t be changed (moved, rotated, scaled, material changed or animated) while dynamic ones can. This concept isn’t limited to lighting, therefore there are different static attributes on a gameObject (it can only be lightmap static, navigation static etc…)

Static Attributes

In this article we’re only focused on the the lightmap static.

Baked Global Illumination

With a baked Global Illumination, we can bake the Indirect lighting into lightmaps during the build time and decode it during the runtime.
The main drawback is that only static geometry and static lights are influencing the indirect lighting. While dynamic objects can receive indirect lighting using light probes, they have no effect on it. With baked GI, you can’t have a dynamic night and day cycle, any dynamic lights won’t affect the GI. Another drawback is the baking time, for large scenes the baking time can be huge (from minutes to hours)…

Our same scene with some static attributes and an baked Global Illumination

As you can see the result is very appealing and you can get extra effects like Ambient Occlusion baked into the lightmap to increase the fidelity.

Precomputed Realtime Global Illumination

Don’t be mislead, even if it says realtime in its name, it still has to precomputed.
The concept behing Precomputed Realitme Global Illumination is to bake partial informations about the scene geometry and to compute with these datas the final output at runtime.
This way, only the geometry needs to be static, the lights can move, change in intensity and color and still contribute to the GI. It’s a huge step forward, because with this technique you can have night and day cycle and still have a good global illumination.

Precomputed Realtime Global Illumination

It still requires static geometry and you can still use light probes to affect dynamic geometry. You can also notice that effect such as AO are not present anymore. One annoying thing to note is that point lights and spot lights don’t support indirect shadows. It means that indirect lighting will go through objects. While most of the time it’s not very important, it can in some context seem very faked so be careful about that.

The light on the left is responsible for all the indirect light you see on the right, even if it’s not it the same room!

Emissive Objects

Finally Emissive objects are a special case because they’re at the same time considered as geometry and lights.
On top of that, the direct lighting coming from these objects is far more complicated to calculate. Therefore, to get any kind of lighting from these you will need to use either baked GI or realtime GI. In both cases the object will need to be static. Don’t forget to set the Global Illumination in the material. The difference between baked GI and realtime GI is that you can change the emitted color in realtime GI (you need to call a function to update the GI: RendererExtensions.UpdateGIMaterials)

The sphere above the cube is set as an emissive object

Global Illumination is a vast subject, and there is a lot of thing I didn’t speak of in this article. It’s a key element to visual fidelity and you shouldn’t overlook it. This introduction will be used for us as a point of reference in future articles.

--

--

IronEqual
IronEqual

Indie gaming studio. Bringing you awesome content randomly!