5 Signs You Need Ray-Tracing Now

Published October 12, 2020 by Ruben Torres Bonet (The Gamedev Guru)
Do you see issues with this article? Let us know.
Advertisement

Developing your game in Unity? Then you need to pay attention to 5 signs that reveal you should to move into Ray-tracing.

Let's celebrate this new series on Ray-tracing in Unity here at The Gamedev Guru.

Woohoo!

Ok, that celebration will do for now.

In this new series, you will learn how to craft high-fidelity and high-performance graphics for your game through ray-casting.

Let's get started with the first blog post.

Here are 5 sneaky signs that you might experience that are pushing you to move into Ray-tracing.

TABLE OF CONTENTS

Sign 1: Your Reflections Look Broken

Sign 2: Long Lightmap Baking Sessions That Lead to Nowhere

Sign 3: Your SSAO Isn't Punchy Enough

Sign 4: Which Contact Shadows?

Sign 5: These Shadows Are Limiting Your Creativity

The Sun Angle

Colored Shadows

Adjustable Light Radius

Ray-Traced Rectangle Light Shadows

Acknowledgments

What's Next?

Sign 1: Your Reflections Look Broken

You want reflections in your game.

Shiny marble, metallic and smooth surfaces or just a mirror.

Most games may well have reflective materials.

So you go ahead and add a reflection probe. You bake it to capture what's around it and you're good to go with your:

  • Standard shader.
  • Lit shader in HDRP/URP.

These shaders will take well care of reflections on metallic and shiny surfaces.

However, more often than not the reflection will look off.

Have a look at this animation:

Unity Baked Reflection Probe Limitations

The reason is that we baked the reflection probe from a specific location. However, we use that captured reflection from different locations. Unity can only correct this mismatch by using approximations that distort the visual output.

Unity will do its best to deliver accurate reflections. But it is just not possible with missing information.

Worse yet, you are missing dynamic objects from the reflections since it's a baked reflection probe.

We would need real-time reflection probes to capture the reflections we need to achieve more accuracy. Possibly more than one.

And that's not a price we can pay. In average, adding a RT reflection probe will just double our draw calls and add significant GPU overhead.

So here's another approach you might take: Screen Space Reflections (SSR).

SSR is a screen-space effect that adds reflections to reflective surfaces on the screen.

And it does so by "mirroring" the reflected pixels on the screen.

That means: you won't see the reflection of these pixels that are not in the screen. It is a screen-space effect, after all.

If you're looking right at your marble floor, you won't see the reflected ceiling. The ceiling is not part of your framebuffer in that frame, hence you can't see it in the reflection.

Here's what I mean:

Unity SSR Reflections Limitations

What to do... what to do...?

Hint: have you thought of ray-tracing in Unity?

Ray-traced reflections actually do ray-tracing. That means, these rays can go offscreen to capture elements you don't have in the framebuffer.

Here's a comparison between SSR and Ray-traced reflections (use the slider to see the differences).

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Reflections)

Perfect reflections. (More) realistic.

With ray-traced reflections, you get the best of both worlds (screen-space reflectionsand real-time reflection probes) at a fraction of the cost (hardware-accelerated ray tracing).

Let's move on to the sign 2.

Sign 2: Long Lightmap Baking Sessions That Lead to Nowhere

Your level is almost ready.

You spent a few hours tweaking the lighting settings and adding light probes to get the perfect illumination.

Indirect lighting is important for your visual target. With that you agree.

So you start the baking process and go to bed.

The next morning, you wake up feeling like Christmas. You go to your PC to get your gifts.

You unlock your computer, alt-tab to Unity and see the results.

What the hell?

The baked lighting looks completely broken.

You wash your eyes just to be sure.

No. It's not your sight. The visual artifacts are still there.

Even worse, you produced 8 huge lightmap textures to cover the entire level.

That's a lot of memory... I bet your players wouldn't like it.

The traditional wisdom tells you:

Keep iterating on your lighting setup until you get it right

...Only that you don't have unlimited time.

So what do you do instead?

You try Unity ray-traced global illumination.

After all, you only heard good things about it.

Except the performance hit. But you know hardware is catching up.

So talking about Global Illumination...

How does Ray-Traced Global Illumination look like?

Use the slider to find out.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing GI)

Not bad.

With ray-traced GI, you move the effort on baking time to real-time through ray-traced hardware.

If you have the performance budget to pay for ray-traced GI, it'll get you good results.

But I won't lie to you. It's expensive.

Next... What's the third sign you might need ray-tracing?

Sign 3: Your SSAO Isn't Punchy Enough

Screen-space Ambient Occlusion (SSAO).

That old friend that darkens occluded areas to simulate the lack of ambient light in tricky spots.

SSAO can be a "cheap" post-processing effect that improves the look of your scene.

But it will look fakey to the trained eye.

Just like with any screen-space effect, SSAO works with incomplete information. So you can't expect too much accuracy from SSAO.

