From 3830e7107628676a6bb64780c6b74b34e6a2d194 Mon Sep 17 00:00:00 2001 From: charlotte Date: Sat, 20 Jul 2024 09:45:04 -0700 Subject: [PATCH] Set scissor on upscale to match camera viewport (#14287) # Objective When the user renders multiple cameras to the same output texture, it can sometimes be confusing what `ClearColorConfig` is necessary for each camera to avoid overwriting the previous camera's output. This is particular true in cases where the user uses mixed HDR cameras, which means that their scene is being rendered to different internal textures. ## Solution When a view has a configured viewport, set the GPU scissor in the upscaling node so we don't overwrite areas that were written to by other cameras. ## Testing Ran the `split_screen` example. --- crates/bevy_core_pipeline/src/upscaling/node.rs | 8 ++++++++ examples/3d/split_screen.rs | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/bevy_core_pipeline/src/upscaling/node.rs b/crates/bevy_core_pipeline/src/upscaling/node.rs index c0a703b208..fda2057845 100644 --- a/crates/bevy_core_pipeline/src/upscaling/node.rs +++ b/crates/bevy_core_pipeline/src/upscaling/node.rs @@ -84,6 +84,14 @@ impl ViewNode for UpscalingNode { .command_encoder() .begin_render_pass(&pass_descriptor); + if let Some(camera) = camera { + if let Some(viewport) = &camera.viewport { + let size = viewport.physical_size; + let position = viewport.physical_position; + render_pass.set_scissor_rect(position.x, position.y, size.x, size.y); + } + } + render_pass.set_pipeline(pipeline); render_pass.set_bind_group(0, bind_group, &[]); render_pass.draw(0..3, 0..1); diff --git a/examples/3d/split_screen.rs b/examples/3d/split_screen.rs index a5e93fc14e..13840ae010 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -68,12 +68,6 @@ fn setup( camera: Camera { // Renders cameras with different priorities to prevent ambiguities order: index as isize, - // Don't clear after the first camera because the first camera already cleared the entire window - clear_color: if index > 0 { - ClearColorConfig::None - } else { - ClearColorConfig::default() - }, ..default() }, ..default()