# How do we limit the size of the auto-sized shadow frustum

**URL:** <https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152>\
**Category:** Questions\
**Tags:** shadows, shadowgenerator, shadow-frustum\
**Created:** [August 9, 2023, 3:31pm UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152 "2023-08-09T15:31:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [August 9, 2023, 3:31pm UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/1 "2023-08-09T15:31:18Z")

</div>

I’ve enabled auto shadow frustum size.

```js
light.autoUpdateExtends = true
light.autoCalcShadowZBounds = true

```

Can we limit the size? I guess maybe I should just set the size manually to the max size, and get the worst case all the time.

The issue I had is things looking pretty good automatically until some objects shoots out far away (f.e. due to physics sending a ball far away), and the shadows then becoming super pixelated.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [August 9, 2023, 4:22pm UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/2 "2023-08-09T16:22:05Z")

</div>

pinging shadow king @Evgeni_Popov

---

<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:** [August 10, 2023, 9:51am UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/3 "2023-08-10T09:51:26Z")

</div>

You can set `autoUpdateExtends` to `false` and provide the X/Y dimensions for the shadow frustum yourself through the `orthoLeft`, `orthoRight`, `orthoTop` and `orthoBottom` properties.

For dimension Z, set `autoCalcShadowZBounds` to `false` and provide values for `shadowMinZ` and `shadowMaxZ`.

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [August 11, 2023, 3:07am UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/4 "2023-08-11T03:07:44Z")

</div>

I was wondering we we could still have auto size, but limit it to a certain max size.

---

<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:** [August 11, 2023, 11:12am UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/5 "2023-08-11T11:12:08Z")

</div>

No, this is not supported.

It would not be difficult to support it (though we would have to add 6 new properties to `DirectionalLight`), but I wonder if it’s not a bit too specific…

cc @sebavan for his opinion.

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [August 11, 2023, 9:27pm UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/6 "2023-08-11T21:27:43Z")

</div>

Yeah, I was thinking simplistically as an end user.

However if the size should be limited, then also the position of the box needs to be heuristically determined somehow.

It is easy to make it “_enclose everything automatically_” or to “_enclose this specific space_”, but perhaps what people really want is something like “_enclose at most this amount of distance from the activeCamera such that the max size is limited AND the space moves along with the view point of the end user_”.

Basically imagine this scenario:

You add a directional light, make it follow the active camera position (that could be an option, but also `light.position = camera.position` does the trick), and limit the shadow frustum size. The result is most of the time shadows look good (with a lower limit of quality depending on the max size), and if something shoots off into space it does not make the shadows get super pixelated all of a sudden.

The main idea is, if everything is kept tight in the world most of the time, the frustum size can shrink and offer _better_ shadows than simply setting a bigger static size.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 6, 2023, 11:47am UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/7 "2023-09-06T11:47:37Z")

</div>

cc @sebavan do we want to add an issue to track this? 🤔

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 6, 2023, 2:24pm UTC](https://forum.babylonjs.com/t/how-do-we-limit-the-size-of-the-auto-sized-shadow-frustum/43152/8 "2023-09-06T14:24:42Z")

</div>

It sounds highly specific and In this case I wonder if it is not “similar - ish” to relying on CSM with 1 cascade.

I guess we can do it in the playground only at the moment by disabling auto compute and following the proposed process. If it works great and it gets traction lets integrate in the framework.
