Getting shadows to update with clip planes

Hi! I’m trying to make our shadows update per mesh as a mesh gets clipped by the a clip plane.
Some things I’ve tried:

  1. I can achieve meshes getting clipped individually (by setting the scene’s clipPlane during onBeforeRenderObservable for each mesh and then setting the clipPlane as null onAfterRenderObservable). However, it doesn’t update shadows.
  2. I’ve found that for a single mesh, I can get the desired effect of the shadows updating, but the entire scene would be subject to the same clipping plane.

Any guidance on how to achieve shadows that update shadows while clipping each mesh individually? Here’s a link to the playground, that has comments to show the two things I tried: update shadows with clip plane | Babylon.js Playground (
To clarify, I’d like to see the object and shadow get clipped/updated, without the bottom surface getting clipped.

Welcome aboard!

I did not find a simple way to do it…

A somewhat complicated way to do it:

  • use the shadowGenerator.onBeforeShadowMapRenderMeshObservable observable to know which mesh is about to be rendered in the shadow map
  • use the shadowGenerator.onBeforeShadowMapRenderObservable observable to bind the clip planes to the effect of the mesh that is about to be rendered if it is the sphere
  • you need to override shadowGenerator._isReadyCustomDefines to set the clip planes on the scene if the mesh which is about to be rendered is the sphere

Here’s the PG:

For demonstration purpose I have added a cube which is not impacted by the clip planes.


Works great, thank you so much! :slight_smile: