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