Oblong Contact Hardening Shadow Fix?

When I add multiple shadow casters to a contact hardening shadow, the shadows take on an oblong shape.

Example:
https://playground.babylonjs.com/#KN4DW1#3

Is there a way to keep the shadow shape uniform in all directions?

Welcome aboard!

That’s how contact hardening shadows work, the intensity of the shadow depends on the distance between the shadowed point and the shadow blocker. You can use the contactHardeningLightSizeUVRatio property of the shadow generator to reduce the “softness” of the shadow:

https://playground.babylonjs.com/#KN4DW1#4

You can also use another filtering method (like PCF) if you don’t want soft shadows at all.

@Evgeni_Popov, thanks for the reply. I experimented with different contactHardeningLightSizeUVRatio values, but that seems to just change the softness of the shadow rather than affecting the oblong shape of the shadow. I’ve added a third sphere even further to the right (at x = 50) to amplify the oblong shape even more:

https://playground.babylonjs.com/#KN4DW1#6

The shadows are blurred more in the x-direction than in the z-direction. I am trying to figure out a way to ensure that the shadow will be blurred equally in both directions. The current shadow shape seems to depend on something like the shape of the minimum size rectangle that encloses all the items that are casting shadows.

Yes. This is the light frustum:

The shadow casters must be in the frustum, so you get a very thing but long frustum because of the 3rd sphere which is quite far.

You can change the shape of this frutum manually so that it has roughly the same dimension in both directions. In that case your shadows will be round again (see lines 19-23):

3 Likes

Ah, that’s it. Thank you for the help! And thanks for the detailed explanation with pictures.