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

Screen Space Ambient Occlusion (SSAO) MVP #7402

Merged
merged 480 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
480 commits
Select commit Hold shift + click to select a range
134b27c
clean up pbr_prepass
IceSentry Dec 30, 2022
2b0f4f9
Apply suggestions from code review
IceSentry Dec 30, 2022
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
d95cc01
Merge branch 'main' into depth-prepass
IceSentry Jan 10, 2023
8e1ffbc
Merge branch 'main' into depth-prepass
IceSentry Jan 11, 2023
d64286f
update to main
IceSentry Jan 11, 2023
c9159a5
add alpha_mask_phase items is_empty check
IceSentry Jan 11, 2023
c99f582
shorten comment
IceSentry Jan 11, 2023
27db3b8
fix ci
IceSentry Jan 11, 2023
060c52d
WIP FSR2 plugin
JMS55 Jan 11, 2023
14efad2
Further plugin setup
JMS55 Jan 12, 2023
fdbb4d2
Merge branch 'main' into depth-prepass
IceSentry Jan 12, 2023
a5ec2f5
Merge branch 'main' into depth-prepass
IceSentry Jan 13, 2023
0af0d67
Merge remote-tracking branch 'icesentry/depth-prepass' into gtao
JMS55 Jan 13, 2023
a3e5c1b
Fix merge
JMS55 Jan 13, 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
c461c26
const instead of let for globals in shaders
Elabajaba Jan 24, 2023
769bd76
empty view_formats
Elabajaba Jan 24, 2023
5f7fa7d
dx12 compiler and new limits
Elabajaba Jan 24, 2023
9597c9a
surface creation
Elabajaba Jan 24, 2023
f60fc7a
wgpu release
Elabajaba Jan 26, 2023
e768e3e
default to DXC shader compiler
Elabajaba Jan 26, 2023
9eab378
Srgb surface
Elabajaba Jan 26, 2023
eb5b86a
add DXC .dlls to .gitignore
Elabajaba Jan 26, 2023
a26a121
fix missed indented global let -> const
Elabajaba Jan 26, 2023
9549bab
spelling
Elabajaba Jan 26, 2023
9846dd9
Merge commit 'aab518af925e3f3b5d9b6a014faaab588ee43047' into taa-only
JMS55 Jan 27, 2023
236aa4e
Merge commit '9549bab349b50eb9d9b8c6b61791dd479eb62b50' into ssao
JMS55 Jan 27, 2023
f45ce48
Rebase fixes
JMS55 Jan 27, 2023
f1a5f09
Merge?
JMS55 Jan 27, 2023
13e1b97
spelling
Elabajaba Jan 26, 2023
45ffa44
iter through formats to find the first good srgb one.
Elabajaba Jan 27, 2023
94a8ccf
potential crash fix when MSAA is unsupported
Elabajaba Jan 27, 2023
e645332
fix wrong doc comment
Elabajaba Jan 27, 2023
4818508
Merge commit 'e645332d5b2aeb43fb02979b58ecb462f660fdf5' into ssao
JMS55 Jan 27, 2023
675acec
whoops, forgot a /
Elabajaba Jan 27, 2023
b5269b3
WIP SSAO
JMS55 Jan 28, 2023
0048555
Merge commit '675acec9bce80bef6b66bc341d65476229dd351a' into ssao
JMS55 Jan 28, 2023
0907b6b
Refactor ssao texture creation
JMS55 Jan 28, 2023
75707e5
Fix weighted average of depths
JMS55 Jan 28, 2023
00594b7
Misc cleanup
JMS55 Jan 28, 2023
ad09b1a
Add SSAO documentation
JMS55 Jan 28, 2023
2c40dac
Add directional light to ssao example
JMS55 Jan 28, 2023
9c7bc40
Clarify ssao docs
JMS55 Jan 28, 2023
5409b3d
Appease clippy
JMS55 Jan 28, 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
ce37025
Skip clipping when confident in history
JMS55 Feb 7, 2023
51a46da
Merge commit 'ce3702503796e17f239b06b453c5f79bded07091' into ssao
JMS55 Feb 7, 2023
c170fa6
TAA fix
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
d6eb01d
Instead of skipping clipping when confident in history, expand clippi…
JMS55 Feb 8, 2023
0fcab25
Merge commit 'd6eb01d7500b48d370dd7780f7fc986f78b7664d' into ssao
JMS55 Feb 8, 2023
0a01d05
Try other clipping approach
JMS55 Feb 8, 2023
2fe6d91
More conservative anti specular flicker
JMS55 Feb 8, 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
c0acf54
Merge commit '69c1dfec0c747923c248579acbadc98d036804fe' into ssao
JMS55 Feb 8, 2023
58efd8f
Fix taa import
JMS55 Feb 8, 2023
0f5ccc5
Improve SSAO example sphere resolution
JMS55 Feb 8, 2023
e179e8a
Merge commit 'fefe5297ad00f93cc92df61153cb15dad3ae4857' into taa-only
JMS55 Feb 9, 2023
2cae300
Misc doc tweak
JMS55 Feb 9, 2023
61b9f78
Merge commit '2cae300a4985cafd51db1e0428f8d62fc9afcd57' into ssao
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
8071f35
Merge branch 'taa-only' into ssao
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
784315c
Merge commit '15b050c6772a35401c2fba95d1c464441856533b' into ssao
JMS55 Mar 9, 2023
84c0664
Misc
JMS55 Mar 9, 2023
4dd6d63
Misc formatting
JMS55 Mar 9, 2023
956d825
Merge commit 'fd1af7c8b8a737b4da79615741f8844069bc6a5c' into taa-only
JMS55 Mar 11, 2023
4e96e73
Remove unnecsary trace
JMS55 Mar 11, 2023
a2b7e61
Fix typo
JMS55 Mar 11, 2023
e5b64a6
Misc fix
JMS55 Mar 12, 2023
9de0664
Merge commit 'e5b64a6fe5f0e0b1c6239a86108fa9b113c1aa89' into ssao
JMS55 Mar 12, 2023
31b15f5
Misc
JMS55 Mar 12, 2023
1295cb0
Merge commit '13196613ee3a1add2e525dc8d6a52d8534ebef81' into taa-only
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
6046146
Merge commit 'd4803b1331ea2356063147a2a67edb5ccc052d24' into ssao
JMS55 Mar 26, 2023
f786b5d
Rebase fixes
JMS55 Mar 27, 2023
3cc7389
Add ssao debug group
JMS55 Mar 27, 2023
302628b
Faster depth conversions
JMS55 Mar 27, 2023
08fbac1
Merge commit '53667dea56d24a17eb60b40bffc6baa1cdc8b063' into ssao
JMS55 Mar 27, 2023
7b8b981
Misc
JMS55 Mar 30, 2023
c16cc1a
Merge commit '09f1bd0be7bb1b6642dab989f1ebafe8807a1473' into ssao
JMS55 Apr 2, 2023
8d3294a
Fix rebase
JMS55 Apr 2, 2023
fc85c3f
Shader import improvement
JMS55 Apr 2, 2023
cbe314b
WIP bent normals (denoising broken)
JMS55 Apr 2, 2023
ebee98a
Merge commit '670f3f0dce2ced27388b10672d30594d399434e1' into ssao
JMS55 Apr 27, 2023
3d6eaee
Misc fix
JMS55 Apr 27, 2023
ca591f9
Revert "WIP bent normals (denoising broken)"
JMS55 May 25, 2023
2c1420a
Revert "Faster depth conversions"
JMS55 May 25, 2023
2d11c9f
Merge commit 'bc9144bcd68999fed29840a57c60c63b79ffc531' into ssao-mvp
JMS55 May 25, 2023
d4af1a9
Implement Plugin::finish()
JMS55 May 25, 2023
3bc851b
Cleanup using new APIs
JMS55 May 25, 2023
0bf5143
Merge commit '3bc851be36cd160a76a8b3fbcddca8ee189bf765' into ssao
JMS55 May 25, 2023
bc2b3e5
Add max_storage_textures_per_shader_stage check
JMS55 May 26, 2023
b621312
Remove visibility modifier
JMS55 May 27, 2023
814392a
Clarify error messages
JMS55 May 27, 2023
61a73f9
Merge commit 'd1158288d5977ccea8c87adf80359ff9e21a852e' into ssao
JMS55 Jun 3, 2023
9e6c18f
Merge remote-tracking branch 'prepass/main' into ssao
JMS55 Jun 10, 2023
82197ea
Misc docs
JMS55 Jun 10, 2023
b39b8c0
Update crates/bevy_pbr/src/ssao/mod.rs
JMS55 Jun 11, 2023
4ba6850
Apply PR feedback
JMS55 Jun 11, 2023
36cd601
Apply more PR feedback
JMS55 Jun 12, 2023
6039c18
handwritten bit pack/unpacking
Elabajaba Jun 6, 2023
460baef
Merge pull request #12 from Elabajaba/ssao-bitpacking
JMS55 Jun 18, 2023
bb025a2
Refactor ssao settings
JMS55 Jun 18, 2023
e308d3b
Fix ssao example
JMS55 Jun 18, 2023
2e73f48
Add ssao platform docs
JMS55 Jun 18, 2023
b5256b9
Appease clippy
cart Jun 18, 2023
04e800c
Fix ssao error message always triggering
JMS55 Jun 18, 2023
5e9b6bb
Tweak error message
JMS55 Jun 18, 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
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,16 @@ description = "Create a custom material to draw 3d lines"
category = "3D Rendering"
wasm = true

