# How to set light frustrum size

Hi guys,

in my scene I have a set of meshes and I want my directional light frustrum size to cover all those meshes but not to be any bigger than that. What is the easiest way to achieve this?

Thank you!

Hey! Directional lights are infinite and reach all the meshes.
Maybe more spotlights?

Hi @Deltakosh,

alright, probably Iâ€™ve used not the right termâ€¦

What I want to achieve - is to get shadows from the light look good. Here we have a tutorial article about shadows where it is written that we have to make the lightâ€™s frustrum as small as we can for the shadows to look better:

And here is that PG with that scene:
https://playground.babylonjs.com/#2898XM#3

So I get the idea that we have to make that â€ścolored boxâ€ť (or frustrum?) as small as possible for the shadows to look better.

So my question is: what is the easiest way to calculate that â€ścolored boxâ€ť based on a list of objects that I define in the scene?

oh this is done automatically now

You can turn the automatic mode off with `light.autoUpdateExtends = false`

1 Like

You should also set `light.autoCalcShadowZBounds = true` to auto-compute the shadowMinZ and shadowMaxZ values.

Note however that it is taken into account only shadow casters in the computation. Depending on your scene, the shadowMaxZ - shadowMinZ range may not be big enough to see all cast shadows.

1 Like

Alright, thanks a lot!

That makes sense and is really helpful, but I have another question then. Can I somehow connect shadow bias and normal bias calculation to a lightâ€™s frustrum size when itâ€™s calculated automatically? This is actually the main thing Iâ€™d want to achieve and that affects work with shadows significantly.

Actually IMHO it would be super logical and great if the engine could perform such a calculation automatically. In that case Babylon shadows mechanism could become a lot better and easier to work with at least for the majority of cases. Do you think it could be possible, @Deltakosh?

Unfortunately I donâ€™t think itâ€™s possible, shadow bias and normal bias depends on each scene, Iâ€™m not aware of any algorithm that could compute the right values whatever the scene. Besides, thereâ€™s no â€śright valuesâ€ť: the values you choose are generally a trade off between more or less shadow acne / peter panning artifacts.

SDSM (Sample Distribution Shadow Maps) could potentially get rid of any bias tweaking but itâ€™s a heavy technic, not available in WebGL2.

I donâ€™t think it will work because it also depends on the geometry of the scene, not only on the light frustum. Note that in your first scene you still had to tweak the parameters.

Look into the litterature for shadow mapping, you will see thereâ€™s no general solution for shadow artifacts with the shadow mapping technic. See for eg Common Techniques to Improve Shadow Depth Maps - Win32 apps | Microsoft Docs.

There are papers on how to auto-adapt the depth bias (https://w3-o.cs.hm.edu/users/nischwit/public_html/AdaptiveDepthBias_WSCG.pdf, http://cwyman.org/papers/i3d14_adaptiveBias.pdf) but if you read the papers you will see there are still some artifacts in some cases.

Yeah, I see.

Anyway, thanks for the info, it was very useful!