Skip to content

Commit

Permalink
Make Core Pipeline Graph Nodes Public (bevyengine#6605)
Browse files Browse the repository at this point in the history
# Objective

Make core pipeline graphic nodes, including `BloomNode`, `FxaaNode`, `TonemappingNode` and `UpscalingNode` public.
This will allow users to construct their own render graphs with these build-in nodes.

## Solution

Make them public.
Also put node names into bevy's core namespace (`core_2d::graph::node`, `core_3d::graph::node`) which makes them consistent.
  • Loading branch information
cryscan committed Nov 18, 2022
1 parent cb8fe5b commit e0c3c6d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
37 changes: 12 additions & 25 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
use crate::{core_2d, core_3d, fullscreen_vertex_shader::fullscreen_shader_vertex_state};
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, HandleUntyped};
use bevy_ecs::{
Expand All @@ -25,19 +25,6 @@ use bevy_utils::tracing::info_span;
use bevy_utils::HashMap;
use std::num::NonZeroU32;

pub mod draw_3d_graph {
pub mod node {
/// Label for the bloom render node.
pub const BLOOM: &str = "bloom_3d";
}
}
pub mod draw_2d_graph {
pub mod node {
/// Label for the bloom render node.
pub const BLOOM: &str = "bloom_2d";
}
}

const BLOOM_SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 929599476923908);

