OnDemand shadows broken in 2021.1?

I’ve just updated to 2021.1.2f1 (HDRP 11.0) and it looks like OnDemand shadows (for realtime punctual lights) are broken now :hushed: Whenever calling RequestShadowMapRendering() on a light with OnDemand shadow maps, this error occurs:

In class HDCachedShadowAtlas, it seems the “MarkAsRendered()” method tries to add the shadowID to the m_ShadowsWithValidData dictionary, but this key already exists apparently.

At the same time, the shadow map is not properly updated. This also breaks rendering for a brief moment (if RequestShadowMapRendering() is called every few frames, or if multiple lights with OnDemand-shadows exist, rendering fully breaks).

It happens for point and spot lights. The new “Always draw dynamic” option apparently has no influence on this issue.

This does not happen if update mode is set to “OnEnable” or “EveryFrame”. This error did not happen with Unity 2020.2. The punctual shadow atlas in the HDRP asset is set to 4K, so there is plenty of free space in it.

There seems to have been a merge problem as I can see myself how this could break; apologies for this.
I will make a fix today and link the PR here.

The second issue you describe, is it happening at the same time as this error? It might be that things get in a bad state after this.

The cached shadow atlas now has its own resolution btw, you might want to check that (also check the debug entry to log the status of cached shadows) (More info https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.mdhttps://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.md )

Here’s the fix, hopefully will make it into a package soon Fix issue with OnDemand shadows assert getting incorrectly triggered by FrancescoC-unity · Pull Request #4121 · Unity-Technologies/Graphics · GitHub

1 Like

Thank you so much @francescoc_unity for the blazingly fast response! :slight_smile: The broken rendering indeed happens at the same moment the error occurs, so it’s very likely caused by the exception. I’m looking forward to the PR getting merged

I’m still getting this error in latest alpha.

I can’t use on demand shadows at all.

1 Like