Too many settings just to have decent shadows

I have read through the shadow generator documentation and new methods are introduced in each version to generate better shadows.
I went mad turning every setting to true only to realize some shadows enhancing techniques doesn’t work with some light type.

I then proceed to remove all shadow enhancing techniques that only works on some light type keeping only techniques that works with all light types.
This is what I am left with:
shadowGenerator.forceBackFacesOnly = true;
shadowGenerator.usePoissonSampling = true;
shadowGenerator.usePercentageCloserFiltering = true;
shadowGenerator.useContactHardeningShadow = true;

Too confusing…TOO confusing, it should just work when you turn shadow on instead of having to deal with all these nonsense.

Question 1:
Can I confirm that these four settings works across all Light/Mesh Types ?

Question 2:
Of the four lines, can I reduce/remove any of them at all because maybe they contradict each other or something ?

The subtle magic of making shadows work is indeed a bit complicated. We tried to document as much as we can but the problem lies within WebGL and even more within our dear graphic cards.

Shadow maps contain depth information and this information really require a lot of precision to work correctly. And thus it is highly dependent on the scene setup (hence all the options you could play with to adapt to your particular situation).

What you “kindly” call nonsense is actually the best we can do to make sure you can achieve fast and good looking shadows.

If you know a better or smarter way to do it please do a PR and will merge it right away!

Regarding your two questions:

  1. usePercentageCloserFiltering should not work with point lights. Same for contact hardening. It could be technically feasible but unfortunately point lights require to generate 6 shadow maps so they are quite expensive so we limit the options for them in order to keep decent framerate
  2. usePoissonSampling is a filtering method like PCF so you should keep only PCF (usePercentageCloserFiltering )
2 Likes

Keep calm and take a breath. Of course sometimes something could miss in the engine, or in the doc, but if so, please ask in a kind way.

Plus, as always in 3D, simplicity quickly turns into complexity, it’s like that :nerd_face:

2 Likes

shadowGenerator.forceBackFacesOnly = true;
shadowGenerator.usePoissonSampling = true;
shadowGenerator.usePercentageCloserFiltering = true;
shadowGenerator.useContactHardeningShadow = true;

Which should I remove if I want to be compatible with ALL light sources ?

After trial and error, I have come to realize only these two are needed:
shadowGenerator.forceBackFacesOnly = true;
shadowGenerator.useContactHardeningShadow = true;

The rest doesn’t do anything.

shadowGenerator can only be of one type PoissonSampling or PercentageCloserFiltering or ContactHardeningShadow putting use to true on one of them invalidates the others. So only the last one stays true.