Hersir
January 21, 2020, 12:52pm
1
Hi,
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.Shadow,
Vector3.Zero(),
Vector3.Zero(),
Tools.ToRadians(35),
0,
scene,
);
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
this.onAfterWorldMatrixUpdateObservable.add(this.updateClipPlane);
this.mesh.onBeforeRenderObservable.add(this.setPlane);
this.mesh.onAfterRenderObservable.add(this.removePlane);
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 https://www.babylonjs-playground.com/#T6NP3F#0 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
Ok seems that there are no takers, so I ll implement it
Hersir
January 27, 2020, 6:55am
7
Thank you @sebavan , sorry for late response, was on tight deadlines
1 Like
alvov
July 7, 2020, 8:05pm
8
@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 https://www.babylonjs-playground.com/#XQ61ID#1 .
Hi, @sebavan
sorry for bringing up old thread, but we faced this issue again
and PG from @alvov is still breaking in latest version.
Is there any way to fix it ?
Thank you
1 Like
See Getting shadows to update with clip planes - #2 by Evgeni_Popov
However, onBeforeShadowMapRenderObservable
and onBeforeShadowMapRenderMeshObservable
are not needed, only _isReadyCustomDefines
needs to be overriden:
1 Like