The Bright Side of Ray-Traced Global Illumination 2

Nov. 10, 2020
protect

[Recommended: read the original blog post "Unity ray-traced global illumination" for proper interactive content]

Let's get back to ray tracing with global illumination in Unity. Discover what global illumination is and choose the better fit for your game:

  • Baked GI

  • Screen-space Raster GI

  • Screen-Space Ray-traced GI

Unity-Ray-Tracing-Global-Illumination-Thumbnail

TABLE OF CONTENTS

Can You Guess What's Missing in This Scene?

What's Unity Global Illumination?

Your Options for Global Illumination in Unity

  3.1 Unity Baked Global Illumination

  3.2 Unity Screen-Space Global Illumination (SSGI)

  3.3 Ray-Traced Global Illumination in Unity

The Performance Cost of Ray-Traced Global Illumination in Unity

Next Steps

Can You Guess What's Missing in This Scene?

Take a second to have a look at the screenshot below.

Can you guess what is this picture missing to be... visually "appealing"?

It's looking either too bright or too dark. That's not an easy thing to see in real life.

Why?

Because light bounces between surfaces.

These bounces soften the "transitions" between bright and dark areas. And you don't see that happening in the screenshot above. 

Now, let's see something more realistic.

Have a look below. Use the slider to transition to a more "visually correct" scene:

Is Global Illumination Overrated? (Answer: NO)

What's the difference?

Global illumination (GI). To be more specific, indirect illumination.

Let's quickly explain how GI works.

What's Unity Global Illumination?

Like I said, light rays bounce off surfaces and lose energy in the process (e.g. brightness, a change in color, etc.). Eventually, light will reach your eyes from different surfaces.

In graphics, we distinguish between:

  • Direct lighting: the sun light hits the floor and reflects into your eyes. That lets you see that specific fragment on the floor.

  • Indirect lighting: the sun light hits the floor, bounces to your hand watch and then bounces towards someone's eyes. That person becomes temporarily stunned.

The difference is that GI takes more bounces into account. Not just one.

Direct lighting is easy and cheap to calculate. Indirect lighting, not so much.

So, how do you do indirect lighting* in Unity?

Here are your options.

* I use the words indirect lighting and global illumination interchangeably. In theory, they're not the same. But in practice, we treat them as if they were.

Your Options for Global Illumination in Unity

Let's build an ultra-simple scene to see and compare the different methods you have in Unity to do global illumination.

Here's the scene we are building:

Light Bounces Global Illumination Diagram

First, take a deep breath and enjoy my drawing skills.

Now, let's explain it.

A wall is covering/occluding another wall, which in real-life would prevent light from reaching it.

However, there's a small gap below.

This bottom gap will allow some sun rays to "escape" the big wall and reach the wall behind after these rays bounce off the floor.

The diagram is clear, right?

Here's how our baseline (just direct lighting + shadows) looks in Unity.

Global Illumination Scenario

We won't use that angle. It's hard to see the effect of indirect lighting later on.

Here's a better angle.

Global Illumination Baseline (No GI)

The wall behind is quite dark.

No global illumination means light is not bouncing. Our black shadow on that wall remains untouched with no secondary light rays coming in.

Not what you want in your game. Nope.

So let's improve this scenario and add some GI with our first method: baked global illumination(Unity Lightmapper).

Unity Baked Global Illumination

Baking global illumination is the cheapest way to do global illumination.

We do all these expensive calculations offline (in the editor). That process produces textures that we later "paint on top" of our scene.

It takes some effort to get the results you want with this method, as there are many settings to play with. And baking takes time.

But once you get it right, it looks great.

In fact, it's probably the best-looking method out there to do (static) global illumination.

The downsides?

Well, it only works with static geometry.

I mean, you can use light probes to add some indirect illumination to dynamic (moving) elements. But that also goes with many downsides.

Anyway, let's see how it looks.

Use the slider to see the evolution from no GI to baked GI.

Just like I promised you, it looks more... correct*.

* You know what I mean. Not the simplified scene per se, but the indirect lighting.

However, did you ever play an interactive game with just static elements?

No, you say?

That's why we need more options.

One is to use light probes together with baked GI. The issue with light probes is that you need many of them to have smooth indirect lighting transitions. And guess what? That's going to break batching for good.

Let's consider instead something else: Screen-space (Raster) Global Illumination.

Unity Screen-Space Global Illumination (SSGI)

The idea with SSGI is simple. It's execution is not.

We analyze the rendered frame (G-buffer) and guesstimate the way light should bounce between surfaces that are within that frame.

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Read More>>