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!
giphy-confetti
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.
5-Signs-Need-Unity-Ray-Tracing-Thumbnail-v2
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
Ray-Traced Rectangle Light Shadows
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 Probes: Limitations
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 Screen-Space Reflections (SSR): Limitations
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.
crying-smiley-transparent
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