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

PCF For DirectionalLight/SpotLight Shadows #8006

Merged
merged 482 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
482 commits
Select commit Hold shift + click to select a range
c157cae
Extract constants
JMS55 Jan 1, 2023
b6acf22
Remove newline
JMS55 Jan 1, 2023
715ca65
fix unwrap on empty frag shader in prepass
IceSentry Jan 2, 2023
35093ed
docs
IceSentry Jan 2, 2023
5c9bb20
Merge commit '35093ed2e81b737fadfa5b50c32a6e49245acdf0' into gtao
JMS55 Jan 8, 2023
826b19a
Fix merge
JMS55 Jan 8, 2023
060c52d
WIP FSR2 plugin
JMS55 Jan 11, 2023
14efad2
Further plugin setup
JMS55 Jan 12, 2023
77ca0c8
WIP: FSR2Plugin
JMS55 Jan 15, 2023
8f5fda4
FSR2 jitter (breaks TAA for now)
JMS55 Jan 16, 2023
1bb796f
Fix shader ifdefs
JMS55 Jan 16, 2023
63003f7
Extract projection
JMS55 Jan 16, 2023
0b757e0
Misc
JMS55 Jan 16, 2023
f48bb83
Fix dep path
JMS55 Jan 16, 2023
1d48c29
Add neccesary texture usages
JMS55 Jan 16, 2023
3d5c81c
Misc
JMS55 Jan 17, 2023
ff68974
Add device field
JMS55 Jan 17, 2023
e9942d7
Cleanup jitter
JMS55 Jan 18, 2023
0e38fb4
Error checking
JMS55 Jan 18, 2023
b35586f
Store device in context
JMS55 Jan 19, 2023
cada547
WIP: Update TAA impl
JMS55 Jan 20, 2023
88112be
Fixes
JMS55 Jan 20, 2023
2cc10d5
Move TAA to core pipeline
JMS55 Jan 20, 2023
bc87f4c
Merge commit 'cab065bad4302e4df427ffbafcdb112e755321ce' into taa-only
JMS55 Jan 20, 2023
bf89ceb
Misc
JMS55 Jan 20, 2023
a545e2a
Merge fixes
JMS55 Jan 20, 2023
c44c33a
Documentation
JMS55 Jan 20, 2023
1ddfa48
Misc formatting
JMS55 Jan 20, 2023
e76cd0e
Appease clippy
JMS55 Jan 20, 2023
bf36eb0
Add plugin note to docs
JMS55 Jan 20, 2023
6b90c2c
Clippy is not yet appeased
JMS55 Jan 20, 2023
a1ca8db
Fix prepass vertex shader ifdefs
JMS55 Jan 20, 2023
742d0a1
Doc improvements
JMS55 Jan 20, 2023
e3f6a7e
Extract temporal jitter elsewhere
JMS55 Jan 20, 2023
f894e83
Merge commit '02637b609e8c9371e8f8b54deae5ee8594fb76c1' into taa-only
JMS55 Jan 20, 2023
0ae10d6
Fix merge
JMS55 Jan 20, 2023
bc5574c
Update crates/bevy_render/src/camera/camera.rs
JMS55 Jan 20, 2023
dd99d43
Merge commit '38691ee95c7f58918aa13264a8a9c91f52fe1355' into taa-only
JMS55 Jan 22, 2023
2aad44e
Fix merge
JMS55 Jan 22, 2023
d138306
Add con of TAA to docs
JMS55 Jan 23, 2023
dc291f0
Combine AA examples
JMS55 Jan 23, 2023
db2e5e5
Fix example metadata
JMS55 Jan 23, 2023
052817a
Doc note
JMS55 Jan 23, 2023
8812cd8
Change tonemapping solution for TAA
JMS55 Jan 24, 2023
7ae829f
Merge commit 'cf612c8349068c2250dddf8190cd9cc5c24763d8' into taa-only
JMS55 Jan 24, 2023
9846dd9
Merge commit 'aab518af925e3f3b5d9b6a014faaab588ee43047' into taa-only
JMS55 Jan 27, 2023
b0bed7b
Merge commit '1e591bf7a5b491ca699ebe1eb3736c04d3cdffb7' into taa-only
JMS55 Jan 30, 2023
230e5fc
Address review feedback
JMS55 Jan 30, 2023
2d3fb83
Fix NaNs
JMS55 Feb 4, 2023
21bbe66
Update crates/bevy_core_pipeline/src/prepass/mod.rs
JMS55 Feb 4, 2023
fe67b5a
Update crates/bevy_core_pipeline/src/prepass/mod.rs
JMS55 Feb 4, 2023
ea22039
Update crates/bevy_core_pipeline/src/taa/taa.wgsl
JMS55 Feb 4, 2023
dbbce60
Gate update_mesh_previous_global_transforms
JMS55 Feb 4, 2023
5091758
Use before() instead of at_start() for prepare_taa_jitter()
JMS55 Feb 4, 2023
d0108eb
Save 4 velocity samples per pixel
JMS55 Feb 4, 2023
c4faea1
Merge commit '12f30f56675220275568d5a51afd32f14e608fd4' into taa-only
JMS55 Feb 4, 2023
bcd0698
Don't allow reinserting taa bundle in example
JMS55 Feb 6, 2023
bcd7a5d
Add TAA reset
JMS55 Feb 6, 2023
13e8ea1
Migrate to stageless: Merge commit 'dcc03724a57e0980bb98d1b642e80fb2d…
JMS55 Feb 6, 2023
e9e0ef6
Prepare non-reset pipeline early
JMS55 Feb 6, 2023
1455078
Fix update_previous_view_projections
JMS55 Feb 6, 2023
039e081
Clear velocity to yellow
JMS55 Feb 6, 2023
d456a1f
Improve TAA docs
JMS55 Feb 6, 2023
ef0845f
Possible faster velocity clear
JMS55 Feb 7, 2023
42c3671
Add TODO about velocity format
JMS55 Feb 7, 2023
9a54c54
Merge commit '943499fcdf2301ea4091b8c4ebaa491dd8c26c33' into taa-only
JMS55 Feb 7, 2023
c845115
Fix schedule import
JMS55 Feb 7, 2023
47bf23f
Switch tonemapping to max3
JMS55 Feb 7, 2023
a577c23
Remove outdated doc comment
JMS55 Feb 7, 2023
5fd9c98
Move TAA to experimental module
JMS55 Feb 7, 2023
4366dd2
Misc rename
JMS55 Feb 7, 2023
52fc423
Reduce noise in static scenes
JMS55 Feb 8, 2023
4feab0e
Misc
JMS55 Feb 8, 2023
69c1dfe
Remove velocity_prepass_location
JMS55 Feb 8, 2023
e179e8a
Merge commit 'fefe5297ad00f93cc92df61153cb15dad3ae4857' into taa-only
JMS55 Feb 9, 2023
2cae300
Misc doc tweak
JMS55 Feb 9, 2023
87ef413
wip
IceSentry Feb 10, 2023
557a278
Merge pull request #6 from IceSentry/taa-moving-sphere
JMS55 Feb 10, 2023
0df70a2
Revert "moving sphere"
JMS55 Feb 10, 2023
e516f88
Merge pull request #7 from JMS55/revert-6-taa-moving-sphere
JMS55 Feb 10, 2023
49e21f6
Misc example cleanup
JMS55 Feb 10, 2023
80ae486
Merge branch 'taa-only' of https://github.com/JMS55/bevy into taa-only
JMS55 Feb 10, 2023
e7e228e
Merge commit 'eaac730617103b61fd5ede9dca463243f2d7900e' into taa-only
JMS55 Feb 12, 2023
2fb3291
Tweak min history blend rate
JMS55 Feb 12, 2023
64a52bf
Misc refactor
JMS55 Feb 12, 2023
f388878
Increase history confidence faster
JMS55 Feb 12, 2023
a10faa3
Update docs
JMS55 Feb 13, 2023
dd80e7c
Merge remote-tracking branch 'bevy/staging' into taa-only
JMS55 Feb 13, 2023
af38b4c
Tweak MIN_HISTORY_BLEND_RATE for smoother edges, at the cost of more …
JMS55 Feb 16, 2023
9f1a497
Tweak blend rate, probably for the final time
JMS55 Feb 17, 2023
5593ef9
Merge commit 'b24ed8bb0cf5567fd2467751d673754d102b47e4' into taa-only
JMS55 Feb 17, 2023
0f79160
Add MSAA sample count selection to AA example
JMS55 Feb 17, 2023
90725a2
Merge commit '3ec87e49ca49767fad658e72fbae353f6687198c' into taa-only
JMS55 Feb 21, 2023
191d1d8
Update Cargo.toml
JMS55 Feb 22, 2023
791460d
Consistent spelling of anti-aliasing
JMS55 Feb 22, 2023
6de0f46
Merge commit '15c55a12ff53c702acb167761424182f77f64dd7' into taa-only
JMS55 Feb 26, 2023
7c19b60
Rustfmt
JMS55 Feb 27, 2023
33012fb
Merge commit '9733613c07d65bc726f0eb1d955c363fb8e2b5c7' into taa-only
JMS55 Mar 2, 2023
56329de
Remove dead code
JMS55 Mar 2, 2023
de7d75b
Add neccesary command flush
JMS55 Mar 2, 2023
9891e8a
Misc
JMS55 Mar 2, 2023
68dbaf5
Revert "Misc"
JMS55 Mar 2, 2023
ea1840f
Shader ifdef fixes
JMS55 Mar 2, 2023
c416630
Rename velocity prepass to motion vector prepasss
JMS55 Mar 2, 2023
51631c0
Misc tweak
JMS55 Mar 2, 2023
b6d8b67
Merge remote-tracking branch 'bevyengine/main' into patch-taa
robtfm Mar 3, 2023
8cbc894
fix target/attach vecs
robtfm Mar 3, 2023
754192d
center jitter at zero
robtfm Mar 3, 2023
a7b0103
alpha-blend comment
robtfm Mar 3, 2023
17771e5
ci
robtfm Mar 3, 2023
81e9d29
Merge pull request #9 from robtfm/patch-taa
JMS55 Mar 3, 2023
aa0310e
Improve TAA jitter
JMS55 Mar 3, 2023
241875b
Update crates/bevy_pbr/src/prepass/mod.rs
JMS55 Mar 3, 2023
84cec18
Fix compile error
JMS55 Mar 3, 2023
04a9722
Fix shader_prepass
JMS55 Mar 3, 2023
415620d
Misc
JMS55 Mar 3, 2023
cccb2c2
Output motion vectors at render resolution, not ndc
JMS55 Mar 3, 2023
946f8d8
Add motion vectors to shader_prepass example
JMS55 Mar 3, 2023
66960e6
Fix label color in shader_prepass example
JMS55 Mar 3, 2023
ad4e19f
Revert "Output motion vectors at render resolution, not ndc"
JMS55 Mar 3, 2023
503deda
Fix update_mesh_previous_global_transforms() missing from schedule
JMS55 Mar 3, 2023
554c9a0
Update crates/bevy_pbr/src/prepass/mod.rs
JMS55 Mar 3, 2023
4af080c
Misc fixes
JMS55 Mar 3, 2023
2fb717e
Fix wrong system set
JMS55 Mar 4, 2023
fd5eeb5
Add comment
JMS55 Mar 4, 2023
d875e1c
Fix missing system
JMS55 Mar 4, 2023
6ec93f7
Improve show_prepass motion vectors
JMS55 Mar 4, 2023
d0ce763
Merge remote-tracking branch 'bevy/main' into taa-only
JMS55 Mar 4, 2023
7537c24
Fix shadow pass when no prepass is enabled
JMS55 Mar 4, 2023
9893d90
Misc formatting
JMS55 Mar 5, 2023
e289178
Merge commit '6124b20f4bb6c706f01c7a71259989696c91dea5' into taa-only
JMS55 Mar 5, 2023
c365924
Merge commit 'f3cf734659dc9e7f33e67364920231f1c51782dd' into taa-only
JMS55 Mar 7, 2023
15b050c
Merge commit '2908bb5e8a3ec00b883c7120a7a69f6e34bb642e' into taa-only
JMS55 Mar 9, 2023
6256fbf
WIP
JMS55 Mar 9, 2023
864b348
Fixes
JMS55 Mar 9, 2023
48b7287
Refactor
JMS55 Mar 9, 2023
6fd8003
Tweak PCF settings
JMS55 Mar 9, 2023
158fea9
Add wrapping stochastic noise sampler
JMS55 Mar 9, 2023
4251947
Many fixes
JMS55 Mar 9, 2023
5067c22
Turn on or off stochastic sampling
JMS55 Mar 9, 2023
4dd6d63
Misc formatting
JMS55 Mar 9, 2023
cc72658
Misc fix
JMS55 Mar 9, 2023
968443b
Fix dumb bug
JMS55 Mar 10, 2023
fb4ce64
Misc fix
JMS55 Mar 10, 2023
956d825
Merge commit 'fd1af7c8b8a737b4da79615741f8844069bc6a5c' into taa-only
JMS55 Mar 11, 2023
02a98d8
Fix stupid bug
JMS55 Mar 11, 2023
4e96e73
Remove unnecsary trace
JMS55 Mar 11, 2023
d80d102
Refactor
JMS55 Mar 11, 2023
2031d02
Refactor
JMS55 Mar 11, 2023
369a12c
Add the witness PCF technique
JMS55 Mar 11, 2023
a2b7e61
Fix typo
JMS55 Mar 11, 2023
bd3e1ed
Use interleaved gradient noise instead of spatiotemporal blue noise f…
JMS55 Mar 11, 2023
f61e294
Remove spatiotemporal blue noise sampling
JMS55 Mar 11, 2023
abb344a
Misc fix
JMS55 Mar 11, 2023
e5b64a6
Misc fix
JMS55 Mar 12, 2023
1295cb0
Merge commit '13196613ee3a1add2e525dc8d6a52d8534ebef81' into taa-only
JMS55 Mar 14, 2023
7feee3b
Merge commit '1295cb0d3e22995da69226ca0f862f2892873d0b' into stochast…
JMS55 Mar 14, 2023
fd09554
PCF for spotlights
JMS55 Mar 14, 2023
6242fd8
Update crates/bevy_core_pipeline/src/prepass/node.rs
JMS55 Mar 16, 2023
f61be1b
Doc tweak
JMS55 Mar 16, 2023
98baa5c
Misc refactor
JMS55 Mar 16, 2023
dc22250
Merge commit '7b7294b8a7c5f7531c52a2524a6a3a456c0519c0' into taa-only
JMS55 Mar 20, 2023
b3de57e
Merge commit 'caa662272ce91028cef6e237bb7c2a3e78727ef4' into taa-only
JMS55 Mar 21, 2023
765fa48
Misc fix
JMS55 Mar 21, 2023
4c03655
Merge commit '2c21d423fde265d1108270bd835b95a5164361cb' into taa-only
JMS55 Mar 21, 2023
12dd618
Remove view entity slot
JMS55 Mar 21, 2023
4227fa6
Update crates/bevy_core_pipeline/src/taa/taa.wgsl
JMS55 Mar 26, 2023
769b0af
Misc refactor
JMS55 Mar 26, 2023
a438db7
Merge branch 'taa-only' of https://github.com/JMS55/bevy into taa-only
JMS55 Mar 26, 2023
46aadc7
Rename TemporalAntialias -> TemporalAntiAlias
JMS55 Mar 26, 2023
b75aa88
Switch MOTION_VECTOR_PREPASS_FORMAT to Rg16Float
JMS55 Mar 26, 2023
a79cfdf
Doc comment
JMS55 Mar 26, 2023
6bb7fd2
Fix clip_towards_aabb_center
JMS55 Mar 26, 2023
c452322
Add docs for blend rates
JMS55 Mar 26, 2023
2479118
Misc
JMS55 Mar 26, 2023
8f6e0f7
Update docs
JMS55 Mar 26, 2023
3ae680c
Update crates/bevy_pbr/src/prepass/prepass.wgsl
JMS55 Mar 26, 2023
d4803b1
Update crates/bevy_pbr/src/render/pbr_prepass.wgsl
JMS55 Mar 26, 2023
1d43e47
Merge commit 'd4803b1331ea2356063147a2a67edb5ccc052d24' into stochast…
JMS55 Mar 27, 2023
d0215f0
Merge commit '53667dea56d24a17eb60b40bffc6baa1cdc8b063' into stochast…
JMS55 Mar 27, 2023
6a276ca
Rename shadow sampling functions
JMS55 Mar 28, 2023
113ed48
Configurable shadow smoothing
JMS55 Mar 30, 2023
dbe84c7
Rename
JMS55 Mar 30, 2023
647a3b1
Merge commit '5f0abbfd157969d82b632552cd7a36d53b41c2cf' into stochast…
JMS55 Mar 30, 2023
9b28ae6
Fix rebase
JMS55 Mar 30, 2023
03679b2
Misc
JMS55 Mar 30, 2023
fa5c456
Misc refactor
JMS55 Mar 30, 2023
5502b30
Rename cascade
JMS55 Mar 31, 2023
3dc995a
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
3a0cf98
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
790ca50
Move variable
JMS55 Apr 1, 2023
c8afd4e
Rename type
JMS55 Apr 1, 2023
4141202
Revert
JMS55 Apr 1, 2023
c510565
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
ac62cd9
Update crates/bevy_pbr/src/material.rs
JMS55 Apr 1, 2023
dec355f
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
1a1069c
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
9b62975
Update crates/bevy_pbr/src/render/mesh.rs
JMS55 Apr 1, 2023
902df9c
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
aa831aa
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
635ef53
Update crates/bevy_pbr/src/render/mesh.rs
JMS55 Apr 1, 2023
7ff265d
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
24b9445
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
1d42314
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Apr 1, 2023
928de12
Merge commit '670f3f0dce2ced27388b10672d30594d399434e1' into stochast…
JMS55 Apr 27, 2023
4094248
Merge commit 'd1158288d5977ccea8c87adf80359ff9e21a852e' into stochast…
JMS55 Jun 3, 2023
6e8b341
Merge remote-tracking branch 'bevy/main' into stochastic_dir_pcf
JMS55 Jun 19, 2023
12f6aa8
Merge commit '4b1a502a4917bd2ab4d17677a9eb29cdaa7cfe0c' into stochast…
JMS55 Jun 26, 2023
cf10ba1
Improve TAA
JMS55 Jun 27, 2023
6882513
Merge commit 'a30da0001ea3479fda32ac286e1a6647c791e5c1' into stochast…
JMS55 Jul 17, 2023
36294d3
Move function to another file
JMS55 Jul 17, 2023
5f4befc
Merge commit 'eb485b1acc619baaae88d5daca0a311b95886281' into stochast…
JMS55 Jul 22, 2023
935e976
Merge commit '0566e73af460b9d128354a20970b1e1e0cc3b719' into taa-impr…
JMS55 Jul 27, 2023
8c98923
Merge commit '08ea1d18aed1a7996c9abeef566a6bcc5e023fc2' into stochast…
JMS55 Jul 31, 2023
c18c106
Fix missing shader defs
JMS55 Aug 5, 2023
346577a
Fix WebGL2 crashes
JMS55 Aug 6, 2023
e994ca4
Tweak Jimenez14 PCF scale
JMS55 Aug 6, 2023
8f09028
Merge commit 'ac8f36743e7cb7e6a85e563e3ff52e57ec1676a5' into stochast…
JMS55 Aug 12, 2023
5118466
Merge commit 'ac8f36743e7cb7e6a85e563e3ff52e57ec1676a5' into taa-impr…
JMS55 Aug 12, 2023
d4fdbfd
Merge commit '505b9a58bd8768c7d31446ee9bb23639cd127cc5' into taa-impr…
JMS55 Aug 15, 2023
4f5faaa
Reword doc comment
JMS55 Aug 15, 2023
97e7c98
Fix bug?
JMS55 Aug 15, 2023
4349adb
Fix TemporalJitter
JMS55 Aug 15, 2023
f44b7c7
Merge commit '4349adbb12035ac52557b928f5ecce526ec2a768' into stochast…
JMS55 Aug 15, 2023
7032da8
Merge commit 'b6a9d8eba7807b63be525e423911c0217706f13a' into stochast…
JMS55 Aug 17, 2023
2241fda
Revert changes to AA example
JMS55 Aug 17, 2023
7076dd5
Improve Jimenez14
JMS55 Aug 17, 2023
c515fd3
Guess halfway value for spotlight texel_size
JMS55 Aug 17, 2023
bc5c6a2
Revert TAA
JMS55 Aug 17, 2023
711f753
Fix extra space in doc
JMS55 Aug 17, 2023
d382a5d
Misc
JMS55 Aug 18, 2023
5b2a434
Merge commit '8a8d43d224fe59cec9edef19037e8c227ae38c64' into stochast…
JMS55 Aug 18, 2023
8d8031f
fix dx12 shader miscompilation with jimenez temporal pcf
Elabajaba Aug 31, 2023
5da5402
fix normal prepass pcf compilation bug
Elabajaba Aug 31, 2023
a8a4199
Merge pull request #14 from Elabajaba/fix_pcf_normal_prepass
JMS55 Aug 31, 2023
18a5571
vec2
Elabajaba Sep 1, 2023
ebaebe0
Merge pull request #13 from Elabajaba/dx12_pcf
JMS55 Sep 1, 2023
7f985bb
Merge commit '02025eff0b25bb8c18103dbafc33a764e1989ad4' into stochast…
JMS55 Sep 1, 2023
6557168
Misc
JMS55 Sep 2, 2023
f6c6f6b
Update crates/bevy_pbr/src/render/shadows.wgsl
JMS55 Sep 6, 2023
4d86b6d
Document numbers
JMS55 Sep 14, 2023
2867d90
Merge commit '8192ac6f1e572601b4ada08fa2f82114e07f8aec' into stochast…
JMS55 Sep 14, 2023
c26f643
Merge commit '8ace2ff9e361dd7ef1bc620b84674def0cb56454' into stochast…
JMS55 Sep 24, 2023
8234d7d
Merge commit '20ed3e0e765405ee334a44ce3c49c72bd29ab753' into stochast…
JMS55 Sep 28, 2023
0e60a90
Update crates/bevy_pbr/src/render/shadows.wgsl
JMS55 Oct 1, 2023
600b3a8
Update crates/bevy_pbr/src/render/shadow_sampling.wgsl
JMS55 Oct 1, 2023
24eab26
Change sample_shadow_map_hardware
JMS55 Oct 1, 2023
e24e1c5
Fix sample_shadow_map_hardware()
JMS55 Oct 5, 2023
394fdba
Merge commit 'a9622408665662eff9ddae83d913c6cfa2fa61d2' into stochast…
JMS55 Oct 5, 2023
4f9dff2
Merge commit '154a49044514fb21b0f83f4f077d76380e12a8a8' into stochast…
JMS55 Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, AssetApp, Assets, Handle};
use bevy_ecs::prelude::*;
use bevy_render::{
camera::CameraUpdateSystem, extract_resource::ExtractResourcePlugin, prelude::Color,
render_asset::prepare_assets, render_graph::RenderGraph, render_phase::sort_phase_system,
render_resource::Shader, texture::Image, view::VisibilitySystems, ExtractSchedule, Render,
RenderApp, RenderSet,
camera::CameraUpdateSystem, extract_component::ExtractComponentPlugin,
extract_resource::ExtractResourcePlugin, prelude::Color, render_asset::prepare_assets,
render_graph::RenderGraph, render_phase::sort_phase_system, render_resource::Shader,
texture::Image, view::VisibilitySystems, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_transform::TransformSystem;
use environment_map::EnvironmentMapPlugin;
Expand All @@ -69,6 +69,7 @@ pub const UTILS_HANDLE: Handle<Shader> = Handle::weak_from_u128(1900548483293416
pub const CLUSTERED_FORWARD_HANDLE: Handle<Shader> = Handle::weak_from_u128(166852093121196815);
pub const PBR_LIGHTING_HANDLE: Handle<Shader> = Handle::weak_from_u128(14170772752254856967);
pub const SHADOWS_HANDLE: Handle<Shader> = Handle::weak_from_u128(11350275143789590502);
pub const SHADOW_SAMPLING_HANDLE: Handle<Shader> = Handle::weak_from_u128(3145627513789590502);
pub const PBR_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(4805239651767701046);
pub const PBR_PREPASS_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(9407115064344201137);
pub const PBR_FUNCTIONS_HANDLE: Handle<Shader> = Handle::weak_from_u128(16550102964439850292);
Expand Down Expand Up @@ -124,6 +125,12 @@ impl Plugin for PbrPlugin {
"render/shadows.wgsl",
Shader::from_wgsl
);
load_internal_asset!(
app,
SHADOW_SAMPLING_HANDLE,
"render/shadow_sampling.wgsl",
Shader::from_wgsl
);
load_internal_asset!(
app,
PBR_FUNCTIONS_HANDLE,
Expand Down Expand Up @@ -168,6 +175,7 @@ impl Plugin for PbrPlugin {
.register_type::<PointLight>()
.register_type::<PointLightShadowMap>()
.register_type::<SpotLight>()
.register_type::<ShadowFilteringMethod>()
.init_resource::<AmbientLight>()
.init_resource::<GlobalVisiblePointLights>()
.init_resource::<DirectionalLightShadowMap>()
Expand All @@ -182,6 +190,7 @@ impl Plugin for PbrPlugin {
EnvironmentMapPlugin,
ExtractResourcePlugin::<AmbientLight>::default(),
FogPlugin,
ExtractComponentPlugin::<ShadowFilteringMethod>::default(),
))
.configure_sets(
PostUpdate,
Expand Down
31 changes: 31 additions & 0 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bevy_reflect::prelude::*;
use bevy_render::{
camera::Camera,
color::Color,
extract_component::ExtractComponent,
extract_resource::ExtractResource,
prelude::Projection,
primitives::{Aabb, CascadesFrusta, CubemapFrusta, Frustum, HalfSpace, Sphere},
Expand Down Expand Up @@ -606,6 +607,36 @@ pub struct NotShadowCaster;
#[reflect(Component, Default)]
pub struct NotShadowReceiver;

/// Add this component to a [`Camera3d`](bevy_core_pipeline::core_3d::Camera3d)
/// to control how to anti-alias shadow edges.
///
/// The different modes use different approaches to
/// [Percentage Closer Filtering](https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-11-shadow-map-antialiasing).
///
/// Currently does not affect point lights.
#[derive(Component, ExtractComponent, Reflect, Clone, Copy, PartialEq, Eq, Default)]
#[reflect(Component, Default)]
pub enum ShadowFilteringMethod {
/// Hardware 2x2.
///
/// Fast but poor quality.
Hardware2x2,
/// Method by Ignacio Castaño for The Witness using 9 samples and smart
/// filtering to achieve the same as a regular 5x5 filter kernel.
///
/// Good quality, good performance.
#[default]
Castano13,
/// Method by Jorge Jimenez for Call of Duty: Advanced Warfare using 8
/// samples in spiral pattern, randomly-rotated by interleaved gradient
/// noise with spatial variation.
///
/// Good quality when used with
/// [`TemporalAntiAliasSettings`](bevy_core_pipeline::experimental::taa::TemporalAntiAliasSettings)
/// and good performance.
Jimenez14,
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum SimulationLightSystems {
AddClusters,
Expand Down
17 changes: 16 additions & 1 deletion crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
render, AlphaMode, DrawMesh, DrawPrepass, EnvironmentMapLight, MeshPipeline, MeshPipelineKey,
PrepassPipelinePlugin, PrepassPlugin, RenderMeshInstances, ScreenSpaceAmbientOcclusionSettings,
SetMeshBindGroup, SetMeshViewBindGroup, Shadow,
SetMeshBindGroup, SetMeshViewBindGroup, Shadow, ShadowFilteringMethod,
};
use bevy_app::{App, Plugin};
use bevy_asset::{Asset, AssetApp, AssetEvent, AssetId, AssetServer, Assets, Handle};
Expand Down Expand Up @@ -440,6 +440,7 @@ pub fn queue_material_meshes<M: Material>(
Option<&Tonemapping>,
Option<&DebandDither>,
Option<&EnvironmentMapLight>,
Option<&ShadowFilteringMethod>,
Option<&ScreenSpaceAmbientOcclusionSettings>,
Option<&NormalPrepass>,
Option<&TemporalAntiAliasSettings>,
Expand All @@ -456,6 +457,7 @@ pub fn queue_material_meshes<M: Material>(
tonemapping,
dither,
environment_map,
shadow_filter_method,
ssao,
normal_prepass,
taa_settings,
Expand All @@ -482,6 +484,19 @@ pub fn queue_material_meshes<M: Material>(
if environment_map_loaded {
view_key |= MeshPipelineKey::ENVIRONMENT_MAP;
}

match shadow_filter_method.unwrap_or(&ShadowFilteringMethod::default()) {
ShadowFilteringMethod::Hardware2x2 => {
view_key |= MeshPipelineKey::SHADOW_FILTER_METHOD_HARDWARE_2X2;
}
ShadowFilteringMethod::Castano13 => {
view_key |= MeshPipelineKey::SHADOW_FILTER_METHOD_CASTANO_13;
}
ShadowFilteringMethod::Jimenez14 => {
view_key |= MeshPipelineKey::SHADOW_FILTER_METHOD_JIMENEZ_14;
}
}

if !view.hdr {
if let Some(tonemapping) = tonemapping {
view_key |= MeshPipelineKey::TONEMAP_IN_SHADER;
Expand Down
35 changes: 29 additions & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,24 +648,35 @@ bitflags::bitflags! {
const TONEMAP_METHOD_ACES_FITTED = 3 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_AGX = 4 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM = 5 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_TONY_MC_MAPFACE = 6 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_BLENDER_FILMIC = 7 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_TONY_MC_MAPFACE = 6 << Self::TONEMAP_METHOD_SHIFT_BITS;
const TONEMAP_METHOD_BLENDER_FILMIC = 7 << Self::TONEMAP_METHOD_SHIFT_BITS;
const SHADOW_FILTER_METHOD_RESERVED_BITS = Self::SHADOW_FILTER_METHOD_MASK_BITS << Self::SHADOW_FILTER_METHOD_SHIFT_BITS;
const SHADOW_FILTER_METHOD_HARDWARE_2X2 = 0 << Self::SHADOW_FILTER_METHOD_SHIFT_BITS;
const SHADOW_FILTER_METHOD_CASTANO_13 = 1 << Self::SHADOW_FILTER_METHOD_SHIFT_BITS;
const SHADOW_FILTER_METHOD_JIMENEZ_14 = 2 << Self::SHADOW_FILTER_METHOD_SHIFT_BITS;
}
}

impl MeshPipelineKey {
const MSAA_MASK_BITS: u32 = 0b111;
const MSAA_SHIFT_BITS: u32 = 32 - Self::MSAA_MASK_BITS.count_ones();

const PRIMITIVE_TOPOLOGY_MASK_BITS: u32 = 0b111;
const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u32 =
Self::MSAA_SHIFT_BITS - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones();

const BLEND_MASK_BITS: u32 = 0b11;
const BLEND_SHIFT_BITS: u32 =
Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS - Self::BLEND_MASK_BITS.count_ones();

const TONEMAP_METHOD_MASK_BITS: u32 = 0b111;
const TONEMAP_METHOD_SHIFT_BITS: u32 =
Self::BLEND_SHIFT_BITS - Self::TONEMAP_METHOD_MASK_BITS.count_ones();

const SHADOW_FILTER_METHOD_MASK_BITS: u32 = 0b11;
const SHADOW_FILTER_METHOD_SHIFT_BITS: u32 =
Self::TONEMAP_METHOD_SHIFT_BITS - Self::SHADOW_FILTER_METHOD_MASK_BITS.count_ones();

pub fn from_msaa_samples(msaa_samples: u32) -> Self {
let msaa_bits =
(msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS;
Expand Down Expand Up @@ -888,6 +899,16 @@ impl SpecializedMeshPipeline for MeshPipeline {
shader_defs.push("TAA".into());
}

let shadow_filter_method =
key.intersection(MeshPipelineKey::SHADOW_FILTER_METHOD_RESERVED_BITS);
if shadow_filter_method == MeshPipelineKey::SHADOW_FILTER_METHOD_HARDWARE_2X2 {
shader_defs.push("SHADOW_FILTER_METHOD_HARDWARE_2X2".into());
} else if shadow_filter_method == MeshPipelineKey::SHADOW_FILTER_METHOD_CASTANO_13 {
shader_defs.push("SHADOW_FILTER_METHOD_CASTANO_13".into());
} else if shadow_filter_method == MeshPipelineKey::SHADOW_FILTER_METHOD_JIMENEZ_14 {
shader_defs.push("SHADOW_FILTER_METHOD_JIMENEZ_14".into());
}

let format = if key.contains(MeshPipelineKey::HDR) {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
Expand Down Expand Up @@ -1053,10 +1074,12 @@ pub fn prepare_mesh_view_bind_groups(
Option<&EnvironmentMapLight>,
&Tonemapping,
)>,
images: Res<RenderAssets<Image>>,
mut fallback_images: FallbackImagesMsaa,
mut fallback_depths: FallbackImagesDepth,
fallback_cubemap: Res<FallbackImageCubemap>,
(images, mut fallback_images, mut fallback_depths, fallback_cubemap): (
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
Res<RenderAssets<Image>>,
FallbackImagesMsaa,
FallbackImagesDepth,
Res<FallbackImageCubemap>,
),
msaa: Res<Msaa>,
globals_buffer: Res<GlobalsBuffer>,
tonemapping_luts: Res<TonemappingLuts>,
Expand Down
123 changes: 123 additions & 0 deletions crates/bevy_pbr/src/render/shadow_sampling.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#define_import_path bevy_pbr::shadow_sampling

#import bevy_pbr::mesh_view_bindings as view_bindings
#import bevy_pbr::utils PI

fn sample_shadow_map_hardware(light_local: vec2<f32>, depth: f32, array_index: i32) -> f32 {
// Do the lookup, using HW 2x2 PCF and comparison
return textureSampleCompareLevel(
view_bindings::directional_shadow_textures,
view_bindings::directional_shadow_textures_sampler,
light_local,
array_index,
depth,
);
superdump marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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.

let shadow_map_size = vec2<f32>(textureDimensions(view_bindings::directional_shadow_textures));
let inv_shadow_map_size = 1.0 / shadow_map_size;

let uv = light_local * shadow_map_size;
var base_uv = floor(uv + 0.5);
let s = (uv.x + 0.5 - base_uv.x);
let t = (uv.y + 0.5 - base_uv.y);
base_uv -= 0.5;
base_uv *= inv_shadow_map_size;

let uw0 = (4.0 - 3.0 * s);
let uw1 = 7.0;
let uw2 = (1.0 + 3.0 * s);

let u0 = (3.0 - 2.0 * s) / uw0 - 2.0;
let u1 = (3.0 + s) / uw1;
let u2 = s / uw2 + 2.0;

let vw0 = (4.0 - 3.0 * t);
let vw1 = 7.0;
let vw2 = (1.0 + 3.0 * t);

let v0 = (3.0 - 2.0 * t) / vw0 - 2.0;
let v1 = (3.0 + t) / vw1;
let v2 = t / vw2 + 2.0;

var sum = 0.0;

sum += uw0 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u0, v0) * inv_shadow_map_size), depth, array_index);
sum += uw1 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u1, v0) * inv_shadow_map_size), depth, array_index);
sum += uw2 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u2, v0) * inv_shadow_map_size), depth, array_index);

sum += uw0 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u0, v1) * inv_shadow_map_size), depth, array_index);
sum += uw1 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u1, v1) * inv_shadow_map_size), depth, array_index);
sum += uw2 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u2, v1) * inv_shadow_map_size), depth, array_index);

