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

Meshlet rendering (initial feature) #10164

Merged
merged 467 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
467 commits
Select commit Hold shift + click to select a range
f370980
Misc?
JMS55 Nov 19, 2023
21e52aa
Fixes
JMS55 Nov 19, 2023
5bf13ba
Merge commit '951c9bb1a25caddc97ac69bbe8a2937f97227e90' into meshlet
JMS55 Nov 20, 2023
a6266e1
Add texture_attachment module
JMS55 Nov 21, 2023
e48b7b1
Switch shadow view to new API
JMS55 Nov 21, 2023
f875497
Depth target attachment
JMS55 Nov 21, 2023
52c429d
Make ColorAttachment hold CachedTexture directly
JMS55 Nov 21, 2023
66aeff0
WIP
JMS55 Nov 21, 2023
d89d118
WIP
JMS55 Nov 22, 2023
50dc55f
WIP
JMS55 Nov 22, 2023
283105a
Fixes
JMS55 Nov 22, 2023
3a21264
Add dummy shader
JMS55 Nov 25, 2023
1d7f6e9
Merge commit 'daa8bf20dfb0d5e3e2c8dbd032d532bde133f221' into meshlet
JMS55 Nov 29, 2023
2c672d0
Use new bind group layout builder
JMS55 Nov 29, 2023
eedb318
Fix
JMS55 Nov 29, 2023
7c46e4c
Merge commit '8067e46049f222d37ac394745805bad98979980f' into meshlet
JMS55 Dec 28, 2023
f3222fe
Rebase fixes
JMS55 Dec 28, 2023
bd36f9f
Merge commit '8067e46049f222d37ac394745805bad98979980f' into target_i…
JMS55 Dec 29, 2023
2874843
Fix rebase
JMS55 Dec 29, 2023
63e8032
Small fix
JMS55 Dec 29, 2023
4e61072
WIP MSAA fix
JMS55 Dec 29, 2023
badd572
Fixes
JMS55 Dec 29, 2023
7e7b9a7
Fix post processing
JMS55 Dec 29, 2023
dceab7a
Address PR feedback
JMS55 Dec 29, 2023
1ced9ff
Fix examples
JMS55 Dec 29, 2023
e798b64
Merge commit '1ced9ff401d5cc7205ede234205c7714b5980527' into meshlet
JMS55 Dec 29, 2023
df725f1
Adapt to merge
JMS55 Dec 29, 2023
88714b2
Fix depth attachment for niche use cases
JMS55 Dec 29, 2023
2caaa9b
Merge commit '88714b25bc2aac8f42d5711654e75906e933c9e1' into meshlet
JMS55 Dec 29, 2023
eaf26c4
Finish rebase
JMS55 Dec 29, 2023
b7c9813
Misc
JMS55 Dec 30, 2023
6d382e3
Misc formatting
JMS55 Dec 30, 2023
936769e
Merge commit '70b0eacc3b5ccf12028fce925d1efc5ae31b5699' into meshlet
JMS55 Dec 31, 2023
d3051b8
Misc
JMS55 Dec 31, 2023
e9cb784
Remove no longer needed code
JMS55 Dec 31, 2023
32b382d
Misc format
JMS55 Dec 31, 2023
842cfe7
Write system to modify depth texture
JMS55 Dec 31, 2023
212919c
fix doc
JMS55 Dec 31, 2023
a7d9b95
Add additional check
JMS55 Dec 31, 2023
e957424
WIP: Shadow pass support
JMS55 Dec 31, 2023
5e0d5b4
Only create prepass pipelines if needed
JMS55 Dec 31, 2023
b374fc6
Misc
JMS55 Dec 31, 2023
6e22026
Fix compile error
JMS55 Dec 31, 2023
3395db9
Fix shadow view handling
JMS55 Dec 31, 2023
b80955d
Finish shadow support
JMS55 Jan 1, 2024
ae85bf7
Clippy
JMS55 Jan 1, 2024
6043dee
Start adding docs
JMS55 Jan 1, 2024
146ea02
Merge commit '443b64a6123f4f0222f7e2631487bf4c512d6ba5' into meshlet
JMS55 Jan 1, 2024
8677b84
Revert mesh flags vertex output changes
JMS55 Jan 1, 2024
28009d6
Remove comment, too expensive to be per-view
JMS55 Jan 1, 2024
08a0dc1
Misc
JMS55 Jan 2, 2024
6b32652
Variable number of depth mips
JMS55 Jan 2, 2024
2cd5051
Document cull shader
JMS55 Jan 2, 2024
1c84f01
Misc TODOs
JMS55 Jan 2, 2024
e19ddbb
Optimize!
JMS55 Jan 3, 2024
5ea6361
Fix meshlet build
JMS55 Jan 3, 2024
e835f51
Merge commit '44424391fe217d9b0b4b0be2649b44a994983a59' into meshlet
JMS55 Jan 3, 2024
51f9669
More asset work
JMS55 Jan 4, 2024
fba7015
Partially fix occlusion culling
JMS55 Jan 4, 2024
0637df4
Add fudge factor to fix culling
JMS55 Jan 4, 2024
8ffda6c
Gate meshopt behind a feature
JMS55 Jan 4, 2024
8f357fe
Revert "Add fudge factor to fix culling"
JMS55 Jan 4, 2024
f473437
Much faster raster using MDI
JMS55 Jan 5, 2024
e4a61b2
Fix occlusion culling
JMS55 Jan 6, 2024
a2034d9
Add TODO
JMS55 Jan 6, 2024
66e11fe
Documentation pass
JMS55 Jan 6, 2024
2f55e90
CI fixes
JMS55 Jan 6, 2024
baee7e7
Clippy lint
JMS55 Jan 6, 2024
8f4c053
Fix doc
JMS55 Jan 6, 2024
57a9d24
Misc doc fix
JMS55 Jan 6, 2024
6d95f97
WIP: Switch back to writing out an index buffer
JMS55 Jan 6, 2024
5c821ad
Split writing the index buffer into a seperate pass for much better p…
JMS55 Jan 7, 2024
c192a93
Merge commit 'cfcb6885e3b475a93ec0fe7e88023ac0f354bbbf' into meshlet
JMS55 Jan 7, 2024
f2186f9
Don't render meshlets in pass 1 again in pass 2
JMS55 Jan 7, 2024
7b88f20
Clippy
JMS55 Jan 7, 2024
66cd167
Actually skip rasterizing previously visible meshlets twice
JMS55 Jan 7, 2024
bb9bff3
Add check for push constant support
JMS55 Jan 7, 2024
5c00bdd
Merge commit 'b257fffef81a1c3a33c867c39dd53fb10bc6fd3b' into meshlet
JMS55 Jan 8, 2024
bac5cf6
Fix rebase
JMS55 Jan 9, 2024
6481b12
Fixes
JMS55 Jan 9, 2024
28daa90
Tried unchecked shaders, no real perf boost
JMS55 Jan 9, 2024
3b7b46d
Merge commit 'a6574786757c0a0a7ddffb99fdc40ce90980fc82' into meshlet
JMS55 Jan 10, 2024
a8fcc38
Cache buffers
JMS55 Jan 10, 2024
a24a61f
Fix doc link
JMS55 Jan 10, 2024
c895e49
Remove loop from queue_meshlet_mesh_upload
ricky26 Jan 12, 2024
20083fa
Parallelise meshlet buffer writes
ricky26 Jan 12, 2024
2283864
Skip some copies during meshlet upload
ricky26 Jan 12, 2024
3f403bb
Merge pull request #17 from ricky26/meshlet
JMS55 Jan 12, 2024
a9f1d9f
Format
JMS55 Jan 12, 2024
3bfa80b
Clippy
JMS55 Jan 12, 2024
c16c3f2
Add TODO
JMS55 Jan 12, 2024
fe3dacb
Move variable out of loop
JMS55 Jan 12, 2024
3c9b361
WIP: Prepass/deferred support
JMS55 Jan 12, 2024
92639e3
Skip prepass draw prepare if only the depth prepass is used
JMS55 Jan 12, 2024
8a4b9aa
WIP: Prepass support
JMS55 Jan 12, 2024
0bd667a
Implement deferred prepass node
JMS55 Jan 12, 2024
cda73dc
Revert example changes comitted by accident
JMS55 Jan 12, 2024
58391d1
Add docs
JMS55 Jan 13, 2024
1d4d89b
Bugfix when using multiple materials
JMS55 Jan 13, 2024
ee2278c
Improve example
JMS55 Jan 13, 2024
737d42d
Fix prepass draws
JMS55 Jan 13, 2024
b04244a
Fix material depth being cleared
JMS55 Jan 13, 2024
ebc68e1
WIP: Prepass/deferred support
JMS55 Jan 13, 2024
bb1490b
Fix imports
JMS55 Jan 13, 2024
25d2943
Finish prepass support
JMS55 Jan 13, 2024
5487522
Revert unintended change
JMS55 Jan 13, 2024
dec0dda
TODO: Remove asset data from buffers on unload
JMS55 Jan 13, 2024
60f2c91
Allow for gaps in PersistentGpuBuffer
JMS55 Jan 14, 2024
e1049d7
Remove outdated doc
JMS55 Jan 14, 2024
0f446fa
Reuse meshlet buffer data where possible
JMS55 Jan 14, 2024
b48daeb
Update crates/bevy_pbr/src/meshlet/material_draw_prepare.rs
JMS55 Jan 14, 2024
109bb4f
Update crates/bevy_pbr/src/meshlet/gpu_scene.rs
JMS55 Jan 14, 2024
11b96e3
Update crates/bevy_pbr/src/meshlet/visibility_buffer_raster_node.rs
JMS55 Jan 14, 2024
1637b6a
Improve docs
JMS55 Jan 14, 2024
f9a8032
Merge commit '4778fbeb65d840eb39bda017fd428ebfc17a1153' into meshlet
JMS55 Jan 14, 2024
f4cb938
Use CameraControllerPlugin
JMS55 Jan 14, 2024
2b665db
Doc lint
JMS55 Jan 14, 2024
684a39f
Replace dragons with bunnies
JMS55 Jan 14, 2024
6bb52d5
Better bunny model
JMS55 Jan 14, 2024
d471820
Fix a bug causing previously visible meshlets to never get marked as …
JMS55 Jan 15, 2024
23207c5
Properly setup view uniform frusta for directional light shadow views
JMS55 Jan 15, 2024
4ddd312
Fix rendering regular meshes when the MeshletPlugin is added
JMS55 Jan 15, 2024
18412d7
Fix deferred compilation on wasm
JMS55 Jan 15, 2024
a03a37e
Add frustums to shadow views for point and spot lights
JMS55 Jan 15, 2024
5f632f1
Merge commit 'aeab690fdb893b6eeb6dbadc646111ea76a5a782' into meshlet
JMS55 Jan 15, 2024
f75dc7a
Update examples/3d/meshlet.rs
JMS55 Jan 15, 2024
932b34f
Merge commit 'ee9a1503edb6ff72cc69514c6336d9f624f0d600' into meshlet
JMS55 Jan 15, 2024
91fd217
Add view instance visibility buffers to gpu scene
atlv24 Jan 16, 2024
ec11c7a
Merge commit 'c9e1fcdb355b049fa3c3df8cb1cd1f4343f1b9d1' into meshlet
JMS55 Jan 18, 2024
9db1a96
Fix rebase lighting
JMS55 Jan 18, 2024
ea38623
Use a single 3d dispatch for write_index_buffer
JMS55 Jan 18, 2024
07bac3c
Remove redundant code
JMS55 Jan 18, 2024
d2903ac
Add TODO
JMS55 Jan 18, 2024
2a6e022
Try to fix occlusion culling (does not seem to be working still)
JMS55 Jan 18, 2024
62d8063
Fix occlusion culling and add meshlet bounding sphere debug viewer
atlv24 Jan 18, 2024
3d96a40
Account for scale
atlv24 Jan 18, 2024
54ac8bb
Merge pull request #22 from rodolphito/meshlet-debug
JMS55 Jan 18, 2024
3d6a7d3
Fix occlusion culling fully
JMS55 Jan 18, 2024
a0f5c6b
Cleanup example
JMS55 Jan 18, 2024
a5cafe3
Improve docs (note limitations)
JMS55 Jan 18, 2024
7979367
Misc wording
JMS55 Jan 18, 2024
2a21ed9
Clippy
JMS55 Jan 18, 2024
e6faae6
Remove rayon
JMS55 Jan 18, 2024
e0b7bf2
Add floor to example
JMS55 Jan 18, 2024
726370a
Fix doc
JMS55 Jan 18, 2024
d0789ae
Merge commit '056b006d4eade8f1bf75e735ed5eda33d9505c9e' into meshlet
JMS55 Jan 18, 2024
4dcc424
Fix occlusion culling in orthographic views
atlv24 Jan 19, 2024
2a5c800
Merge pull request #23 from rodolphito/meshlet-orthographic
JMS55 Jan 19, 2024
ddfbe8a
Misc cleanup
JMS55 Jan 19, 2024
eb4967b
Merge remote-tracking branch 'jasmine/meshlet' into meshlet
atlv24 Jan 19, 2024
fd26948
Misc format
JMS55 Jan 19, 2024
7831a97
Fix initialization
atlv24 Jan 19, 2024
e11b9b0
Add bindings and cull instances
atlv24 Jan 19, 2024
633137d
resize preview
atlv24 Jan 19, 2024
3284621
Merge remote-tracking branch 'jasmine/meshlet' into meshlet
atlv24 Jan 19, 2024
c3b4d34
Move renderlayers/notshadowcaster out to prepare resources
atlv24 Jan 20, 2024
76a9a62
Cleanup
atlv24 Jan 20, 2024
54070b9
better preview
atlv24 Jan 20, 2024
683a4e1
Feedback address
atlv24 Jan 20, 2024
6e20432
Merge pull request #19 from rodolphito/meshlet
JMS55 Jan 20, 2024
f380cb4
Misc
JMS55 Jan 20, 2024
ac5ce53
Remove push constant usage
JMS55 Jan 20, 2024
086ed77
Fix typos
JMS55 Jan 20, 2024
1250949
Merge commit '63eb151619f23b21384cc28e9e11e488c01c4fb9' into meshlet
JMS55 Jan 20, 2024
19e46c3
Fix doc
JMS55 Jan 20, 2024
6c8b8bf
Fix deferred rendering
JMS55 Jan 20, 2024
dd0ec04
Merge branch 'main' into meshlet
JMS55 Jan 20, 2024
67a0bc5
Fix meshlet normal prepass
JMS55 Jan 21, 2024
6e72360
Use crates.io version of meshopt, rename meshopt feature
JMS55 Jan 24, 2024
dc5c57e
Merge commit '02bf4efe64f2d10c8063edc760303e67e9b99e19' into meshlet
JMS55 Jan 24, 2024
ded44f3
Fix rebase
JMS55 Jan 24, 2024
ea39e34
Fix example
JMS55 Jan 24, 2024
fa75dd2
Improve shadows and docs
atlv24 Jan 25, 2024
6bbb428
Improve docs
atlv24 Jan 25, 2024
93fed23
Fix import
atlv24 Jan 25, 2024
ac89611
Merge pull request #24 from rodolphito/meshlet-docs
JMS55 Jan 26, 2024
2249e00
Merge commit '35ac1b152ee1b2c7b2930f67d93be0db6f395b47' into meshlet
JMS55 Jan 26, 2024
1cdd044
Fix type name
JMS55 Jan 26, 2024
16ff589
More fixes
JMS55 Jan 26, 2024
0463f47
Move to an experimental module
JMS55 Jan 26, 2024
084b1a2
Misc doc tweaks
JMS55 Jan 26, 2024
48d5c89
Merge commit '886a2560d24ac248776eea11afabaccfbafa58f4' into meshlet
JMS55 Jan 27, 2024
a0ba8d1
Add some more docs
JMS55 Jan 28, 2024
6328d03
Support modified assets (unlikely that this would ever be used though…
JMS55 Jan 28, 2024
98d375d
Merge commit 'dad379cdca45c31a9b6888f58e6950222aa6842a' into meshlet
JMS55 Jan 28, 2024
c8711bf
Merge commit 'e0778bf407631f9ae0f1e7326bb63e98d0e6fe87' into meshlet
JMS55 Feb 18, 2024
6fd9dc2
Replace deprecated shape API
JMS55 Feb 18, 2024
a22848e
Merge commit 'dc696c0e11515c1c767d4855e545c4f1485b964a' into meshlet
JMS55 Feb 24, 2024
d961c94
Fix rebase
JMS55 Feb 24, 2024
baa8318
Fix meshlets
atlv24 Feb 25, 2024
6a845d7
Merge branch 'main' into meshlet-rebase
atlv24 Feb 25, 2024
7a4f6ca
LegacyColor
atlv24 Feb 25, 2024
4f8cbda
Merge pull request #25 from rodolphito/meshlet-rebase
JMS55 Feb 25, 2024
83debc4
Add comments to clarify shader dispatch sizes and bindings
JMS55 Feb 25, 2024
d33aa85
Merge commit '557e582ec55f325256011ee6e39e97a3d44b2fc3' into meshlet
JMS55 Feb 28, 2024
9e7655a
Fix typo
JMS55 Feb 28, 2024
52eedf2
Fix another typo
JMS55 Feb 28, 2024
d7eb81c
Docs
JMS55 Feb 28, 2024
81ce951
Doc
JMS55 Feb 28, 2024
3ef551a
Fix doc links
JMS55 Feb 29, 2024
474bae2
Fix more doc links
JMS55 Feb 29, 2024
21786e2
Merge commit 'f418de8eb66d0bf1bf42903f8f713167280a3491' into meshlet
JMS55 Feb 29, 2024
a7e7930
Rename direction type
JMS55 Feb 29, 2024
afbd441
Rename thread_id -> cluster_id
JMS55 Feb 29, 2024
8004df0
Example disclaimer
JMS55 Feb 29, 2024
4a69f8a
Update example description
JMS55 Feb 29, 2024
82cb1d8
Doc tweaks
JMS55 Feb 29, 2024
69184bf
Add another doc link
JMS55 Feb 29, 2024
0e7874d
Cleanup persistent_buffer_impls magic numbers
JMS55 Feb 29, 2024
d7fd5d4
Add some more comments
JMS55 Feb 29, 2024
096ea24
Add misc comments
JMS55 Feb 29, 2024
97e2a50
Silence clippy
JMS55 Feb 29, 2024
8db797f
Merge commit '499c978176435efaaf8ccfe3a1141efadfd340eb' into meshlet
JMS55 Mar 1, 2024
182fb8f
Use new color types
JMS55 Mar 1, 2024
b08e45f
Reformat safety doc
JMS55 Mar 1, 2024
12e982e
Use new color API in example
JMS55 Mar 1, 2024
a903873
Merge commit '0746b8eb4c811b473807dfd81091d191f5bcf828' into meshlet
JMS55 Mar 6, 2024
2916dd3
Fix rebase
JMS55 Mar 6, 2024
2f1b399
Fix rebase
JMS55 Mar 6, 2024
24fe534
Misc
JMS55 Mar 6, 2024
c687e59
Merge commit 'a1974a473809c2c6c31fad08174898c220d777bd' into meshlet
JMS55 Mar 7, 2024
328edcd
Merge commit '52e3f2007b54f6be215e59e74aaf3d30b3dad67c' into meshlet
JMS55 Mar 8, 2024
99b18d5
Fix import of thiserror
JMS55 Mar 8, 2024
7d67997
Fix check
JMS55 Mar 9, 2024
c768471
Fix bug with meshlets_slice
JMS55 Mar 10, 2024
be03224
Merge commit '1b3c2b0fed4821d2a8a7554330310ae7f675373d' into meshlet
JMS55 Mar 10, 2024
9680e1b
Merge commit 'c7298599ee11b1f788a248ccd17ccbbaa5a9abb1' into meshlet
JMS55 Mar 12, 2024
0f4de29
Fix normal map sampling
JMS55 Mar 12, 2024
60af7da
Misc refactor
JMS55 Mar 12, 2024
8ac2e94
[WIP] Switch to non-indexed draw buffer
JMS55 Mar 13, 2024
0a7f76c
Misc fix
JMS55 Mar 13, 2024
6be2f94
Clarify comment
JMS55 Mar 13, 2024
a6f8f62
Fix shader
JMS55 Mar 14, 2024
3fc104c
Update asset total_meshlet_triangles
JMS55 Mar 15, 2024
bb77e5a
Merge commit '16fb995697f93d48df565281a9d615606b4b3082' into meshlet
JMS55 Mar 15, 2024
edccb65
Merge commit '1323de7cd74ba7a6fe801e0fa47c357b7760b049' into meshlet
JMS55 Mar 16, 2024
cb58dde
Import rand_f
JMS55 Mar 16, 2024
36787dc
Merge commit '737b719dda79e15aa70b3a390c871070519f34e0' into meshlet
JMS55 Mar 17, 2024
bdc87f1
Add warning on the material trait methods
JMS55 Mar 18, 2024
8510640
Add warning to example
JMS55 Mar 18, 2024
7eb151c
Update crates/bevy_pbr/src/material.rs
JMS55 Mar 18, 2024
b13b324
Update crates/bevy_pbr/src/material.rs
JMS55 Mar 18, 2024
a0b2bbf
Update crates/bevy_pbr/src/material.rs
JMS55 Mar 18, 2024
cdd83cb
Merge commit '67cc605e9ff1f7b8d059e7bed32c76732e02d8b5' into meshlet
JMS55 Mar 23, 2024
78dec88
Rename indirect draw buffer
JMS55 Mar 23, 2024
8636e82
Gate meshlets behind a feature (kinda ugly)
JMS55 Mar 23, 2024
f27af6e
Use async asset loader/saver
JMS55 Mar 23, 2024
898f527
Regen feature docs
JMS55 Mar 23, 2024
95bf6e5
Early submission for GPU data uploads
JMS55 Mar 24, 2024
087ab5c
Ensure we halve depth pyramid mip 0 even when the view size is alread…
JMS55 Mar 25, 2024
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
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ embedded_watcher = ["bevy_internal/embedded_watcher"]
# Enable stepping-based debugging of Bevy systems
bevy_debug_stepping = ["bevy_internal/bevy_debug_stepping"]

# Enables processing meshes into meshlet meshes for bevy_pbr
meshlet_processor = ["bevy_internal/meshlet_processor"]

# Enable support for the ios_simulator by downgrading some rendering capabilities
ios_simulator = ["bevy_internal/ios_simulator"]

Expand Down Expand Up @@ -949,6 +952,17 @@ description = "Demonstrates irradiance volumes"
category = "3D Rendering"
wasm = false

[[example]]
name = "meshlet"
path = "examples/3d/meshlet.rs"
doc-scrape-examples = true

[package.metadata.example.meshlet]
name = "Meshlet"
description = "Meshlet rendering for dense high-poly scenes (experimental)"
category = "3D Rendering"
wasm = false

[[example]]
name = "lightmaps"
path = "examples/3d/lightmaps.rs"
Expand Down
Binary file added assets/models/bunny.meshlet_mesh
Binary file not shown.
2 changes: 2 additions & 0 deletions crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub mod upscaling;
pub use skybox::Skybox;

/// Experimental features that are not yet finished. Please report any issues you encounter!
///
/// Expect bugs, missing features, compatibility issues, low performance, and/or future breaking changes.
pub mod experimental {
pub mod taa {
pub use crate::taa::{
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ bevy_debug_stepping = [
"bevy_app/bevy_debug_stepping",
]

# Enables processing meshes into meshlet meshes for bevy_pbr
meshlet_processor = ["bevy_pbr?/meshlet_processor"]

# Provides a collection of developer tools
bevy_dev_tools = ["dep:bevy_dev_tools"]

Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pbr_transmission_textures = []
shader_format_glsl = ["bevy_render/shader_format_glsl"]
trace = ["bevy_render/trace"]
ios_simulator = ["bevy_render/ios_simulator"]
# Enables processing meshes into meshlet meshes
meshlet_processor = ["dep:meshopt", "dep:thiserror"]

[dependencies]
# bevy
Expand All @@ -34,12 +36,17 @@ bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" }

# other
meshopt = { version = "0.2", optional = true }
thiserror = { version = "1", optional = true }
bitflags = "2.3"
fixedbitset = "0.5"
# direct dependency required for derive macro
bytemuck = { version = "1", features = ["derive"] }
radsort = "0.1"
smallvec = "1.6"
serde = { version = "1", features = ["derive", "rc"] }
bincode = "1"
range-alloc = "0.1"
nonmax = "0.5"

[lints]
Expand Down
12 changes: 11 additions & 1 deletion crates/bevy_pbr/src/deferred/pbr_deferred_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
rgb9e5,
mesh_view_bindings::view,
utils::{octahedral_encode, octahedral_decode},
prepass_io::{VertexOutput, FragmentOutput},
prepass_io::FragmentOutput,
view_transformations::{position_ndc_to_world, frag_coord_to_ndc},
}

#ifdef MESHLET_MESH_MATERIAL_PASS
#import bevy_pbr::meshlet_visibility_buffer_resolve::VertexOutput
#else
#import bevy_pbr::prepass_io::VertexOutput
#endif

#ifdef MOTION_VECTOR_PREPASS
#import bevy_pbr::pbr_prepass_functions::calculate_motion_vector
#endif
Expand Down Expand Up @@ -116,7 +122,11 @@ fn deferred_output(in: VertexOutput, pbr_input: PbrInput) -> FragmentOutput {
#endif
// motion vectors if required
#ifdef MOTION_VECTOR_PREPASS
#ifdef MESHLET_MESH_MATERIAL_PASS
out.motion_vector = in.motion_vector;
#else
out.motion_vector = calculate_motion_vector(in.world_position, in.previous_world_position);
#endif
#endif

return out;
Expand Down
42 changes: 42 additions & 0 deletions crates/bevy_pbr/src/extended_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh fragment shader will be used.
#[allow(unused_variables)]
fn meshlet_mesh_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] prepass fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh prepass fragment shader will be used.
#[allow(unused_variables)]
fn meshlet_mesh_prepass_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] deferred fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh deferred fragment shader will be used.
#[allow(unused_variables)]
fn meshlet_mesh_deferred_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Customizes the default [`RenderPipelineDescriptor`] for a specific entity using the entity's
/// [`MaterialPipelineKey`] and [`MeshVertexBufferLayoutRef`] as input.
/// Specialization for the base material is applied before this function is called.
Expand Down Expand Up @@ -211,6 +232,27 @@ impl<B: Material, E: MaterialExtension> Material for ExtendedMaterial<B, E> {
}
}

fn meshlet_mesh_fragment_shader() -> ShaderRef {
match E::meshlet_mesh_fragment_shader() {
ShaderRef::Default => B::meshlet_mesh_fragment_shader(),
specified => specified,
}
}

fn meshlet_mesh_prepass_fragment_shader() -> ShaderRef {
match E::meshlet_mesh_prepass_fragment_shader() {
ShaderRef::Default => B::meshlet_mesh_prepass_fragment_shader(),
specified => specified,
}
}

fn meshlet_mesh_deferred_fragment_shader() -> ShaderRef {
match E::meshlet_mesh_deferred_fragment_shader() {
ShaderRef::Default => B::meshlet_mesh_deferred_fragment_shader(),
specified => specified,
}
}

fn specialize(
pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
Expand Down
15 changes: 14 additions & 1 deletion crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
#![allow(missing_docs)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

mod meshlet;
pub mod wireframe;

/// Experimental features that are not yet finished. Please report any issues you encounter!
///
/// Expect bugs, missing features, compatibility issues, low performance, and/or future breaking changes.
pub mod experimental {
pub mod meshlet {
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
pub use crate::meshlet::*;
}
}

mod bundle;
pub mod deferred;
mod extended_material;
Expand Down Expand Up @@ -65,7 +75,9 @@ pub mod graph {
}
}

use crate::{deferred::DeferredPbrLightingPlugin, graph::NodePbr};
use crate::{
deferred::DeferredPbrLightingPlugin, graph::NodePbr, meshlet::MeshletDummyShaderPlugin,
};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, AssetApp, Assets, Handle};
use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
Expand Down Expand Up @@ -256,6 +268,7 @@ impl Plugin for PbrPlugin {
.init_resource::<DefaultOpaqueRendererMethod>()
.add_plugins((
MeshRenderPlugin,
MeshletDummyShaderPlugin,
MaterialPlugin::<StandardMaterial> {
prepass_enabled: self.prepass_enabled,
..Default::default()
Expand Down
42 changes: 41 additions & 1 deletion crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::*;
use crate::{
meshlet::{
prepare_material_meshlet_meshes_main_opaque_pass, queue_material_meshlet_meshes,
MeshletGpuScene,
},
*,
};
use bevy_asset::{Asset, AssetEvent, AssetId, AssetServer};
use bevy_core_pipeline::{
core_3d::{
Expand Down Expand Up @@ -170,6 +176,33 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh fragment shader will be used.
///
/// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s.
#[allow(unused_variables)]
fn meshlet_mesh_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] prepass fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh prepass fragment shader will be used.
///
/// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s.
#[allow(unused_variables)]
fn meshlet_mesh_prepass_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Returns this material's [`crate::meshlet::MeshletMesh`] deferred fragment shader. If [`ShaderRef::Default`] is returned,
/// the default meshlet mesh deferred fragment shader will be used.
///
/// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s.
#[allow(unused_variables)]
fn meshlet_mesh_deferred_fragment_shader() -> ShaderRef {
ShaderRef::Default
}

/// Customizes the default [`RenderPipelineDescriptor`] for a specific entity using the entity's
/// [`MaterialPipelineKey`] and [`MeshVertexBufferLayoutRef`] as input.
#[allow(unused_variables)]
Expand Down Expand Up @@ -237,6 +270,13 @@ where
queue_material_meshes::<M>
.in_set(RenderSet::QueueMeshes)
.after(prepare_materials::<M>),
(
prepare_material_meshlet_meshes_main_opaque_pass::<M>,
queue_material_meshlet_meshes::<M>,
)
.chain()
.in_set(RenderSet::Queue)
.run_if(resource_exists::<MeshletGpuScene>),
),
);
}
Expand Down
107 changes: 107 additions & 0 deletions crates/bevy_pbr/src/meshlet/asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use bevy_asset::{
io::{Reader, Writer},
saver::{AssetSaver, SavedAsset},
Asset, AssetLoader, AsyncReadExt, AsyncWriteExt, LoadContext,
};
use bevy_math::Vec3;
use bevy_reflect::TypePath;
use bevy_utils::BoxedFuture;
use bytemuck::{Pod, Zeroable};
use serde::{Deserialize, Serialize};
use std::sync::Arc;

/// A mesh that has been pre-processed into multiple small clusters of triangles called meshlets.
///
/// A [`bevy_render::mesh::Mesh`] can be converted to a [`MeshletMesh`] using `MeshletMesh::from_mesh` when the `meshlet_processor` cargo feature is enabled.
/// The conversion step is very slow, and is meant to be ran once ahead of time, and not during runtime. This type of mesh is not suitable for
/// dynamically generated geometry.
///
/// There are restrictions on the [`crate::Material`] functionality that can be used with this type of mesh.
/// * Materials have no control over the vertex shader or vertex attributes.
/// * Materials must be opaque. Transparent, alpha masked, and transmissive materials are not supported.
/// * Materials must use the [`crate::Material::meshlet_mesh_fragment_shader`] method (and similar variants for prepass/deferred shaders)
/// which requires certain shader patterns that differ from the regular material shaders.
/// * Limited control over [`bevy_render::render_resource::RenderPipelineDescriptor`] attributes.
///
/// See also [`super::MaterialMeshletMeshBundle`] and [`super::MeshletPlugin`].
#[derive(Asset, TypePath, Serialize, Deserialize, Clone)]
pub struct MeshletMesh {
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
/// The total amount of triangles summed across all meshlets in the mesh.
pub total_meshlet_triangles: u64,
/// Raw vertex data bytes for the overall mesh.
pub vertex_data: Arc<[u8]>,
/// Indices into `vertex_data`.
pub vertex_ids: Arc<[u32]>,
/// Indices into `vertex_ids`.
pub indices: Arc<[u8]>,
/// The list of meshlets making up this mesh.
pub meshlets: Arc<[Meshlet]>,
/// A list of spherical bounding volumes, 1 per meshlet.
pub meshlet_bounding_spheres: Arc<[MeshletBoundingSphere]>,
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
}

/// A single meshlet within a [`MeshletMesh`].
#[derive(Serialize, Deserialize, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Meshlet {
/// The offset within the parent mesh's [`MeshletMesh::vertex_ids`] buffer where the indices for this meshlet begin.
pub start_vertex_id: u32,
/// The offset within the parent mesh's [`MeshletMesh::indices`] buffer where the indices for this meshlet begin.
pub start_index_id: u32,
/// The amount of triangles in this meshlet.
pub triangle_count: u32,
}

/// A spherical bounding volume used for culling a [`Meshlet`].
#[derive(Serialize, Deserialize, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct MeshletBoundingSphere {
pub center: Vec3,
pub radius: f32,
}

