Use contact shadows
Contact Shadows are shadows that HDRP ray marches in screen space, inside the depth buffer, at a close range. They provide small, detailed, shadows for details in geometry that shadow maps can't usually capture.
The Contact Shadows Volume Override specifies properties which control the behavior of Contact Shadows. Contact Shadows are shadows that The High Definition Render Pipeline (HDRP) ray marches in screen space inside the depth buffer. The goal of using Contact Shadows is to capture small details that regular shadow mapping algorithms fail to capture.
24 Lights (Direction, Point or Spot) can cast Contact Shadows at a time.
For information about contact shadow properties, refer to Contact shadows override reference.
Enable contact shadows
To use this feature in your Scene, you must first enable it for your project and then enable it for your Cameras. To enable features in your project, you use the HDRP Asset and to enable features for your Cameras, you use Frame Settings. You can enable features either for all Cameras, using the Default Frame Settings, or for specific Cameras, by overriding each Camera's individual Frame Settings.
Enable the following properties:
- In the HDRP Asset: Lighting > Shadows > Use Contact Shadows.
- In the Frame Settings window: Lighting > Contact Shadows.
Use contact shadows
Contact Shadows use the Volume framework, so to enable and modify Contact Shadow properties, you must add a Contact Shadows override to a Volume in your Scene. To add Contact Shadows to a Volume:
- In the Scene or Hierarchy view, select a GameObject that contains a Volume component to view it in the Inspector.
- In the Inspector, navigate to Add Override > Shadowing and click on Contact Shadows. HDRP now applies Contact Shadows to any Camera this Volume affects.
You can enable Contact Shadows on a per Light basis for Directional, Point, and Spot Lights. Tick the Enable checkbox under the Contact Shadows drop-down in the Shadows section of each Light to indicate that HDRP should calculate Contact Shadows for that Light.
Only one Light can cast Contact Shadows at a time. This means that, if you have more than one Light that casts Contact Shadows visible on the screen, only the dominant Light renders Contact Shadows. HDRP chooses the dominant Light using the screen space size of the Light’s bounding box. A Directional Light that casts Contact Shadows is always the dominant Light.
Note: A Light casts Contact Shadows for every Mesh Renderer that uses a Material that writes to the depth buffer. This is regardless of whether you enable or disable the Cast Shadows property on the Mesh Renderer. This means that you can disable Cast Shadows on small GameObjects/props and still have them cast Contact Shadows. This is good if you do not want HDRP to render these GameObjects in shadow maps. If you do not want this behavior, use Shader Graph to author a Material that does not write to the depth buffer.
API
To access and control this override at runtime, use the Volume scripting API. Because of how the Volume system works, you edit properties in a different way to standard Unity components. There are also other nuances to be aware of too, such as each property has an overrideState. This indicates to the Volume system whether to use the property value you set, or use the default value stored in the Volume Profile. For information on how to use the API correctly, see Volume scripting API.
Details
For Mesh Renderer components, setting Cast Shadows to Off does not apply to Contact Shadows.
Contact shadow have a variable cost between 0.5 and 1.3 ms on the base PS4 at 1080p.