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

[Merged by Bors] - Add depth and normal prepass #6284

Closed
wants to merge 111 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
d2af71e
robswain depth prepass
IceSentry Oct 11, 2022
0ecce68
robtfm depth prepass
IceSentry Oct 11, 2022
8458d1f
fix update to main
IceSentry Oct 11, 2022
e6bd4a2
show_depth example
IceSentry Oct 11, 2022
3327950
custom prepass shaders per material
IceSentry Oct 13, 2022
9754bae
reorder some stuff
IceSentry Oct 13, 2022
48c16e4
Prepass naming/doc cleanup
JMS55 Oct 13, 2022
1e7cb75
Remove PrepassSettings from example/3d_scene.rs
JMS55 Oct 13, 2022
06fa29e
Add PrepassPlugin within MaterialPlugin
JMS55 Oct 13, 2022
c0d528a
Misc fixes
JMS55 Oct 13, 2022
0b9f67b
Merge pull request #1 from JMS55/depth-prepass
IceSentry Oct 13, 2022
793352e
prepass wip
IceSentry Oct 27, 2022
40591ab
Merge branch 'main' into depth-prepass
IceSentry Oct 27, 2022
a3f2121
fix merge
IceSentry Oct 27, 2022
6c60290
simplify configuration
IceSentry Oct 27, 2022
5e9de81
yeet match bool
IceSentry Oct 27, 2022
4a3be2d
extract prepass node
IceSentry Oct 27, 2022
c619e94
rename phases
IceSentry Oct 27, 2022
8763721
fix targets for alpha mask only
IceSentry Oct 28, 2022
f26c4f7
rename some things
IceSentry Oct 28, 2022
a64cb56
remove unnecessary comment
IceSentry Oct 28, 2022
98da061
pr fixes
IceSentry Oct 30, 2022
8112944
Merge branch 'main' into depth-prepass
IceSentry Oct 30, 2022
d637d5b
Update crates/bevy_core_pipeline/src/prepass/node.rs
IceSentry Nov 5, 2022
745586d
Update crates/bevy_pbr/src/render/prepass.rs
IceSentry Nov 5, 2022
c584835
Apply suggestions from code review
IceSentry Nov 5, 2022
3a10291
Merge branch 'main' into depth-prepass
IceSentry Nov 5, 2022
0b43b35
use match to unwrap textures
IceSentry Nov 5, 2022
d312da4
fix plugin
IceSentry Nov 5, 2022
b3e2415
fmt
IceSentry Nov 5, 2022
9a5511e
update normal mapping
IceSentry Nov 5, 2022
94c5ac3
more warn
IceSentry Nov 5, 2022
b6efa0e
depth format
IceSentry Nov 11, 2022
3de2d75
Merge branch 'main' into depth-prepass
IceSentry Nov 11, 2022
a238ca7
Merge branch 'main' into depth-prepass
IceSentry Nov 12, 2022
1ffe9b4
Merge branch 'main' into depth-prepass
IceSentry Nov 20, 2022
47b41d6
simplify code related to texture cache
IceSentry Nov 20, 2022
1f776b3
reduce nesting a bit with let else
IceSentry Nov 20, 2022
f5bf3f8
Apply suggestions from code review
IceSentry Nov 20, 2022
1754e29
docs and minor renames
IceSentry Nov 20, 2022
a40b3bd
docs
IceSentry Nov 20, 2022
400bb5f
create new layout_entries
IceSentry Nov 20, 2022
a0d722a
docs
IceSentry Nov 20, 2022
4426530
fix docs ci
IceSentry Nov 20, 2022
24080de
update normal prepass
IceSentry Nov 24, 2022
e41ca17
Merge branch 'main' into depth-prepass
IceSentry Nov 24, 2022
7d3effd
remove unwraps
IceSentry Nov 24, 2022
8dc5bac
fix shader_defs
IceSentry Nov 24, 2022
f31a04d
clean up
IceSentry Nov 24, 2022
6dd5272
Merge branch 'main' into depth-prepass
IceSentry Dec 6, 2022
c2f1698
Apply suggestions from code review
IceSentry Dec 6, 2022
cc419af
Merge remote-tracking branch 'origin/depth-prepass' into depth-prepass
IceSentry Dec 6, 2022
7c5a5eb
docs
IceSentry Dec 6, 2022
9be7e5e
Merge branch 'main' into depth-prepass
IceSentry Dec 8, 2022
d077237
address pr comments
IceSentry Dec 12, 2022
ef4b3e9
Merge branch 'main' into depth-prepass
IceSentry Dec 12, 2022
314dea0
docs
IceSentry Dec 12, 2022
4ebf55c
Merge branch 'main' into depth-prepass
IceSentry Dec 24, 2022
433605d
use separate prepass components
IceSentry Dec 24, 2022
722b580
fix ci
IceSentry Dec 24, 2022
1e5fb5a
derive default and don't run when not present
IceSentry Dec 25, 2022
324eecf
Merge branch 'main' into depth-prepass
IceSentry Dec 25, 2022
e20e15f
use depth buffer if present
IceSentry Dec 25, 2022
7b2fbbc
enable prepass by default
IceSentry Dec 25, 2022
005dcb8
extract prepass to module and standardize naming
IceSentry Dec 25, 2022
a54b73e
register type in core_pipeline
IceSentry Dec 25, 2022
fab7dc3
fix FragmentInput
IceSentry Dec 26, 2022
e083a7d
better example
IceSentry Dec 26, 2022
b5d37d9
Merge branch 'main' into depth-prepass
IceSentry Dec 26, 2022
d42b611
Apply suggestions from code review
IceSentry Dec 30, 2022
684a061
Apply suggestions from code review
IceSentry Dec 30, 2022
c3fa4e0
Apply suggestions from code review
IceSentry Dec 30, 2022
d134000
Update crates/bevy_pbr/src/prepass/prepass.wgsl
IceSentry Dec 30, 2022
1cb5ed6
Merge branch 'main' into depth-prepass
IceSentry Dec 30, 2022
51c7eea
remove unnecessary comment
IceSentry Dec 30, 2022
f61053e
use pbr_functions import
IceSentry Dec 30, 2022
1e3b173
clean up example
IceSentry Dec 30, 2022
969f3ad
add TODOs
IceSentry Dec 30, 2022
2f83d4b
add comment
IceSentry Dec 30, 2022
134b27c
clean up pbr_prepass
IceSentry Dec 30, 2022
2b0f4f9
Apply suggestions from code review
IceSentry Dec 30, 2022
715ca65
fix unwrap on empty frag shader in prepass
IceSentry Jan 2, 2023
35093ed
docs
IceSentry Jan 2, 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
fdbb4d2
Merge branch 'main' into depth-prepass
IceSentry Jan 12, 2023
a5ec2f5
Merge branch 'main' into depth-prepass
IceSentry Jan 13, 2023
8e3c28b
remove needless viewport
IceSentry Jan 15, 2023
4fdb631
fix ci
IceSentry Jan 15, 2023
4113981
Merge branch 'main' into depth-prepass
IceSentry Jan 15, 2023
37dc019
fix ci again
IceSentry Jan 15, 2023
4c93b78
reintroduce viewport
IceSentry Jan 16, 2023
40a6ed5
Merge branch 'main' into depth-prepass
IceSentry Jan 16, 2023
30c0c8b
fix merge
IceSentry Jan 16, 2023
59cdf6f
Update crates/bevy_pbr/src/render/pbr_functions.wgsl
IceSentry Jan 18, 2023
66e4ab4
Update crates/bevy_pbr/src/render/pbr_functions.wgsl
IceSentry Jan 18, 2023
55839ea
fix fallback with multisamples
IceSentry Jan 18, 2023
30393b0
wording
IceSentry Jan 18, 2023
048b08c
fix
IceSentry Jan 18, 2023
b002ef6
spelling
IceSentry Jan 18, 2023
522f49b
don't create or bind prepass textures with webgl
IceSentry Jan 19, 2023
0dd8d89
Merge branch 'main' into depth-prepass
IceSentry Jan 19, 2023
ed86541
don't log warning
IceSentry Jan 19, 2023
69a1da5
Merge branch 'main' into depth-prepass
IceSentry Jan 19, 2023
8a2b381
Apply suggestions from code review
IceSentry Jan 19, 2023
678aec7
Merge branch 'main' into depth-prepass
IceSentry Jan 19, 2023
9dc998e
add backticks
IceSentry Jan 19, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ path = "examples/shader/shader_prepass.rs"
name = "Material Prepass"
description = "A shader that uses the depth texture generated in a prepass"
category = "Shaders"
wasm = true
wasm = false


