Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official HDRP DXR/Realtime Ray Tracing Lighting Troubleshooting Guide

Discussion in 'High Definition Render Pipeline' started by auzaiffe, Mar 4, 2022.

  1. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    This post's goal is to regroup all the information that would help you to clarify all the potential lighting issues that you may be getting with Real-time Ray Tracing in Unity's High Definition Render Pipeline (alias HDRP). This post will focus on Ray Traced Reflections (alias RTR) and Ray Traced Global Illumination (alias RTGI) and how to correctly setup/modify your scene to solve all these issues.

    Ray Tracing Effects are unfortunately not "magic" and enabling them will not automatically give you a path tracing rendering quality for your whole scene. You need to understand where the lighting is coming from for each category of lighting and make sure that the scene is configured properly to ensure the coherence of the scene's lighting.

    For each rasterized pixel the lighting comes from (at least, sometimes more) 5 distinct sources:
    - Directional (global) lights and their shadows.
    - Direct Local lights (point, spot, area) and their shadows.
    - Indirect Specular Lighting (SSR/RTR, Planar Reflection, Reflection Probes, Sky Cubemap.
    - Indirect Diffuse Lighting (SSGI/RTGI, APV, Legacy Probes, Lightmaps and ambient probes).
    - Fog.

    These lighting categories need to be clear for you for:
    • Each pixel that is seen directly through the camera.
    • The points that are hit by a given ray in the context of RTR and RTGI.
    This means that when a ray intersects a surface, the source of each of these lighting should be perfectly defined and coherent with your scene setup. All leaks that you may get in your scene are because the mechanic that generates these lighting doesn't match what you'd want it to.
     
    Last edited: Mar 9, 2022
    jeremedia, Ruchir, sqallpl and 9 others like this.
  2. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    Directional lights:
    Directional lights will affect every point of the scene independently of the location, which makes it automatically affect every ray intersection. The trickier part of this is the shadow (make sure shadows maps are enabled on the light).

    Cascade shadow maps are generated based on the camera's frustum which doesn't include all the possible locations where ray intersections can occur. Two options are available to help you solve this problem:

    Extended Shadow Culling: This option allows you to include more objects into the shadow maps (even if their shadows will not affect pixels inside the frustum). Note that this does not increase the size of the cascade shadow map due to internal engine limitations.

    Directional Shadow Fallback Intensity: This allows HDRP to know what shadow value to apply in case the intersection points it outside of the shadow map.
    • For interior scenarios, this is likely to be 0.0 which means in shadow.
    • For outdoor scenarios, it is likely to be 1.0 which means fully lit.
    upload_2022-3-4_14-50-7.png
     
    Last edited: Mar 4, 2022
    keeponshading likes this.
  3. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    Direct Local Lights:
    Direct Local Lights have a high impact on the final result of RTR and RTGI.

    In rasterization, the local lights are stored in a Tile Structure and/or in a Frustum Cluster Structure which is very convenient when lighting pixels that are visible on screen, but useless when lighting points outside of the frustum. A special structure is used for storing local lights (as well as reflection probes) for ray tracing, called “Light Cluster”. It is an axis aligned grid that stores a given number of lights per cell around the camera.



    The number of lights that a given cell can hold can be set in the HDRP asset. The higher the value is, the more local lights can be stored and contribute to the lighting of a given ray intersection, the higher the cost lighting pass.



    The other option available is to configure the size (in meters) of the light cluster around the camera in the “Light Cluster” Volume component. If this value is smaller than what the reflections allow the camera to perceive, you’ll have missing contributions in your lighting

    A debug menu called “Light Cluster”, allows you to ensure that the number of lights per cell doesn’t exceed the limit set in the asset and covers enough of the scene.


     
    valarnur likes this.
  4. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    Indirect Specular Lighting

    When evaluating the indirect specular lighting of a given point, a hierarchy of techniques are used in order to provide a complete signal for indirect specular lighting. In order of priority, the techniques are.
    • SSR (rasterization only) / RTR (rasterization and quality + multibounce RTR only).
    • Planar reflections.
    • Reflection probes.
    • Sky Cubemap.
    On Screen Space Reflections and Screen Space Global Illumination volume override, the “Last Bounce” override allows you to specify which fallback to include/skip.



    One of the most common leaks that you can get is due to the camera being in a closed environment and the sky being used because no reflection probes are available to provide an input for the indirect specular lighting at a ray intersection. To solve this problem, two options are available:
    • Create, place and bake (or realtime) reflection probe.
    • Select “Reflection Probes” or “None” in the last bounce dropdown menu.
    Note that being in quality mode and adding more bounces doesn’t solve the issue as you will still need to specify a valid source of indirect specular lighting for the last bounce.
     
  5. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    Indirect Diffuse Lighting

    In Ray Traced Reflections Only, the ambient probe, legacy light probes and lightmaps are used (if defined) as a source of indirect diffuse lighting. Which means if you have only set up a Dynamic ambient probe as the indirect lighting source, you will get light leaking in interiors or shaded areas coming from reflections. To get rid of this, you need to disable the ambient light probe.



    Note that this will change in the future as we will include the Adaptative Probe Volume in the fallback hierarchy and an ambient probe dimmer on the Screen Space Reflection volume override to avoid changing the scene to solve this issue.

    Ray Tracing Global Illumination forces the indirect diffuse lighting at ray intersection to be black (except for Quality Mode and Multi-bounces). It will also benefit from the change that includes APV and an ambient probe dimmer.
     
    ftejada and keeponshading like this.
  6. auzaiffe

    auzaiffe

    Unity Technologies

    Joined:
    Sep 4, 2018
    Posts:
    255
    Fog
    Fog is applied on top of the lighting coming from every lit ray intersection, which is fine in most cases. Except when the Color mode is set to Sky Color.



    This will use the sky color to tint the fog even in fully closed interiors. This light leak isn’t specific to ray tracing, but is more visible in ray tracing because all the other leaks are eliminated by ray tracing.

    You need to make sure to set it to a constant black color in closed environments.
     
    ftejada and keeponshading like this.