Skip to content

Bloom not restricted to cameras with BloomSettings? #7361

@rparrett

Description

@rparrett

Bevy version

Relevant system information

AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
SystemInfo { os: "MacOS 13.1 ", kernel: "22.2.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }

What you did

I want bloom to be applied only to a subset of my scene, so I added a separate camera with BloomSettings.

use bevy::{
    core_pipeline::{bloom::BloomSettings, clear_color::ClearColorConfig},
    prelude::*,
    render::view::RenderLayers,
    sprite::MaterialMesh2dBundle,
};

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::rgb(0.1, 0.1, 0.1)))
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    let no_bloom_layer = RenderLayers::layer(0);
    let bloom_layer = RenderLayers::layer(1);

    commands.spawn((
        Camera2dBundle {
            camera: Camera {
                hdr: true,
                ..default()
            },
            ..default()
        },
        no_bloom_layer,
    ));

    commands.spawn((
        Camera2dBundle {
            camera_2d: Camera2d {
                clear_color: ClearColorConfig::None,
                ..default()
            },
            camera: Camera {
                hdr: true,
                order: 1,
                ..default()
            },
            ..default()
        },
        bloom_layer,
        BloomSettings {
            threshold: 0.5,
            ..default()
        },
    ));

    let (saturation, lightness, alpha) = (0.8, 0.7, 1.0);

    // Circle
    commands.spawn((
        MaterialMesh2dBundle {
            mesh: meshes.add(shape::Circle::new(100.).into()).into(),
            material: materials.add(ColorMaterial::from(Color::Hsla {
                hue: 180.,
                saturation,
                lightness,
                alpha,
            })),
            transform: Transform::from_translation(Vec3::new(-125., 0., 0.)),
            ..default()
        },
        no_bloom_layer,
    ));

    // Hexagon
    commands.spawn((
        MaterialMesh2dBundle {
            mesh: meshes
                .add(shape::RegularPolygon::new(100., 6).into())
                .into(),
            material: materials.add(ColorMaterial::from(Color::Hsla {
                hue: 120.,
                saturation,
                lightness,
                alpha,
            })),
            transform: Transform::from_translation(Vec3::new(125., 0., 0.)),
            ..default()
        },
        bloom_layer,
    ));
}

What went wrong

BloomSettings is only on the camera that renders the hexagon, so I expected only the hexagon to get bloom.

Instead, both shapes get bloom.

image

Additional information

It's not clear if this is user error, a known limitation, or a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions