CascadedShadowGenerator set meshes to consider for bounds?

Hi there,

i am trying to get the cascadedshadowgenerator to generate its bounds from pecific meshes, or better to exclude meshes for the generation of bounds.
currently as far as i understand the function autoCalcDepthBounds takes all babylon meshes and the current camera and calculates minz and maxz for the bounds of the shadowgenerator. is there any way to generate this from specific meshes? so how would it work in this example if the bounds should be only calculated from the cubes, and not the floor: https://www.babylonjs-playground.com/#50R7XO#2

any help would be great!! Thanks a lot!!

pcace

A shadow map is rendered for shadow casters. So bounds are only computed from caster bounds. In other words, if you want to change the bounds of the shadow maps, add or remove casters.
In the PG you pointed, scaling the floor by 1000 will not make the shadow map 1000 less detailed.

Hi, thanks for the reply!

it is not really about the details of the shadows. the issue i am having in a much larger scene, that i have to generate meshes wich should not be included in the generation of the cascaded shadow map and not in the bounds for the shadow cascades either.

so i guess the question should be: how can i manually set the bounds of the cascades to the cubes, no matter where the camera is, nor what other meshes are around.

cheers,
pcace

This is a video which maybe makes it a little bit more obvious what i am talking about:
what you can see is the scene moving around. and while moving other meshes (terrain tiles) are generated and shortly included in the bounds for the shadow map. that leads to weird artifacs sometimes. so my idea was to define which meshes should be taken into consideration for the calculation:

I think what you want is to set a lower value for shadowMaxZ than camera.maxZ (which is the default)?

https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows_csm#shadowmaxz

No, i dont think so. So is there no way to define the bbox used for the calculation?

Do you set the tiles as shadow casters?

no. not willingly, but does that matter? in the babylon example i have also not added the floor to the shadowCasters, but still it is used to calculate the bbox.

what i try to do is something like this: Babylon.js Playground
BUT instead of clipping the camera view to minZ and maxZ i want to use the depth map of the second camera to generate the csm, and then use this in camera 1 to display everything ( just the shadow beeing calculated inside of the depthmap of camera2)
is this somehow understandable?

Thanks a lot for help!

Shadows are not calculated inside the depthmap of camera2. Note that depthMap does not exist as a property of CSM.

I don’t really understand what you want to achieve with camera2, but I don’t think you need it. autoCalcDepthBounds = true makes sure that the best minZ and maxZ values are used for the depth range of the scene (the setMinMaxDistance function is called with these values).

Now, if what you want is to calculate the minZ/maxZ of the scene from a different camera (camera2 for eg), and then use these values in the CSM calculation of the first camera, you can pass the depth renderer of camera2 with a call to CSM.setDepthRenderer:

However, I don’t see the point of it, as you will get artifacts: the values that must be passed to the setMinMaxDistance function are the minZ/maxZ from the CSM camera.