diff --git a/examples/shader/custom_render_phase.rs b/examples/shader/custom_render_phase.rs index 5a306d39a93f76..2636ec0236001b 100644 --- a/examples/shader/custom_render_phase.rs +++ b/examples/shader/custom_render_phase.rs @@ -21,6 +21,7 @@ use bevy::{ }, prelude::*, render::{ + batching::batch_and_prepare_render_phase, extract_component::{ ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin, @@ -47,7 +48,6 @@ use bevy::{ }, utils::{nonmax::NonMaxU32, FloatOrd}, }; -use bevy_internal::render::{batching::batch_and_prepare_render_phase, camera::ExtractedCamera}; fn main() { App::new() @@ -176,10 +176,8 @@ pub struct CustomNode; impl CustomNode { const NAME: &'static str = "custom_node"; } - impl ViewNode for CustomNode { type ViewData = ( - &'static ExtractedCamera, &'static RenderPhase, &'static ViewTarget, &'static ViewDepthTexture, @@ -188,14 +186,9 @@ impl ViewNode for CustomNode { &self, graph: &mut RenderGraphContext, render_context: &mut RenderContext, - (camera, custom_phase, target, depth): QueryItem, + (custom_phase, target, depth): QueryItem, world: &World, ) -> Result<(), NodeRunError> { - // If the phase has no items it means there's nothing to render - if custom_phase.items.is_empty() { - return Ok(()); - } - // The render pass that will be used by the draw commands of the render phase. // A render phase can only use a single render pass. // If you need multiple passes you'll need a separate phase. @@ -207,10 +200,6 @@ impl ViewNode for CustomNode { occlusion_query_set: None, }); - if let Some(viewport) = camera.viewport.as_ref() { - render_pass.set_camera_viewport(viewport); - } - // This will automatically call the draw command on each items in the render phase custom_phase.render(&mut render_pass, world, graph.view_entity()); @@ -395,16 +384,14 @@ fn prepare_custom_bind_group( render_device: Res, custom_material_uniforms: Res>, ) { - let Some(uniform) = custom_material_uniforms.binding() else { - return; - }; - - let bind_group = render_device.create_bind_group( - "custom_material_bind_group", - &custom_pipeline.bind_group_layout, - &BindGroupEntries::single(uniform), - ); - commands.insert_resource(CustomMaterialBindGroup(bind_group)); + if let Some(uniform) = custom_material_uniforms.binding() { + let bind_group = render_device.create_bind_group( + "custom_material_bind_group", + &custom_pipeline.bind_group_layout, + &BindGroupEntries::single(uniform), + ); + commands.insert_resource(CustomMaterialBindGroup(bind_group)); + } } // To keep this example simple this struct is also a valid ShaderType. @@ -454,6 +441,7 @@ fn queue_mesh_custom_phase( let rangefinder = view.rangefinder3d(); for visible_entity in &visible_entities.entities { + // We only want meshes with our custom material to be rendered so we need to filter the other visible meshes if filter_meshes.get(*visible_entity).is_err() { continue; }