ClipPlane and shadow

I run in the issue with clipPlane and shadows.
I cut off part a mesh with clipPlane and this mesh is shadow caster.
And shadow generator creates shadow for full mesh not only visible part (ignores clipPlane).

Shadow generator (light position is updated later)

const light = new SpotLight(
    light.specular = new Color3(0, 0, 0);
    light.intensity = 0;
    const generator = new ShadowGenerator(1024, light);
    generator.transparencyShadow = true;
    if (pcfFilter && scene.getEngine().webGLVersion > 1) {
        generator.filter = ShadowGenerator.FILTER_PCF;
    } else {
        generator.filter = ShadowGenerator.FILTER_BLUREXPONENTIALSHADOWMAP;

Clip plane is set / updated on mesh


Missing something, or its desired behaviour?

Thank you

Could you create a Playground so that it’s easier for us to have a look?

Thanks in advance.

Hi Hersir

The clipPlane is property of the scene , not the mesh and so you might want to use another approach.

CSG is one way that will get you the results you want.

You are right, clipplanes are not supported in the shadow generator so far.

Anyone fancy doing a PR ? it consists in adding the

  • #include<clipPlaneVertexDeclaration>

  • #include<clipPlaneVertex>
    In the shadowMap.vertex.fx

  • #include<clipPlaneFragmentDeclaration>

  • #include<clipPlaneFragment>
    In the shadowMap.fragment.fx

as well as the Binding code in the ShadowGenerator and CSMShadowGenerator.

I am proposing only as it might be a nice and easy first contrib if somebody wants to Jump in ???

Else I ll do it tomorrow :slight_smile:

Ok seems that there are no takers, so I ll implement it :slight_smile:

PR is up and running it will be in the next nightly: Add clip planes support in shadow generation. by sebavan · Pull Request #7519 · BabylonJS/Babylon.js · GitHub


Thank you @sebavan, sorry for late response, was on tight deadlines :smiley:

1 Like

@sebavan, as a note - the specific case described by @Hersir doesn’t seem to be fixed (please check this PG).

@Michael_Prosser CSG wouldn’t work as the clipping has to be animated - like here