Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderGraph Labelization #10644

Merged
merged 22 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod upsampling_pipeline;
pub use settings::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings};

use crate::{
core_2d::{self, CORE_2D},
core_3d::{self, CORE_3D},
core_2d::graph::{Labels2d, SubGraph2d},
core_3d::graph::{Labels3d, SubGraph3d},
};
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Handle};
Expand Down Expand Up @@ -72,30 +72,20 @@ impl Plugin for BloomPlugin {
),
)
// Add bloom to the 3d render graph
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(
CORE_3D,
core_3d::graph::node::BLOOM,
)
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(SubGraph3d, Labels3d::Bloom)
.add_render_graph_edges(
CORE_3D,
&[
core_3d::graph::node::END_MAIN_PASS,
core_3d::graph::node::BLOOM,
core_3d::graph::node::TONEMAPPING,
],
SubGraph3d,
(
Labels3d::EndMainPass,
Labels3d::Bloom,
Labels3d::Tonemapping,
),
)
// Add bloom to the 2d render graph
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(
CORE_2D,
core_2d::graph::node::BLOOM,
)
.add_render_graph_node::<ViewNodeRunner<BloomNode>>(SubGraph2d, Labels2d::Bloom)
.add_render_graph_edges(
CORE_2D,
&[
core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
core_2d::graph::node::TONEMAPPING,
],
SubGraph2d,
(Labels2d::MainPass, Labels2d::Bloom, Labels2d::Tonemapping),
);
}

Expand Down
46 changes: 26 additions & 20 deletions crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
core_2d::{self, CORE_2D},
core_3d::{self, CORE_3D},
core_2d::graph::{Labels2d, SubGraph2d},
core_3d::graph::{Labels3d, SubGraph3d},
fullscreen_vertex_shader::fullscreen_shader_vertex_state,
};
use bevy_app::prelude::*;
Expand Down Expand Up @@ -124,31 +124,37 @@ impl Plugin for CASPlugin {
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));

