Skip to content

Commit

Permalink
render graph utils
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Mar 29, 2023
1 parent 36ada9d commit bed44df
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 141 deletions.
56 changes: 21 additions & 35 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Expand Up @@ -16,7 +16,7 @@ use bevy_render::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
prelude::Color,
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
render_graph::{add_node, Node, NodeRunError, RenderGraphContext},
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},
Expand Down Expand Up @@ -74,42 +74,28 @@ impl Plugin for BloomPlugin {
);

// Add bloom to the 3d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_3d_graph = graph
.get_sub_graph_mut(crate::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_3d_graph.add_node_edge(
crate::core_3d::graph::node::END_MAIN_PASS,
core_3d::graph::node::BLOOM,
);
draw_3d_graph.add_node_edge(
add_node::<BloomNode>(
render_app,
core_3d::graph::NAME,
core_3d::graph::node::BLOOM,
&[
core_3d::graph::node::END_MAIN_PASS,
core_3d::graph::node::BLOOM,
crate::core_3d::graph::node::TONEMAPPING,
);
}
core_3d::graph::node::TONEMAPPING,
],
);

// Add bloom to the 2d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_2d_graph = graph
.get_sub_graph_mut(crate::core_2d::graph::NAME)
.unwrap();
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_2d_graph.add_node_edge(
crate::core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
);
draw_2d_graph.add_node_edge(
add_node::<BloomNode>(
render_app,
core_2d::graph::NAME,
core_2d::graph::node::BLOOM,
&[
core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
crate::core_2d::graph::node::TONEMAPPING,
);
}
core_2d::graph::node::TONEMAPPING,
],
);
}
}

Expand All @@ -126,8 +112,8 @@ pub struct BloomNode {
)>,
}

impl BloomNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for BloomNode {
fn from_world(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
Expand Down
11 changes: 5 additions & 6 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Expand Up @@ -73,15 +73,14 @@ impl Plugin for Core2dPlugin {
draw_2d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
draw_2d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_2d_graph.add_node(graph::node::UPSCALING, upscaling);
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
draw_2d_graph.add_node_edge(

draw_2d_graph.add_node_edges(&[
graph::node::MAIN_PASS,
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_2d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_2d_graph);
}
}
Expand Down
18 changes: 3 additions & 15 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Expand Up @@ -103,25 +103,13 @@ impl Plugin for Core3dPlugin {
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);

draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::START_MAIN_PASS);
draw_3d_graph.add_node_edge(graph::node::START_MAIN_PASS, graph::node::MAIN_OPAQUE_PASS);
draw_3d_graph.add_node_edge(
graph::node::MAIN_OPAQUE_PASS,
graph::node::MAIN_TRANSPARENT_PASS,
);
draw_3d_graph.add_node_edge(
graph::node::MAIN_TRANSPARENT_PASS,
draw_3d_graph.add_node_edges(&[
graph::node::END_MAIN_PASS,
);
draw_3d_graph.add_node_edge(graph::node::END_MAIN_PASS, graph::node::TONEMAPPING);
draw_3d_graph.add_node_edge(
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_3d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_3d_graph);
}
}
Expand Down
41 changes: 15 additions & 26 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Expand Up @@ -9,7 +9,7 @@ use bevy_reflect::{
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
prelude::Camera,
render_graph::RenderGraph,
render_graph::add_node,
render_resource::*,
renderer::RenderDevice,
texture::BevyDefault,
Expand Down Expand Up @@ -92,38 +92,27 @@ impl Plugin for FxaaPlugin {
.init_resource::<SpecializedRenderPipelines<FxaaPipeline>>()
.add_systems(Render, prepare_fxaa_pipelines.in_set(RenderSet::Prepare));

{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();

graph.add_node(core_3d::graph::node::FXAA, fxaa_node);

graph.add_node_edge(
add_node::<FxaaNode>(
render_app,
core_3d::graph::NAME,
core_3d::graph::node::FXAA,
&[
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::FXAA,
);
graph.add_node_edge(
core_3d::graph::node::FXAA,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
);
}
{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();

graph.add_node(core_2d::graph::node::FXAA, fxaa_node);
],
);

graph.add_node_edge(
add_node::<FxaaNode>(
render_app,
core_2d::graph::NAME,
core_2d::graph::node::FXAA,
&[
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::FXAA,
);
graph.add_node_edge(
core_2d::graph::node::FXAA,
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
);
}
],
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Expand Up @@ -27,8 +27,8 @@ pub struct FxaaNode {
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
}

impl FxaaNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for FxaaNode {
fn from_world(world: &mut World) -> Self {
Self {
query: QueryState::new(world),
cached_texture_bind_group: Mutex::new(None),
Expand Down
30 changes: 13 additions & 17 deletions crates/bevy_core_pipeline/src/taa/mod.rs
@@ -1,4 +1,5 @@
use crate::{
core_3d,
fullscreen_vertex_shader::fullscreen_shader_vertex_state,
prelude::Camera3d,
prepass::{DepthPrepass, MotionVectorPrepass, ViewPrepassTextures},
Expand All @@ -18,7 +19,7 @@ use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::{
camera::{ExtractedCamera, TemporalJitter},
prelude::{Camera, Projection},
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
render_graph::{add_node, Node, NodeRunError, RenderGraphContext},
render_resource::{
BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId,
Expand Down Expand Up @@ -73,21 +74,16 @@ impl Plugin for TemporalAntiAliasPlugin {
),
);

let taa_node = TAANode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_3d_graph = graph
.get_sub_graph_mut(crate::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(draw_3d_graph::node::TAA, taa_node);
// MAIN_PASS -> TAA -> BLOOM -> TONEMAPPING
draw_3d_graph.add_node_edge(
crate::core_3d::graph::node::END_MAIN_PASS,
add_node::<TAANode>(
render_app,
core_3d::graph::NAME,
draw_3d_graph::node::TAA,
);
draw_3d_graph.add_node_edge(draw_3d_graph::node::TAA, crate::core_3d::graph::node::BLOOM);
draw_3d_graph.add_node_edge(
draw_3d_graph::node::TAA,
crate::core_3d::graph::node::TONEMAPPING,
&[
core_3d::graph::node::END_MAIN_PASS,
draw_3d_graph::node::TAA,
core_3d::graph::node::BLOOM,
core_3d::graph::node::TONEMAPPING,
],
);
}
}
Expand Down Expand Up @@ -168,8 +164,8 @@ struct TAANode {
)>,
}

impl TAANode {
fn new(world: &mut World) -> Self {
impl FromWorld for TAANode {
fn from_world(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
Expand Down

0 comments on commit bed44df

Please sign in to comment.