Seems like a recurring battle with these shadows. I switched away from CSM shadows which were causing problems with Ocean shader -back to simplest case shadows, but they’re getting clipped (by frustum, i think). I created a PG with the same light/shadow code, but cant replicate precisely, although the same thing is happening (just a little less obviously on the box)
The automatic calculation of shadow Z limits only takes account of shadow casters, not receivers.
In your case, the maximum Z bound calculated is a little too small to encompass all the ground, which is why the shadow is cut off. You can either inflate the frustum a little by setting something like
this.light_dir.shadowOrthoScale = 0.2; (this makes the frustum 20% larger than the one tightly calculated), or set a fixed frustum “by hand” (by setting the
My bad, orthoScale does not apply to the Z dimension…
So, the solution is to set the
shadowMaxZ values manually and not use
Note that while you walk away from the cube, the shadow becomes more and more fuzzy and bad looking. That’s because the light frustum is stretching to keep both the cube and the character inside:
I think you should also disable the automatic calculation of the X and Y dimensions of the light frustum (
light.autoUpdateExtends = false) and set the orthoTop/Bottom/Right/Left properties manually, to create a frustum light with a fixed size. Also, you should make the position of the light move with the character. That way, the shadow will already be well defined for the main character and the meshes inside the frustum light.
Obviously, doing it that way, at some point the cube (or some other objects) won’t be in the light frustum anymore and won’t have any shadow. Shadow support is always a trade-off at some point