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

Scale normal bias by texel size #26

Merged

Conversation

superdump
Copy link

This PR:

  • is based on Better depth biases #23.
  • removes incorrect bilinear filtering.
  • sets DepthBiasState constant bias to 0 and slope scale bias to 0.0 to remove their effect. This will be added back as a configurable alternative biasing approach shortly.
  • adds a shadow_biases_pipelined example with a free-look camera that initialises the lights' depth biases to 0.0 to show full self-shadowing and allows adjustment of the biases for point and directional lights.
    • Move the camera with WSAD, E is up, Q is down, LShift is 'run', mouse for looking around.
    • PointLight depth bias can be adjusted down/up with 1/2, normal bias with 3/4, DirectionalLight depth bias with 5/6, normal bias with 7/8.
    • Initially the directional light is used, press L to switch lights.
  • Scale the normal bias according to the shadow map texel size. More details can be seen in this article about directional shadows and this article about point shadows.

This list looks like a lot, but the PR files diff looks fairly straightforward so I think it will be quite ok to review.

superdump added 18 commits July 10, 2021 08:23
This is useful for stress testing biases.
…size

This allows the normal bias to be small close to the light source where the
shadow map texel to screen texel ratio is high, but is appropriately large
further away from the light source where the shadow map texel can easily cover
multiple screen texels.
…ojection

Before this change, sampling a fragment position from outside the ndc volume
would result in the return sample being clamped to the edge in x,y or possibly
always casting a shadow for fragment positions past the orthographic
projection's far plane.
@cart
Copy link
Owner

cart commented Jul 16, 2021

Looks good to me!

@cart
Copy link
Owner

cart commented Jul 16, 2021

Resolve conflicts and we're good to go!

@superdump superdump force-pushed the scale-normal-bias-by-texel-size branch from a35f681 to 17e96ed Compare July 17, 2021 14:14
@superdump
Copy link
Author

* removes incorrect bilinear filtering.

I was wrong about this so I reverted that commit. The sampler needs to have filtering: true and min/mag filters set to Linear for the hardware bilinear 2x2 PCF sampling.

adds a shadow_biases_pipelined example with a free-look camera that initialises the lights' depth biases to 0.0 to show full self-shadowing and allows adjustment of the biases for point and directional lights.
* Move the camera with WSAD, E is up, Q is down, LShift is 'run', mouse for looking around.
* PointLight depth bias can be adjusted down/up with 1/2, normal bias with 3/4, DirectionalLight depth bias with 5/6, normal bias with 7/8.
* Initially the directional light is used, press L to switch lights.

I printed the usage to stdout when starting the example.

@cart cart merged commit 6604d47 into cart:pipelined-rendering Jul 19, 2021
cart pushed a commit that referenced this pull request Jul 24, 2021
* 3d_scene_pipelined: Use a shallower directional light angle to provoke acne

* cornell_box_pipelined: Remove bias tweaks

* bevy_pbr2: Simplify shadow biases by moving them to linear depth

* bevy_pbr2: Do not use DepthBiasState

* bevy_pbr2: Do not use bilinear filtering for sampling depth textures

* pbr.wgsl: Remove unnecessary comment

* bevy_pbr2: Do manual shadow map depth comparisons for more flexibility

* examples: Add shadow_biases_pipelined example

This is useful for stress testing biases.

* bevy_pbr2: Scale the point light normal bias by the shadow map texel size

This allows the normal bias to be small close to the light source where the
shadow map texel to screen texel ratio is high, but is appropriately large
further away from the light source where the shadow map texel can easily cover
multiple screen texels.

* shadow_biases_pipelined: Add support for toggling directional / point light

* shadow_biases_pipelined: Cleanup

* bevy_pbr2: Scale the directional light normal bias by the shadow map texel size

* shadow_biases_pipelined: Fit the orthographic projection around the scene

* bevy_pbr2: Directional lights should have no shadows outside their projection

Before this change, sampling a fragment position from outside the ndc volume
would result in the return sample being clamped to the edge in x,y or possibly
always casting a shadow for fragment positions past the orthographic
projection's far plane.

* bevy_pbr2: Fix the default directional light normal bias

* Revert "bevy_pbr2: Do manual shadow map depth comparisons for more flexibility"

This reverts commit 7df1bab.

* shadow_biases_pipelined: Adjust directional light normal bias in 0.1 increments

* pbr.wgsl: Add a couple of clarifying comments

* Revert "bevy_pbr2: Do not use bilinear filtering for sampling depth textures"

This reverts commit f53baab.

* shadow_biases_pipelined: Print usage to terminal
cart pushed a commit that referenced this pull request Jul 24, 2021
* 3d_scene_pipelined: Use a shallower directional light angle to provoke acne

* cornell_box_pipelined: Remove bias tweaks

* bevy_pbr2: Simplify shadow biases by moving them to linear depth

* bevy_pbr2: Do not use DepthBiasState

* bevy_pbr2: Do not use bilinear filtering for sampling depth textures

* pbr.wgsl: Remove unnecessary comment

* bevy_pbr2: Do manual shadow map depth comparisons for more flexibility

* examples: Add shadow_biases_pipelined example

This is useful for stress testing biases.

* bevy_pbr2: Scale the point light normal bias by the shadow map texel size

This allows the normal bias to be small close to the light source where the
shadow map texel to screen texel ratio is high, but is appropriately large
further away from the light source where the shadow map texel can easily cover
multiple screen texels.

* shadow_biases_pipelined: Add support for toggling directional / point light

* shadow_biases_pipelined: Cleanup

* bevy_pbr2: Scale the directional light normal bias by the shadow map texel size

* shadow_biases_pipelined: Fit the orthographic projection around the scene

* bevy_pbr2: Directional lights should have no shadows outside their projection

Before this change, sampling a fragment position from outside the ndc volume
would result in the return sample being clamped to the edge in x,y or possibly
always casting a shadow for fragment positions past the orthographic
projection's far plane.

* bevy_pbr2: Fix the default directional light normal bias

* Revert "bevy_pbr2: Do manual shadow map depth comparisons for more flexibility"

This reverts commit 7df1bab.

* shadow_biases_pipelined: Adjust directional light normal bias in 0.1 increments

* pbr.wgsl: Add a couple of clarifying comments

* Revert "bevy_pbr2: Do not use bilinear filtering for sampling depth textures"

This reverts commit f53baab.

* shadow_biases_pipelined: Print usage to terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants