How to know if a point of a face is in shadow?

I am using this PG to manually check if a point of ground is in shadow:

Is there a better method than manual check, which is very slow?
I also experimented with subdivision of ground in submeshes, but I can’t assign a material/color to them, why doesn’t this work?

ground.subMeshes[i].material = markers[i].material.clone();

You could reuse the shadow map created by the shadow generator, transform the point(s) you want to test in the light coordinate system and check if the z of the transformed point is smaller or greater than the value stored in the shadow map. However, it means a roundtrip from the GPU to the CPU to retrieve the shadow map, which may be slow… You would have to compare with your method, to know if it’s faster or not.

Have a look at multi-materials in the doc:

Another suggestion would be to try Havok raycasts as they are faster than pickWithRay :slight_smile: Raycast | Babylon.js Documentation (

Is the ray casting done against the real mesh geometry or the physics shape?

Oh, it’s done against the shape, but it shouldn’t be an issue if it’s a simple shape? Or maybe there is and I didn’t notice :sweat_smile:

I don’t know, it depends on @jumpjack2 constraints!

I would use just boxes as shadow generators (but I don’t know how to associate a physics shape to a box)

Using A Physics Engine | Babylon.js Documentation (