{
use core_3d::graph::node::*;
render_app
.add_render_graph_node::<CASNode>(CORE_3D, CONTRAST_ADAPTIVE_SHARPENING)
.add_render_graph_edge(CORE_3D, TONEMAPPING, CONTRAST_ADAPTIVE_SHARPENING)
.add_render_graph_node::<CASNode>(SubGraph3d, Labels3d::ContrastAdaptiveSharpening)
.add_render_graph_edge(
SubGraph3d,
Labels3d::Tonemapping,
Labels3d::ContrastAdaptiveSharpening,
)
.add_render_graph_edges(
CORE_3D,
&[
FXAA,
CONTRAST_ADAPTIVE_SHARPENING,
END_MAIN_PASS_POST_PROCESSING,
],
SubGraph3d,
(
Labels3d::Fxaa,
Labels3d::ContrastAdaptiveSharpening,
Labels3d::EndMainPassPostProcessing,
),
);
}
{
use core_2d::graph::node::*;
render_app
.add_render_graph_node::<CASNode>(CORE_2D, CONTRAST_ADAPTIVE_SHARPENING)
.add_render_graph_edge(CORE_2D, TONEMAPPING, CONTRAST_ADAPTIVE_SHARPENING)
.add_render_graph_node::<CASNode>(SubGraph2d, Labels2d::ConstrastAdaptiveSharpening)
.add_render_graph_edge(
SubGraph2d,
Labels2d::Tonemapping,
Labels2d::ConstrastAdaptiveSharpening,
)
.add_render_graph_edges(
CORE_2D,
&[
FXAA,
CONTRAST_ADAPTIVE_SHARPENING,
END_MAIN_PASS_POST_PROCESSING,
],
SubGraph2d,
(
Labels2d::Fxaa,
Labels2d::ConstrastAdaptiveSharpening,
Labels2d::EndMainPassPostProcessing,
),
);
}
}
Expand Down
11 changes: 8 additions & 3 deletions crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::tonemapping::{DebandDither, Tonemapping};
use crate::{
core_3d::graph::SubGraph3d,
tonemapping::{DebandDither, Tonemapping},
};
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
use bevy_render::{
Expand All @@ -12,6 +15,8 @@ use bevy_render::{
};
use bevy_transform::prelude::{GlobalTransform, Transform};

use super::graph::SubGraph2d;

#[derive(Component, Default, Reflect, Clone, ExtractComponent)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component)]
Expand Down Expand Up @@ -49,7 +54,7 @@ impl Default for Camera2dBundle {
projection.far(),
);
Self {
camera_render_graph: CameraRenderGraph::new(crate::core_2d::graph::NAME),
camera_render_graph: CameraRenderGraph::new(SubGraph2d),
projection,
visible_entities: VisibleEntities::default(),
frustum,
Expand Down Expand Up @@ -88,7 +93,7 @@ impl Camera2dBundle {
projection.far(),
);
Self {
camera_render_graph: CameraRenderGraph::new(crate::core_2d::graph::NAME),
camera_render_graph: CameraRenderGraph::new(SubGraph3d),
projection,
visible_entities: VisibleEntities::default(),
frustum,
Expand Down
57 changes: 33 additions & 24 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ mod camera_2d;
mod main_pass_2d_node;

pub mod graph {
pub const NAME: &str = "core_2d";
use bevy_render::render_graph::{RenderLabel, RenderSubGraph};

#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderSubGraph)]
pub struct SubGraph2d;

pub mod input {
pub const VIEW_ENTITY: &str = "view_entity";
}
pub mod node {
pub const MSAA_WRITEBACK: &str = "msaa_writeback";
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 CONTRAST_ADAPTIVE_SHARPENING: &str = "contrast_adaptive_sharpening";
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";

#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
pub enum Labels2d {
MsaaWriteback,
MainPass,
Bloom,
Tonemapping,
Fxaa,
Upscaling,
ConstrastAdaptiveSharpening,
EndMainPassPostProcessing,
}
}
pub const CORE_2D: &str = graph::NAME;

use std::ops::Range;

Expand All @@ -41,6 +46,8 @@ use bevy_utils::{nonmax::NonMaxU32, FloatOrd};

use crate::{tonemapping::TonemappingNode, upscaling::UpscalingNode};

use self::graph::{Labels2d, SubGraph2d};

pub struct Core2dPlugin;

impl Plugin for Core2dPlugin {
Expand All @@ -60,21 +67,23 @@ impl Plugin for Core2dPlugin {
sort_phase_system::<Transparent2d>.in_set(RenderSet::PhaseSort),
);

use graph::node::*;
render_app
.add_render_sub_graph(CORE_2D)
.add_render_graph_node::<MainPass2dNode>(CORE_2D, MAIN_PASS)
.add_render_graph_node::<ViewNodeRunner<TonemappingNode>>(CORE_2D, TONEMAPPING)
.add_render_graph_node::<EmptyNode>(CORE_2D, END_MAIN_PASS_POST_PROCESSING)
.add_render_graph_node::<ViewNodeRunner<UpscalingNode>>(CORE_2D, UPSCALING)
.add_render_sub_graph(SubGraph2d)
.add_render_graph_node::<MainPass2dNode>(SubGraph2d, Labels2d::MainPass)
.add_render_graph_node::<ViewNodeRunner<TonemappingNode>>(
SubGraph2d,
Labels2d::Tonemapping,
)
.add_render_graph_node::<EmptyNode>(SubGraph2d, Labels2d::EndMainPassPostProcessing)
.add_render_graph_node::<ViewNodeRunner<UpscalingNode>>(SubGraph2d, Labels2d::Upscaling)
.add_render_graph_edges(
CORE_2D,
&[
MAIN_PASS,
TONEMAPPING,
END_MAIN_PASS_POST_PROCESSING,
UPSCALING,
],
SubGraph2d,
(
Labels2d::MainPass,
Labels2d::Tonemapping,
Labels2d::EndMainPassPostProcessing,
Labels2d::Upscaling,
),
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use bevy_render::{
use bevy_transform::prelude::{GlobalTransform, Transform};
use serde::{Deserialize, Serialize};

use super::graph::SubGraph3d;

/// Configuration for the "main 3d render graph".
#[derive(Component, Reflect, Clone, ExtractComponent)]
#[extract_component_filter(With<Camera>)]
Expand Down Expand Up @@ -150,7 +152,7 @@ pub struct Camera3dBundle {
impl Default for Camera3dBundle {
fn default() -> Self {
Self {
camera_render_graph: CameraRenderGraph::new(crate::core_3d::graph::NAME),
camera_render_graph: CameraRenderGraph::new(SubGraph3d),
camera: Default::default(),
projection: Default::default(),
visible_entities: Default::default(),
Expand Down
Loading