Skip to content

Commit

Permalink
Picking support to alpha mask, transparency 3d
Browse files Browse the repository at this point in the history
Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
  • Loading branch information
torsteingrindvik committed Jan 15, 2023
1 parent e8b2bee commit 3a6c6c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
29 changes: 21 additions & 8 deletions crates/bevy_core_pipeline/src/core_3d/main_pass_3d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Node for MainPass3dNode {
if let Some(picking_textures) = picking_textures {
color_attachments.push(Some(picking_textures.get_color_attachment(Operations {
// If the wish is to not clear the screen, don't clear the picking buffer either.
// This may happen in situations such as a split screen game.
load: match camera_3d.clear_color {
ClearColorConfig::None => LoadOp::Load,
_ => LoadOp::Clear(PickingTextures::clear_color()),
Expand Down Expand Up @@ -132,13 +133,19 @@ impl Node for MainPass3dNode {
#[cfg(feature = "trace")]
let _main_alpha_mask_pass_3d_span = info_span!("main_alpha_mask_pass_3d").entered();

let operations = Operations {
load: LoadOp::Load,
store: true,
};
let mut color_attachments = vec![Some(target.get_color_attachment(operations))];
if let Some(picking_textures) = picking_textures {
color_attachments.push(Some(picking_textures.get_color_attachment(operations)));
}

let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("main_alpha_mask_pass_3d"),
// NOTE: The alpha_mask pass loads the color buffer as well as overwriting it where appropriate.
color_attachments: &[Some(target.get_color_attachment(Operations {
load: LoadOp::Load,
store: true,
}))],
color_attachments: &color_attachments,
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
view: &depth.view,
// NOTE: The alpha mask pass loads the depth buffer and possibly overwrites it
Expand All @@ -163,13 +170,19 @@ impl Node for MainPass3dNode {
#[cfg(feature = "trace")]
let _main_transparent_pass_3d_span = info_span!("main_transparent_pass_3d").entered();

let operations = Operations {
load: LoadOp::Load,
store: true,
};
let mut color_attachments = vec![Some(target.get_color_attachment(operations))];
if let Some(picking_textures) = picking_textures {
color_attachments.push(Some(picking_textures.get_color_attachment(operations)));
}

let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("main_transparent_pass_3d"),
// NOTE: The transparent pass loads the color buffer as well as overwriting it where appropriate.
color_attachments: &[Some(target.get_color_attachment(Operations {
load: LoadOp::Load,
store: true,
}))],
color_attachments: &color_attachments,
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
view: &depth.view,
// NOTE: For the transparent pass we load the depth buffer. There should be no
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ impl SpecializedMeshPipeline for MeshPipeline {

targets.push(Some(ColorTargetState {
format: PICKING_TEXTURE_FORMAT,
// TODO: Check that we support both pipelines
blend,
write_mask: ColorWrites::ALL,
}));
Expand Down
16 changes: 10 additions & 6 deletions examples/3d/transparency_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
//! Shows the effects of different blend modes.
//! The `fade_transparency` system smoothly changes the transparency over time.
use bevy::prelude::*;
use bevy::{prelude::*, render::picking::Picking};

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
// .insert_resource(Msaa { samples: 4 })
.insert_resource(Msaa { samples: 1 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(fade_transparency)
Expand Down Expand Up @@ -99,10 +100,13 @@ fn setup(
..default()
});
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Picking::default(),
));
}

/// Fades the alpha channel of all materials between 0 and 1 over time.
Expand Down

0 comments on commit 3a6c6c2

Please sign in to comment.