Skip to content

Commit c579c55

Browse files
committed
update code after main merge
impacts from bevyengine#4867 and bevyengine#4745
1 parent 6b69e18 commit c579c55

File tree

2 files changed

+16
-73
lines changed

2 files changed

+16
-73
lines changed

assets/shaders/custom_material_chromatic_aberration.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import bevy_pbr::mesh_view_bind_group
1+
#import bevy_pbr::mesh_view_bindings
22

33
[[group(1), binding(0)]]
44
var texture: texture_2d<f32>;

examples/shader/post_processing.rs

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
//! edge detection, blur, pixelization, vignette... and countless others.
55
66
use bevy::{
7-
core_pipeline::{draw_2d_graph, node, RenderTargetClearColors},
7+
core_pipeline::clear_color::ClearColorConfig,
88
ecs::system::{lifetimeless::SRes, SystemParamItem},
99
prelude::*,
1010
reflect::TypeUuid,
1111
render::{
12-
camera::{Camera, CameraTypePlugin, RenderTarget},
12+
camera::{Camera, RenderTarget},
1313
render_asset::{PrepareAssetError, RenderAsset, RenderAssets},
1414
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext, SlotValue},
1515
render_resource::{
@@ -35,60 +35,12 @@ fn main() {
3535
let mut app = App::new();
3636
app.add_plugins(DefaultPlugins)
3737
.add_plugin(Material2dPlugin::<PostProcessingMaterial>::default())
38-
.add_plugin(CameraTypePlugin::<PostProcessingPassCamera>::default())
3938
.add_startup_system(setup)
4039
.add_system(main_pass_cube_rotator_system);
4140

42-
let render_app = app.sub_app_mut(RenderApp);
43-
let driver = PostProcessPassCameraDriver::new(&mut render_app.world);
44-
45-
let mut graph = render_app.world.resource_mut::<RenderGraph>();
46-
47-
// Add a node for the post processing pass.
48-
graph.add_node(POST_PROCESS_PASS_DRIVER, driver);
49-
50-
// The post process pass's dependencies include those of the main pass.
51-
graph
52-
.add_node_edge(node::MAIN_PASS_DEPENDENCIES, POST_PROCESS_PASS_DRIVER)
53-
.unwrap();
54-
55-
// Insert the post process pass node: CLEAR_PASS_DRIVER -> MAIN_PASS_DRIVER -> POST_PROCESS_PASS_DRIVER
56-
graph
57-
.add_node_edge(POST_PROCESS_PASS_DRIVER, node::MAIN_PASS_DRIVER)
58-
.unwrap();
5941
app.run();
6042
}
6143

62-
/// A node for the `PostProcessingPassCamera` that runs `draw_2d_graph` with this camera.
63-
struct PostProcessPassCameraDriver {
64-
query: QueryState<Entity, With<PostProcessingPassCamera>>,
65-
}
66-
67-
impl PostProcessPassCameraDriver {
68-
pub fn new(render_world: &mut World) -> Self {
69-
Self {
70-
query: QueryState::new(render_world),
71-
}
72-
}
73-
}
74-
impl Node for PostProcessPassCameraDriver {
75-
fn update(&mut self, world: &mut World) {
76-
self.query.update_archetypes(world);
77-
}
78-
79-
fn run(
80-
&self,
81-
graph: &mut RenderGraphContext,
82-
_render_context: &mut RenderContext,
83-
world: &World,
84-
) -> Result<(), NodeRunError> {
85-
for camera in self.query.iter_manual(world) {
86-
graph.run_sub_graph(draw_2d_graph::NAME, vec![SlotValue::Entity(camera)])?;
87-
}
88-
Ok(())
89-
}
90-
}
91-
9244
/// Marks the Main pass cube (rendered to a texture.)
9345
#[derive(Component)]
9446
struct MainPassCube;
@@ -100,7 +52,6 @@ fn setup(
10052
mut post_processing_materials: ResMut<Assets<PostProcessingMaterial>>,
10153
mut materials: ResMut<Assets<StandardMaterial>>,
10254
mut images: ResMut<Assets<Image>>,
103-
mut clear_colors: ResMut<RenderTargetClearColors>,
10455
) {
10556
let window = windows.get_primary_mut().unwrap();
10657
let size = Extent3d {
@@ -156,16 +107,17 @@ fn setup(
156107
});
157108

158109
// Main pass camera
159-
let render_target = RenderTarget::Image(image_handle.clone());
160-
clear_colors.insert(render_target.clone(), Color::WHITE);
161-
commands.spawn_bundle(PerspectiveCameraBundle {
110+
commands.spawn_bundle(Camera3dBundle {
111+
camera_3d: Camera3d {
112+
clear_color: ClearColorConfig::Custom(Color::WHITE),
113+
},
162114
camera: Camera {
163-
target: render_target,
115+
target: RenderTarget::Image(image_handle.clone()),
164116
..default()
165117
},
166118
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
167119
.looking_at(Vec3::default(), Vec3::Y),
168-
..PerspectiveCameraBundle::default()
120+
..default()
169121
});
170122

171123
// 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(
196148

197149
// The post-processing pass camera.
198150
commands
199-
.spawn_bundle(OrthographicCameraBundle {
200-
..OrthographicCameraBundle::new_2d()
151+
.spawn_bundle(Camera2dBundle {
152+
camera: Camera {
153+
// render after the "main pass" camera
154+
priority: 1,
155+
..default()
156+
},
157+
..Camera2dBundle::default()
201158
})
202159
.insert(PostProcessingPassCamera)
203160
.insert(post_processing_pass_layer);
204-
205-
// NOTE: omitting the RenderLayers component for this camera may cause a validation error:
206-
//
207-
// thread 'main' panicked at 'wgpu error: Validation Error
208-
//
209-
// Caused by:
210-
// In a RenderPass
211-
// note: encoder = `<CommandBuffer-(0, 1, Metal)>`
212-
// In a pass parameter
213-
// note: command buffer = `<CommandBuffer-(0, 1, Metal)>`
214-
// Attempted to use texture (5, 1, Metal) mips 0..1 layers 0..1 as a combination of COLOR_TARGET within a usage scope.
215-
//
216-
// This happens because the texture would be written and read in the same frame, which is not allowed.
217-
// So either render layers must be used to avoid this, or the texture must be double buffered.
218161
}
219162

220163
/// Rotates the inner cube (main pass)

0 commit comments

Comments
 (0)