December 01 2020

Unity Ray-Tracing: Get Started Now (Short Tutorial)


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.

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

  • Open Unity Hub
  • Create a 3D Unity project based on 2020.2 or later (these versions are better for ray-tracing)

End of project creation tutorial.

Next, let’s import HDRP and activate Ray-Tracing.

Import & Activate HDRP + DXR

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.

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.

Allow Screen-Space Effects

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:

  • Lighting → Screen Space Ambient Occlusion
  • Lighting → Screen Space Global Illumination
  • Lighting → Reflections → Screen Space Reflection
  • Lighting → Shadows → Screen Space Shadows

In my case, I wanted colored shadows. So I needed Screen Space Shadows.

Implement Ray-Tracing Effects

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.

HDRP: Creating Volumes

Then, go to Profile and select DefaultSettingsVolumeProfile.

Unity will add a ton of effects there.

HDRP Global Volume: Default Profile

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.

5-Signs-Need-Unity-Ray-Tracing-Thumbnail-v2

What’s Next?

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:

  1. Create a 3d project (Unity 2020.2+)
  2. Import HDRP (latest 10.2.0+)
  3. Enable HDRP + DXR & fix configuration
  4. Create your scene
  5. Allow your desired screen-space effects in project settings
  6. Implement ray-your tracing effects.

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.

5 Signs Need Unity Ray Tracing Thumbnail v2

You will learn a lot from that one 🙂

Ruben (The Gamedev Guru)

The Gamedev Guru Logo

Performance Labs SL
Paseo de la Castellana 194, Ground Floor B
28046 Madrid, Spain

This website is not sponsored by or affiliated with Facebook, Unity Technologies, Gamedev.net or Gamasutra.

The content you find here is based on my own opinions. Use this information at your own risk.
Some icons provided by Icons8