Assert in Distance Field Shadows

We are running into the following check inside `CullDistanceFieldObjectsForLight`

```

check(NumPlanes <= 12);

```

[Image Removed]

Looking at the code inside `ComputeShadowCullingVolume` where the shadow hull planes are constructed, it seems that the plane count can be up to 18. Can you confirm whether that is the case and we can update to that safely?

Also, this seems to happen intermittently and has just started popping up for us although distance field shadows have been enabled for a long time. Any advice you can share about content setup we should keep an eye on would be very valuable as well, specially if it can adversely affect perf.

Thanks!

Hi,

thanks for reaching out. I investigated the code and, as I understand it, ComputeShadowCullingVolume determines which planes should be added to the planes array that forms the convex shadow culling volume by adding two sets of planes:

  • the first for-loop iterates over the 6 subfrustum planes and determines if they are back-facing (from the perspective of the shadowing light) by checking if the dot product of their normal with the light direction is negative. Since the frustum is shaped like a truncated pyramid, the number of back-facing subfrustum planes can be between 1 and 5 (1 when the light is positioned behind the frustum’s near plane, occluding only the far plane, and 5 when the light is positioned such that it can only see the frustum’s left/right/top/bottom or far plane, occluding the other 5 sides).
  • the second for-loop iterates over each of the 12 plane index pairs in AdjacentPlanePairs (pairs of plane indices whose intersections form the edges of the frustum) and checks if they form a silhouette edge (from the perspective of the shadowing light), which is the case if the planes’ dot products of their normals with the light direction have opposite signs. In that case, a new plane will be formed by extending the silhouette edge towards the light, which will be added to the array of planes forming the shadow volume. The number of these newly created planes can be either 4 (when the light sees either only one side of the frustum or 5 sides) or 6.

The total number of shadow culling volume planes obtained from summing these should be between 5 and 10 depending on where the light is relative to the camera frustum (this can be verified by viewing a truncated pyramid from different angles in 3D and summing the back-faces and silhouette edges).

I hope this calculation makes sense, but the total number of planes should definitely not exceed 12, so this cannot explain why this assert check fails. It might be an “edge” case, where the light is on one of the plane frustum planes and is within some tolerance. To help debug this further, would you be able to place a conditional breakpoint on the last line in ComputeShadowCullingVolume() (ConvexVolumeOut = FConvexVolume(Planes)) which breaks when Planes.Num > 10 ? It would be interesting to know what the actual value of Planes.Num() is when the assert fails.

Thanks,

Sam

Thanks for looking into it Sam. Since I don’t have a local repro, the only other option is to enable DF shadows again and change the check to a checkf to log out the number of planes. Would that be helpful? There have been some reports around this, though not very helpful Assertion failed: NumPlanes <= 12 [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Renderer\Private\DistanceFieldShadowing.cpp] [Line: 583]

Thanks for your reply and the link, it’s helpful to know this is not an isolated issue and might be scene specific.

I found a potentially related issue on the Unreal dev forums, where the crash was caused by a directional light blueprint with an excessively high distance. Changing the distance back to the default for distance field shadows solved that crash. Could you try reducing the DistanceField Shadow Distance or DistanceField Trace Distance (under Distance Field Shadows > Advanced on the Directional Light) and see if that helps?

Without a good repro case it will be difficult to debug this further given its intermittent character, but knowing the number of planes that fails the assert (using checkf) can provide another clue. It might also be related to setting the graphics settings to High or Epic when in PIE mode.

Thanks,

Sam