Skip to content

Commit 59d6262

Browse files
Add doc comments, combine phases in main_opaque_pass, add label nodes
1 parent 4ae7193 commit 59d6262

File tree

7 files changed

+55
-76
lines changed

7 files changed

+55
-76
lines changed

crates/bevy_core_pipeline/src/bloom/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Plugin for BloomPlugin {
9494
);
9595
// MAIN_PASS -> BLOOM -> TONEMAPPING
9696
draw_3d_graph.add_node_edge(
97-
crate::core_3d::graph::node::MAIN_TRANSPARENT_PASS,
97+
crate::core_3d::graph::node::START_MAIN_PASS,
9898
core_3d::graph::node::BLOOM,
9999
);
100100
draw_3d_graph.add_node_edge(

crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use bevy_utils::tracing::info_span;
1717

1818
use super::{AlphaMask3d, Camera3dDepthLoadOp};
1919

20+
/// A [`Node`] that runs the [`Opaque3d`] and [`AlphaMask3d`] [`RenderPhase`].
2021
pub struct MainOpaquePass3dNode {
2122
query: QueryState<
2223
(
@@ -76,81 +77,50 @@ impl Node for MainOpaquePass3dNode {
7677
return Ok(());
7778
};
7879

79-
// Always run opaque pass to ensure screen is cleared
80-
{
81-
// Run the opaque pass, sorted front-to-back
82-
// NOTE: Scoped to drop the mutable borrow of render_context
83-
#[cfg(feature = "trace")]
84-
let _main_opaque_pass_3d_span = info_span!("main_opaque_pass_3d").entered();
85-
86-
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
87-
label: Some("main_opaque_pass_3d"),
88-
// NOTE: The opaque pass loads the color
89-
// buffer as well as writing to it.
90-
color_attachments: &[Some(target.get_color_attachment(Operations {
91-
load: match camera_3d.clear_color {
92-
ClearColorConfig::Default => {
93-
LoadOp::Clear(world.resource::<ClearColor>().0.into())
94-
}
95-
ClearColorConfig::Custom(color) => LoadOp::Clear(color.into()),
96-
ClearColorConfig::None => LoadOp::Load,
97-
},
80+
// Run the opaque pass, sorted front-to-back
81+
#[cfg(feature = "trace")]
82+
let _main_opaque_pass_3d_span = info_span!("main_opaque_pass_3d").entered();
83+
84+
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
85+
label: Some("main_opaque_pass_3d"),
86+
// NOTE: The opaque pass loads the color
87+
// buffer as well as writing to it.
88+
color_attachments: &[Some(target.get_color_attachment(Operations {
89+
load: match camera_3d.clear_color {
90+
ClearColorConfig::Default => {
91+
LoadOp::Clear(world.resource::<ClearColor>().0.into())
92+
}
93+
ClearColorConfig::Custom(color) => LoadOp::Clear(color.into()),
94+
ClearColorConfig::None => LoadOp::Load,
95+
},
96+
store: true,
97+
}))],
98+
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
99+
view: &depth.view,
100+
// NOTE: The opaque main pass loads the depth buffer and possibly overwrites it
101+
depth_ops: Some(Operations {
102+
load: if depth_prepass.is_some() || normal_prepass.is_some() {
103+
// if any prepass runs, it will generate a depth buffer so we should use it,
104+
// even if only the normal_prepass is used.
105+
Camera3dDepthLoadOp::Load
106+
} else {
107+
// NOTE: 0.0 is the far plane due to bevy's use of reverse-z projections.
108+
camera_3d.depth_load_op.clone()
109+
}
110+
.into(),
98111
store: true,
99-
}))],
100-
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
101-
view: &depth.view,
102-
// NOTE: The opaque main pass loads the depth buffer and possibly overwrites it
103-
depth_ops: Some(Operations {
104-
load: if depth_prepass.is_some() || normal_prepass.is_some() {
105-
// if any prepass runs, it will generate a depth buffer so we should use it,
106-
// even if only the normal_prepass is used.
107-
Camera3dDepthLoadOp::Load
108-
} else {
109-
// NOTE: 0.0 is the far plane due to bevy's use of reverse-z projections.
110-
camera_3d.depth_load_op.clone()
111-
}
112-
.into(),
113-
store: true,
114-
}),
115-
stencil_ops: None,
116112
}),
117-
});
118-
119-
if let Some(viewport) = camera.viewport.as_ref() {
120-
render_pass.set_camera_viewport(viewport);
121-
}
113+
stencil_ops: None,
114+
}),
115+
});
122116

123-
opaque_phase.render(&mut render_pass, world, view_entity);
117+
if let Some(viewport) = camera.viewport.as_ref() {
118+
render_pass.set_camera_viewport(viewport);
124119
}
125120

126-
if !alpha_mask_phase.items.is_empty() {
127-
// Run the alpha mask pass, sorted front-to-back
128-
// NOTE: Scoped to drop the mutable borrow of render_context
129-
#[cfg(feature = "trace")]
130-
let _main_alpha_mask_pass_3d_span = info_span!("main_alpha_mask_pass_3d").entered();
131-
132-
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
133-
label: Some("main_alpha_mask_pass_3d"),
134-
// NOTE: The alpha_mask pass loads the color buffer as well as overwriting it where appropriate.
135-
color_attachments: &[Some(target.get_color_attachment(Operations {
136-
load: LoadOp::Load,
137-
store: true,
138-
}))],
139-
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
140-
view: &depth.view,
141-
// NOTE: The alpha mask pass loads the depth buffer and possibly overwrites it
142-
depth_ops: Some(Operations {
143-
load: LoadOp::Load,
144-
store: true,
145-
}),
146-
stencil_ops: None,
147-
}),
148-
});
149-
150-
if let Some(viewport) = camera.viewport.as_ref() {
151-
render_pass.set_camera_viewport(viewport);
152-
}
121+
opaque_phase.render(&mut render_pass, world, view_entity);
153122

