Skip to content

Commit 959e7f2

Browse files
committed
render graph utils
1 parent 3442a13 commit 959e7f2

File tree

10 files changed

+214
-141
lines changed

10 files changed

+214
-141
lines changed

crates/bevy_core_pipeline/src/bloom/mod.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bevy_render::{
1616
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
1717
},
1818
prelude::Color,
19-
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
19+
render_graph::{add_node, Node, NodeRunError, RenderGraphContext},
2020
render_resource::*,
2121
renderer::{RenderContext, RenderDevice},
2222
texture::{CachedTexture, TextureCache},
@@ -74,42 +74,28 @@ impl Plugin for BloomPlugin {
7474
);
7575

7676
// Add bloom to the 3d render graph
77-
{
78-
let bloom_node = BloomNode::new(&mut render_app.world);
79-
let mut graph = render_app.world.resource_mut::<RenderGraph>();
80-
let draw_3d_graph = graph
81-
.get_sub_graph_mut(crate::core_3d::graph::NAME)
82-
.unwrap();
83-
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
84-
// MAIN_PASS -> BLOOM -> TONEMAPPING
85-
draw_3d_graph.add_node_edge(
86-
crate::core_3d::graph::node::END_MAIN_PASS,
87-
core_3d::graph::node::BLOOM,
88-
);
89-
draw_3d_graph.add_node_edge(
77+
add_node::<BloomNode>(
78+
render_app,
79+
core_3d::graph::NAME,
80+
core_3d::graph::node::BLOOM,
81+
&[
82+
core_3d::graph::node::END_MAIN_PASS,
9083
core_3d::graph::node::BLOOM,
91-
crate::core_3d::graph::node::TONEMAPPING,
92-
);
93-
}
84+
core_3d::graph::node::TONEMAPPING,
85+
],
86+
);
9487

9588
// Add bloom to the 2d render graph
96-
{
97-
let bloom_node = BloomNode::new(&mut render_app.world);
98-
let mut graph = render_app.world.resource_mut::<RenderGraph>();
99-
let draw_2d_graph = graph
100-
.get_sub_graph_mut(crate::core_2d::graph::NAME)
101-
.unwrap();
102-
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
103-
// MAIN_PASS -> BLOOM -> TONEMAPPING
104-
draw_2d_graph.add_node_edge(
105-
crate::core_2d::graph::node::MAIN_PASS,
106-
core_2d::graph::node::BLOOM,
107-
);
108-
draw_2d_graph.add_node_edge(
89+
add_node::<BloomNode>(
90+
render_app,
91+
core_2d::graph::NAME,
92+
core_2d::graph::node::BLOOM,
93+
&[
94+
core_2d::graph::node::MAIN_PASS,
10995
core_2d::graph::node::BLOOM,
110-
crate::core_2d::graph::node::TONEMAPPING,
111-
);
112-
}
96+
core_2d::graph::node::TONEMAPPING,
97+
],
98+
);
11399
}
114100
}
115101

@@ -126,8 +112,8 @@ pub struct BloomNode {
126112
)>,
127113
}
128114

129-
impl BloomNode {
130-
pub fn new(world: &mut World) -> Self {
115+
impl FromWorld for BloomNode {
116+
fn from_world(world: &mut World) -> Self {
131117
Self {
132118
view_query: QueryState::new(world),
133119
}

crates/bevy_core_pipeline/src/core_2d/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ impl Plugin for Core2dPlugin {
7373
draw_2d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
7474
draw_2d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
7575
draw_2d_graph.add_node(graph::node::UPSCALING, upscaling);
76-
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
77-
draw_2d_graph.add_node_edge(
76+
77+
draw_2d_graph.add_node_edges(&[
78+
graph::node::MAIN_PASS,
7879
graph::node::TONEMAPPING,
7980
graph::node::END_MAIN_PASS_POST_PROCESSING,
80-
);
81-
draw_2d_graph.add_node_edge(
82-
graph::node::END_MAIN_PASS_POST_PROCESSING,
8381
graph::node::UPSCALING,
84-
);
82+
]);
83+
8584
graph.add_sub_graph(graph::NAME, draw_2d_graph);
8685
}
8786
}

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,13 @@ impl Plugin for Core3dPlugin {
103103
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
104104
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);
105105

106-
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::START_MAIN_PASS);
107-
draw_3d_graph.add_node_edge(graph::node::START_MAIN_PASS, graph::node::MAIN_OPAQUE_PASS);
108-
draw_3d_graph.add_node_edge(
109-
graph::node::MAIN_OPAQUE_PASS,
110-
graph::node::MAIN_TRANSPARENT_PASS,
111-
);
112-
draw_3d_graph.add_node_edge(
113-
graph::node::MAIN_TRANSPARENT_PASS,
106+
draw_3d_graph.add_node_edges(&[
114107
graph::node::END_MAIN_PASS,
115-
);
116-
draw_3d_graph.add_node_edge(graph::node::END_MAIN_PASS, graph::node::TONEMAPPING);
117-
draw_3d_graph.add_node_edge(
118108
graph::node::TONEMAPPING,
119109
graph::node::END_MAIN_PASS_POST_PROCESSING,
120-
);
121-
draw_3d_graph.add_node_edge(
122-
graph::node::END_MAIN_PASS_POST_PROCESSING,
123110
graph::node::UPSCALING,
124-
);
111+
]);
112+
125113
graph.add_sub_graph(graph::NAME, draw_3d_graph);
126114
}
127115
}

