From 61bcd0a838f684496db999b86f75a34dc756941b Mon Sep 17 00:00:00 2001 From: Luo Zhiaho Date: Tue, 26 May 2026 16:50:20 +0800 Subject: [PATCH] Change `CameraOutputMode::Write::blend_state` behavior and default to alpha blending --- .../camera_output_mode_blend_state.md | 13 +++++++++++++ crates/bevy_camera/src/camera.rs | 4 ++-- crates/bevy_core_pipeline/src/upscaling/mod.rs | 17 +---------------- 3 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 _release-content/migration-guides/camera_output_mode_blend_state.md diff --git a/_release-content/migration-guides/camera_output_mode_blend_state.md b/_release-content/migration-guides/camera_output_mode_blend_state.md new file mode 100644 index 0000000000000..c88da973a2f05 --- /dev/null +++ b/_release-content/migration-guides/camera_output_mode_blend_state.md @@ -0,0 +1,13 @@ +--- +title: "`CameraOutputMode::Write::blend_state` behavior change" +pull_requests: [24452] +--- + +Previously `CameraOutputMode::Write::blend_state` defaulted to `None`. And when set to `None` the first camera +for the render target will disable blending (overwrite existing data of the texture) and subsequent cameras will use alpha blending. + +Now `CameraOutputMode::Write::blend_state` has been changed to default to `BlendState::ALPHA_BLENDING`, and the `blend_state` is used as-is, +which means `None` will always disable blending instead of applying the above logic. + +If you want the original behavior, you can manually set the `CameraOutputMode::Write::blend_state` of the first camera to `None` +and subsequent cameras to `BlendState::ALPHA_BLENDING`. diff --git a/crates/bevy_camera/src/camera.rs b/crates/bevy_camera/src/camera.rs index 38ecb39a016cb..fdbb0c547abda 100644 --- a/crates/bevy_camera/src/camera.rs +++ b/crates/bevy_camera/src/camera.rs @@ -27,7 +27,7 @@ use wgpu_types::{BlendState, TextureUsages}; /// ///
/// -/// Note that the physical position is in actual screen coordinates and not virtual pixels for window targets. +/// Note that the physical position is in actual screen coordinates and not virtual pixels for window targets. /// You should use the scaling factor reported by the window, which on some OS's defaults to a value other than 1. /// Please see the example code (which assumes a single camera and window) /// @@ -879,7 +879,7 @@ pub enum CameraOutputMode { impl Default for CameraOutputMode { fn default() -> Self { CameraOutputMode::Write { - blend_state: None, + blend_state: Some(BlendState::ALPHA_BLENDING), clear_color: ClearColorConfig::Default, } } diff --git a/crates/bevy_core_pipeline/src/upscaling/mod.rs b/crates/bevy_core_pipeline/src/upscaling/mod.rs index ba6a95ee79891..62ab001065124 100644 --- a/crates/bevy_core_pipeline/src/upscaling/mod.rs +++ b/crates/bevy_core_pipeline/src/upscaling/mod.rs @@ -61,22 +61,7 @@ fn prepare_view_upscaling_pipelines( let blend_state = if let Some(extracted_camera) = camera { match extracted_camera.output_mode { CameraOutputMode::Skip => None, - CameraOutputMode::Write { blend_state, .. } => { - match blend_state { - None => { - // Auto-detect: the first camera to render to this output - // (sorted_camera_index_for_target == 0) uses replace mode; - // subsequent cameras default to alpha blending so they don't - // accidentally overwrite earlier cameras' output. - if extracted_camera.sorted_camera_index_for_target > 0 { - Some(BlendState::ALPHA_BLENDING) - } else { - None - } - } - _ => blend_state, - } - } + CameraOutputMode::Write { blend_state, .. } => blend_state, } } else { None