Path tracing
Path tracing is a ray tracing algorithm that sends rays from the Camera and, when a ray hits a reflective or refractive surface, recurses the process until it reaches a light source. The series of rays from the Camera to the Light form a "path".
It enables HDRP to compute many different effects (such as hard or soft shadows, mirror or glossy reflections and refractions, and indirect illumination) in one single unified process.
A notable downside to path tracing is noise. However, noise vanishes as more paths accumulate, and eventually converges toward a clean image. For more information about path tracing limitations in HDRP, see Unsupported features of path tracing.
Noisy image with Maximum Samples set to 1
Clean image with Maximum Samples set to 256
The current implementation for path tracing in the High Definition Render Pipeline (HDRP) accumulates paths for every pixel up to a maximum count unless the Camera moves. If the Camera moves, HDRP restarts the path accumulation. Path tracing supports Lit, LayeredLit, Stacklit, AxF, and Unlit materials, and area, point, directional, and environment lights.
Setting up path tracing
Path tracing shares the general requirements and setup as other ray tracing effects, so for information on hardware requirements and set up, see getting started with ray tracing. You must carry out this setup before you can add path tracing to your Scene.
Adding path tracing to a Scene
Path tracing uses the Volume framework, so to enable this feature, and modify its properties, you must add a Path Tracing override to a Volume in your Scene. To do this:
- In the Scene or Hierarchy view, select a GameObject that contains a Volume component to view it in the Inspector.
- In the Inspector, select Add Override > Ray Tracing > Path Tracing.
- In the Inspector for the Path Tracing Volume Override, check the Enable option. If you do not see the Enable option, make sure your HDRP Project supports ray tracing. For information on setting up ray tracing in HDRP, see getting started with ray tracing. This switches HDRP to path-traced rendering and you should initially see a noisy image that converges towards a clean result.
- If the image does not converge over time, select the drop-down next to the effect toggle and enable Always Refresh.
Properties
Property | Description |
---|---|
Maximum Samples | Set the number of frames to accumulate for the final image. There is a progress bar at the bottom of the Scene view which indicates the current accumulation with respect to this value. |
Minimum Depth | Set the minimum number of light bounces in each path. |
Maximum Depth | Set the maximum number of light bounces in each path. You can not set this to be lower than Minimum Depth. Note: You can set this and Minimum Depth to 1 if you only want to direct lighting. You can set them both to 2 if you only want to visualize indirect lighting (which is only visible on the second bounce). |
Maximum Intensity | Set a value to clamp the intensity of the light value each bounce returns. This avoids very bright, isolated pixels in the final result. Note: This property makes the final image dimmer, so if the result looks dark, increase the value of this property. |
Minimum Depth set to 1, Maximum Depth set to 2: direct and indirect lighting (1 bounce)
Minimum Depth set to 1, Maximum Depth set to 1: direct lighting only
Minimum Depth set to 2, Maximum Depth set to 2: indirect lighting only (1 bounce)
Materials parameterization
Some phenomena like refraction, absorption in transmissive objects, or subsurface scattering, can be expressed more naturally in a path tracing setting than in its rasterized counterpart, and as such require less material parameters (e.g. additional thickness information, expected shape of the refractive object, ...). For that reason, some parameters have no effect in path tracing, while others bear a slightly different meaning.
Refraction model
In the Lit family of materials, when the surface type is set to Transparent, you can select between None, Box, Sphere or Thin refraction models.
For path tracing, the distinction between Box or Sphere makes no sense (as rays can intersect the real objects in the scene), and both effectively carry the common meaning of a thick mode, to be used on solid objects represented by a closed surface. On the other hand, Thin conveys the same idea as its rasterized version, and None is a special case of thin refractive surface, hardcoded to be fully smooth to simulate alpha blending. Additionally, transparent surfaces should be Double-Sided, so that they get intersected from both sides, and normal mode should be selected appropriately for each situation, as described right below.
Refraction model | Path tracing meaning | Surface sidedness |
---|---|---|
Box or Sphere | Thick object (e.g magnifying paperweight) | Double sided, with None normal mode |
Thin | Thin object (e.g soap bubble or window) | Double sided, with Flip or Mirror normal mode |
None | Thin object, with smoothness = 1 and no Fresnel | Double sided, with Flip or Mirror normal mode |
The reason why normal mode should be set to None for thick objects, is that we want the intersection with a front normal to represent entering the medium (say, from air into glass), but also the back normal to represent leaving it.
Subsurface scattering
In path tracing, the Transmission option of subsurface scattering will only take effect if the surface is also set to be Double-Sided (any normal mode will do), in which case it will receive light from both sides.
Here is an example of a sheet of fabric, lit from below by a point light:
Single-sided or no Transmission
Double-sided + Transmission
Limitations
This section contains information on the limitations of HDRP's path tracing implementation. Mainly, this is a list of features that HDRP supports in its rasterized render pipeline, but not in its path-traced render pipeline.
Unsupported features of path tracing
There is no support for path tracing on platforms other than DX12 for now.
HDRP path tracing in Unity 2020.2 has the following limitations:
- If a Mesh in your scene has a Material assigned that does not have the
HDRenderPipeline
tag, the mesh will not appear in your scene. For more information, see Ray tracing and Meshes. - Does not support 3D Text and TextMeshPro.
- Does not support Shader Graph nodes that use derivatives (for example, a normal map that derives from a texture).
- Does not support decals.
- Does not support tessellation.
- Does not support Tube and Disc-shaped Area Lights.
- Does not support Translucent Opaque Materials.
- Does not support several of HDRP's Materials. This includes Eye, Hair, and Decal.
- Does not support per-pixel displacement (parallax occlusion mapping, height map, depth offset).
- Does not support MSAA.
- Does not support Graphics.DrawMesh.
- Does not support Streaming Virtual Texturing.