[[example]]
name = "ssao"
path = "examples/3d/ssao.rs"

[package.metadata.example.ssao]
name = "Screen Space Ambient Occlusion"
description = "A scene showcasing screen space ambient occlusion"
category = "3D Rendering"
wasm = false

[[example]]
name = "spotlight"
path = "examples/3d/spotlight.rs"
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_core_pipeline/src/prepass/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl ViewNode for PrepassNode {
stencil_ops: None,
}),
});

if let Some(viewport) = camera.viewport.as_ref() {
render_pass.set_camera_viewport(viewport);
}
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod parallax;
mod pbr_material;
mod prepass;
mod render;
mod ssao;

pub use alpha::*;
pub use bundle::*;
Expand All @@ -23,6 +24,7 @@ pub use parallax::*;
pub use pbr_material::*;
pub use prepass::*;
pub use render::*;
pub use ssao::*;

pub mod prelude {
#[doc(hidden)]
Expand All @@ -38,6 +40,7 @@ pub mod prelude {
material::{Material, MaterialPlugin},
parallax::ParallaxMappingMethod,
pbr_material::StandardMaterial,
ssao::ScreenSpaceAmbientOcclusionPlugin,
};
}

Expand Down Expand Up @@ -182,6 +185,7 @@ impl Plugin for PbrPlugin {
prepass_enabled: self.prepass_enabled,
..Default::default()
})
.add_plugin(ScreenSpaceAmbientOcclusionPlugin)
.add_plugin(EnvironmentMapPlugin)
.init_resource::<AmbientLight>()
.init_resource::<GlobalVisiblePointLights>()
Expand Down
10 changes: 8 additions & 2 deletions 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,
MeshUniform, PrepassPipelinePlugin, PrepassPlugin, RenderLightSystems, SetMeshBindGroup,
SetMeshViewBindGroup, Shadow,
MeshUniform, PrepassPipelinePlugin, PrepassPlugin, RenderLightSystems,
ScreenSpaceAmbientOcclusionSettings, SetMeshBindGroup, SetMeshViewBindGroup, Shadow,
};
use bevy_app::{App, Plugin};
use bevy_asset::{AddAsset, AssetEvent, AssetServer, Assets, Handle};
Expand Down Expand Up @@ -387,6 +387,7 @@ pub fn queue_material_meshes<M: Material>(
Option<&Tonemapping>,
Option<&DebandDither>,
Option<&EnvironmentMapLight>,
Option<&ScreenSpaceAmbientOcclusionSettings>,
Option<&NormalPrepass>,
Option<&TemporalAntiAliasSettings>,
&mut RenderPhase<Opaque3d>,
Expand All @@ -402,6 +403,7 @@ pub fn queue_material_meshes<M: Material>(
tonemapping,
dither,
environment_map,
ssao,
normal_prepass,
taa_settings,
mut opaque_phase,
Expand Down Expand Up @@ -455,6 +457,10 @@ pub fn queue_material_meshes<M: Material>(
}
}

if ssao.is_some() {
view_key |= MeshPipelineKey::SCREEN_SPACE_AMBIENT_OCCLUSION;
}

let rangefinder = view.rangefinder3d();
for visible_entity in &visible_entities.entities {
if let Ok((material_handle, mesh_handle, mesh_uniform)) =
Expand Down
53 changes: 42 additions & 11 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
environment_map, prepass, EnvironmentMapLight, FogMeta, GlobalLightMeta, GpuFog, GpuLights,
GpuPointLights, LightMeta, NotShadowCaster, NotShadowReceiver, PreviousGlobalTransform,
ShadowSamplers, ViewClusterBindings, ViewFogUniformOffset, ViewLightsUniformOffset,
ViewShadowBindings, CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT, MAX_CASCADES_PER_LIGHT,
MAX_DIRECTIONAL_LIGHTS,
ScreenSpaceAmbientOcclusionTextures, ShadowSamplers, ViewClusterBindings, ViewFogUniformOffset,
ViewLightsUniformOffset, ViewShadowBindings, CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT,
MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS,
};
use bevy_app::Plugin;
use bevy_asset::{load_internal_asset, Assets, Handle, HandleUntyped};
Expand Down Expand Up @@ -433,22 +433,33 @@ impl FromWorld for MeshPipeline {
},
count: None,
},
// Screen space ambient occlusion texture
BindGroupLayoutEntry {
binding: 11,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled: false,
sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2,
},
count: None,
},
];

