Adding all meshes in the scene to the ShadowCaster:

I have a scene that has al the scene stuff in it like cameras and lights and stuff. I am created meshes in other classes separately and then bringing them into the scene……now I want to add them to the shadow caster, and I am not sure how to do this…I have done this but it is not working.

for (let mesh of scene.meshes)
{
shadowGenerator.addShadowCaster(mesh);
}

Is this possible to even do?

this should work, please repro your issue (with a reduced case) in the playground so that we can have a look.

Not sure a PG will work as I am calling other classes in separate files into the scene. Can PG accommodate that?

Also, i have no clue how to do a PG…

That is why I mentioned
image

We do not need those to repro, you need to chop down all but the code fully necessary to repro the issue you face so that we do not need to learn all your code and can help you as fast as possible.

1 Like

Hope this works….

It doesn’t work in here either.

Although there is a strip of I am guessing shadow fragment ont he ground plane.

The issue is with your entire shadow setup not the way you add the meshes in the generator :slight_smile:

First the position of the light should not be in the mesh to cast shadow but a bit further away

Second your scene far plane should be set accurately to best benefit of shadows:
image

This would lead to this:

Those artifacts are the main concern with self shadows. in most cases receivers and casters are well identified so setting them manually helps.

But if you really want it, you need to at least use PCF with some bias:

Basically, setting shadows is not as easy the first time but it is all documented here: Shadows | Babylon.js Documentation

2 Likes

I was stumbling on to this as you replied. I saw another person had issues with the maxZ number then tried that and it worked….but had the frags….the bias helped. Thank you.

1 Like