1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/// Color space in which compositing arithmetic is evaluated.
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum BlendSpace {
/// Convert sRGB-encoded inputs to linear light before blending.
#[default]
LinearLight,
/// Blend directly in sRGB-encoded component space.
SrgbEncoded,
}
impl BlendSpace {
pub(crate) const fn shader_value(self) -> f32 {
match self {
Self::LinearLight => 0.0,
Self::SrgbEncoded => 1.0,
}
}
}
/// Artistic RGB operation applied before Porter-Duff source-over coverage.
///
/// The modes and their formulas are those of W3C Compositing and Blending
/// Level 1, evaluated in the renderer's [`BlendSpace`]. The first twelve are
/// separable (each channel on its own); `Hue`, `Saturation`, `Color`, and
/// `Luminosity` are not.
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq)]
pub enum BlendMode {
/// Preserve the source color.
#[default]
Normal,
/// Multiply source and backdrop components.
Multiply,
/// Inverse-multiply source and backdrop components.
Screen,
/// Multiply dark backdrop regions and screen light regions.
Overlay,
/// The darker of source and backdrop, per channel.
Darken,
/// The lighter of source and backdrop, per channel.
Lighten,
/// Brighten the backdrop to reflect the source.
ColorDodge,
/// Darken the backdrop to reflect the source.
ColorBurn,
/// Multiply or screen, depending on the source.
HardLight,
/// Darken or lighten, depending on the source: a diffused hard light.
SoftLight,
/// The absolute difference of source and backdrop.
Difference,
/// Like difference, with lower contrast.
Exclusion,
/// The source's hue with the backdrop's saturation and luminosity.
Hue,
/// The source's saturation with the backdrop's hue and luminosity.
Saturation,
/// The source's hue and saturation with the backdrop's luminosity.
Color,
/// The source's luminosity with the backdrop's hue and saturation.
Luminosity,
}
impl BlendMode {
/// Every mode, in the order of W3C Compositing and Blending Level 1.
pub const ALL: [Self; 16] = [
Self::Normal,
Self::Multiply,
Self::Screen,
Self::Overlay,
Self::Darken,
Self::Lighten,
Self::ColorDodge,
Self::ColorBurn,
Self::HardLight,
Self::SoftLight,
Self::Difference,
Self::Exclusion,
Self::Hue,
Self::Saturation,
Self::Color,
Self::Luminosity,
];
/// The index `composite.wesl` switches on.
pub(crate) const fn shader_value(self) -> f32 {
match self {
Self::Normal => 0.0,
Self::Multiply => 1.0,
Self::Screen => 2.0,
Self::Overlay => 3.0,
Self::Darken => 4.0,
Self::Lighten => 5.0,
Self::ColorDodge => 6.0,
Self::ColorBurn => 7.0,
Self::HardLight => 8.0,
Self::SoftLight => 9.0,
Self::Difference => 10.0,
Self::Exclusion => 11.0,
Self::Hue => 12.0,
Self::Saturation => 13.0,
Self::Color => 14.0,
Self::Luminosity => 15.0,
}
}
}