/// An [`AssetLoader`] and [`AssetSaver`] for `.meshlet_mesh` [`MeshletMesh`] assets.
pub struct MeshletMeshSaverLoad;

impl AssetLoader for MeshletMeshSaverLoad {
type Asset = MeshletMesh;
type Settings = ();
type Error = bincode::Error;

fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
bincode::deserialize(&bytes)
})
}

fn extensions(&self) -> &[&str] {
&["meshlet_mesh"]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Am I right in thinking this is the first Bevy-proprietary format? If so, it might be worth picking an extension that alludes to Bevy. (Or potentially not exposing an extension at all and requiring a processor if we don't want to have a stable file format for it.)

}
}

impl AssetSaver for MeshletMeshSaverLoad {
type Asset = MeshletMesh;
type Settings = ();
type OutputLoader = Self;
type Error = bincode::Error;

fn save<'a>(
&'a self,
writer: &'a mut Writer,
asset: SavedAsset<'a, Self::Asset>,
_settings: &'a Self::Settings,
) -> BoxedFuture<'a, Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error>> {
Box::pin(async move {
let bytes = bincode::serialize(asset.get())?;
writer.write_all(&bytes).await?;
Ok(())
})
}
}
10 changes: 10 additions & 0 deletions crates/bevy_pbr/src/meshlet/copy_material_depth.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput

@group(0) @binding(0) var material_depth: texture_2d<u32>;

/// This pass copies the R16Uint material depth texture to an actual Depth16Unorm depth texture.

@fragment
fn copy_material_depth(in: FullscreenVertexOutput) -> @builtin(frag_depth) f32 {
return f32(textureLoad(material_depth, vec2<i32>(in.position.xy), 0).r) / 65535.0;
}
Loading