#bevy-plugin #blur #region #screen #camera #bevy-ui #selectively

bevy_blur_regions

A Bevy plugin to selectively blur regions of the screen

5 releases (breaking)

0.5.0 Oct 27, 2024
0.4.0 Sep 19, 2024
0.3.0 Jul 6, 2024
0.2.0 Mar 31, 2024
0.1.0 Mar 30, 2024

#511 in Game dev

Download history 80/week @ 2024-08-16 27/week @ 2024-08-23 22/week @ 2024-08-30 21/week @ 2024-09-06 131/week @ 2024-09-13 240/week @ 2024-09-20 114/week @ 2024-09-27 91/week @ 2024-10-04 139/week @ 2024-10-11 88/week @ 2024-10-18 167/week @ 2024-10-25 100/week @ 2024-11-01 104/week @ 2024-11-08 161/week @ 2024-11-15 153/week @ 2024-11-22 51/week @ 2024-11-29

485 downloads per month

MIT/Apache

390KB
659 lines

Bevy Blur Regions

crates.io

A Bevy plugin to selectively blur regions of the screen.

screenshot

Usage

Add the plugin:

use bevy::prelude::*;
use bevy_blur_regions::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(BlurRegionsPlugin::default())
        .run();
}

Add the BlurRegionsCamera component to the 3D camera whose output should be blurred:

commands.spawn((
    BlurRegionsCamera::default(),
    Camera3dBundle::default(),
));

When using Bevy UI, add the BlurRegion marker component to any Bevy UI nodes which should have a blurry background:

commands.spawn((
    BlurRegion,
    NodeBundle {
        style: Style {
            width: Val::Percent(50.0),
            height: Val::Percent(50.0),
            left: Val::Percent(25.0),
            top: Val::Percent(25.0),
            ..default()
        },
        ..default()
    },
));

When using egui, enable the egui feature and then use the show_with_blur function instead of show when adding contents to an egui window:

fn draw_ui(
    mut contexts: EguiContexts,
{
    let frame = egui::Frame::window(&contexts.ctx_mut().style())
        .fill(egui::Color32::from_rgba_premultiplied(27, 27, 27, 100))
        .rounding(0.0)
        .shadow(egui::epaint::Shadow::NONE);

    egui::Window::new("Blurry Window")
        .frame(frame)
        .show_with_blur(contexts.ctx_mut(), |ui| {
            ui.label("This window has a nice blurry background.")
        });
}

For other use cases, the immediate mode blurring api can be called each frame:

fn update(mut blur_region_cameras: Query<&mut BlurRegionsCamera>) {
    let Ok(mut blur_regions) = blur_region_cameras.get_single_mut() else {
        return;
    };
    blur_regions.blur(Rect::from_center_size(vec2(100.0, 100.0), vec2(200.0, 200.0)));
}

See the examples for working implementations of all of the above.

Caveats

The number of blur regions is limited

The number of blur regions that can be present on the screen at the same time is limited to 20.

Compatibility

bevy_blur_regions bevy bevy_egui
0.5.0 0.14 0.30
0.4.0 0.14 0.28
0.3.0 0.14 0.28
0.2.0 0.13 0.26
0.1.0 0.13 N/A

License

All code in this repository is dual-licensed under either:

MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)

at your option. This means you can select the license you prefer.

Dependencies

~38–75MB
~1.5M SLoC