sum += uw0 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u0, v2) * inv_shadow_map_size), depth, array_index);
sum += uw1 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u1, v2) * inv_shadow_map_size), depth, array_index);
sum += uw2 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u2, v2) * inv_shadow_map_size), depth, array_index);

return sum * (1.0 / 144.0);
}

// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>) -> f32 {
let frame = f32(view_bindings::globals.frame_count % 64u);
let xy = pixel_coordinates + 5.588238 * frame;
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
}

fn map(min1: f32, max1: f32, min2: f32, max2: f32, value: f32) -> f32 {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}

fn sample_shadow_map_jimenez_fourteen(light_local: vec2<f32>, depth: f32, array_index: i32, texel_size: f32) -> f32 {
let shadow_map_size = vec2<f32>(textureDimensions(view_bindings::directional_shadow_textures));

let random_angle = 2.0 * PI * interleaved_gradient_noise(light_local * shadow_map_size);
let m = vec2(sin(random_angle), cos(random_angle));
let rotation_matrix = mat2x2(
m.y, -m.x,
m.x, m.y
);

// Empirically chosen fudge factor to make PCF look better across different CSM cascades
let f = map(0.00390625, 0.022949219, 0.015, 0.035, texel_size);
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
let uv_offset_scale = f / (texel_size * shadow_map_size);

// https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare (slides 120-135)
let sample_offset1 = (rotation_matrix * vec2(-0.7071, 0.7071)) * uv_offset_scale;
let sample_offset2 = (rotation_matrix * vec2(-0.0000, -0.8750)) * uv_offset_scale;
let sample_offset3 = (rotation_matrix * vec2( 0.5303, 0.5303)) * uv_offset_scale;
let sample_offset4 = (rotation_matrix * vec2(-0.6250, -0.0000)) * uv_offset_scale;
let sample_offset5 = (rotation_matrix * vec2( 0.3536, -0.3536)) * uv_offset_scale;
let sample_offset6 = (rotation_matrix * vec2(-0.0000, 0.3750)) * uv_offset_scale;
let sample_offset7 = (rotation_matrix * vec2(-0.1768, -0.1768)) * uv_offset_scale;
let sample_offset8 = (rotation_matrix * vec2( 0.1250, 0.0000)) * uv_offset_scale;

var sum = 0.0;
sum += sample_shadow_map_hardware(light_local + sample_offset1, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset2, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset3, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset4, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset5, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset6, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset7, depth, array_index);
sum += sample_shadow_map_hardware(light_local + sample_offset8, depth, array_index);
return sum / 8.0;
}

fn sample_shadow_map(light_local: vec2<f32>, depth: f32, array_index: i32, texel_size: f32) -> f32 {
#ifdef SHADOW_FILTER_METHOD_CASTANO_13
return sample_shadow_map_castano_thirteen(light_local, depth, array_index);
#else ifdef SHADOW_FILTER_METHOD_JIMENEZ_14
return sample_shadow_map_jimenez_fourteen(light_local, depth, array_index, texel_size);
#else ifdef SHADOW_FILTER_METHOD_HARDWARE_2X2
return sample_shadow_map_hardware(light_local, depth, array_index);
#else
// This needs a default return value to avoid shader compilation errors if it's compiled with no SHADOW_FILTER_METHOD_* defined.
// (eg. if the normal prepass is enabled it ends up compiling this due to the normal prepass depending on pbr_functions, which depends on shadows)
superdump marked this conversation as resolved.
Show resolved Hide resolved
// This should never actually get used, as anyone using bevy's lighting/shadows should always have a SHADOW_FILTER_METHOD defined.
// Set to 0 to make it obvious that something is wrong.
return 0.0;
#endif
}
Loading