From c579c55664788e7aa6751755bfa2cb6abc82d30d Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 2 Jun 2022 22:44:34 +0200 Subject: [PATCH] update code after main merge impacts from https://github.com/bevyengine/bevy/pull/4867 and https://github.com/bevyengine/bevy/pull/4745 --- .../custom_material_chromatic_aberration.wgsl | 2 +- examples/shader/post_processing.rs | 87 ++++--------------- 2 files changed, 16 insertions(+), 73 deletions(-) diff --git a/assets/shaders/custom_material_chromatic_aberration.wgsl b/assets/shaders/custom_material_chromatic_aberration.wgsl index 61615747f420d..f932b7a798b73 100644 --- a/assets/shaders/custom_material_chromatic_aberration.wgsl +++ b/assets/shaders/custom_material_chromatic_aberration.wgsl @@ -1,4 +1,4 @@ -#import bevy_pbr::mesh_view_bind_group +#import bevy_pbr::mesh_view_bindings [[group(1), binding(0)]] var texture: texture_2d; diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 51babdbe37f36..a00033194e538 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -4,12 +4,12 @@ //! edge detection, blur, pixelization, vignette... and countless others. use bevy::{ - core_pipeline::{draw_2d_graph, node, RenderTargetClearColors}, + core_pipeline::clear_color::ClearColorConfig, ecs::system::{lifetimeless::SRes, SystemParamItem}, prelude::*, reflect::TypeUuid, render::{ - camera::{Camera, CameraTypePlugin, RenderTarget}, + camera::{Camera, RenderTarget}, render_asset::{PrepareAssetError, RenderAsset, RenderAssets}, render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext, SlotValue}, render_resource::{ @@ -35,60 +35,12 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) .add_plugin(Material2dPlugin::::default()) - .add_plugin(CameraTypePlugin::::default()) .add_startup_system(setup) .add_system(main_pass_cube_rotator_system); - let render_app = app.sub_app_mut(RenderApp); - let driver = PostProcessPassCameraDriver::new(&mut render_app.world); - - let mut graph = render_app.world.resource_mut::(); - - // Add a node for the post processing pass. - graph.add_node(POST_PROCESS_PASS_DRIVER, driver); - - // The post process pass's dependencies include those of the main pass. - graph - .add_node_edge(node::MAIN_PASS_DEPENDENCIES, POST_PROCESS_PASS_DRIVER) - .unwrap(); - - // Insert the post process pass node: CLEAR_PASS_DRIVER -> MAIN_PASS_DRIVER -> POST_PROCESS_PASS_DRIVER - graph - .add_node_edge(POST_PROCESS_PASS_DRIVER, node::MAIN_PASS_DRIVER) - .unwrap(); app.run(); } -/// A node for the `PostProcessingPassCamera` that runs `draw_2d_graph` with this camera. -struct PostProcessPassCameraDriver { - query: QueryState>, -} - -impl PostProcessPassCameraDriver { - pub fn new(render_world: &mut World) -> Self { - Self { - query: QueryState::new(render_world), - } - } -} -impl Node for PostProcessPassCameraDriver { - fn update(&mut self, world: &mut World) { - self.query.update_archetypes(world); - } - - fn run( - &self, - graph: &mut RenderGraphContext, - _render_context: &mut RenderContext, - world: &World, - ) -> Result<(), NodeRunError> { - for camera in self.query.iter_manual(world) { - graph.run_sub_graph(draw_2d_graph::NAME, vec![SlotValue::Entity(camera)])?; - } - Ok(()) - } -} - /// Marks the Main pass cube (rendered to a texture.) #[derive(Component)] struct MainPassCube; @@ -100,7 +52,6 @@ fn setup( mut post_processing_materials: ResMut>, mut materials: ResMut>, mut images: ResMut>, - mut clear_colors: ResMut, ) { let window = windows.get_primary_mut().unwrap(); let size = Extent3d { @@ -156,16 +107,17 @@ fn setup( }); // Main pass camera - let render_target = RenderTarget::Image(image_handle.clone()); - clear_colors.insert(render_target.clone(), Color::WHITE); - commands.spawn_bundle(PerspectiveCameraBundle { + commands.spawn_bundle(Camera3dBundle { + camera_3d: Camera3d { + clear_color: ClearColorConfig::Custom(Color::WHITE), + }, camera: Camera { - target: render_target, + target: RenderTarget::Image(image_handle.clone()), ..default() }, transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)) .looking_at(Vec3::default(), Vec3::Y), - ..PerspectiveCameraBundle::default() + ..default() }); // This specifies the layer used for the post processing pass, which will be attached to the post processing pass camera and 2d quad. @@ -196,25 +148,16 @@ fn setup( // The post-processing pass camera. commands - .spawn_bundle(OrthographicCameraBundle { - ..OrthographicCameraBundle::new_2d() + .spawn_bundle(Camera2dBundle { + camera: Camera { + // render after the "main pass" camera + priority: 1, + ..default() + }, + ..Camera2dBundle::default() }) .insert(PostProcessingPassCamera) .insert(post_processing_pass_layer); - - // NOTE: omitting the RenderLayers component for this camera may cause a validation error: - // - // thread 'main' panicked at 'wgpu error: Validation Error - // - // Caused by: - // In a RenderPass - // note: encoder = `` - // In a pass parameter - // note: command buffer = `` - // Attempted to use texture (5, 1, Metal) mips 0..1 layers 0..1 as a combination of COLOR_TARGET within a usage scope. - // - // This happens because the texture would be written and read in the same frame, which is not allowed. - // So either render layers must be used to avoid this, or the texture must be double buffered. } /// Rotates the inner cube (main pass)