[[example]]
Expand Down
167 changes: 87 additions & 80 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl FromWorld for MeshPipeline {
clustered_forward_buffer_binding_type: BufferBindingType,
multisampled: bool,
) -> Vec<BindGroupLayoutEntry> {
vec![
let mut entries = vec![
// View
BindGroupLayoutEntry {
binding: 0,
Expand Down Expand Up @@ -400,8 +400,10 @@ impl FromWorld for MeshPipeline {
},
count: None,
},
];
if cfg!(not(feature = "webgl")) {
// Depth texture
BindGroupLayoutEntry {
entries.push(BindGroupLayoutEntry {
binding: 10,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
Expand All @@ -410,9 +412,9 @@ impl FromWorld for MeshPipeline {
view_dimension: TextureViewDimension::D2,
},
count: None,
},
});
// Normal texture
BindGroupLayoutEntry {
entries.push(BindGroupLayoutEntry {
binding: 11,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
Expand All @@ -421,8 +423,9 @@ impl FromWorld for MeshPipeline {
view_dimension: TextureViewDimension::D2,
},
count: None,
},
]
});
}
entries
}

let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
Expand Down Expand Up @@ -874,87 +877,91 @@ pub fn queue_mesh_view_bind_groups(
globals_buffer.buffer.binding(),
) {
for (entity, view_shadow_bindings, view_cluster_bindings, prepass_textures) in &views {
let depth_view = match prepass_textures.and_then(|x| x.depth.as_ref()) {
Some(texture) => &texture.default_view,
None => {
&fallback_depths
.image_for_samplecount(msaa.samples)
.texture_view
}
};

let normal_view = match prepass_textures.and_then(|x| x.normal.as_ref()) {
Some(texture) => &texture.default_view,
None => {
&fallback_images
.image_for_samplecount(msaa.samples)
.texture_view
}
};

let layout = if msaa.samples > 1 {
&mesh_pipeline.view_layout_multisampled
} else {
&mesh_pipeline.view_layout
};

let mut entries = vec![
BindGroupEntry {
binding: 0,
resource: view_binding.clone(),
},
BindGroupEntry {
binding: 1,
resource: light_binding.clone(),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(
&view_shadow_bindings.point_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 3,
resource: BindingResource::Sampler(&shadow_pipeline.point_light_sampler),
},
BindGroupEntry {
binding: 4,
resource: BindingResource::TextureView(
&view_shadow_bindings.directional_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 5,
resource: BindingResource::Sampler(&shadow_pipeline.directional_light_sampler),
},
BindGroupEntry {
binding: 6,
resource: point_light_binding.clone(),
},
BindGroupEntry {
binding: 7,
resource: view_cluster_bindings.light_index_lists_binding().unwrap(),
},
BindGroupEntry {
binding: 8,
resource: view_cluster_bindings.offsets_and_counts_binding().unwrap(),
},
BindGroupEntry {
binding: 9,
resource: globals.clone(),
},
];

// When using webgl with msaa, we can't create the fallback textures required by the prepass
// When msaa is disabled, we can't bind the textures either
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
if cfg!(not(feature = "webgl")) {
let depth_view = match prepass_textures.and_then(|x| x.depth.as_ref()) {
Some(texture) => &texture.default_view,
None => {
&fallback_depths
.image_for_samplecount(msaa.samples)
.texture_view
}
};
entries.push(BindGroupEntry {
binding: 10,
resource: BindingResource::TextureView(depth_view),
});

let normal_view = match prepass_textures.and_then(|x| x.normal.as_ref()) {
Some(texture) => &texture.default_view,
None => {
&fallback_images
.image_for_samplecount(msaa.samples)
.texture_view
}
};
entries.push(BindGroupEntry {
binding: 11,
resource: BindingResource::TextureView(normal_view),
});
}

let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
entries: &[
BindGroupEntry {
binding: 0,
resource: view_binding.clone(),
},
BindGroupEntry {
binding: 1,
resource: light_binding.clone(),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(
&view_shadow_bindings.point_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 3,
resource: BindingResource::Sampler(&shadow_pipeline.point_light_sampler),
},
BindGroupEntry {
binding: 4,
resource: BindingResource::TextureView(
&view_shadow_bindings.directional_light_depth_texture_view,
),
},
BindGroupEntry {
binding: 5,
resource: BindingResource::Sampler(
&shadow_pipeline.directional_light_sampler,
),
},
BindGroupEntry {
binding: 6,
resource: point_light_binding.clone(),
},
BindGroupEntry {
binding: 7,
resource: view_cluster_bindings.light_index_lists_binding().unwrap(),
},
BindGroupEntry {
binding: 8,
resource: view_cluster_bindings.offsets_and_counts_binding().unwrap(),
},
BindGroupEntry {
binding: 9,
resource: globals.clone(),
},
BindGroupEntry {
binding: 10,
resource: BindingResource::TextureView(depth_view),
},
BindGroupEntry {
binding: 11,
resource: BindingResource::TextureView(normal_view),
},
],
entries: &entries,
label: Some("mesh_view_bind_group"),
layout,
});
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/texture/fallback_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ impl FromWorld for FallbackImage {
/// A Cache of fallback textures that uses the sample count as a key
///
/// # WARNING
/// Images using MSAA with sample count > 1 are not initialised with data, therefore,
/// Images using MSAA with sample count > 1 are not initialized with data, therefore,
/// you shouldn't sample them before writing data to them first.
#[derive(Resource, Deref, DerefMut, Default)]
pub struct FallbackImageMsaaCache(HashMap<u32, GpuImage>);

/// A Cache of fallback depth textures that uses the sample count as a key
///
/// # WARNING
/// Detph images are never initialised with data, therefore,
/// Detph images are never initialized with data, therefore,
/// you shouldn't sample them before writing data to them first.
#[derive(Resource, Deref, DerefMut, Default)]
pub struct FallbackImageDepthCache(HashMap<u32, GpuImage>);
Expand Down
3 changes: 3 additions & 0 deletions examples/shader/shader_prepass.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Bevy has an optional prepass that is controlled per-material. A prepass is a rendering pass that runs before the main pass.
//! It will optionally generate various view textures. Currently it supports depth and normal textures.
//! The textures are not generated for any material using alpha blending.
//!
//! # WARNING
//! The prepass currently doesn't work in wasm.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

use bevy::{
core_pipeline::prepass::{DepthPrepass, NormalPrepass},
Expand Down