bevy/crates/bevy_pbr/src
Charles 3f4ac65682 set alpha_mode based on alpha value (#4658)
# Objective

- When spawning a sprite the alpha is used for transparency, but when using the `Color::into()` implementation to spawn a `StandardMaterial`, the alpha is ignored.
- Pretty much everytime I want to make something transparent I started with a `Color::rgb().into()` and I'm always surprised that it doesn't work when changing it to  `Color::rgba().into()`
- It's possible there's an issue with this approach I am not thinking of, but I'm not sure what's the point of setting an alpha value without the goal of making a color transparent.

## Solution

- Set the alpha_mode to AlphaMode::Blend when the alpha is not the default value.

---

## Migration Guide

This is not a breaking change, but it can easily be migrated to reduce boilerplate

```rust
commands.spawn_bundle(PbrBundle {
    mesh: meshes.add(shape::Cube::default().into()),
    material: materials.add(StandardMaterial {
        base_color: Color::rgba(1.0, 0.0, 0.0, 0.75),
        alpha_mode: AlphaMode::Blend,
        ..default()
    }),
    ..default()
});

// becomes

commands.spawn_bundle(PbrBundle {
    mesh: meshes.add(shape::Cube::default().into()),
    material: materials.add(Color::rgba(1.0, 0.0, 0.0, 0.75).into()),
    ..default()
});
```


Co-authored-by: Charles <IceSentry@users.noreply.github.com>
2022-05-04 22:10:20 +00:00
..
render Do not create nor execute render passes which have no phase items to draw (#4643) 2022-05-02 20:22:30 +00:00
alpha.rs add #[reflect(Default)] to create default value for reflected types (#3733) 2022-05-03 19:20:13 +00:00
bundle.rs add Visibility for lights (#3958) 2022-03-05 03:23:01 +00:00
lib.rs Converted exclusive systems to parallel systems wherever possible (#2774) 2022-04-25 14:32:56 +00:00
light.rs add #[reflect(Default)] to create default value for reflected types (#3733) 2022-05-03 19:20:13 +00:00
material.rs Filter material handles on extraction (#4178) 2022-05-03 18:28:04 +00:00
pbr_material.rs set alpha_mode based on alpha value (#4658) 2022-05-04 22:10:20 +00:00
wireframe.rs add #[reflect(Default)] to create default value for reflected types (#3733) 2022-05-03 19:20:13 +00:00