Crate bevy_firefly

Crate bevy_firefly 

Source
Expand description

Firefly is an open-source 2d lighting crate made for the Bevy game engine.

Feel free to create an issue if you want to request a specific feature or report a bug.

§Example

Here is a basic example of implementing Firefly into a Bevy game.

use bevy::prelude::*;
use bevy_firefly::prelude::*;

fn main() {
    App:new()
        // add FireflyPlugin to your app
        .add_plugins((DefaultPlugins, FireflyPlugin))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn((
        Camera2d,
        // make sure to also have the FireflyConfig component on your camera
        FireflyConfig::default()
    ));
     
    // spawn a simple red light
    commands.spawn((
        PointLight2d {
            color: Color::srgb(1.0, 0.0, 0.0),
            range: 100.0,
            ..default()
        },
        Transform::default()
    ));
     
    // spawn a circle occluder
    commands.spawn((
        Occluder2d::circle(10.0),
        Transform::from_translation(vec3(0.0, 50.0, 0.0)),
    ));
}

§Occluders

Occluders are shapes that block light and cast shadows.

Current supported shapes include:

Occluders have an opacity, ranging from transprent to fully opaque, and can cast colored shadows.

Occluders can be moved and rotated via the Transform component.

§Lights

You can create lights by spawning entities with the PointLight2d component.

Lights have adjustable range, falloff mode and a variety of other features.

§Features

Here are some of the main features currently implemented :

  • Soft Shadows: FireflyConfig has a Softness field that can be adjusted to disable / enable soft shadows, as well as give it a value (0 to 1) to set how soft the shadows should be.

  • Occlusion Layers: You can enable z-sorting on FireflyConfig to have shadows only render over sprites with a lower z position than the occluder that cast them. This is extremely useful for certain 2d games, such as top-down games. Additionally, Occluders have a list of entities that they won’t cast shadows over.

  • Normal maps: You can enable normal maps by changing the normal mode field. You can then add the NormalMap component to sprites. Normal maps need to have the same exact layout as their entity’s sprite image. If normal mode is set to top down, you can use LightHeight and SpriteHeight to emulate 3d directions for the normal maps.

  • Light Banding: You can enable light bands on FireflyConfig to reduce the lightmap to a certain number of ‘bands’, creating a stylized retro look.

§Upcoming Features

Here are some of the features that are still being worked on:

  • Multiple lightmaps.
  • Sprite-based shadows.
  • Light textures.

Modules§

app
data
lights
occluders
prelude

Structs§

ApplyLightmapLabel
Render graph label for when the lightmap is applied over the camera view.
CreateLightmapLabel
Render graph label for creating the lightmap.
SpriteNormalLabel
Render graph label for when the normal map is created.
SpriteStencilLabel
Render graph label for when the sprite stencil is created.