bevy_render/
alpha.rs

1use bevy_reflect::std_traits::ReflectDefault;
2use bevy_reflect::Reflect;
3
4// TODO: add discussion about performance.
5/// Sets how a material's base color alpha channel is used for transparency.
6#[derive(Debug, Default, Reflect, Copy, Clone, PartialEq)]
7#[reflect(Default, Debug)]
8pub enum AlphaMode {
9    /// Base color alpha values are overridden to be fully opaque (1.0).
10    #[default]
11    Opaque,
12    /// Reduce transparency to fully opaque or fully transparent
13    /// based on a threshold.
14    ///
15    /// Compares the base color alpha value to the specified threshold.
16    /// If the value is below the threshold,
17    /// considers the color to be fully transparent (alpha is set to 0.0).
18    /// If it is equal to or above the threshold,
19    /// considers the color to be fully opaque (alpha is set to 1.0).
20    Mask(f32),
21    /// The base color alpha value defines the opacity of the color.
22    /// Standard alpha-blending is used to blend the fragment's color
23    /// with the color behind it.
24    Blend,
25    /// Similar to [`AlphaMode::Blend`], however assumes RGB channel values are
26    /// [premultiplied](https://en.wikipedia.org/wiki/Alpha_compositing#Straight_versus_premultiplied).
27    ///
28    /// For otherwise constant RGB values, behaves more like [`AlphaMode::Blend`] for
29    /// alpha values closer to 1.0, and more like [`AlphaMode::Add`] for
30    /// alpha values closer to 0.0.
31    ///
32    /// Can be used to avoid “border” or “outline” artifacts that can occur
33    /// when using plain alpha-blended textures.
34    Premultiplied,
35    /// Spreads the fragment out over a hardware-dependent number of sample
36    /// locations proportional to the alpha value. This requires multisample
37    /// antialiasing; if MSAA isn't on, this is identical to
38    /// [`AlphaMode::Mask`] with a value of 0.5.
39    ///
40    /// Alpha to coverage provides improved performance and better visual
41    /// fidelity over [`AlphaMode::Blend`], as Bevy doesn't have to sort objects
42    /// when it's in use. It's especially useful for complex transparent objects
43    /// like foliage.
44    ///
45    /// [alpha to coverage]: https://en.wikipedia.org/wiki/Alpha_to_coverage
46    AlphaToCoverage,
47    /// Combines the color of the fragments with the colors behind them in an
48    /// additive process, (i.e. like light) producing lighter results.
49    ///
50    /// Black produces no effect. Alpha values can be used to modulate the result.
51    ///
52    /// Useful for effects like holograms, ghosts, lasers and other energy beams.
53    Add,
54    /// Combines the color of the fragments with the colors behind them in a
55    /// multiplicative process, (i.e. like pigments) producing darker results.
56    ///
57    /// White produces no effect. Alpha values can be used to modulate the result.
58    ///
59    /// Useful for effects like stained glass, window tint film and some colored liquids.
60    Multiply,
61}
62
63impl Eq for AlphaMode {}