Skip to content

Commit

Permalink
more clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Jan 15, 2024
1 parent b4c6477 commit 7679788
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions examples/shader/custom_render_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bevy::{
},
prelude::*,
render::{
batching::batch_and_prepare_render_phase,
extract_component::{
ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin,
UniformComponentPlugin,
Expand All @@ -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()
Expand Down Expand Up @@ -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<CustomPhaseItem>,
&'static ViewTarget,
&'static ViewDepthTexture,
Expand All @@ -188,14 +186,9 @@ impl ViewNode for CustomNode {
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext,
(camera, custom_phase, target, depth): QueryItem<Self::ViewData>,
(custom_phase, target, depth): QueryItem<Self::ViewData>,
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.
Expand All @@ -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());

Expand Down Expand Up @@ -395,16 +384,14 @@ fn prepare_custom_bind_group(
render_device: Res<RenderDevice>,
custom_material_uniforms: Res<ComponentUniforms<CustomMaterial>>,
) {
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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7679788

Please sign in to comment.