I’ve just updated to 2021.1.2f1 (HDRP 11.0) and it looks like OnDemand shadows (for realtime punctual lights) are broken now Whenever calling RequestShadowMapRendering()
on a light with OnDemand shadow maps, this error occurs:
ArgumentException: An item with the same key has already been added. Key: 6
System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Collections.Generic.Dictionary
2[TKey,TValue].Add (TKey key, TValue value) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.Rendering.HighDefinition.HDCachedShadowAtlas.MarkAsRendered (System.Int32 shadowIdx) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/Lighting/Shadow/HDCachedShadowAtlas.cs:621)
UnityEngine.Rendering.HighDefinition.HDCachedShadowManager.MarkShadowAsRendered (System.Int32 shadowIdx, UnityEngine.Rendering.HighDefinition.ShadowMapType shadowMapType) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/Lighting/Shadow/HDCachedShadowManager.cs:405)
UnityEngine.Rendering.HighDefinition.HDAdditionalLightData.UpdateShadowRequest (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.HighDefinition.HDShadowManager manager, UnityEngine.Rendering.HighDefinition.HDShadowSettings shadowSettings, UnityEngine.Rendering.VisibleLight visibleLight, UnityEngine.Rendering.CullingResults cullResults, System.Int32 lightIndex, UnityEngine.Rendering.HighDefinition.LightingDebugSettings lightingDebugSettings, UnityEngine.Rendering.HighDefinition.HDShadowFilteringQuality filteringQuality, System.Int32& shadowRequestCount) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/Lighting/Light/HDAdditionalLightData.cs:2276)
UnityEngine.Rendering.HighDefinition.HDRenderPipeline.PrepareGPULightdata (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.CullingResults cullResults, System.Int32 processedLightCount) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/Lighting/LightLoop/LightLoop.cs:2325)
UnityEngine.Rendering.HighDefinition.HDRenderPipeline.PrepareLightsForGPU (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.CullingResults cullResults, UnityEngine.Rendering.HighDefinition.HDProbeCullingResults hdProbeCullingResults, UnityEngine.Rendering.HighDefinition.DensityVolumeList densityVolumes, UnityEngine.Rendering.HighDefinition.ProbeVolumeList probeVolumes, UnityEngine.Rendering.HighDefinition.DebugDisplaySettings debugDisplaySettings, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/Lighting/LightLoop/LightLoop.cs:2640)
UnityEngine.Rendering.HighDefinition.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Rendering.HighDefinition.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/RenderPipeline/HDRenderPipeline.cs:2102)
UnityEngine.Rendering.HighDefinition.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.high-definition@11.0.0/Runtime/RenderPipeline/HDRenderPipeline.cs:1911) UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List
1[T] cameras) (at <9244fb8344e84288877b43b45b29c242>:0)
UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, System.Collections.Generic.List`1[T] renderRequests, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <9244fb8344e84288877b43b45b29c242>:0)
UnityEngine.GUIUtility ProcessEvent(Int32, IntPtr, Boolean&)
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 )
Thank you so much @francescoc_unity for the blazingly fast response! 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