Ray-traced shadows
Ray-traced shadows are shadows that HDRP generates by tracing rays of light from the following Light sources:
When you enable ray-traced shadows in your HDRP Project, they replace shadow maps for opaque GameObjects.
Using ray-traced shadows
All ray-traced shadows are screen space shadows. This means that HDRP stores them in a screen space buffer which holds the information for every pixel on the screen that is in the depth buffer (which only stores opaque GameObjects).
To use ray-traced shadows, enable screen space shadows in your HDRP Project. To do this:
- Click on your HDRP Asset in the Project window to view it in the Inspector.
- In the Lighting section, enable Screen Space Shadows.
- Set the value for Maximum to be the maximum number of screen space shadows you want to evaluate each frame. If there are more than this number of Lights in your Scene then HDRP only ray casts the shadows for this number of them, then uses a shadow map for the rest.
Then make sure you enable Screen Space Shadows for your Cameras. To do this:
- 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 Lighting section, enable Screen Space Shadows.
Finally, to make HDRP process ray-traced shadows for your Directional, Point, or Rectangle Light:
- Under the Shadow Map fold-out in the Shadows section, click the Enable checkbox.
- Also in the Shadow Map foldout, enable Ray-Traced Shadows. For Directional Lights, you need to enable Screen Space Shadows to access this property.
- To change the behavior of the shadows, edit the properties under Ray-Traced Shadows.
Directional Light
Ray-traced shadows offer an alternative to the cascade shadow map that Directional Lights use for opaque GameObjects.
Directional Light cascade shadow map
Ray-traced Directional Light shadows (Sun Angle = 0)
Ray-traced Directional Light shadows (Sun Angle = 0.53, the angle of the Sun as seen from Earth)
Ray-traced shadows allow for transparent and transmissive GameObjects, lit by Directional Lights, to cast colored shadows.
Ray-traced Directional Light shadows with colored shadows
Ray-traced Directional Light shadows without colored shadows
Properties
Property | Description |
---|---|
Sun Angle | Sets the size of the Sun in the sky, in degrees. For example, the value for the Sun on Earth is 0.53°. |
Sample Count | Controls the number of rays that HDRP uses per pixel, per frame. Higher values produce more accurate shadows. Increasing this value increases execution time linearly. |
Color Shadow | Allows transparent and transmissive GameObjects to cast colored shadows. |
Denoise | Enables the spatio-temporal filter that HDRP uses to remove noise from the ray-traced shadows; making them smoother. |
- Denoiser Radius | Controls the radius of the spatio-temporal filter. |
Point And Spot Light
Ray-traced shadows offer an alternative to the shadow map that Point and Spot Lights use for opaque GameObjects. HDRP still evaluates the lighting of a Point Light as coming from a single point in space (the light is punctual), but it evaluates the shadowing as if the light was coming from the surface of a sphere. On the other side, HDRP evaluates the lighting of a Spot Light as coming from a single point in space, but it evaluates the shadowing as if the light was coming from the surface of a cone.
Point Light shadow map
Ray-traced Point Light shadows (Radius = 0.001m)
Ray-traced Point Light shadows (radius = 0.5m)
Ray-traced shadows offer the possibility of semi-transparent shadows for Point Lights cast by tranparent and transmissive GameObjects.
Ray-traced Point Light shadows with semi-transparent shadows
Ray-traced Point Light shadows without semi-transparent shadows
Properties
Property | Description |
---|---|
Sample Count | Controls the number of rays that HDRP uses per pixel, per frame. A low number of samples produces a noisier image that requires more denoising. Increasing this value increases execution time linearly. |
Semi-Transparent Shadow | Allows transparent and transmissive GameObjects to cast semi-transparent shadows. |
Radius | Sets the radius of the sphere light that HDRP uses to evaluate the shadows. This increases the size of the surface that emits light. |
Denoise | Enables the spatio-temporal filter that HDRP uses to remove noise from the ray-traced shadows. |
- Denoiser Radius | Controls the radius of the spatio-temporal filter. |
- Distance Based Denoising | Specifies whether HDRP should take the distance to the occluder into account when it denoises the shadow. This increases the denoiser quality but also its resource intensity. |
Rectangle Light
Ray-traced shadows offer an alternative to the exponential variance shadow map that Rectangle Lights use for opaque GameObjects.
Rectangle Light shadow map
Ray-traced Rectangle Light shadows
Note: When rendering in deferred mode, HDRP provides accurate ray-traced area light shadows for the Lit shader. When HDRP renders for any other shader, or for the Lit shader in forward mode, it uses an approximation to calculate ray-traced shadows for area lights. This approximation is not perfectly accurate, but does produce plausible results.
Properties
Property | Description |
---|---|
Sample Count | Controls the number of rays that HDRP uses per pixel, per frame. Increasing this values increases execution time linearly. |
Denoise | Enables the spatio-temporal filter that HDRP uses to remove noise from the ray-traced shadows. |
- Denoiser Radius | Controls the radius of the spatio-temporal filter. |
Limitations
Double-sided shadows
Ray-traced shadows do not support the Two Sided option for the Mesh Renderer's Cast Shadows property. To use double-sided shadows for a mesh, open the Mesh Renderer's Material in the Inspector and, in the Surface Options section, enable the Double-Sided property.
Recursive rendering
GameObjects HDRP renders using recursive rendering cannot receive ray-traced shadows. If you enable both effects, HDRP renders rasterized shadows on recursively rendered GameObjects.