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 b6f82e0
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 191 deletions.
63 changes: 24 additions & 39 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, system::lifetimeless::Read};
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,46 +113,27 @@ impl Plugin for BloomPlugin {
}
}

pub struct BloomNode {
view_query: QueryState<(
&'static ExtractedCamera,
&'static ViewTarget,
&'static BloomTexture,
&'static BloomBindGroups,
&'static DynamicUniformIndex<BloomUniforms>,
&'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);
}
struct BloomNode;
impl ViewNode for BloomNode {
type ViewWorldQuery = (
Read<ExtractedCamera>,
Read<ViewTarget>,
Read<BloomTexture>,
Read<BloomBindGroups>,
Read<DynamicUniformIndex<BloomUniforms>>,
Read<BloomSettings>,
Read<UpsamplingPipelineIds>,
Read<BloomDownsamplingPipelineIds>,
);

// 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
9 changes: 5 additions & 4 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,12 @@ 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 = 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_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::new(FxaaNode::new(), &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::new(FxaaNode::new(), &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
37 changes: 14 additions & 23 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,51 @@ use std::sync::Mutex;

use crate::fxaa::{CameraFxaaPipeline, Fxaa, FxaaPipeline};
use bevy_ecs::prelude::*;
use bevy_ecs::query::QueryState;
use bevy_ecs::query::ROQueryItem;
use bevy_ecs::system::lifetimeless::Read;
use bevy_render::{
render_graph::{Node, NodeRunError, RenderGraphContext},
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, FilterMode, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor,
TextureViewId,
},
renderer::RenderContext,
view::{ExtractedView, ViewTarget},
view::ViewTarget,
};
use bevy_utils::default;

pub struct FxaaNode {
query: QueryState<
(
&'static ViewTarget,
&'static CameraFxaaPipeline,
&'static Fxaa,
),
With<ExtractedView>,
>,
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
}

impl FxaaNode {
pub fn new(world: &mut World) -> Self {
pub fn new() -> Self {
Self {
query: QueryState::new(world),
cached_texture_bind_group: Mutex::new(None),
}
}
}

impl Node for FxaaNode {
fn update(&mut self, world: &mut World) {
self.query.update_archetypes(world);
impl Default for FxaaNode {
fn default() -> Self {
Self::new()
}
}

impl ViewNode for FxaaNode {
type ViewWorldQuery = (Read<ViewTarget>, Read<CameraFxaaPipeline>, Read<Fxaa>);

fn run(
&self,
graph: &mut RenderGraphContext,
_graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(target, pipeline, fxaa): ROQueryItem<Self::ViewWorldQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();
let pipeline_cache = world.resource::<PipelineCache>();
let fxaa_pipeline = world.resource::<FxaaPipeline>();

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

if !fxaa.enabled {
return Ok(());
};
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
Loading

0 comments on commit b6f82e0

Please sign in to comment.