Incorrect face culling in shadow rendering in right-handed scene

Playground reproduction (toggle scene.useRightHandedSystem): Babylon.js Playground

Hello :slight_smile: Here’s a bug I found in our project, unfortunately I don’t have the time currently to make a PR for this, but I thought I’d at least report it.
But essentially, it seems like at least for directional light shadows & spotlight shadows, but maybe others as well, when using a right-handed system it seems that the face culling is inverted in shadow rendering.

My guess for the cause is that there seems to be no distinction between left- and right-handed projection matrices in the shadow generators.

Interestingly in our project, we get another behaviour that I’m not able to re-create in the Playground, but that might be because we are on an older 6.x version currently.
But the behaviour we’re seeing is if we set the shadowGenerator.forceBackFacesOnly flag to true in a right-handed scene, we actually get front-faces rendering in the shadows instead of backfaces, with the exception on models with a negative transform determinant where the backfaces are rendered instead. But again, I’m unable to re-create in the Playground in 7, but do you know if this is something you have fixed or worked on potentially, otherwise I’ll dig deeper and see if I can find the issue behind that.

cc @Evgeni_Popov

This PR will fix the problem:

When the PR is merged, this PG will work as expected:

You will get:

Instead of:

2 Likes