The Dark Side Of Ray-Traced Ambient Occlusion (RTAO)

Oct. 21, 2020
protect

In this post, you will learn the magic behind Unity Ray-Traced Ambient Occlusion (RTAO).

Today, you will see:

  • What ambient occlusion will do for you

  • The visual superiority of Ray-Traced Ambient Occlusion (RTAO) over Screen-Space Ambient Occlusion (SSAO)

Let's get your game to look the way you always intended.

TABLE OF CONTENTS

Basics First: What Is Ambient Occlusion?

How Does Screen-Space Ambient Occlusion (SSAO) Look Like in Unity?

How Better Is Unity Ray-Traced Ambient Occlusion (RTAO)?

The Ray-Traced AO Parameters You Can Play With

  RTAO Intensity

  RTAO Direct Lighting Strength

  RTAO Ray Length

  RTAO Sample Count

  RTAO Denoise

  RTAO Denoise Radius

The Performance Cost of Ray-Traced Ambient Occlusion in Unity

What's Next?

Basics First: What Is Ambient Occlusion?

Let's first bring the topic of ambient occlusion to the real world. It'll help you understand why you need this effect in your Unity game.

The next time you go out during daylight, pay attention to the world around you.

The reason you can see surfaces is because of the light coming from the sun. Sunlight hits the surfaces and part of that light is reflected into your eye.

That's what we call direct lighting and we have been doing that in graphics pretty well for decades.

However, light can also bounce to other surfaces, not just to your eyes. And some of these future bounces will end up reaching your eyes, increasing the perceived brightness of that spot in the surface.

That's what we call indirect lighting. And in graphics we have a bigger problem with indirect lighting because it's very expensive to calculate in real-time.

Here's an example of indirect lighting. The purple lights are not directly hitting the chairs, but the rays indirectly reach them. That makes them look purple.

Indirect lighting (source: loxone.com)

Now, talking about light bounces...

Light doesn't reach all surfaces equally.

Think of a long but narrow pipe. If you look through it, you will see how its inner surface darkens as you look deeper into it.

You will see the same darkening effect in isolated corners and in the gaps between objects, e.g. bricks.

Why?

Because fewer light rays hit those areas. They are more occluded, i.e. they have a smaller exposed surface. They have a lower chance of receiving bounced light.

That's why secluded areas look darker in real life.

Clay (credits: Sebastian Zapata)

Like I said, in graphics we are quite capable of doing direct lighting. And very often we simulate indirect lighting by brightening up the whole scene through ambient lighting. Simply put, that's often a constant color we add to every pixel.

The problem?

Now these secluded areas don't look as dark as they should. We added a constant color in our scene, not taking into account the occlusion of the surfaces.

And this is why we had to come up with a technique called Ambient Occlusion (AO).

AO is a rendering technique that simply darkens less-exposed spots. AO adds "fake shadows" to these "secluded" areas because the traditional graphics rendering methods hardly take real indirect lighting into account.

With AO, hard to reach areas become darker. And your eyes will appreciate it, as otherwise it'll look quite artificial.

But let's cut the chat for a bit. We want pictures.

How does ambient occlusion look like?

How Does Screen-Space Ambient Occlusion (SSAO) Look Like in Unity?

(Ok, just a few short paragraphs first. They're important)

The traditional method of rendering ambient occlusion is to use a post-processing effect.

We call it Screen-Space Ambient Occlusion. It is screen-space because we use information coming from the current frame/screen to add these fake shadows on top of the surfaces.

In Unity, you add SSAO by using post-processing volumes. You can do this in URP, HDRP and the built-in render pipeline. It's quite easy, really.

I'd love to go on, but I promised to cut the chat for a bit.

Let's see the visual impact of Ambient Occlusion.

Screen-Space Ambient Occlusion (SSAO)

Use the slider below to see the effect that ambient occlusion has on the realism of a scene (this redirects to my blog)

You see the areas around edges and inner surfaces becoming darker?

Without AO, there'll be something off about all your graphics. And SSAO is not perfect, as we will discuss later. But it helps add some realism.

Ok, now that you see what AO does... Let's talk about something important.

While SSAO is the typical method for rendering AO, there are other ways.

For example, we can use Unity Lightmapper to bake the ambient occlusion into your (static) scene during editor time. This kinda means that Unity generates a darker texture that we paint on top of your original textures (simplified explanation).

Baked AO looks well, although baking it takes timetweaking effort and it has a memory performance hit on your target device.

And now we come to the main point of this post...

There's new method of rendering Ambient Occlusion in real-time with more accuracy.

Any guess?

Real-time Ray-Traced Ambient Occlusion (RTAO).

Let's get to it.

decoration-meme-mind-blown

How Better Is Unity Ray-Traced Ambient Occlusion (RTAO)?

If you can recall it, SSAO only works with data in your current frame (your frame buffer). This incomplete information leads to inaccuracies, just like with most screen-space post-processing effects like reflections. After all, we are missing information about the rest of the scene.

The big advantage of Ray-Traced AO over Screen-Space AO is that it works with information of the entire scene (off-screen data).

But what about baked AO? After all, I said Unity Lightmapper does a great job at rendering AO.

Well, the main issue is that baked AO only works with static objects. I mean, it's pre-baked. And it takes baking (and human) time to get it right.

That's why you should consider real-time ray-traced AO for your project.

RTAO brings the best of both worlds:

  • RTAO looks much better than SSAO (as it works with complete information).

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>>