But what if you could go offscreen? With a complete understanding of the entire scene, we could surely achieve better AO.. right?

Let's see how ray-traced ambient occlusion looks like in Unity.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Ambient Occlusion)

Which one do you like best?

Easy choice for me.

Now, let's talk about shadows...

Sign 4: Which Contact Shadows?

Contact shadows are those tiny shadows that you can't render with traditional shadow mapping. This happens because of the limited resolution of your shadow maps.

You often need contact shadows for small objects that are in close proximity to other surfaces.

HDRP lets you add contact shadows as a post-processing effect.

But again, these work with limited information. And you might not like the result.

So how can ray-tracing help us get better contact shadows?

Let's do a three-way comparison this time:

  • No contact shadows.
  • Screen-space contact shadows.
  • Ray-traced contact shadows.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Contact Shadows)

Again, the choice is clear for me.

And what about shadows in general?

Sign 5: These Shadows Are Limiting Your Creativity

Shadow mapping has its limitations.

But ray-traced shadows don't (apart from the higher performance cost).

With ray-traced shadows, you get better shadows and extra artistic parameters to play with.

These extra parameters will move your project closer to your artistic goals.

Here are some of these parameters:

  • Sun angle
  • Light radius
  • Colored shadows
  • Denoising

Let's check them out.

The Sun Angle

The sun angle is size of the sun in the sky measured in degrees. Basically:

  • A lower angle will give you hard-looking shadows.
  • A higher angle will make your shadows look softer.

By the way, shadows tend to look softer the more far away they are from the original object (the shadow caster).

Below you have another three-way comparison:

  • Shadow mapping (no ray tracing).
  • Ray-traced shadows: sun angle 0
  • Ray-traced shadows: sun angle 0.53.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Shadows Sun Angle)

What about colored shadows?

Colored Shadows

I don't believe in God but I personally like visiting churchs and monasteries. They are a truly amazing architectural feat.

What I often like most is the stained glasses. They project a colorful shadow onto the floor at the right time of the day.

Stained Glass (Colored Shadows)

Stained Glass (Colored Shadows)

So I always wondered how to recreate this effect in Unity.

In the past, I always had to resort to fake colored-planes. They did the trick but the workflow was quite rigid.

One small change in the scene and I had to redo everything again. Not to mention, I couldn't really adjust the daylight settings in real-time, e.g. the angle of the sun.

Good news for everyone now: Unity now supports ray-traced colored shadows out of the box.

A few settings in your directional light and your materials, and you're ready to go.

See the comparison below.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Colored Shadows)

Beautiful.

Adjustable Light Radius

With ray-tracing, you can now specify your light radius for your point and spot lights.

This radius is the size of the sphere representing your lights. Basically:

  • A small radius will give you hard shadows.
  • A bigger radius will get you in softer shadows.

See the comparison below.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Light Radius)

As a game developer, this parameter means freedom.

Freedom to alter radically the way your game looks... in real-time.

Last, let's have a look at rectangle lights.

Ray-Traced Rectangle Light Shadows

Rectangle lights are a beautiful addition to any game. They really look great and add an immersive atmospheric effect to the players' experience.

Unity supports rentangle lights for some time already. You just need to set your light type to Area and your light shape to rectangle.

And again, the trained eye will quickly see the limitations of rectangle lights.

I'm talking about the shadows that these rectangle lights project. They will look weird on surfaces with reflective materials.

To show you that, below is a comparison between rectangle area lights and ray-traced rectangle lights.

(Sorry, I can't get my slider to work on here due to custom javascript. To see the comparison, visit Unity Ray-Tracing Rectangle Shadows)

With ray-tracing, we take advantage of the information of the entire scene through consecutive light bounces. And this results in more accurate shadows on irregular surfaces.

Yup. Much better.

It's been a long post. So let's wrap this up and warm up for the upcoming posts.

Acknowledgments

Big thanks to:

  • NVIDIA for sending me a beefy Titan GPU. Without NVIDIA technology, I would not have been able to write this post.
  • Unity for promoting my content and offering support in the area of graphics. In fact, I took most pictures from their HDRP documentation (thanks!).

What's Next?

This visual guide is just the start of a brand new series on ray-tracing in Unity.

I hope you enjoyed it.

In the upcoming Ray-tracing posts, you will learn:

  • When to use each ray-tracing effect in your project.
  • What do they mean to you.
  • The performance cost of ray-tracing effects.
  • How to make your own ray-tracing effects.

Subscribe to The Gamedev Guru newsletter below to embark in this ray-tracing journey with me.

By subscribing to the newsletter, you will get:

  • A 5-day introduction to Unity game performance.
  • A weekly e-mail on high-performance Unity game development and ray-tracing.

~ Ruben (The Gamedev Guru)

The Gamedev Guru Logo
Cancel Save
0 Likes 0 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

Featured Tutorial

Developing your game in Unity? Then you need to pay attention to 5 signs that reveal you should to move into Ray-tracing.

Advertisement
Advertisement