Skip to content

Commit c019a60

Browse files
committed
Add "end of main pass post processing" render graph node (#6468)
# Objective Bevy UI (and third party plugins) currently have no good way to position themselves after all post processing effects. They currently use the tonemapping node, but this is not adequate if there is anything after tonemapping (such as FXAA). ## Solution Add a logical `END_MAIN_PASS_POST_PROCESSING` RenderGraph node that main pass post processing effects position themselves before, and things like UIs can position themselves after.
1 parent e590537 commit c019a60

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

crates/bevy_core_pipeline/src/core_2d/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod graph {
1010
pub const MAIN_PASS: &str = "main_pass";
1111
pub const TONEMAPPING: &str = "tonemapping";
1212
pub const UPSCALING: &str = "upscaling";
13+
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
1314
}
1415
}
1516

@@ -21,7 +22,7 @@ use bevy_ecs::prelude::*;
2122
use bevy_render::{
2223
camera::Camera,
2324
extract_component::ExtractComponentPlugin,
24-
render_graph::{RenderGraph, SlotInfo, SlotType},
25+
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
2526
render_phase::{
2627
batch_phase_system, sort_phase_system, BatchedPhaseItem, CachedRenderPipelinePhaseItem,
2728
DrawFunctionId, DrawFunctions, EntityPhaseItem, PhaseItem, RenderPhase,
@@ -63,6 +64,7 @@ impl Plugin for Core2dPlugin {
6364
let mut draw_2d_graph = RenderGraph::default();
6465
draw_2d_graph.add_node(graph::node::MAIN_PASS, pass_node_2d);
6566
draw_2d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
67+
draw_2d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
6668
draw_2d_graph.add_node(graph::node::UPSCALING, upscaling);
6769
let input_node_id = draw_2d_graph.set_input(vec![SlotInfo::new(
6870
graph::input::VIEW_ENTITY,
@@ -96,7 +98,16 @@ impl Plugin for Core2dPlugin {
9698
.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING)
9799
.unwrap();
98100
draw_2d_graph
99-
.add_node_edge(graph::node::TONEMAPPING, graph::node::UPSCALING)
101+
.add_node_edge(
102+
graph::node::TONEMAPPING,
103+
graph::node::END_MAIN_PASS_POST_PROCESSING,
104+
)
105+
.unwrap();
106+
draw_2d_graph
107+
.add_node_edge(
108+
graph::node::END_MAIN_PASS_POST_PROCESSING,
109+
graph::node::UPSCALING,
110+
)
100111
.unwrap();
101112
graph.add_sub_graph(graph::NAME, draw_2d_graph);
102113
}

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod graph {
1010
pub const MAIN_PASS: &str = "main_pass";
1111
pub const TONEMAPPING: &str = "tonemapping";
1212
pub const UPSCALING: &str = "upscaling";
13+
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
1314
}
1415
}
1516

@@ -24,7 +25,7 @@ use bevy_render::{
2425
camera::{Camera, ExtractedCamera},
2526
extract_component::ExtractComponentPlugin,
2627
prelude::Msaa,
27-
render_graph::{RenderGraph, SlotInfo, SlotType},
28+
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
2829
render_phase::{
2930
sort_phase_system, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions,
3031
EntityPhaseItem, PhaseItem, RenderPhase,
@@ -73,6 +74,7 @@ impl Plugin for Core3dPlugin {
7374
let mut draw_3d_graph = RenderGraph::default();
7475
draw_3d_graph.add_node(graph::node::MAIN_PASS, pass_node_3d);
7576
draw_3d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
77+
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
7678
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);
7779
let input_node_id = draw_3d_graph.set_input(vec![SlotInfo::new(
7880
graph::input::VIEW_ENTITY,
@@ -106,7 +108,16 @@ impl Plugin for Core3dPlugin {
106108
.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING)
107109
.unwrap();
108110
draw_3d_graph
109-
.add_node_edge(graph::node::TONEMAPPING, graph::node::UPSCALING)
111+
.add_node_edge(
112+
graph::node::TONEMAPPING,
113+
graph::node::END_MAIN_PASS_POST_PROCESSING,
114+
)
115+
.unwrap();
116+
draw_3d_graph
117+
.add_node_edge(
118+
graph::node::END_MAIN_PASS_POST_PROCESSING,
119+
graph::node::UPSCALING,
120+
)
110121
.unwrap();
111122
graph.add_sub_graph(graph::NAME, draw_3d_graph);
112123
}

crates/bevy_core_pipeline/src/fxaa/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ impl Plugin for FxaaPlugin {
118118
graph
119119
.add_node_edge(core_3d::graph::node::TONEMAPPING, FXAA_NODE_3D)
120120
.unwrap();
121+
graph
122+
.add_node_edge(
123+
FXAA_NODE_3D,
124+
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
125+
)
126+
.unwrap();
121127
}
122128
{
123129
let fxaa_node = FxaaNode::new(&mut render_app.world);
@@ -138,6 +144,12 @@ impl Plugin for FxaaPlugin {
138144
graph
139145
.add_node_edge(core_2d::graph::node::TONEMAPPING, FXAA_NODE_2D)
140146
.unwrap();
147+
graph
148+
.add_node_edge(
149+
FXAA_NODE_2D,
150+
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
151+
)
152+
.unwrap();
141153
}
142154
}
143155
}

crates/bevy_ui/src/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn build_ui_render(app: &mut App) {
117117
.unwrap();
118118
graph_2d
119119
.add_node_edge(
120-
bevy_core_pipeline::core_2d::graph::node::TONEMAPPING,
120+
bevy_core_pipeline::core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
121121
draw_ui_graph::node::UI_PASS,
122122
)
123123
.unwrap();
@@ -143,7 +143,7 @@ pub fn build_ui_render(app: &mut App) {
143143
.unwrap();
144144
graph_3d
145145
.add_node_edge(
146-
bevy_core_pipeline::core_3d::graph::node::TONEMAPPING,
146+
bevy_core_pipeline::core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
147147
draw_ui_graph::node::UI_PASS,
148148
)
149149
.unwrap();

0 commit comments

Comments
 (0)