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:

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 :slight_smile:

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 (, 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!