Weird shadow artefacts

Here are my settings :

        this.shadowGenerator = new BABYLON.ShadowGenerator(512, this.light, false);
        this.shadowGenerator.useContactHardeningShadow = true;
        this.shadowGenerator.bias = 0.0003;
        this.shadowGenerator.forceBackFacesOnly = true;

Can you repro this in a playground? That will help a lot.


The thing is, I can’t really.

See here :

The playground has similar geometry, same material / light / shadow settings and the glitch don’t want to appear.

The only infos I have is that, the issue appears only when using useContactHardeningShadow, and forceBackFacesOnly. It is also 100% consistent, where if i remove / put back a geometry, the exact same glitch appear.

This could be difficult to reproduce because it would require a more complex geometry to glitch? I am not quite sure, still trying again

If you have any suggestion about what could cause such issue, it would be greatly appreaciated as it would help me reproduce the issue in the playground.

EDIT: May be this video can help : YouTube

Thanks you in advance!

Make sure to read this:

For the PG repro: make sure to create a scene with same size (minZ, maxZ), and same parameters for the light.

You problem is likely to come from a precision issue (like scene too large)

1 Like

That’s what I assumed as well. but the geometry is split in smaller pieces of 120x120x120, which are pretty empty most of the time, and the bug also appear regardless of the complexity of the current geometry.

I also realise that i could also get the issue without the “forceBackFacesOnly”.

Also I find weird that without “useContactHardeningShadow” the shadow looks as expected. I would assume if the issue was a precision issue, I would be able to observe it on the raw shadow?

I followed the link and tried a few things but without success.

Just a question: Is it still possible that it is a precision issue even if the raw shadow looks fine ?

EDIT: I also did a test with the most simple geometry possible (a flat terrain). The green lines shows were the geometry is split. Each geo gets their own direction light and their own shadow maps (set with renderList and lightOnly). Considering this is as simple as the geometry can possibly get, I doubt the issue is really arround precision ?

EDIT 2: I feel like this is related. With and without useContactHardeningShadow. When it’s on, it’s doing this weird staircase thing, but most likely the staircase approximation doesn’t play well with a single cube. As you can see the artefact doesnt appear when multiple cubes are involved, but the contours are very odd

EDIT 3: Switching to usePercentageCloserFiltering instead of useContactHardeningShadow does not have the issue. (I’m going to settle on that in the meantime. Feel free to tell if you think this is a non-issue, I will mark this as resolved)

I think the problem is definitely precision related (precision of depth buffer)

Let me invoke @sebavan who wrote the PCF shadows;)

1 Like

Yup I guess it is again a client for cascaded in 4.2