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

Automatically adjust Light3D shadow bias to account for resolution #57638

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Feb 4, 2022

Follow-up to #55758.

Higher shadowmap resolutions make it possible to use lower bias values without exhibiting shadow acne. On the other hand, shadow bias should be increased when using lower shadowmap resolutions (but not as much, to avoid peter-panning).

The formula was determined empirically and is subject to changes. Nonetheless, I think it's a good start to make graphics settings adjustments easier for users to manage.

The bias values are unchanged at the default shadow size on desktop platforms (4096).

Testing project: test_shadow_bias_auto_resolution.zip

Preview

Each video starts at the highest shadow resolution and progressively decreases to the lowest shadow resolution.
It's recommended to view each video in fullscreen.

Before

Directional shadows

Visible acne at low shadow resolutions, even up close on the cubes. The distant shadow splits in particular are full of acne.

simplescreenrecorder-2022-02-04_19.49.04.mp4

Point light shadows

Visible acne at low shadow resolutions.

simplescreenrecorder-2022-02-04_19.48.38.mp4

After

Directional shadows

No more acne at low shadow resolutions. Shadow resolutions above the default value also have less visible peter-panning.

simplescreenrecorder-2022-02-04_19.45.50.mp4

Point light shadows

No more acne at low shadow resolutions. Shadow resolutions above the default value also have less visible peter-panning.

simplescreenrecorder-2022-02-04_19.46.21.mp4

@Calinou Calinou requested a review from a team as a code owner February 4, 2022 18:50
@Calinou Calinou added this to the 4.0 milestone Feb 4, 2022

float bias_scale;
if (directional_shadow.size < 4096) {
// For shadow map sizes below the default, don't increase bias too much to avoid peter-panning.
Copy link
Member Author

@Calinou Calinou Feb 4, 2022

Choose a reason for hiding this comment

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

Technically, we should be using the same formula as with shadow sizes above the default. However, this would result in too much peter-panning, so I went for a half-way compromise between not adjusting the bias at all and adjusting it to match the resolution perfectly.

The bias factors used for each resolution are:

  • 256: 8.5
  • 512: 4.5
  • 1024: 2.5
  • 2048: 1.5
  • 4096: 1.0
  • 8192: 0.5
  • 16384: 0.25

This applies to both directional and point light shadows.

Copy link
Contributor

@mrjustaguy mrjustaguy Feb 17, 2022

Choose a reason for hiding this comment

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

This logic should be different for Point Light Shadows, as you have to have the resolution of the cell the shadow is using, not the entire shadow map.

This would incorrectly change bias for the same effective resolution of shadow if you go from a 4k shadow map with 4 4 4 4 quadrants and change to 8k shadow map resolution with 16 16 16 16 quadrants which effectively results in same resolution, just more shadows available.

Higher shadowmap resolutions make it possible to use lower bias
values without exhibiting shadow acne. On the other hand,
shadow bias should be increased when using lower shadowmap resolutions
(but not as much, to avoid peter-panning).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants