Ray Tracing in Unity with HDRP

In this webinar originally created for NVIDIA, I demonstrate how to use the ray tracing effects provided by Unity’s High Definition Render Pipeline (HDRP). I showcase in detail ray-traced ambient occlusion, reflections, global illumination, shadows, and path tracing.

I also explain how to use the various debug views to isolate these effects and offer recommendations to ensure a suitable frame rate for a wide variety of use cases, from games to high-end visualizations.

Ray Traced Ambient Occlusion (RTAO)

The screen-space ambient occlusion (SSAO) has been a staple of real-time rendering for games for more than a decade. It is used to simulate the environment’s diffuse occlusion, in order to improve visual contact between objects in the world and darken the lighting in concave areas. However, this effect, when pushed too far, can produce halos around geometries, and even a cartoony look. On top of it, one of the main drawbacks of this screen-space technique is its inability to generate occlusion from objects which reside outside the frame, as it only relies on the depth information available in the z-buffer. On the plus side, this effect is still great at handling micro occlusion of small areas in the camera’s perspective, for a relatively low-performance cost.

Hopefully, thanks to Ray Tracing, rays can be shot at surfaces beyond the camera frustum, and therefore they are able to reach objects located outside the frame. This way, you can get great macro occlusion from large objects located all around the camera. Although technically AO is only a rough approximation of environment lighting, it can complement other lighting techniques such as lightmaps or lightprobes, whose resolution or density is limited and therefore unable to capture micro occlusion.

Ray Traced Reflections (RTR)

In a similar fashion to SSAO, screen-space reflections (SSR) can only reflect objects located in the frame: again, surfaces that aren’t immediately visible to the camera cannot be reflected. For instance, looking at the floor will result in the SSR technique being unable to provide any useful information. Therefore, SSR is very approximative, and this technique tends to have many detractors, including yours truly, as a good placement of static Reflection Probes can often provide more appealing and less distracting results for most static scenarios. However, one area where SSR shines literally is when dealing with planar reflections for surfaces parallel to the view direction, such as floors, walls, and ceilings. An optimal use-case for SSR would be a camera whose pitch is locked, such as in a racing game.

With Ray Tracing, however, we are able to get access to information that resides outside the screen, and as a consequence, we can offer a more exact reflection of the world, at least within a certain radius around the camera, defined by the Light Cluster and the length of the rays.

Ray Traced Global Illumination (RTGI)

One of the most impressive features of Ray Tracing is the ability to generate real-time global illumination, that is the simulation of indirect lighting, or simply put, the lighting bouncing in the environment.

Typically in game engines, the indirect lighting is handled with pre-computed or baking techniques, such as light probes or lightmaps, and they can greatly slow down the iteration time of artists and designers dealing with the lighting.

Thankfully, HDRP offers 2 techniques for RTGI: a Performance and a Quality one. The former is geared towards high frame rate scenarios in direct light, whereas the second one can provide very accurate results in more complex interiors thanks to multiple bounces and samples, for a very high computational cost nonetheless.

Ray-traced Shadows

Out of the box, when using the High shadow filtering quality (PCSS), HDRP provides great looking shadow maps that simulate the natural smoothness of shadows, while ensuring they remain sharp near the shadow casters, like in real life. However, when using the cheaper Medium filtering quality, results can be underwhelming, as the entire shadow map is filtered uniformly, regardless of the distances between casters and receivers.

Results can be improved dramatically with Ray Traced shadows, by shooting rays from surfaces towards the lights to figure out the amount of occlusion between them. This can therefore provide an extremely realistic approximation of the shadowing, for a moderate performance cost. In addition, HDRP supports transparent shadows!

Credits

Pierre Yves Donzallaz (Technical Art Manager, Video Editor, Writer & Producer)
Anis Benyoub (Senior Graphics Developer)