Skip to content

Commit

Permalink
Set scissor on upscale to match camera viewport (bevyengine#14287)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
tychedelia authored and mmatvein committed Aug 22, 2024
1 parent d65eb39 commit 98bcb9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_core_pipeline/src/upscaling/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions examples/3d/split_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 98bcb9b

Please sign in to comment.