diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 9684899ffc7bd..5bee9f4c1cd41 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -381,9 +381,6 @@ pub fn extract_camera_prepass_phase( if camera.is_active { let mut entity = commands.get_or_spawn(entity); - // deferred requires depth - let depth_prepass = depth_prepass || deferred_prepass; - if depth_prepass || normal_prepass || motion_vector_prepass { entity.insert(( RenderPhase::::default(), @@ -510,15 +507,17 @@ pub fn prepare_prepass_textures( ( Entity, &ExtractedCamera, - Option<&DepthPrepass>, - Option<&NormalPrepass>, - Option<&MotionVectorPrepass>, - Option<&DeferredPrepass>, + Has, + Has, + Has, + Has, ), - ( + Or<( With>, With>, - ), + With>, + With>, + )>, >, ) { let mut depth_textures = HashMap::default(); @@ -539,7 +538,7 @@ pub fn prepare_prepass_textures( height: physical_target_size.y, }; - let cached_depth_texture = depth_prepass.is_some().then(|| { + let cached_depth_texture = depth_prepass.then(|| { depth_textures .entry(camera.target.clone()) .or_insert_with(|| { @@ -560,7 +559,7 @@ pub fn prepare_prepass_textures( .clone() }); - let cached_normals_texture = normal_prepass.is_some().then(|| { + let cached_normals_texture = normal_prepass.then(|| { normal_textures .entry(camera.target.clone()) .or_insert_with(|| { @@ -582,7 +581,7 @@ pub fn prepare_prepass_textures( .clone() }); - let cached_motion_vectors_texture = motion_vector_prepass.is_some().then(|| { + let cached_motion_vectors_texture = motion_vector_prepass.then(|| { motion_vectors_textures .entry(camera.target.clone()) .or_insert_with(|| { @@ -604,7 +603,7 @@ pub fn prepare_prepass_textures( .clone() }); - let cached_deferred_texture = deferred_prepass.is_some().then(|| { + let cached_deferred_texture = deferred_prepass.then(|| { deferred_textures .entry(camera.target.clone()) .or_insert_with(|| { @@ -626,7 +625,7 @@ pub fn prepare_prepass_textures( .clone() }); - let deferred_lighting_pass_id_texture = deferred_prepass.is_some().then(|| { + let deferred_lighting_pass_id_texture = deferred_prepass.then(|| { deferred_lighting_id_textures .entry(camera.target.clone()) .or_insert_with(|| { diff --git a/crates/bevy_core_pipeline/src/prepass/mod.rs b/crates/bevy_core_pipeline/src/prepass/mod.rs index ba4de1952c82e..63b8c764af5ff 100644 --- a/crates/bevy_core_pipeline/src/prepass/mod.rs +++ b/crates/bevy_core_pipeline/src/prepass/mod.rs @@ -55,6 +55,7 @@ pub struct NormalPrepass; pub struct MotionVectorPrepass; /// If added to a [`crate::prelude::Camera3d`] then deferred materials will be rendered to the deferred gbuffer texture and will be available to subsequent passes. +/// Note the default deferred lighting plugin also requires `DepthPrepass` to work correctly. #[derive(Component, Default, Reflect)] pub struct DeferredPrepass; diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 54155ce385a0e..9761c186d1e64 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -810,9 +810,6 @@ pub fn queue_prepass_material_meshes( view_key |= MeshPipelineKey::MOTION_VECTOR_PREPASS; } - let mut opaque_phase_deferred = opaque_deferred_phase.as_mut(); - let mut alpha_mask_phase_deferred = alpha_mask_deferred_phase.as_mut(); - let rangefinder = view.rangefinder3d(); for visible_entity in &visible_entities.entities { @@ -879,7 +876,7 @@ pub fn queue_prepass_material_meshes( match alpha_mode { AlphaMode::Opaque => { if deferred { - opaque_phase_deferred + opaque_deferred_phase .as_mut() .unwrap() .add(Opaque3dDeferred { @@ -890,8 +887,8 @@ pub fn queue_prepass_material_meshes( batch_range: 0..1, dynamic_offset: None, }); - } else { - opaque_phase.as_mut().unwrap().add(Opaque3dPrepass { + } else if let Some(opaque_phase) = opaque_phase.as_mut() { + opaque_phase.add(Opaque3dPrepass { entity: *visible_entity, draw_function: opaque_draw_prepass, pipeline_id, @@ -903,7 +900,7 @@ pub fn queue_prepass_material_meshes( } AlphaMode::Mask(_) => { if deferred { - alpha_mask_phase_deferred + alpha_mask_deferred_phase .as_mut() .unwrap() .add(AlphaMask3dDeferred { @@ -914,8 +911,8 @@ pub fn queue_prepass_material_meshes( batch_range: 0..1, dynamic_offset: None, }); - } else { - alpha_mask_phase.as_mut().unwrap().add(AlphaMask3dPrepass { + } else if let Some(alpha_mask_phase) = alpha_mask_phase.as_mut() { + alpha_mask_phase.add(AlphaMask3dPrepass { entity: *visible_entity, draw_function: alpha_mask_draw_prepass, pipeline_id,