Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak shadow bias defaults for DirectionalLight3D and OmniLight3D #55757

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Dec 9, 2021

Follow-up to #51335.

Light3D now uses a normal bias of 2 (instead of 1) to better combat shadow acne, without introducing more peter-panning.

The new values behave fairly well at increased blur values (between 1 and 2.5), but extreme blur values still don't look good out of the box. We can further improve reduce acne/peter-panning at high blur values by multiplying the shadow bias by the blur value (when it's above 1), but I think this is better to do in a separate PR.
Edit: Done in #55758 🙂

This closes #54523.

Testing project: test_shadows.zip

Preview

Click to view at full size.

Note: Debanding is enabled to ensure that color banding doesn't get confused for shadow acne. Lights also have their Specular property set to 0.0.

DirectionalLight3D

Before After
2021-12-09_16 42 20 2021-12-09_16 42 35

OmniLight3D

Before After
2021-12-09_16 44 07 2021-12-09_16 44 16

@mrjustaguy
Copy link
Contributor

mrjustaguy commented Jan 10, 2022

Do note that when using blending, higher Normal Bias will result in a more clearly visible Blend-fade effect when transitioning between splits. Not that it's a big deal with 2, just something to keep in mind.

Example at Normal 10:
Normal 10

The Black Area is the Shadow in Both splits, The gray Area is where the Shadow in the split that's fading. as the normal bias decreases, the gray area decreases too because the 2nd split is mapped more closely to the expected result.

@mrjustaguy
Copy link
Contributor

Maybe Normal Bias should be set to 2 for Omni lights too, as this seems to very well clear out Shadow Acne, and doesn't really seem to have any clear downsides compared to their current default. Spot Lights should remain as they are, as they don't benefit from this, and do actually suffer from adverse side-effects

Here is an Omni Light for comparison, Ultra Soft Shadows with 2048 General Shadows and quadrant used is split into 4 shadows, using 0.03 bias
Normal Bias 1
N1
Normal Bias 2
N2

@mrjustaguy
Copy link
Contributor

mrjustaguy commented Mar 18, 2022

Omni Lights should not have such a low bias, as it creates acne for larger lights, I've found 0.1 bias and 2 normal bias works best for them (even with Complex Objects such as Humans casting shadows)

Small Light (5 radius, 1 Energy, Proposed Settings)
image

Moderate Light (50 radius, 10 Energy, Proposed Settings)
image

Large Light (500 radius, 100 Energy, Proposed Settings) Note some acne, but users would generally have to increase the Bias for larger lights anyway and these objects are super tiny compared to the light and far away... Might be doable automatically? in which case 0.03 for 5 makes sense, but how to get to larger lights and keep them acne free?
image

Here's Moderate Light for comparison with This PR's settings, and Normal Bias at 2 Doesn't Help, and at Higher it just makes a ton of other problems
image

@Calinou
Copy link
Member Author

Calinou commented Jul 16, 2022

Redone to only increase Normal Bias. Standard shadow bias is no longer changed by this PR.

Note that this PR will make the difference between directional shadow splits more noticeable until #60178 is merged.

@Calinou Calinou force-pushed the light-3d-tweak-shadow-bias branch 2 times, most recently from 8502e3a to 1695cca Compare July 16, 2022 19:59
@reduz
Copy link
Member

reduz commented Jul 31, 2022

Bias needs to be different per light type, so please make sure to test this well.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran your test project again to test these settings on Beta 7. I found that the SpotLight looked fine as it was. The Omnilight indeed benefited from decreasing shadow_bias, but it did not benefit from increasing the normal_bias. DirectionalLight3D did benefit from increasing normal_bias to 2 and it is fine with its current shadow bias of 1.0.

All in, what appeared to be the ideal settings are:

  • SpotLight3D: leave as is
  • Omnilight3D: decrease shadow bias to 0.1
  • DirectionalLight3D: increase normal_bias to 2

- Increase DirectionalLight3D normal bias to 2.0 to reduce shadow acne
  at grazing angles.
- Decrease OmniLight3D bias to 0.1 to reduce shadow peter-panning.
@Calinou Calinou force-pushed the light-3d-tweak-shadow-bias branch from ef33a29 to e560971 Compare December 5, 2022 20:53
@Calinou
Copy link
Member Author

Calinou commented Dec 5, 2022

@clayjohn I've pushed an update according to your suggestions.

One (unrelated) issue I noticed is that at very low Blur values, spot light shadows exhibit severe acne with the default bias settings:

Blur 0.1 Blur 0.03 Blur 0.0
2022-12-05_21 51 45 2022-12-05_21 51 49 2022-12-05_21 51 53

This only occurs with spot light shadows, not omni or directional light shadows. This may be a result of #68339.

Also, omni and spot lights still exhibit some peter-panning, but we need to keep the bias relatively high as it's currently not scaled when the shadow map resolution is decreased due to the shadow being moved to a smaller quadrant in the atlas. (This is worth a separate issue with a dedicated MRP, which I can create if needed.)

Edit: Issue opened: #69866

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Although I am confused why the docs indicate the Light3D normal bias is 2.0 (which should only be the case for DirectionalLight3D). You would think it would be reversed and the Light3D normal bias would be 1.0 and only DirectionalLight3D would override it to change it to 2.0

I guess this is an issue that can be investigated in the docs binding later.

@akien-mga
Copy link
Member

akien-mga commented Dec 6, 2022

Looks fine to me. Although I am confused why the docs indicate the Light3D normal bias is 2.0 (which should only be the case for DirectionalLight3D). You would think it would be reversed and the Light3D normal bias would be 1.0 and only DirectionalLight3D would override it to change it to 2.0

I guess this is an issue that can be investigated in the docs binding later.

Light3D is abstract so it can't be instantiated by the doc generator to get its default values. So they end up inferred from a derived class, and it seems to pick one relatively arbitrarily.

We can probably work it around with some ADD_PROPERTY_DEFAULT for Light3D. Or figure out a way for doctool to still be able to instantiate abstract classes to get their default values.

@akien-mga akien-mga merged commit 6fd5162 into godotengine:master Dec 6, 2022
@akien-mga
Copy link
Member

Thanks!

@Calinou Calinou deleted the light-3d-tweak-shadow-bias branch December 6, 2022 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants