# Best shadow parameters for specific scene

**URL:** <https://forum.babylonjs.com/t/best-shadow-parameters-for-specific-scene/19722>\
**Category:** Questions\
**Created:** [April 5, 2021, 8:24pm UTC](https://forum.babylonjs.com/t/best-shadow-parameters-for-specific-scene/19722 "2021-04-05T20:24:47Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 14, 2021, 5:49pm UTC](https://forum.babylonjs.com/t/best-shadow-parameters-for-specific-scene/19722/12 "2021-04-14T17:49:02Z")

</div>

> [@Evgeni\_Popov](#):
>
> That would require some thinking… Will try to come up with something when I have a little time.

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#10D6YT%23413)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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.

---

_[View the full topic](https://forum.babylonjs.com/t/best-shadow-parameters-for-specific-scene/19722)._
