bevyengine / bevyengine/bevy

Blend modes for 2D sprite bundles

Open
#9,314 4 comments 8 reactions 0 assignees View on GitHub
A-Rendering C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 2D BLEND MODES

Add blend modes to 2D sprite bundle.

Blend modes is a **crucial 2D functionality** that allows implementation of several important VFX for 2D.
The most prominent one is **_"fake sprite lighting"_**, where you use grayscale sprites for imitating shadows and light in your game.

This method is **very common and very cheap** for computing power.

![image](https://github.com/bevyengine/bevy/assets/49441831/36f2fd97-da5d-48c0-af8b-649370ffd208)

Here is list of all blend modes in **Aseprite**:

![image](https://github.com/bevyengine/bevy/assets/49441831/4b37e922-8caf-421c-967c-32b8a432ee44)

## What to add
I would suggest implementing these 5 primary blend modes:
* Lighten
* Darken
* Addition
* Subtraction
* Overlay

## Difficulty
Switching between blend modes on GPU might be be rather slow process and we want to minimize that. We would need to somehow sort and group entities with same blend modes together, so they can be rendered in one batch. But that might fight with depth sorting.

But I am not knowledgeable with shader programming much, so I cannot say for sure. That's just my observation from other engines.

## Usability
I propose creating new component that will define how texture will be rendered. We can then create enum and add another field to SpriteBundle.
```rust
pub enum BlendMode {
Normal,
Lighten,
Darken,
Addition,
Subtraction,
Overlay,
}

pub struct SpriteBundle {
pub sprite: Sprite,
pub transform: Transform,
pub blend_mode: BlendMode, // Add this new component
pub global_transform: GlobalTransform],
pub texture: Handle,
pub visibility: Visibility,
pub computed_visibility: ComputedVisibility,
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.