Expand Down Expand Up @@ -68,25 +55,25 @@ impl Plugin for BloomPlugin {
let draw_3d_graph = graph
.get_sub_graph_mut(crate::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(draw_3d_graph::node::BLOOM, bloom_node);
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
draw_3d_graph
.add_slot_edge(
draw_3d_graph.input_node().unwrap().id,
crate::core_3d::graph::input::VIEW_ENTITY,
draw_3d_graph::node::BLOOM,
core_3d::graph::node::BLOOM,
BloomNode::IN_VIEW,
)
.unwrap();
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_3d_graph
.add_node_edge(
crate::core_3d::graph::node::MAIN_PASS,
draw_3d_graph::node::BLOOM,
core_3d::graph::node::BLOOM,
)
.unwrap();
draw_3d_graph
.add_node_edge(
draw_3d_graph::node::BLOOM,
core_3d::graph::node::BLOOM,
crate::core_3d::graph::node::TONEMAPPING,
)
.unwrap();
Expand All @@ -98,25 +85,25 @@ impl Plugin for BloomPlugin {
let draw_2d_graph = graph
.get_sub_graph_mut(crate::core_2d::graph::NAME)
.unwrap();
draw_2d_graph.add_node(draw_2d_graph::node::BLOOM, bloom_node);
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
draw_2d_graph
.add_slot_edge(
draw_2d_graph.input_node().unwrap().id,
crate::core_2d::graph::input::VIEW_ENTITY,
draw_2d_graph::node::BLOOM,
core_2d::graph::node::BLOOM,
BloomNode::IN_VIEW,
)
.unwrap();
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_2d_graph
.add_node_edge(
crate::core_2d::graph::node::MAIN_PASS,
draw_2d_graph::node::BLOOM,
core_2d::graph::node::BLOOM,
)
.unwrap();
draw_2d_graph
.add_node_edge(
draw_2d_graph::node::BLOOM,
core_2d::graph::node::BLOOM,
crate::core_2d::graph::node::TONEMAPPING,
)
.unwrap();
Expand Down Expand Up @@ -164,7 +151,7 @@ impl Default for BloomSettings {
}
}

struct BloomNode {
pub struct BloomNode {
view_query: QueryState<(
&'static ExtractedCamera,
&'static ViewTarget,
Expand All @@ -175,9 +162,9 @@ struct BloomNode {
}

impl BloomNode {
const IN_VIEW: &'static str = "view";
pub const IN_VIEW: &'static str = "view";

fn new(world: &mut World) -> Self {
pub fn new(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub mod graph {
}
pub mod node {
pub const MAIN_PASS: &str = "main_pass";
pub const BLOOM: &str = "bloom";
pub const TONEMAPPING: &str = "tonemapping";
pub const FXAA: &str = "fxaa";
pub const UPSCALING: &str = "upscaling";
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
}
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub mod graph {
}
pub mod node {
pub const MAIN_PASS: &str = "main_pass";
pub const BLOOM: &str = "bloom";
pub const TONEMAPPING: &str = "tonemapping";
pub const FXAA: &str = "fxaa";
pub const UPSCALING: &str = "upscaling";
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
}
Expand Down
36 changes: 19 additions & 17 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
mod node;

use crate::{
core_2d, core_3d, fullscreen_vertex_shader::fullscreen_shader_vertex_state,
fxaa::node::FxaaNode,
};
use crate::{core_2d, core_3d, fullscreen_vertex_shader::fullscreen_shader_vertex_state};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, HandleUntyped};
use bevy_derive::Deref;
Expand All @@ -20,6 +15,10 @@ use bevy_render::{
RenderApp, RenderStage,
};

mod node;

pub use node::FxaaNode;

#[derive(Eq, PartialEq, Hash, Clone, Copy)]
pub enum Sensitivity {
Low,
Expand Down Expand Up @@ -79,9 +78,6 @@ impl ExtractComponent for Fxaa {
const FXAA_SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 4182761465141723543);

pub const FXAA_NODE_3D: &str = "fxaa_node_3d";
pub const FXAA_NODE_2D: &str = "fxaa_node_2d";

/// Adds support for Fast Approximate Anti-Aliasing (FXAA)
pub struct FxaaPlugin;
impl Plugin for FxaaPlugin {
Expand All @@ -104,23 +100,26 @@ impl Plugin for FxaaPlugin {
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();

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

graph
.add_slot_edge(
graph.input_node().unwrap().id,
core_3d::graph::input::VIEW_ENTITY,
FXAA_NODE_3D,
core_3d::graph::node::FXAA,
FxaaNode::IN_VIEW,
)
.unwrap();

graph
.add_node_edge(core_3d::graph::node::TONEMAPPING, FXAA_NODE_3D)
.add_node_edge(
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::FXAA,
)
.unwrap();
graph
.add_node_edge(
FXAA_NODE_3D,
core_3d::graph::node::FXAA,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
)
.unwrap();
Expand All @@ -130,23 +129,26 @@ impl Plugin for FxaaPlugin {
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();

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

graph
.add_slot_edge(
graph.input_node().unwrap().id,
core_2d::graph::input::VIEW_ENTITY,
FXAA_NODE_2D,
core_2d::graph::node::FXAA,
FxaaNode::IN_VIEW,
)
.unwrap();

graph
.add_node_edge(core_2d::graph::node::TONEMAPPING, FXAA_NODE_2D)
.add_node_edge(
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::FXAA,
)
.unwrap();
graph
.add_node_edge(
FXAA_NODE_2D,
core_2d::graph::node::FXAA,
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
)
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
mod node;

pub use node::TonemappingNode;

use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, HandleUntyped};
Expand All @@ -14,6 +10,10 @@ use bevy_render::renderer::RenderDevice;
use bevy_render::view::ViewTarget;
use bevy_render::{render_resource::*, RenderApp, RenderStage};

mod node;

pub use node::TonemappingNode;

const TONEMAPPING_SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 17015368199668024512);

Expand Down
10 changes: 4 additions & 6 deletions crates/bevy_core_pipeline/src/upscaling/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
mod node;

pub use node::UpscalingNode;

use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, HandleUntyped};
use bevy_ecs::prelude::*;
use bevy_reflect::TypeUuid;
use bevy_render::renderer::RenderDevice;
use bevy_render::view::ViewTarget;
use bevy_render::{render_resource::*, RenderApp, RenderStage};

use bevy_reflect::TypeUuid;
mod node;

use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
pub use node::UpscalingNode;

const UPSCALING_SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 14589267395627146578);
Expand Down

0 comments on commit e0c3c6d

Please sign in to comment.