Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional clear color in ColorAttachment. #11884

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,18 @@ pub fn prepare_prepass_textures(
});

commands.entity(entity).insert(ViewPrepassTextures {
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
normal: cached_normals_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
normal: cached_normals_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
// Red and Green channels are X and Y components of the motion vectors
// Blue channel doesn't matter, but set to 0.0 for possible faster clear
// https://gpuopen.com/performance/#clears
motion_vectors: cached_motion_vectors_texture
.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
deferred: cached_deferred_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
deferred: cached_deferred_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
deferred_lighting_pass_id: cached_deferred_lighting_pass_id_texture
.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
size,
});
}
Expand Down
18 changes: 8 additions & 10 deletions crates/bevy_render/src/texture/texture_attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use wgpu::{
pub struct ColorAttachment {
pub texture: CachedTexture,
pub resolve_target: Option<CachedTexture>,
clear_color: Color,
clear_color: Option<Color>,
is_first_call: Arc<AtomicBool>,
}

impl ColorAttachment {
pub fn new(
texture: CachedTexture,
resolve_target: Option<CachedTexture>,
clear_color: Color,
clear_color: Option<Color>,
) -> Self {
Self {
texture,
Expand All @@ -43,10 +43,9 @@ impl ColorAttachment {
view: &resolve_target.default_view,
resolve_target: Some(&self.texture.default_view),
ops: Operations {
load: if first_call {
LoadOp::Clear(self.clear_color.into())
} else {
LoadOp::Load
load: match (self.clear_color, first_call) {
(Some(clear_color), true) => LoadOp::Clear(clear_color.into()),
(None, _) | (Some(_), false) => LoadOp::Load,
},
store: StoreOp::Store,
},
Expand All @@ -67,10 +66,9 @@ impl ColorAttachment {
view: &self.texture.default_view,
resolve_target: None,
ops: Operations {
load: if first_call {
LoadOp::Clear(self.clear_color.into())
} else {
LoadOp::Load
load: match (self.clear_color, first_call) {
(Some(clear_color), true) => LoadOp::Clear(clear_color.into()),
(None, _) | (Some(_), false) => LoadOp::Load,
},
store: StoreOp::Store,
},
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,9 @@ pub fn prepare_view_targets(
};

let clear_color = match camera.clear_color {
ClearColorConfig::Custom(color) => color,
_ => clear_color_global.0,
ClearColorConfig::Custom(color) => Some(color),
ClearColorConfig::None => None,
_ => Some(clear_color_global.0),
};

let (a, b, sampled) = textures
Expand Down