crates/bevy_core_pipeline/src/fxaa/mod.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bevy_reflect::{
99
use bevy_render::{
1010
extract_component::{ExtractComponent, ExtractComponentPlugin},
1111
prelude::Camera,
12-
render_graph::RenderGraph,
12+
render_graph::add_node,
1313
render_resource::*,
1414
renderer::RenderDevice,
1515
texture::BevyDefault,
@@ -92,38 +92,27 @@ impl Plugin for FxaaPlugin {
9292
.init_resource::<SpecializedRenderPipelines<FxaaPipeline>>()
9393
.add_systems(Render, prepare_fxaa_pipelines.in_set(RenderSet::Prepare));
9494

95-
{
96-
let fxaa_node = FxaaNode::new(&mut render_app.world);
97-
let mut binding = render_app.world.resource_mut::<RenderGraph>();
98-
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();
99-
100-
graph.add_node(core_3d::graph::node::FXAA, fxaa_node);
101-
102-
graph.add_node_edge(
95+
add_node::<FxaaNode>(
96+
render_app,
97+
core_3d::graph::NAME,
98+
core_3d::graph::node::FXAA,
99+
&[
103100
core_3d::graph::node::TONEMAPPING,
104101
core_3d::graph::node::FXAA,
105-
);
106-
graph.add_node_edge(
107-
core_3d::graph::node::FXAA,
108102
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
109-
);
110-
}
111-
{
112-
let fxaa_node = FxaaNode::new(&mut render_app.world);
113-
let mut binding = render_app.world.resource_mut::<RenderGraph>();
114-
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();
115-
116-
graph.add_node(core_2d::graph::node::FXAA, fxaa_node);
103+
],
104+
);
117105

118-
graph.add_node_edge(
106+
add_node::<FxaaNode>(
107+
render_app,
108+
core_2d::graph::NAME,
109+
core_2d::graph::node::FXAA,
110+
&[
119111
core_2d::graph::node::TONEMAPPING,
120112
core_2d::graph::node::FXAA,
121-
);
122-
graph.add_node_edge(
123-
core_2d::graph::node::FXAA,
124113
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
125-
);
126-
}
114+
],
115+
);
127116
}
128117
}
129118

crates/bevy_core_pipeline/src/fxaa/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct FxaaNode {
2727
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
2828
}
2929

30-
impl FxaaNode {
31-
pub fn new(world: &mut World) -> Self {
30+
impl FromWorld for FxaaNode {
31+
fn from_world(world: &mut World) -> Self {
3232
Self {
3333
query: QueryState::new(world),
3434
cached_texture_bind_group: Mutex::new(None),

crates/bevy_core_pipeline/src/taa/mod.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
core_3d,
23
fullscreen_vertex_shader::fullscreen_shader_vertex_state,
34
prelude::Camera3d,
45
prepass::{DepthPrepass, MotionVectorPrepass, ViewPrepassTextures},
@@ -18,7 +19,7 @@ use bevy_reflect::{Reflect, TypeUuid};
1819
use bevy_render::{
1920
camera::{ExtractedCamera, TemporalJitter},
2021
prelude::{Camera, Projection},
21-
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
22+
render_graph::{add_node, Node, NodeRunError, RenderGraphContext},
2223
render_resource::{
2324
BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
2425
BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId,
@@ -73,21 +74,16 @@ impl Plugin for TemporalAntiAliasPlugin {
7374
),
7475
);
7576

76-
let taa_node = TAANode::new(&mut render_app.world);
77-
let mut graph = render_app.world.resource_mut::<RenderGraph>();
78-
let draw_3d_graph = graph
79-
.get_sub_graph_mut(crate::core_3d::graph::NAME)
80-
.unwrap();
81-
draw_3d_graph.add_node(draw_3d_graph::node::TAA, taa_node);
82-
// MAIN_PASS -> TAA -> BLOOM -> TONEMAPPING
83-
draw_3d_graph.add_node_edge(
84-
crate::core_3d::graph::node::END_MAIN_PASS,
77+
add_node::<TAANode>(
78+
render_app,
79+
core_3d::graph::NAME,
8580
draw_3d_graph::node::TAA,
86-
);
87-
draw_3d_graph.add_node_edge(draw_3d_graph::node::TAA, crate::core_3d::graph::node::BLOOM);
88-
draw_3d_graph.add_node_edge(
89-
draw_3d_graph::node::TAA,
90-
crate::core_3d::graph::node::TONEMAPPING,
81+
&[
82+
core_3d::graph::node::END_MAIN_PASS,
83+
draw_3d_graph::node::TAA,
84+
core_3d::graph::node::BLOOM,
85+
core_3d::graph::node::TONEMAPPING,
86+
],
9187
);
9288
}
9389
}
@@ -168,8 +164,8 @@ struct TAANode {
168164
)>,
169165
}
170166

171-
impl TAANode {
172-
fn new(world: &mut World) -> Self {
167+
impl FromWorld for TAANode {
168+
fn from_world(world: &mut World) -> Self {
173169
Self {
174170
view_query: QueryState::new(world),
175171
}

0 commit comments

Comments
 (0)