Shadow issues with right-handed system and back-face culling

Hello,

I am in the process of upgrading our project from Babylon 6 to 7, but I am having issues with the ceilings of our rooms not casting shadows after upgrading.

Example playground:
test light | Babylon.js Playground (babylonjs.com)

I want to be able to see through the ceiling from above, but still have the ceiling cast a shadow. The playground works in Babylon 6 and below but in Babylon 7 there is no shadow cast. Is this related to the breaking changes made in 7.11?

In fact, it’s a bug in versions prior to the one in which we made the correction (7.6.2, in this PR).

The plane is not visible from the light (what you see is the frustum of the light):

You don’t see the plane in this picture, because of the value of sideOrientation. As a result, the plane will not be rendered in the shadow map and will therefore not generate shadows.

If you change the orientation, the plane will be visible, as well as the shadow:

The easiest way to fix it in your PG, is to set boxMaterial.backFaceCulling = false. Or you can use a thin box instead of a plane for the mesh.

2 Likes

Hi all!

I have a question to this topic, because i have the same situation as @jarredcm was asking:
is there a solution to have a ceiling where i can see through and this ceiling still cast a shadow?

You could set material.disableColorWrite = true when the camera is above the ceiling, and reset it to false when it is below. This way, the ceiling won’t be rendered to the screen, but the shadow map will still be generated correctly.

1 Like

Perfect ! :+1:
That’s exactly what i was looking for!
Thx!

I’ve tested with this advice and on first look all was fine.
But: i’ve recognized that all meshes, which are using materials with textures are disappearing below the ceiling when looking from above.
Only meshes with color materials are visible through the ceiling mesh.

Is there a solution for this behavior?

I don’t see why having textures would change the behavior: are you able to setup a repro in the Playground?

I’ve tested a little bit and found out that the order of creating the material is important:

not working:
https://playground.babylonjs.com/#B48X7G#373

working:
https://playground.babylonjs.com/#B48X7G#374

Why?

This is expected. When you draw the ceiling first, it writes to the zbuffer even though it doesn’t write colors to the screen, so when the floor is drawn next, some parts are obscured by the invisible ceiling because of the zbuffer.

When you draw the floor first, the zbuffer is still empty, so the entire floor will be drawn.

1 Like

Thanks for explanation! :+1: