Skip to content

macOS pink screen with Camera2d on HDR scene #25344

Description

@jsrgb

Bevy version and features

commit e8b3598
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 #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<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    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)),
    ));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    Status
    Needs SME Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions