Skip to content

Commit

Permalink
rework it
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Oct 23, 2023
1 parent 784d783 commit 60c7239
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
27 changes: 13 additions & 14 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Opaque3dPrepass>::default(),
Expand Down Expand Up @@ -510,15 +507,17 @@ pub fn prepare_prepass_textures(
(
Entity,
&ExtractedCamera,
Option<&DepthPrepass>,
Option<&NormalPrepass>,
Option<&MotionVectorPrepass>,
Option<&DeferredPrepass>,
Has<DepthPrepass>,
Has<NormalPrepass>,
Has<MotionVectorPrepass>,
Has<DeferredPrepass>,
),
(
Or<(
With<RenderPhase<Opaque3dPrepass>>,
With<RenderPhase<AlphaMask3dPrepass>>,
),
With<RenderPhase<Opaque3dDeferred>>,
With<RenderPhase<AlphaMask3dDeferred>>,
)>,
>,
) {
let mut depth_textures = HashMap::default();
Expand All @@ -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(|| {
Expand All @@ -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(|| {
Expand All @@ -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(|| {
Expand All @@ -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(|| {
Expand All @@ -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(|| {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core_pipeline/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 6 additions & 9 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,6 @@ pub fn queue_prepass_material_meshes<M: Material>(
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 {
Expand Down Expand Up @@ -879,7 +876,7 @@ pub fn queue_prepass_material_meshes<M: Material>(
match alpha_mode {
AlphaMode::Opaque => {
if deferred {
opaque_phase_deferred
opaque_deferred_phase
.as_mut()
.unwrap()
.add(Opaque3dDeferred {
Expand All @@ -890,8 +887,8 @@ pub fn queue_prepass_material_meshes<M: Material>(
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,
Expand All @@ -903,7 +900,7 @@ pub fn queue_prepass_material_meshes<M: Material>(
}
AlphaMode::Mask(_) => {
if deferred {
alpha_mask_phase_deferred
alpha_mask_deferred_phase
.as_mut()
.unwrap()
.add(AlphaMask3dDeferred {
Expand All @@ -914,8 +911,8 @@ pub fn queue_prepass_material_meshes<M: Material>(
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,
Expand Down

0 comments on commit 60c7239

Please sign in to comment.