Best shadow parameters for specific scene

One way to do it is to get the bounding box of the mesh (+sub meshes), compute a bounding sphere for it and use the center of the sphere to compute a point on that sphere in the inverse direction of the light: that will be the light position. The shadow max Z is simply the diameter of the sphere:

Be careful, however, because it creates a quite tightly fit frustum of the mesh, but some filtering methods require that the frustum intersects with the mesh receiving the shadow (the plane in the PG): if you change the filtering method to PCF, you will see that the shadow is truncated because the frustum is not long enough: you need to raise the shadowMaxZ value.

2 Likes