bevyengine / bevyengine/bevy

macOS pink screen with `Camera2d` on HDR scene

Open
#25,344 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version and features

commit e8b3598ff5e5ec40e8ba84edd5750a1c0e4d4e59
adapter:
```
AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, device_pci_bus_id: "", driver: "", driver_info: "", backend: Metal, subgroup_min_size: 4, subgroup_max_size: 64, transient_saves_memory: Some(true), limit_bucket: None }
```

## Bug

A pink screen appears on startup when a Camera2d configured without a clear color op is composited on top of a camera with HDR. Resizing the window (or redraw) fixes the issue. Found while trying out hanabi examples. Related #18901

## Additional information

Related pink screen Metal bug #25176 https://github.com/bevyengine/bevy/issues/20318 but looks like the issue is still present in specific camera configurations.

A dumb "workaround" is to use `ClearColorConfig::Custom(Color::NONE)` on the 2d camera, but not a real fix since this will actually clear the render target whereas `ClearColorConfig::None` shouldn't clear anything. Repro:
```
use bevy::{
camera::{CameraOutputMode, Hdr},
core_pipeline::tonemapping::Tonemapping,
prelude::*,
render::render_resource::BlendState,
};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
Camera3d::default(),
Hdr,
Tonemapping::None,
Transform::from_xyz(3.0, 2.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));

commands.spawn((
PointLight {
intensity: 2_000_000.0,
shadow_maps_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));

commands.spawn((
Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))),
MeshMaterial3d(materials.add(Color::WHITE)),
));

let ui_camera = commands
.spawn((
Camera2d,
Camera {
order: 1,
clear_color: ClearColorConfig::None, // workaround: clear_color: ClearColorConfig::Custom(Color::NONE),
output_mode: CameraOutputMode::Write {
blend_state: Some(BlendState::ALPHA_BLENDING),
clear_color: ClearColorConfig::None, // workaround: clear_color: ClearColorConfig::Custom(Color::NONE),
},
..default()
},
))
.id();

commands.spawn((
UiTargetCamera(ui_camera),
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 1.0)),
));
}
```

Contributor guide

Open the contributing guide

Research direction

Start by running the provided reproduction on macOS with the HDR Camera3d and Camera2d using ClearColorConfig::None. Inspect the camera compositing and render-pass handling for this configuration, then verify that startup no longer shows a pink screen and that resizing is not required to redraw correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.