December 01 2020
December 01, 2020
If you read my visual series on Unity ray-tracing effects, I might have motivated you to give it a try.
But here’s one of the questions that I often get when it comes to ray-tracing in Unity: how do I get started?
In this blog post, I’ll show you my favorite way to get ray-tracing up & running.
P.S. This is part of the live Unity Now event I took part in on real-time ray-tracing.
First things first: you need the hardware.
That means: you need (as of today) a GTX 2000 series or above. Also, NVIDIA ported ray-tracing back to the 1000 series, just note it will be quite slower.
Okay, let’s create an empty project.
This section won’t take long. I’m sure there are a few tutorials out there about creating projects in Unity.
Here are the basics:
End of project creation tutorial.
Next, let’s import HDRP and activate Ray-Tracing.
Open Window → Package Manager and show the packages from the Unity Registry.
Then, look for the latest High Definition RP and install it. Something like 10.2.0 or above will work.
It will take a few minutes, so grab a coffee & relax.
Eventually, the HDRP Wizard will pop up. Here, you want to open the HDRP + DXR tab and press Fix all (issues).
After another while, Unity will ask you regarding HDRP assets & resources. Just tell Unity to create the default ones.
As the last step, Unity will politely ask you to restart the editor, since it changed its API to Direct X 12.
So be kind to Unity and restart the editor.
Good! HDRP is now ready to do ray-tracing.
What you need now is to create your scene.
Here is where you create or import the HDRP scene you want to play with.
In my case, I went the efficient (lazy) way and got a package from the asset store. Don’t blame me, I am no artist.
Anyway, I spent quite some time upgrading it to HDRP, but hey…
Get something in your scene. Even if it’s just a plane as your ground and a few spheres on top.
The next step is to add support to screen-space effects in your project.
In this step, you are going to allow the ray-tracing effects that you want in your scene.
You do this by navigating to your Edit → Project Settings and opening the HDRP tab.
There, you will have plenty of options. Got you scared? That’s ok, it’s quite a common reaction.
Depending on the ray-tracing effect you want to use, you need to tick specific checkboxes.
But since you are playing around, you can just activate support for all screen-space effects. Don’t be shy about it.
Here are they:
In my case, I wanted colored shadows. So I needed Screen Space Shadows.
Okay, now you are ready to start using ray tracing.
Which effect do you want to start with?
You control most effects through rendering volumes. Create a new one by right-clicking on the hierarchy and selecting Volume → Global Volume.
Then, go to Profile and select DefaultSettingsVolumeProfile.
Unity will add a ton of effects there.
That’s the place where you add and tweak most of the effects.
These effects are raster-based by default. But for some effects, you also have the choice to go for the ray-tracing variant. That’s the case of Ambient Occlusion, for instance.
One of the most noticeable ray-tracing effects is Screen-Space Reflections (Add Override → Lighting). You just need a high-metallic, high-smooth material and you’ll be able to see off-screen reflections.
With the raster-based variant, you can only see on-screen reflections, which is a big limitation.
Below is a sample scene I got from the Wreck ‘n’ Ships Package in the Asset Store (careful, it’s a referral link! these few cents will me help pay a few streaming seconds of this video). Binary Impact is the author of this beautiful package (make sure to check out their Youtube & Twitch channels btw).
Regarding ray-tracing, I added a couple of perfectly reflective surfaces to show screen-space ray-traced reflections.
For colored shadows, for instance, you set up ray-tracing shadows in your directional light instead of in your volume. Here’s another scene I set up.
In any case, it’s best to check the documentation of the specific ray-tracing effect you want to use.
Yup, I know it’s been a lighting-fast tutorial.
I hope you have fewer questions than earlier… but something tells me that might not be the case.
But here’s the deal: the implementation details are not as important as getting the high-level picture first.
You can figure out the details later.
Stick with the general process for now:
And talking about ray-tracing effects. Do you know what they do?
Have a look at my most popular interactive blog post about ray-tracing.
You will learn a lot from that one 🙂
Ruben (The Gamedev Guru)