Shadow issues in performancePriority Intermediate

I noticed that when using Intermediate performance mode, my materials aren’t receiving shadows if my shadow casters are all added async.

I figured out that I can mesh.resetDrawCache to get the shadows to work after adding async casters.

I -think- what’s happening is that materials are freezing and if there isn’t at least 1 registered shadow caster, they freeze without the ability to display shadows.

If you have at least 1 registered shadow caster when the materials compile, then adding other shadow casters async later works fine.

This might be expected behavior for this performance mode, but it seems possible that materials could tell there are lights w/ ShadowGenerators that exist and then freeze with the ability to receive shadows even if nothing is registered to cast a shadow yet.

Here’s a minimal repro:

You can uncomment a synchronous shadow caster and then both sync + async shadow casters will work.

Adding @Deltakosh himself, the master mind of the priority modes

This is actually an expected behavior. I mentioned it in the docs but I understand it could be touchy to follow (Man, I wish ChatGPT could write docs for me ;))

Here is your fix:
Testing shadows + draw cache w/ intermediate performance priority | Babylon.js Playground (babylonjs.com)

The doc:

3 Likes

Aah got it! Thank you so much.

Since I can’t predict exactly when my shadow casters will be added, I opted to make the ground itself cast a shadow before it sets up its material. This seems to cause any “main thread synchronous” mesh materials to freeze with the ability to display shadows.

(Then to clean up I remove the ground as a shadow caster once mats are compiled)

1 Like