Skip to content

Commit

Permalink
impl more nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Mar 31, 2023
1 parent 1ed359a commit 3cbfa5e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 70 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl Plugin for Core2dPlugin {
);

let pass_node_2d = MainPass2dNode::new(&mut render_app.world);
let tonemapping = ViewNodeRunner::new(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
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ impl Plugin for Core3dPlugin {
),
);

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

Expand Down
55 changes: 22 additions & 33 deletions crates/bevy_core_pipeline/src/prepass/node.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use bevy_ecs::prelude::*;
use bevy_ecs::query::QueryState;
use bevy_ecs::query::ROQueryItem;
use bevy_ecs::{prelude::*, system::lifetimeless::Read};
use bevy_render::render_graph::ViewNode;
use bevy_render::{
camera::ExtractedCamera,
prelude::Color,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_graph::{NodeRunError, RenderGraphContext},
render_phase::RenderPhase,
render_resource::{
LoadOp, Operations, RenderPassColorAttachment, RenderPassDepthStencilAttachment,
RenderPassDescriptor,
},
renderer::RenderContext,
view::{ExtractedView, ViewDepthTexture},
view::ViewDepthTexture,
};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
Expand All @@ -20,48 +21,36 @@ use super::{AlphaMask3dPrepass, Opaque3dPrepass, ViewPrepassTextures};
/// Render node used by the prepass.
///
/// By default, inserted before the main pass in the render graph.
pub struct PrepassNode {
main_view_query: QueryState<
(
&'static ExtractedCamera,
&'static RenderPhase<Opaque3dPrepass>,
&'static RenderPhase<AlphaMask3dPrepass>,
&'static ViewDepthTexture,
&'static ViewPrepassTextures,
),
With<ExtractedView>,
>,
}

impl PrepassNode {
pub fn new(world: &mut World) -> Self {
Self {
main_view_query: QueryState::new(world),
}
pub struct PrepassNode;
impl FromWorld for PrepassNode {
fn from_world(_world: &mut World) -> Self {
Self
}
}

impl Node for PrepassNode {
fn update(&mut self, world: &mut World) {
self.main_view_query.update_archetypes(world);
}
impl ViewNode for PrepassNode {
type ViewWorldQuery = (
Read<ExtractedCamera>,
Read<RenderPhase<Opaque3dPrepass>>,
Read<RenderPhase<AlphaMask3dPrepass>>,
Read<ViewDepthTexture>,
Read<ViewPrepassTextures>,
);

fn run(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();
let Ok((
(
camera,
opaque_prepass_phase,
alpha_mask_prepass_phase,
view_depth_texture,
view_prepass_textures,
)) = self.main_view_query.get_manual(world, view_entity) else {
return Ok(());
};
): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();

let mut color_attachments = vec![];
color_attachments.push(
Expand Down
10 changes: 2 additions & 8 deletions crates/bevy_core_pipeline/src/tonemapping/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ pub struct TonemappingNode {
last_tonemapping: Mutex<Option<Tonemapping>>,
}

impl TonemappingNode {
pub fn new() -> Self {
impl FromWorld for TonemappingNode {
fn from_world(_world: &mut World) -> Self {
Self {
cached_bind_group: Mutex::new(None),
last_tonemapping: Mutex::new(None),
}
}
}

impl Default for TonemappingNode {
fn default() -> Self {
Self::new()
}
}

impl ViewNode for TonemappingNode {
type ViewWorldQuery = (
Read<ViewUniformOffset>,
Expand Down
36 changes: 12 additions & 24 deletions crates/bevy_core_pipeline/src/upscaling/node.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
use crate::{blit::BlitPipeline, upscaling::ViewUpscalingPipeline};
use bevy_ecs::prelude::*;
use bevy_ecs::query::QueryState;
use bevy_ecs::{prelude::*, query::ROQueryItem};
use bevy_render::{
camera::{CameraOutputMode, ExtractedCamera},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, LoadOp, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor,
TextureViewId,
},
renderer::RenderContext,
view::{ExtractedView, ViewTarget},
view::ViewTarget,
};
use std::sync::Mutex;

pub struct UpscalingNode {
query: QueryState<
(
&'static ViewTarget,
&'static ViewUpscalingPipeline,
Option<&'static ExtractedCamera>,
),
With<ExtractedView>,
>,
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
}

impl UpscalingNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for UpscalingNode {
fn from_world(_world: &mut World) -> Self {
Self {
query: QueryState::new(world),
cached_texture_bind_group: Mutex::new(None),
}
}
}

impl Node for UpscalingNode {
fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
}
impl ViewNode for UpscalingNode {
type ViewWorldQuery = (
&'static ViewTarget,
&'static ViewUpscalingPipeline,
Option<&'static ExtractedCamera>,
);

fn run(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(target, upscaling_target, camera): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();

let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
let blit_pipeline = world.get_resource::<BlitPipeline>().unwrap();

let (target, upscaling_target, camera) = match self.query.get_manual(world, view_entity) {
Ok(query) => query,
Err(_) => return Ok(()),
};

let color_attachment_load_op = if let Some(camera) = camera {
match camera.output_mode {
CameraOutputMode::Write {
Expand Down

0 comments on commit 3cbfa5e

Please sign in to comment.