Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Mar 16, 2023
1 parent 9a977b1 commit bbc8a09
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 1,262 deletions.
16 changes: 2 additions & 14 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use bevy_render::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
prelude::Color,
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},
Expand Down Expand Up @@ -83,8 +83,6 @@ impl Plugin for BloomPlugin {
render_app,
core_3d::graph::NAME,
core_3d::graph::node::BLOOM,
core_3d::graph::input::VIEW_ENTITY,
BloomNode::IN_VIEW,
&[
core_3d::graph::node::MAIN_PASS,
core_3d::graph::node::BLOOM,
Expand All @@ -97,8 +95,6 @@ impl Plugin for BloomPlugin {
render_app,
core_2d::graph::NAME,
core_2d::graph::node::BLOOM,
core_2d::graph::input::VIEW_ENTITY,
BloomNode::IN_VIEW,
&[
core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
Expand All @@ -121,10 +117,6 @@ pub struct BloomNode {
)>,
}

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

impl FromWorld for BloomNode {
fn from_world(world: &mut World) -> Self {
Self {
Expand All @@ -134,10 +126,6 @@ impl FromWorld for BloomNode {
}

impl Node for BloomNode {
fn input(&self) -> Vec<SlotInfo> {
vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
}

fn update(&mut self, world: &mut World) {
self.view_query.update_archetypes(world);
}
Expand All @@ -157,7 +145,7 @@ impl Node for BloomNode {
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
let pipeline_cache = world.resource::<PipelineCache>();
let uniforms = world.resource::<ComponentUniforms<BloomUniforms>>();
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let view_entity = graph.view_entity();
let Ok((
camera,
view_target,
Expand Down
8 changes: 2 additions & 6 deletions crates/bevy_core_pipeline/src/core_2d/main_pass_2d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use bevy_ecs::prelude::*;
use bevy_render::{
camera::ExtractedCamera,
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_phase::RenderPhase,
render_resource::{LoadOp, Operations, RenderPassDescriptor},
renderer::RenderContext,
Expand Down Expand Up @@ -37,10 +37,6 @@ impl MainPass2dNode {
}

impl Node for MainPass2dNode {
fn input(&self) -> Vec<SlotInfo> {
vec![SlotInfo::new(MainPass2dNode::IN_VIEW, SlotType::Entity)]
}

fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
Expand All @@ -51,7 +47,7 @@ impl Node for MainPass2dNode {
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let view_entity = graph.view_entity();
let (camera, transparent_phase, target, camera_2d) =
if let Ok(result) = self.query.get_manual(world, view_entity) {
result
Expand Down
53 changes: 20 additions & 33 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use bevy_ecs::prelude::*;
use bevy_render::{
camera::Camera,
extract_component::ExtractComponentPlugin,
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
render_graph::{EmptyNode, RenderGraph},
render_phase::{
batch_phase_system, sort_phase_system, BatchedPhaseItem, CachedRenderPipelinePhaseItem,
DrawFunctionId, DrawFunctions, PhaseItem, RenderPhase,
Expand Down Expand Up @@ -61,46 +61,33 @@ impl Plugin for Core2dPlugin {
));

let pass_node_2d = MainPass2dNode::new(&mut render_app.world);
let tonemapping = TonemappingNode::new(&mut render_app.world);
let upscaling = UpscalingNode::new(&mut render_app.world);
let tonemapping = TonemappingNode::from_world(&mut render_app.world);
let upscaling = UpscalingNode::from_world(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();

let mut draw_2d_graph = RenderGraph::default();
draw_2d_graph.add_node(graph::node::MAIN_PASS, pass_node_2d);
draw_2d_graph.add_node(graph::node::TONEMAPPING, tonemapping);

draw_2d_graph.add_node_with_edges(graph::node::MAIN_PASS, pass_node_2d, &[]);
draw_2d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_2d_graph.add_node(graph::node::UPSCALING, upscaling);
let input_node_id = draw_2d_graph.set_input(vec![SlotInfo::new(
graph::input::VIEW_ENTITY,
SlotType::Entity,
)]);
draw_2d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
graph::node::MAIN_PASS,
MainPass2dNode::IN_VIEW,
);
draw_2d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
graph::node::TONEMAPPING,
TonemappingNode::IN_VIEW,
);
draw_2d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
graph::node::UPSCALING,
UpscalingNode::IN_VIEW,
);
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
draw_2d_graph.add_node_edge(

draw_2d_graph.add_node_with_edges(
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
tonemapping,
&[
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,
draw_2d_graph.add_node_with_edges(
graph::node::UPSCALING,
upscaling,
&[
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
],
);

graph.add_sub_graph(graph::NAME, draw_2d_graph);
}
}
Expand Down
19 changes: 9 additions & 10 deletions crates/bevy_core_pipeline/src/core_3d/main_pass_3d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use bevy_ecs::prelude::*;
use bevy_render::{
camera::ExtractedCamera,
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_phase::RenderPhase,
render_resource::{LoadOp, Operations, RenderPassDepthStencilAttachment, RenderPassDescriptor},
renderer::RenderContext,
Expand Down Expand Up @@ -34,21 +34,19 @@ pub struct MainPass3dNode {
>,
}

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

pub fn new(world: &mut World) -> Self {
impl FromWorld for MainPass3dNode {
fn from_world(world: &mut World) -> Self {
Self {
query: world.query_filtered(),
}
}
}

impl Node for MainPass3dNode {
fn input(&self) -> Vec<SlotInfo> {
vec![SlotInfo::new(MainPass3dNode::IN_VIEW, SlotType::Entity)]
}
impl MainPass3dNode {
pub const IN_VIEW: &'static str = "view";
}

impl Node for MainPass3dNode {
fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
Expand All @@ -59,7 +57,7 @@ impl Node for MainPass3dNode {
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let view_entity = graph.view_entity();
let Ok((
camera,
opaque_phase,
Expand All @@ -71,6 +69,7 @@ impl Node for MainPass3dNode {
depth_prepass,
normal_prepass,
)) = self.query.get_manual(world, view_entity) else {
bevy_utils::tracing::error!("no view_entity");
// No window
return Ok(());
};
Expand Down
69 changes: 26 additions & 43 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
prelude::Msaa,
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
render_graph::{EmptyNode, RenderGraph},
render_phase::{
sort_phase_system, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem,
RenderPhase,
Expand Down Expand Up @@ -78,57 +78,40 @@ impl Plugin for Core3dPlugin {
sort_phase_system::<Transparent3d>.in_set(RenderSet::PhaseSort),
));

let prepass_node = PrepassNode::new(&mut render_app.world);
let pass_node_3d = MainPass3dNode::new(&mut render_app.world);
let tonemapping = TonemappingNode::new(&mut render_app.world);
let upscaling = UpscalingNode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let prepass_node = PrepassNode::from_world(&mut render_app.world);
let pass_node_3d = MainPass3dNode::from_world(&mut render_app.world);
let tonemapping = TonemappingNode::from_world(&mut render_app.world);
let upscaling = UpscalingNode::from_world(&mut render_app.world);

let mut graph = render_app.world.resource_mut::<RenderGraph>();
let mut draw_3d_graph = RenderGraph::default();
draw_3d_graph.add_node(graph::node::PREPASS, prepass_node);
draw_3d_graph.add_node(graph::node::MAIN_PASS, pass_node_3d);
draw_3d_graph.add_node(graph::node::TONEMAPPING, tonemapping);

draw_3d_graph.add_node_with_edges(graph::node::MAIN_PASS, pass_node_3d, &[]);
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);

let input_node_id = draw_3d_graph.set_input(vec![SlotInfo::new(
graph::input::VIEW_ENTITY,
SlotType::Entity,
)]);
draw_3d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,

draw_3d_graph.add_node_with_edges(
graph::node::PREPASS,
PrepassNode::IN_VIEW,
);
draw_3d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
graph::node::MAIN_PASS,
MainPass3dNode::IN_VIEW,
prepass_node,
&[graph::node::PREPASS, graph::node::MAIN_PASS],
);
draw_3d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
draw_3d_graph.add_node_with_edges(
graph::node::TONEMAPPING,
TonemappingNode::IN_VIEW,
tonemapping,
&[
graph::node::MAIN_PASS,
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
],
);
draw_3d_graph.add_slot_edge(
input_node_id,
graph::input::VIEW_ENTITY,
graph::node::UPSCALING,
UpscalingNode::IN_VIEW,
);
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::MAIN_PASS);
draw_3d_graph.add_node_edge(graph::node::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,
draw_3d_graph.add_node_with_edges(
graph::node::UPSCALING,
upscaling,
&[
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
],
);

graph.add_sub_graph(graph::NAME, draw_3d_graph);
}
}
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,21 @@ impl Plugin for FxaaPlugin {
.init_resource::<SpecializedRenderPipelines<FxaaPipeline>>()
.add_system(prepare_fxaa_pipelines.in_set(RenderSet::Prepare));

// Add node to 3d graph
add_node::<FxaaNode>(
render_app,
core_3d::graph::NAME,
core_3d::graph::node::FXAA,
core_3d::graph::input::VIEW_ENTITY,
FxaaNode::IN_VIEW,
&[
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::FXAA,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
],
);
// Add node to 2d graph

add_node::<FxaaNode>(
render_app,
core_2d::graph::NAME,
core_2d::graph::node::FXAA,
core_2d::graph::input::VIEW_ENTITY,
FxaaNode::IN_VIEW,
&[
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::FXAA,
Expand Down
8 changes: 2 additions & 6 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::fxaa::{CameraFxaaPipeline, Fxaa, FxaaPipeline};
use bevy_ecs::prelude::*;
use bevy_ecs::query::QueryState;
use bevy_render::{
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, FilterMode, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor,
Expand Down Expand Up @@ -41,10 +41,6 @@ impl FromWorld for FxaaNode {
}

impl Node for FxaaNode {
fn input(&self) -> Vec<SlotInfo> {
vec![SlotInfo::new(FxaaNode::IN_VIEW, SlotType::Entity)]
}

fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
Expand All @@ -55,7 +51,7 @@ impl Node for FxaaNode {
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let view_entity = graph.view_entity();
let pipeline_cache = world.resource::<PipelineCache>();
let fxaa_pipeline = world.resource::<FxaaPipeline>();

Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ pub fn add_node<T: Node + FromWorld>(
render_app: &mut App,
sub_graph_name: &'static str,
node_name: &'static str,
output_slot: &'static str,
input_slot: &'static str,
edges: &[&'static str],
) {
let node = T::from_world(&mut render_app.world);
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();

let graph = render_graph.get_sub_graph_mut(sub_graph_name).unwrap();
let graph = render_graph.sub_graph_mut(sub_graph_name);
graph.add_node_with_edges(node_name, node, edges);

graph.add_slot_edge(graph.input_node().id, output_slot, node_name, input_slot);
}

0 comments on commit bbc8a09

Please sign in to comment.