// EnvironmentMapLight
let environment_map_entries =
environment_map::get_bind_group_layout_entries([11, 12, 13]);
environment_map::get_bind_group_layout_entries([12, 13, 14]);
entries.extend_from_slice(&environment_map_entries);

// Tonemapping
let tonemapping_lut_entries = get_lut_bind_group_layout_entries([14, 15]);
let tonemapping_lut_entries = get_lut_bind_group_layout_entries([15, 16]);
entries.extend_from_slice(&tonemapping_lut_entries);

if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32")))
|| (cfg!(all(feature = "webgl", target_arch = "wasm32")) && !multisampled)
{
entries.extend_from_slice(&prepass::get_bind_group_layout_entries(
[16, 17, 18],
[17, 18, 19],
multisampled,
));
}
Expand Down Expand Up @@ -586,8 +597,9 @@ bitflags::bitflags! {
const MAY_DISCARD = (1 << 6); // Guards shader codepaths that may discard, allowing early depth tests in most cases
// See: https://www.khronos.org/opengl/wiki/Early_Fragment_Test
const ENVIRONMENT_MAP = (1 << 7);
const DEPTH_CLAMP_ORTHO = (1 << 8);
const TAA = (1 << 9);
const SCREEN_SPACE_AMBIENT_OCCLUSION = (1 << 8);
const DEPTH_CLAMP_ORTHO = (1 << 9);
const TAA = (1 << 10);
const BLEND_RESERVED_BITS = Self::BLEND_MASK_BITS << Self::BLEND_SHIFT_BITS; // ← Bitmask reserving bits for the blend state
const BLEND_OPAQUE = (0 << Self::BLEND_SHIFT_BITS); // ← Values are just sequential within the mask, and can range from 0 to 3
const BLEND_PREMULTIPLIED_ALPHA = (1 << Self::BLEND_SHIFT_BITS); //
Expand Down Expand Up @@ -727,6 +739,10 @@ impl SpecializedMeshPipeline for MeshPipeline {
bind_group_layout.push(self.mesh_layout.clone());
};

if key.contains(MeshPipelineKey::SCREEN_SPACE_AMBIENT_OCCLUSION) {
shader_defs.push("SCREEN_SPACE_AMBIENT_OCCLUSION".into());
}

let vertex_buffer_layout = layout.get_layout(&vertex_attributes)?;

let (label, blend, depth_write_enabled);
Expand Down Expand Up @@ -974,6 +990,7 @@ pub fn queue_mesh_view_bind_groups(
Entity,
&ViewShadowBindings,
&ViewClusterBindings,
Option<&ScreenSpaceAmbientOcclusionTextures>,
Option<&ViewPrepassTextures>,
Option<&EnvironmentMapLight>,
&Tonemapping,
Expand Down Expand Up @@ -1003,11 +1020,17 @@ pub fn queue_mesh_view_bind_groups(
entity,
view_shadow_bindings,
view_cluster_bindings,
ssao_textures,
prepass_textures,
environment_map,
tonemapping,
) in &views
{
let fallback_ssao = fallback_images
.image_for_samplecount(1)
.texture_view
.clone();

let layout = if msaa.samples() > 1 {
&mesh_pipeline.view_layout_multisampled
} else {
Expand Down Expand Up @@ -1063,18 +1086,26 @@ pub fn queue_mesh_view_bind_groups(
binding: 10,
resource: fog_binding.clone(),
},
BindGroupEntry {
binding: 11,
resource: BindingResource::TextureView(
ssao_textures
.map(|t| &t.screen_space_ambient_occlusion_texture.default_view)
.unwrap_or(&fallback_ssao),
),
},
];

let env_map = environment_map::get_bindings(
environment_map,
&images,
&fallback_cubemap,
[11, 12, 13],
[12, 13, 14],
);
entries.extend_from_slice(&env_map);

let tonemapping_luts =
get_lut_bindings(&images, &tonemapping_luts, tonemapping, [14, 15]);
get_lut_bindings(&images, &tonemapping_luts, tonemapping, [15, 16]);
entries.extend_from_slice(&tonemapping_luts);

// When using WebGL, we can't have a depth texture with multisampling
Expand All @@ -1086,7 +1117,7 @@ pub fn queue_mesh_view_bind_groups(
&mut fallback_images,
&mut fallback_depths,
&msaa,
[16, 17, 18],
[17, 18, 19],
));
}

Expand Down
23 changes: 13 additions & 10 deletions crates/bevy_pbr/src/render/mesh_view_bindings.wgsl
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,32 @@ var<uniform> globals: Globals;
var<uniform> fog: Fog;

@group(0) @binding(11)
var environment_map_diffuse: texture_cube<f32>;
var screen_space_ambient_occlusion_texture: texture_2d<f32>;
JMS55 marked this conversation as resolved.
Show resolved Hide resolved

@group(0) @binding(12)
var environment_map_specular: texture_cube<f32>;
var environment_map_diffuse: texture_cube<f32>;
@group(0) @binding(13)
var environment_map_specular: texture_cube<f32>;
@group(0) @binding(14)
var environment_map_sampler: sampler;

@group(0) @binding(14)
var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(15)
var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(16)
var dt_lut_sampler: sampler;

#ifdef MULTISAMPLED
@group(0) @binding(16)
var depth_prepass_texture: texture_depth_multisampled_2d;
@group(0) @binding(17)
var normal_prepass_texture: texture_multisampled_2d<f32>;
var depth_prepass_texture: texture_depth_multisampled_2d;
@group(0) @binding(18)
var normal_prepass_texture: texture_multisampled_2d<f32>;
@group(0) @binding(19)
var motion_vector_prepass_texture: texture_multisampled_2d<f32>;
#else
@group(0) @binding(16)
var depth_prepass_texture: texture_depth_2d;
@group(0) @binding(17)
var normal_prepass_texture: texture_2d<f32>;
var depth_prepass_texture: texture_depth_2d;
@group(0) @binding(18)
var normal_prepass_texture: texture_2d<f32>;
@group(0) @binding(19)
var motion_vector_prepass_texture: texture_2d<f32>;
#endif
16 changes: 14 additions & 2 deletions crates/bevy_pbr/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#import bevy_pbr::prepass_utils

#ifdef SCREEN_SPACE_AMBIENT_OCCLUSION
#import bevy_pbr::gtao_utils
#endif

struct FragmentInput {
@builtin(front_facing) is_front: bool,
@builtin(position) frag_coord: vec4<f32>,
Expand Down Expand Up @@ -88,12 +92,20 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
pbr_input.material.metallic = metallic;
pbr_input.material.perceptual_roughness = perceptual_roughness;

var occlusion: f32 = 1.0;
// TODO: Split into diffuse/specular occlusion?
var occlusion: vec3<f32> = vec3(1.0);
#ifdef VERTEX_UVS
if ((material.flags & STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) {
occlusion = textureSample(occlusion_texture, occlusion_sampler, uv).r;
occlusion = vec3(textureSample(occlusion_texture, occlusion_sampler, in.uv).r);
}
#endif
#ifdef SCREEN_SPACE_AMBIENT_OCCLUSION
let ssao = textureLoad(screen_space_ambient_occlusion_texture, vec2<i32>(in.frag_coord.xy), 0i).r;
let ssao_multibounce = gtao_multibounce(ssao, pbr_input.material.base_color.rgb);
occlusion = min(occlusion, ssao_multibounce);
#endif
pbr_input.occlusion = occlusion;

pbr_input.frag_coord = in.frag_coord;
pbr_input.world_position = in.world_position;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/pbr_ambient.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn ambient_light(
diffuse_color: vec3<f32>,
specular_color: vec3<f32>,
perceptual_roughness: f32,
occlusion: f32,
occlusion: vec3<f32>,
) -> vec3<f32> {
let diffuse_ambient = EnvBRDFApprox(diffuse_color, F_AB(1.0, NdotV)) * occlusion;
let specular_ambient = EnvBRDFApprox(specular_color, F_AB(perceptual_roughness, NdotV));
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn calculate_view(

struct PbrInput {
material: StandardMaterial,
occlusion: f32,
occlusion: vec3<f32>,
frag_coord: vec4<f32>,
world_position: vec4<f32>,
// Normalized world normal used for shadow mapping as normal-mapping is not used for shadow
Expand All @@ -146,7 +146,7 @@ fn pbr_input_new() -> PbrInput {
var pbr_input: PbrInput;

pbr_input.material = standard_material_new();
pbr_input.occlusion = 1.0;
pbr_input.occlusion = vec3<f32>(1.0);

pbr_input.frag_coord = vec4<f32>(0.0, 0.0, 0.0, 1.0);
pbr_input.world_position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_pbr/src/render/utils.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define_import_path bevy_pbr::utils

const PI: f32 = 3.141592653589793;
const HALF_PI: f32 = 1.57079632679;
const E: f32 = 2.718281828459045;

fn hsv2rgb(hue: f32, saturation: f32, value: f32) -> vec3<f32> {
Expand Down
Loading