Shadow Casting and Physics V2

Hello,
I started with Babylon.js’s Physics Helpers example

and added a few lines to casts shadow:
changed lights - line 29
added shadow generator - line 32
made the ground to receive the shadow - line 36
and made boxes to cast shadow - line 152

When I click “radial explosion” and run for 10 seconds, shadows become corrupted.
Any suggestions why that happens and how that can be fixed?
thank you

Pretty interesting bug :smiley:

After I reduced the box count, I am getting a more stable behavior but if you wait long enough, you will see the problem :frowning:

I think there’s some limit of objects to cast shadow, but we can change, I don’t remember where is…

I am guessing that I am not hitting the limit of object to cast because even with the original object count initially I am getting the correct shadows. The problem starts when I use one of the helpers. Therefore, we might be dealing with memory corruption…

I see that we have the same bug in Ammo solver as well

Also here is a playground that recreates the problem with only 10 spheres

On the other hand, if there is no simulator, I can easily have 50 spheres and I am getting correct shadows

That’s because, by default, the light frustum is calculated automatically according to the shadow caster positions. So, it also takes into account the boxes when they have fallen far apart from the ground, which extents the light frustum and reduce the shadow quality.

You should use a static light frustum, by setting light.autoUpdateExtends = false; and set values to orthoLeft/orthoRight/orthoTop/orthoBottom/shadowMinZ/shadowMaxZ:

6 Likes

@Evgeni_Popov HUGE Thank you for the solution and the explanation! This light frustrum setup does resolve my problem

1 Like