Getting started with ray tracing
The High Definition Render Pipeline (HDRP) includes preview ray tracing support from Unity 2019.3. Ray tracing allows you to access data that is not on screen. For example, you can use it to request position data, normal data, or lighting data, and then use this data to compute quantities that are hard to approximate using classic rasterization techniques.
This document covers:
- Hardware requirements.
- Integrate ray tracing into your HDRP Project.
- HDRP effects that use ray tracing.
Hardware requirements
Full ray tracing hardware acceleration is available on following GPUs:
- NVIDIA GeForce 20 series:
- RTX 2060
- RTX 2060 Super
- RTX 2070
- RTX 2070 Super
- RTX 2080
- RTX 2080 Super
- RTX 2080 Ti
- NVIDIA TITAN RTX
- NVIDIA GeForce 30 series:
- RTX 3060
- RTX 3060Ti
- RTX 3070
- RTX 3080
- RTX 3090
- NVIDIA Quadro:
- RTX 3000 (laptop only)
- RTX 4000
- RTX 5000
- RTX 6000
- RTX 8000
NVIDIA also provides a ray tracing fallback for some previous generation graphics cards:
- NVIDIA GeForce GTX
- Turing generation: GTX 1660 Super, GTX 1660 Ti
- Pascal generation: GTX 1060 6GB, GTX 1070, GTX 1080, GTX 1080 Ti
- NVIDIA TITAN V
- NVIDIA Quadro: P4000, P5000, P6000, V100
If your computer has one of these graphics cards, it can run ray tracing in Unity.
Before you open Unity, make sure to update your NVIDIA drivers to the latest version, and also make sure your Windows version is at least 1809.
Integrating ray tracing into your HDRP Project
Before you use ray tracing features in your HDRP Project, you need to set up your HDRP Project for ray tracing support. HDRP only supports ray tracing using the DirectX 12 API, so ray tracing only works in the Unity Editor or the Windows Unity Player when they render with DirectX 12. You need to change the default graphics API of your HDRP project from DirectX 11 to DirectX 12.
There are two ways to do this:
Once you have completed one of these, move onto Final setup.
Render Pipeline Wizard setup
You can use the Render Pipeline Wizard to set up ray tracing in your HDRP Project.
- To open the HDRP Wizard, go to Window > Rendering > HDRP Wizard.
- Select the HDRP + DXR tab.
- Click the Fix All button.
- (Optional) Enable the HDRP asset features that are required for the ray tracing effects.
Your HDRP Project now supports ray tracing. For information on how to set up ray tracing for your Scene, see final setup.
Manual setup
To set up ray tracing manually, you need to:
- Make your HDRP project use DirectX 12.
- Disable static batching on your HDRP project.
- Enable and configure ray tracing in your HDRP Asset.
- Ensure ray tracing resources are properly assigned.
- (Optional) Enable ray-traced effects in your HDRP Asset.
Upgrading to DirectX 12
- Open the Project Settings window (menu: Edit > Project Settings), then select the Player tab.
- Select the Other Settings fold-out, and in the Rendering section, disable Auto Graphics API for Windows. This exposes the Graphics APIs for Windows section.
- In the Graphics APIs for Windows section, click the plus (+) button and select Direct3d12.
- Unity uses Direct3d11 by default. To make Unity use Direct3d12, move Direct3d12 (Experimental) to the top of the list.
- To apply the changes, you may need to restart the Unity Editor. If a window prompt appears telling you to restart the Editor, click Restart Editor in the window.
The Unity Editor window should now include the <DX12> tag in the title bar like so:
Disabling static batching
Next, you need to disable static batching, because HDRP does not support this feature with ray tracing in Play Mode. To do this:
- Open the Project Settings window (menu: Edit > Project Settings), then select the Player tab.
- Select the Other Settings fold-out, then in the Rendering section, disable Static Batching.
HDRP Asset configuration
Now that Unity is running in DirectX 12, and you have disabled static batching, enable and configure ray tracing in your HDRP Asset. The previous steps configured Unity to support ray tracing; the following step enables it in your HDRP Unity Project.
- Click on your HDRP Asset in the Project window to view it in the Inspector.
- In the Rendering section, enable Realtime Ray Tracing. This triggers a recompilation, which makes ray tracing available in your HDRP Project.
Ray tracing resources
To verify that HDRP has properly assigned ray tracing resources:
- Open the Project Settings window (menu: Edit > Project Settings), then select the HDRP Default Settings tab.
- Make sure there is a Render Pipeline Resources Asset assigned to the Render Pipeline Resources field.
(Optional) Enable ray-traced effects in your HDRP Asset
HDRP uses ray tracing to replace certain rasterized effects. In order to use a ray tracing effect in your Project, you must first enable the rasterized version of the effect. The four effects that require you to modify your HDRP Asset are:
- Screen Space Shadows
- Screen Space Reflections
- Transparent Screen Space Reflections
- Screen Space Global Illumination
To enable the above effects in your HDRP Unity Project:
- Click on your HDRP Asset in the Project window to view it in the Inspector.
- Go to Lighting > Reflections and enable Screen Space Reflection.
- After enabling Screen Space Reflections, go to Lighting > Reflections and enable Transparent Screen Space Reflection.
- Go to Lighting > Shadows and enable Screen Space Shadows.
- Go to Lighting > Lighting and enable Screen Space Global Illumination.
Your HDRP Project now fully supports ray tracing. For information on how to set up ray tracing for your Scene, see final setup.
Final setup
Now that your HDRP Project supports ray tracing, there are a few steps you must complete in order to actually use it in your Scene.
Frame Settings
To make HDRP calculate ray tracing effects for Cameras in your Scene, make sure your Cameras use Frame Settings that have ray tracing enabled. You can enable ray tracing for all Cameras by default, or you can enable ray tracing for specific Cameras in your Scene.
To enable ray tracing by default:
- Open the Project Settings window (menu: Edit > Project Settings), then select the HDRP Default Settings tab.
- Select Camera from the Default Frame Settings For drop-down.
- In the Rendering section, enable Ray Tracing.
To enable ray tracing for a specific Camera:
- Click on the Camera in the Scene or Hierarchy to view it in the Inspector.
- In the General section, enable Custom Frame Settings. This exposes Frame Settings just for this Camera.
- in the Rendering section, enable Ray Tracing.
Build settings
To build your Project to a Unity Player, ray tracing requires that the build uses 64 bits architecture. To set your build to use 64 bits architecture:
- Open the Build Settings window (menu: File > Build Settings).
- From the Architecture drop-down, select x86_64.
Scene validation
To check whether it is possible to use ray tracing in a Scene, HDRP includes a menu option that validates each GameObject in the Scene. If you do not setup GameObjects correctly, this process throws warnings in the Console window. For the list of things this option checks for, see Menu items. To use it:
- Click Edit > Rendering > Check Scene Content for HDRP Ray Tracing.
- In the Console window (menu: Window > General > Console), check if there are any warnings.
Ray tracing effects overview
HDRP uses ray tracing to replace some of its screen space effects, shadowing techniques, and Mesh rendering techniques.
- Ray-Traced Ambient Occlusion replaces screen space ambient occlusion with a more accurate, ray-traced, ambient occlusion technique that can use off screen data.
- Ray-Traced Contact Shadows replaces contact shadows with a more accurate, ray-traced, contact shadow technique that can use off screen data.
- Ray-Traced Global Illumination is an alternative to Light Probes and lightmaps in HDRP.
- Ray-Traced Reflections is a replacement for screen space reflection that uses a ray-traced reflection technique that can use off-screen data.
- Ray-Traced Shadows replace shadow maps for Directional, Point, and Area Lights.
- Recursive Ray Tracing replaces the rendering pipeline for Meshes. Meshes that use this feature cast refraction and reflection rays recursively.
- Ray-Traced Subsurface Scattering replaces subsurface scattering with a more accurate, ray-traced, subsurface scattering technique that can use off screen data.
Ray tracing and Meshes
HDRP changes how it handles Meshes in your scene when you integrate a ray traced effect into your project.
When you enable ray tracing, HDRP automatically creates a ray tracing acceleration structure. This structure allows Unity to calculate ray tracing for Meshes in your scene efficiently in real time.
As a result, ray tracing can change how some Meshes appear in your scene in the following ways:
- If your Mesh has a Material assigned that does not have the HDRenderPipeline tag, HDRP does not add it to the acceleration structure and does not apply any ray traced effects to the mesh as a result.
- If your Mesh has a Decal Material assigned, HDRP does not add it to the acceleration structure and the Mesh does not appear in your scene.
- If a Mesh has a combination of Materials that are single and double-sided, HDRP flags all Materials you have assigned to this mesh as double-sided.
Ray tracing light culling
Ray tracing requires HDRP to cull lights differently to how it culls lights for rasterization. With rasterization, only lights that affect the current frustum matter. Since ray tracing uses off-screen data for effects such as reflection, HDRP needs to take into account lights that affect off screen geometry. For this reason, HDRP defines a range around the camera where it gathers light. To control this range, use the Light Cluster Volume override. It is important to set a range that accurately represents the environment scale. A higher range makes HDRP include lights further away, but it also increases the resource intensity of light culling for ray tracing.
Ray tracing mode
HDRP includes two ray tracing modes that define how it evaluates certain ray-traced effects. The modes are:
- Performance: This mode targets real-time applications. If you select this mode, ray-traced effects include presets that you can change to balance performance with quality.
- Quality: This mode targets technical demos and applications that want the best quality results.
Depending on which ray tracing mode you select, HDRP may expose different properties for some ray-traced effects.
You can change which ray tracing mode HDRP uses on either a Project level or effect level. To change it for your entire Project:
- Click on your HDRP Asset in the Project window to view it in the Inspector.
- In the Rendering section, select a ray tracing mode from the Supported Ray Tracing Mode drop-down.
If you select Both, you can change the ray tracing mode for each ray-traced effect. To do this:
- In the Scene or Hierarchy view, select a GameObject that contains a Volume component that includes a ray-traced effect.
- In the Inspector for the ray-traced effect, change the Mode property to use the ray tracing mode you want the effect to use. This changes the properties available in the Inspector.
Ray tracing project
You can find a small ray tracing project that contains all the effects mentioned above here: https://github.com/Unity-Technologies/SmallOfficeRayTracing This Project is already set up with ray tracing support.
Limitations
This section contains information on the limitations of HDRP's ray tracing implementation. Mainly, this is a list of features that HDRP supports in its rasterized render pipeline, but not in its ray-traced render pipeline.
Unsupported features of ray tracing
There is no support for ray tracing on platforms other than DX12 for now.
HDRP ray tracing in Unity 2020.2 has the following limitations:
- Does not support vertex animation.
- Does not support decals.
- Does not support tessellation.
- Does not support per pixel displacement (parallax occlusion mapping, height map, depth offset).
- Does not support VFX and Terrain.
- Does not have accurate culling for shadows, you may experience missing shadows in the ray traced effects.
- Does not support MSAA.
- Does not support Graphics.DrawMesh.
- Ray tracing is not supported when rendering Reflection Probes.
- HDRP does not support orthographic projection. If you enable orthographic projection mode, you might experience rendering problems for Transparent Materials, volumetrics and planar reflections.
Unsupported shader graph nodes for ray tracing
When building your custom shaders using shader graph, some nodes are incompatible with ray tracing. You need either to avoid using them or provide an alternative behavior using the ray tracing shader node. Here is the list of the incompatible nodes:
- DDX, DDY and DDXY nodes.
- All the nodes under Inputs > Geometry (Position, View Direction, Normal, etc.) in View Space mode.
- Checkerboard node.
Unsupported features of path tracing
For information about unsupported features of path tracing, see Path tracing limitations.