diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index c54c15e216..12e0e55c10 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -15,7 +15,8 @@ use bevy::{ prelude::*, render::{ extract_component::{ - ComponentUniforms, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin, + ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin, + UniformComponentPlugin, }, render_graph::{ NodeRunError, RenderGraphApp, RenderGraphContext, RenderLabel, ViewNode, ViewNodeRunner, @@ -127,6 +128,9 @@ impl ViewNode for PostProcessNode { &'static ViewTarget, // This makes sure the node only runs on cameras with the PostProcessSettings component &'static PostProcessSettings, + // As there could be multiple post processing components sent to the GPU (one per camera), + // we need to get the index of the one that is associated with the current view. + &'static DynamicUniformIndex, ); // Runs the node logic @@ -140,7 +144,7 @@ impl ViewNode for PostProcessNode { &self, _graph: &mut RenderGraphContext, render_context: &mut RenderContext, - (view_target, _post_process_settings): QueryItem, + (view_target, _post_process_settings, settings_index): QueryItem, world: &World, ) -> Result<(), NodeRunError> { // Get the pipeline resource that contains the global data we need @@ -212,7 +216,10 @@ impl ViewNode for PostProcessNode { // This is mostly just wgpu boilerplate for drawing a fullscreen triangle, // using the pipeline/bind_group created above render_pass.set_render_pipeline(pipeline); - render_pass.set_bind_group(0, &bind_group, &[]); + // By passing in the index of the post process settings on this view, we ensure + // that in the event that multiple settings were sent to the GPU (as would be the + // case with multiple cameras), we use the correct one. + render_pass.set_bind_group(0, &bind_group, &[settings_index.index()]); render_pass.draw(0..3, 0..1); Ok(()) @@ -243,7 +250,7 @@ impl FromWorld for PostProcessPipeline { // The sampler that will be used to sample the screen texture sampler(SamplerBindingType::Filtering), // The settings uniform that will control the effect - uniform_buffer::(false), + uniform_buffer::(true), ), ), );