Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Mar 31, 2023
1 parent f201a9d commit da15a35
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 267 deletions.
47 changes: 16 additions & 31 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use settings::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings};
use crate::{core_2d, core_3d};
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, HandleUntyped};
use bevy_ecs::prelude::*;
use bevy_ecs::{prelude::*, query::ROQueryItem};
use bevy_math::UVec2;
use bevy_reflect::TypeUuid;
use bevy_render::{
Expand All @@ -16,7 +16,7 @@ use bevy_render::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
prelude::Color,
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
render_graph::{NodeRunError, RenderGraph, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Plugin for BloomPlugin {

// Add bloom to the 3d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let bloom_node = ViewNodeRunner::new(BloomNode, &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)
Expand All @@ -94,7 +94,7 @@ impl Plugin for BloomPlugin {

// Add bloom to the 2d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let bloom_node = ViewNodeRunner::new(BloomNode, &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)
Expand All @@ -113,8 +113,9 @@ impl Plugin for BloomPlugin {
}
}

pub struct BloomNode {
view_query: QueryState<(
struct BloomNode;
impl ViewNode for BloomNode {
type ViewWorldQuery = (
&'static ExtractedCamera,
&'static ViewTarget,
&'static BloomTexture,
Expand All @@ -123,36 +124,16 @@ pub struct BloomNode {
&'static BloomSettings,
&'static UpsamplingPipelineIds,
&'static BloomDownsamplingPipelineIds,
)>,
}

impl BloomNode {
pub fn new(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
}
}

impl Node for BloomNode {
fn update(&mut self, world: &mut World) {
self.view_query.update_archetypes(world);
}
);

// Atypically for a post-processing effect, we do not need to
// use a secondary texture normally provided by view_target.post_process_write(),
// instead we write into our own bloom texture and then directly back onto main.
fn run(
&self,
graph: &mut RenderGraphContext,
_graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
let pipeline_cache = world.resource::<PipelineCache>();
let uniforms = world.resource::<ComponentUniforms<BloomUniforms>>();
let view_entity = graph.view_entity();
let Ok((
(
camera,
view_target,
bloom_texture,
Expand All @@ -161,8 +142,12 @@ impl Node for BloomNode {
bloom_settings,
upsampling_pipeline_ids,
downsampling_pipeline_ids,
)) = self.view_query.get_manual(world, view_entity)
else { return Ok(()) };
): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
let pipeline_cache = world.resource::<PipelineCache>();
let uniforms = world.resource::<ComponentUniforms<BloomUniforms>>();

let (
Some(uniforms),
Expand Down
6 changes: 3 additions & 3 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},
render_graph::{EmptyNode, RenderGraph, ViewNodeRunner},
render_phase::{
batch_phase_system, sort_phase_system, BatchedPhaseItem, CachedRenderPipelinePhaseItem,
DrawFunctionId, DrawFunctions, PhaseItem, RenderPhase,
Expand Down Expand Up @@ -64,8 +64,8 @@ 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 = ViewNodeRunner::<TonemappingNode>::from_world(&mut render_app.world);
let upscaling = ViewNodeRunner::<UpscalingNode>::from_world(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();

let mut draw_2d_graph = RenderGraph::default();
Expand Down
65 changes: 23 additions & 42 deletions crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,40 @@ use crate::{
core_3d::{Camera3d, Opaque3d},
prepass::{DepthPrepass, MotionVectorPrepass, NormalPrepass},
};
use bevy_ecs::prelude::*;
use bevy_ecs::{prelude::*, query::ROQueryItem};
use bevy_render::{
camera::ExtractedCamera,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_phase::RenderPhase,
render_resource::{LoadOp, Operations, RenderPassDepthStencilAttachment, RenderPassDescriptor},
renderer::RenderContext,
view::{ExtractedView, ViewDepthTexture, ViewTarget},
view::{ViewDepthTexture, ViewTarget},
};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;

use super::{AlphaMask3d, Camera3dDepthLoadOp};

/// A [`Node`] that runs the [`Opaque3d`] and [`AlphaMask3d`] [`RenderPhase`].
pub struct MainOpaquePass3dNode {
query: QueryState<
(
&'static ExtractedCamera,
&'static RenderPhase<Opaque3d>,
&'static RenderPhase<AlphaMask3d>,
&'static Camera3d,
&'static ViewTarget,
&'static ViewDepthTexture,
Option<&'static DepthPrepass>,
Option<&'static NormalPrepass>,
Option<&'static MotionVectorPrepass>,
),
With<ExtractedView>,
>,
}

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

impl Node for MainOpaquePass3dNode {
fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
pub struct MainOpaquePass3dNode;
impl ViewNode for MainOpaquePass3dNode {
type ViewWorldQuery = (
&'static ExtractedCamera,
&'static RenderPhase<Opaque3d>,
&'static RenderPhase<AlphaMask3d>,
&'static Camera3d,
&'static ViewTarget,
&'static ViewDepthTexture,
Option<&'static DepthPrepass>,
Option<&'static NormalPrepass>,
Option<&'static MotionVectorPrepass>,
);

fn run(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();
let Ok((
(
camera,
opaque_phase,
alpha_mask_phase,
Expand All @@ -64,12 +45,10 @@ impl Node for MainOpaquePass3dNode {
depth,
depth_prepass,
normal_prepass,
motion_vector_prepass
)) = self.query.get_manual(world, view_entity) else {
// No window
return Ok(());
};

motion_vector_prepass,
): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
// Run the opaque pass, sorted front-to-back
// NOTE: Scoped to drop the mutable borrow of render_context
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -115,6 +94,8 @@ impl Node for MainOpaquePass3dNode {
render_pass.set_camera_viewport(viewport);
}

let view_entity = graph.view_entity();

opaque_phase.render(&mut render_pass, world, view_entity);

if !alpha_mask_phase.items.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,34 @@
use crate::core_3d::Transparent3d;
use bevy_ecs::prelude::*;
use bevy_ecs::{prelude::*, query::ROQueryItem};
use bevy_render::{
camera::ExtractedCamera,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_phase::RenderPhase,
render_resource::{LoadOp, Operations, RenderPassDepthStencilAttachment, RenderPassDescriptor},
renderer::RenderContext,
view::{ExtractedView, ViewDepthTexture, ViewTarget},
view::{ViewDepthTexture, ViewTarget},
};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;

/// A [`Node`] that runs the [`Transparent3d`] [`RenderPhase`].
pub struct MainTransparentPass3dNode {
query: QueryState<
(
&'static ExtractedCamera,
&'static RenderPhase<Transparent3d>,
&'static ViewTarget,
&'static ViewDepthTexture,
),
With<ExtractedView>,
>,
}

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

impl Node for MainTransparentPass3dNode {
fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
pub struct MainTransparentPass3dNode;

impl ViewNode for MainTransparentPass3dNode {
type ViewWorldQuery = (
&'static ExtractedCamera,
&'static RenderPhase<Transparent3d>,
&'static ViewTarget,
&'static ViewDepthTexture,
);
fn run(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(camera, transparent_phase, target, depth): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();
let Ok((
camera,
transparent_phase,
target,
depth,
)) = self.query.get_manual(world, view_entity) else {
// No window
return Ok(());
};

if !transparent_phase.items.is_empty() {
// Run the transparent pass, sorted back-to-front
Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
prelude::Msaa,
render_graph::{EmptyNode, RenderGraph},
render_graph::{EmptyNode, RenderGraph, ViewNodeRunner},
render_phase::{
sort_phase_system, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem,
RenderPhase,
Expand Down Expand Up @@ -86,11 +86,13 @@ impl Plugin for Core3dPlugin {
),
);

let prepass_node = PrepassNode::new(&mut render_app.world);
let opaque_node_3d = MainOpaquePass3dNode::new(&mut render_app.world);
let transparent_node_3d = MainTransparentPass3dNode::new(&mut render_app.world);
let tonemapping = TonemappingNode::new(&mut render_app.world);
let upscaling = UpscalingNode::new(&mut render_app.world);
let prepass_node = ViewNodeRunner::<PrepassNode>::from_world(&mut render_app.world);
let opaque_node_3d = ViewNodeRunner::new(MainOpaquePass3dNode, &mut render_app.world);
let transparent_node_3d =
ViewNodeRunner::new(MainTransparentPass3dNode, &mut render_app.world);
let tonemapping = ViewNodeRunner::<TonemappingNode>::from_world(&mut render_app.world);
let upscaling = ViewNodeRunner::<UpscalingNode>::from_world(&mut render_app.world);

let mut graph = render_app.world.resource_mut::<RenderGraph>();

let mut draw_3d_graph = RenderGraph::default();
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_reflect::{
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
prelude::Camera,
render_graph::RenderGraph,
render_graph::{RenderGraph, ViewNodeRunner},
render_resource::*,
renderer::RenderDevice,
texture::BevyDefault,
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Plugin for FxaaPlugin {
.add_systems(Render, prepare_fxaa_pipelines.in_set(RenderSet::Prepare));

{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let fxaa_node = ViewNodeRunner::<FxaaNode>::from_world(&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();

Expand All @@ -109,7 +109,7 @@ impl Plugin for FxaaPlugin {
);
}
{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let fxaa_node = ViewNodeRunner::<FxaaNode>::from_world(&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();

Expand Down
Loading

0 comments on commit da15a35

Please sign in to comment.