Vertex_Before_PositionUpdated does not work for shadows

I am using CustomMaterial’s Vertex_Before_PositionUpdated to modify positions and normals which works fine, as you can see on the following screenshot (I am rounding the corners):


However, the shadows of the box do not show any rounded corners. So I think that the code I have added through Vertex_Before_PositionUpdated is not executed when the shadow is generated.

How can I get correct shadows in this case?

1 Like

Adding @nasimiasl the daddy of the custom materials

1 Like

Try to set yourCustomMaterial.shadowDepthWrapper = new BABYLON.ShadowDepthWrapper(yourCustomMaterial, scene) and see if that helps.


Indeed, that solved it for the custom material that uses Vertex_Before_PositionUpdated with a BABYLON.MeshBuilder.CreateTiledBox-created model, namely the thing that produces the box with rounded corners from the screenshot above. Thank you!

However, for a different case where I use a CustomMaterial with Vertex_Before_PositionUpdated, it does not work. I see neither a shadow nor an error message. I would have to investigate further.

And in yet another different case, where I try to wrap a BABYLON.ShaderMaterial with BABYLON.ShadowDepthWrapper, I get the following error:

Uncaught TypeError: shader.substr is not a function
    at Effect._loadShader (effect.ts:615:20)
    at new Effect (effect.ts:381:14)
    at Engine.createEffect (thinEngine.ts:2867:24)
    at ShadowDepthWrapper._makeEffect (shadowDepthWrapper.ts:282:48)
    at ShadowDepthWrapper.isReadyForSubMesh (shadowDepthWrapper.ts:169:21)
    at ShadowGenerator.isReady (shadowGenerator.ts:1457:37)
    at ShadowGenerator._renderSubMeshForShadowMap (shadowGenerator.ts:1189:18)
    at ShadowGenerator._renderForShadowMap (shadowGenerator.ts:1128:18)
    at RenderingGroup.render (renderingGroup.ts:129:13)
    at RenderingManager.render (renderingManager.ts:217:28)

Any thoughts/advice on this?

There are bad parameters passed somewhere, but it will be impossible to say more without a repro!

But it is interesting that BABYLON.ShadowDepthWrapper works with one specific custom material, but not with a different one.

Anyways, I’d have to create a minimal example that shows the error. I’ll see what I can do…