-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
PCF For DirectionalLight/SpotLight Shadows #8006
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically ready to approve this, just a few nits/minor comments.
And we must make an issue and remember to implement Receiver Plane Depth Bias ( https://web.archive.org/web/20230309054654/http://developer.amd.com/wordpress/media/2012/10/Isidoro-ShadowMapping.pdf slides 36-38). We could additionally implement Adaptive Depth Bias for Shadows ( https://jcgt.org/published/0003/04/08/ ) with the tweaks from Adaptive Depth Bias for Soft Shadows ( https://w3-o.cs.hm.edu/users/nischwit/public_html/AdaptiveDepthBias_WSCG.pdf ) separately from this PR.
// NOTE: Due to non-uniform control flow above, we must use the level variant of the texture | ||
// sampler to avoid use of implicit derivatives causing possible undefined behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now this is split into its own function that this is no longer true. I have some memory of the control flow only applying within a function scope. Though I also remember thinking that was weird given it sounds like shader compilers generally inline everything? @cwfitzgerald - is the non-uniform control flow for the entire execution of the shader after entering the region of non-uniform control flow? Or is it scoped to functions? Or is the validation scoped to functions but the rule does apply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cwfitzgerald confirmed that naga should emit validation errors if the texture sampling is done inside non-uniform control flow even if the code calls to another function.
Still, I think the Level
variant makes sense regardless for shadow maps as they are not mipmapped and don't need gradients / mip level calculation to be done.
} | ||
|
||
// https://web.archive.org/web/20230210095515/http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1 | ||
fn sample_shadow_map_castano_thirteen(light_local: vec2<f32>, depth: f32, array_index: i32) -> f32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implements the 5x5 filter size but the implementation in MJP's has code for 3, 5, 7. We could add options for 3 and 7 later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5x5 I found to give good results, didn't feel the need to do 3 or 7 atm, but yeah we can add it trivially in the future (at the cost of more pipeline key bits).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or some view flags or something.
// NOTE: Due to non-uniform control flow above, we must use the level variant of the texture | ||
// sampler to avoid use of implicit derivatives causing possible undefined behavior. | ||
#ifdef NO_ARRAY_TEXTURES_SUPPORT | ||
return textureSampleCompareLevel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment on this in the place where the code was moved. I want to double-check with cwfitzgerald. :)
Co-authored-by: Robert Swain <[email protected]>
Co-authored-by: Robert Swain <[email protected]>
// NOTE: Due to non-uniform control flow above, we must use the level variant of the texture | ||
// sampler to avoid use of implicit derivatives causing possible undefined behavior. | ||
#ifdef NO_ARRAY_TEXTURES_SUPPORT | ||
return textureSampleCompareLevel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, bother blocks are needed and both should be textureSampleCompareLevel.
# Objective - Improve antialiasing for non-point light shadow edges. - Very partially addresses bevyengine#3628. ## Solution - Implements "The Witness"'s shadow map sampling technique. - Ported from @superdump's old branch, all credit to them :) - Implements "Call of Duty: Advanced Warfare"'s stochastic shadow map sampling technique when the velocity prepass is enabled, for use with TAA. - Uses interleaved gradient noise to generate a random angle, and then averages 8 samples in a spiral pattern, rotated by the random angle. - I also tried spatiotemporal blue noise, but it was far too noisy to be filtered by TAA alone. In the future, we should try spatiotemporal blue noise + a specialized shadow denoiser such as https://gpuopen.com/fidelityfx-denoiser/#shadow. This approach would also be useful for hybrid rasterized applications with raytraced shadows. - The COD presentation has an interesting temporal dithering of the noise for use with temporal supersampling that we should revisit when we get DLSS/FSR/other TSR. --- ## Changelog * Added `ShadowFilteringMethod`. Improved directional light and spotlight shadow edges to be less aliased. ## Migration Guide * Shadows cast by directional lights or spotlights now have smoother edges. To revert to the old behavior, add `ShadowFilteringMethod::Hardware2x2` to your cameras. --------- Co-authored-by: IceSentry <[email protected]> Co-authored-by: Daniel Chia <[email protected]> Co-authored-by: robtfm <[email protected]> Co-authored-by: Brandon Dyer <[email protected]> Co-authored-by: Edgar Geier <[email protected]> Co-authored-by: Robert Swain <[email protected]> Co-authored-by: Elabajaba <[email protected]> Co-authored-by: IceSentry <[email protected]>
# Objective - Improve antialiasing for non-point light shadow edges. - Very partially addresses bevyengine#3628. ## Solution - Implements "The Witness"'s shadow map sampling technique. - Ported from @superdump's old branch, all credit to them :) - Implements "Call of Duty: Advanced Warfare"'s stochastic shadow map sampling technique when the velocity prepass is enabled, for use with TAA. - Uses interleaved gradient noise to generate a random angle, and then averages 8 samples in a spiral pattern, rotated by the random angle. - I also tried spatiotemporal blue noise, but it was far too noisy to be filtered by TAA alone. In the future, we should try spatiotemporal blue noise + a specialized shadow denoiser such as https://gpuopen.com/fidelityfx-denoiser/#shadow. This approach would also be useful for hybrid rasterized applications with raytraced shadows. - The COD presentation has an interesting temporal dithering of the noise for use with temporal supersampling that we should revisit when we get DLSS/FSR/other TSR. --- ## Changelog * Added `ShadowFilteringMethod`. Improved directional light and spotlight shadow edges to be less aliased. ## Migration Guide * Shadows cast by directional lights or spotlights now have smoother edges. To revert to the old behavior, add `ShadowFilteringMethod::Hardware2x2` to your cameras. --------- Co-authored-by: IceSentry <[email protected]> Co-authored-by: Daniel Chia <[email protected]> Co-authored-by: robtfm <[email protected]> Co-authored-by: Brandon Dyer <[email protected]> Co-authored-by: Edgar Geier <[email protected]> Co-authored-by: Robert Swain <[email protected]> Co-authored-by: Elabajaba <[email protected]> Co-authored-by: IceSentry <[email protected]>
# Objective - Improve antialiasing for non-point light shadow edges. - Very partially addresses bevyengine#3628. ## Solution - Implements "The Witness"'s shadow map sampling technique. - Ported from @superdump's old branch, all credit to them :) - Implements "Call of Duty: Advanced Warfare"'s stochastic shadow map sampling technique when the velocity prepass is enabled, for use with TAA. - Uses interleaved gradient noise to generate a random angle, and then averages 8 samples in a spiral pattern, rotated by the random angle. - I also tried spatiotemporal blue noise, but it was far too noisy to be filtered by TAA alone. In the future, we should try spatiotemporal blue noise + a specialized shadow denoiser such as https://gpuopen.com/fidelityfx-denoiser/#shadow. This approach would also be useful for hybrid rasterized applications with raytraced shadows. - The COD presentation has an interesting temporal dithering of the noise for use with temporal supersampling that we should revisit when we get DLSS/FSR/other TSR. --- ## Changelog * Added `ShadowFilteringMethod`. Improved directional light and spotlight shadow edges to be less aliased. ## Migration Guide * Shadows cast by directional lights or spotlights now have smoother edges. To revert to the old behavior, add `ShadowFilteringMethod::Hardware2x2` to your cameras. --------- Co-authored-by: IceSentry <[email protected]> Co-authored-by: Daniel Chia <[email protected]> Co-authored-by: robtfm <[email protected]> Co-authored-by: Brandon Dyer <[email protected]> Co-authored-by: Edgar Geier <[email protected]> Co-authored-by: Robert Swain <[email protected]> Co-authored-by: Elabajaba <[email protected]> Co-authored-by: IceSentry <[email protected]>
Objective
Solution
Changelog
ShadowFilteringMethod
. Improved directional light and spotlight shadow edges to be less aliased.Migration Guide
ShadowFilteringMethod::Hardware2x2
to your cameras.