123+
if !alpha_mask_phase.items.is_empty() {
154124
alpha_mask_phase.render(&mut render_pass, world, view_entity);
155125
}
156126

crates/bevy_core_pipeline/src/core_3d/main_transparent_pass_3d_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bevy_render::{
1111
#[cfg(feature = "trace")]
1212
use bevy_utils::tracing::info_span;
1313

14+
/// A [`Node`] that runs the [`Transparent3d`] [`RenderPhase`].
1415
pub struct MainTransparentPass3dNode {
1516
query: QueryState<
1617
(

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ pub mod graph {
1010
pub mod node {
1111
pub const MSAA_WRITEBACK: &str = "msaa_writeback";
1212
pub const PREPASS: &str = "prepass";
13+
pub const START_MAIN_PASS: &str = "start_main_pass";
1314
pub const MAIN_OPAQUE_PASS: &str = "main_opaque_pass";
1415
pub const MAIN_TRANSPARENT_PASS: &str = "main_transparent_pass";
16+
pub const END_MAIN_PASS: &str = "end_main_pass";
1517
pub const BLOOM: &str = "bloom";
1618
pub const TONEMAPPING: &str = "tonemapping";
1719
pub const FXAA: &str = "fxaa";
@@ -90,8 +92,10 @@ impl Plugin for Core3dPlugin {
9092

9193
let mut draw_3d_graph = RenderGraph::default();
9294
draw_3d_graph.add_node(graph::node::PREPASS, prepass_node);
95+
draw_3d_graph.add_node(graph::node::START_MAIN_PASS, EmptyNode);
9396
draw_3d_graph.add_node(graph::node::MAIN_OPAQUE_PASS, opaque_node_3d);
9497
draw_3d_graph.add_node(graph::node::MAIN_TRANSPARENT_PASS, transparent_node_3d);
98+
draw_3d_graph.add_node(graph::node::END_MAIN_PASS, EmptyNode);
9599
draw_3d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
96100
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
97101
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);
@@ -130,13 +134,17 @@ impl Plugin for Core3dPlugin {
130134
graph::node::UPSCALING,
131135
UpscalingNode::IN_VIEW,
132136
);
133-
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::MAIN_OPAQUE_PASS);
137+
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::START_MAIN_PASS);
138+
draw_3d_graph.add_node_edge(graph::node::START_MAIN_PASS, graph::node::MAIN_OPAQUE_PASS);
134139
draw_3d_graph.add_node_edge(
135140
graph::node::MAIN_OPAQUE_PASS,
136141
graph::node::MAIN_TRANSPARENT_PASS,
137142
);
138-
draw_3d_graph.add_node_edge(graph::node::MAIN_TRANSPARENT_PASS, graph::node::TONEMAPPING);
139-
143+
draw_3d_graph.add_node_edge(
144+
graph::node::MAIN_TRANSPARENT_PASS,
145+
graph::node::END_MAIN_PASS,
146+
);
147+
draw_3d_graph.add_node_edge(graph::node::END_MAIN_PASS, graph::node::TONEMAPPING);
140148
draw_3d_graph.add_node_edge(
141149
graph::node::TONEMAPPING,
142150
graph::node::END_MAIN_PASS_POST_PROCESSING,

crates/bevy_core_pipeline/src/msaa_writeback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Plugin for MsaaWritebackPlugin {
5050
);
5151
core_3d.add_node_edge(
5252
crate::core_3d::graph::node::MSAA_WRITEBACK,
53-
crate::core_3d::graph::node::MAIN_OPAQUE_PASS,
53+
crate::core_3d::graph::node::START_MAIN_PASS,
5454
);
5555
core_3d.add_slot_edge(
5656
input_node,

crates/bevy_pbr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl Plugin for PbrPlugin {
284284
draw_3d_graph.add_node(draw_3d_graph::node::SHADOW_PASS, shadow_pass_node);
285285
draw_3d_graph.add_node_edge(
286286
draw_3d_graph::node::SHADOW_PASS,
287-
bevy_core_pipeline::core_3d::graph::node::MAIN_OPAQUE_PASS,
287+
bevy_core_pipeline::core_3d::graph::node::START_MAIN_PASS,
288288
);
289289
draw_3d_graph.add_slot_edge(
290290
draw_3d_graph.input_node().id,

crates/bevy_ui/src/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn build_ui_render(app: &mut App) {
130130
RunGraphOnViewNode::new(draw_ui_graph::NAME),
131131
);
132132
graph_3d.add_node_edge(
133-
bevy_core_pipeline::core_3d::graph::node::MAIN_TRANSPARENT_PASS,
133+
bevy_core_pipeline::core_3d::graph::node::END_MAIN_PASS,
134134
draw_ui_graph::node::UI_PASS,
135135
);
136136
graph_3d.add_node_edge(

0 commit comments

Comments
 (0)