By default, High Definition Render Pipeline (HDRP) updates the realtime shadow maps every frame. This script adds more options to customize the on-demand shadow rendering to optimize the runtime performance. It relies on RequestShadowMapRendering
and RequestSubShadowMapRendering
functions which you can read about in the HDRP documentation.
Special thanks to Remy for introducing me to this feature.
- Update shadow map on camera movement.
- This is especially useful for Directional Lights, since their shadows are view-dependent.
- The MainCamera is automatically selected, if none is assigned.
- Three shadow map update modes:
- Entire Shadow Map. Intended for all light types.
- Cascades. Intended for Directions Lights.
- Subshadows. Intended for Point Lights.
- Update shadows on a per-second or per-frame basis.
- Clone the repository, or download the latest release.
- Import the project using Unity 2021.3.33f1 or newer.
- Open the
IndoorsScene.unity
file to explore the example scene.
- Select an existing light in your scene, or add a new one.
- Under its Light component, find the Shadows header.
- Enable the shadows, and set the Update Mode to On Demand.
- Attach the
OnDemandShadowMapUpdate
script to the light either by dragging and dropping it, or by using the Add Component button.
If done correctly, you should see the UI shown in the screenshot below:
Please note that any changes made to the script will only be visible in Play mode or in standalone builds.