How to get shadow of the village

As shown in my playground, I want to get the projection of the entire village, but I have two questions. Does the directional light have to be given a position (refer to https://forum.babylonjs.com/t/directionallight-position-has-meaning /9490/2), how can I determine the value of this position if necessary?(The ninth line of code)
The second problem is that this shadow looks weird. How can I get a shadow that looks good for the whole village?

Hello! As @Evgeni_Popov so nicely explained, setting the directional light position can help you adjust the shadow frustum. When creating shadows, think of the light as the camera from where the shadow projection will come from; if you place the camera in a different position, you will see something different. You can check the light frustum using one of the inspector options, here is the one in your PG:


(I also removed the skybox and added an axes viewer for added clarity)

You can see it’s not catching the village very well

After moving it on the Y and Z axis, I get this frustum:

So now we have shadows, but they’re a bit blocky and we can improve on them:

So I tweaked the shadow’s position, minZ and maxZ values a bit using the inspector, and also the shadow bias value, as shadow acne was happening, and I got the final values of
shadow.position = (0,10,-10)
shadowMinZ = -5
shadowMaxZ = 25
shadow bias = 0.05

The frustum looks like this:

Way tighter than the previous one, and then I added PCF filtering to make the shadows go from blocky:

To a nice blur:

Here’s the updated PG:
Create a Simple World Series | Babylon.js Playground (babylonjs.com)

Hope it helps!

3 Likes

Great advices! This doc could also help: Shadows | Babylon.js Documentation

If you don’t need the large ground to cast shadows, you can even improve the shadows further:

3 Likes

Thanks for the replies both of you, I will try it!

1 Like