alpha2-render 0.5.0

Render graph and effect registry for alpha2.
Documentation
/// 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,
        }
    }
}

/// RGB blend operation applied before Porter-Duff source-over.
///
/// Formulas follow W3C Compositing and Blending Level 1, evaluated in the renderer's
/// [`BlendSpace`]. The first twelve are separable; `Hue`, `Saturation`, `Color` and
/// `Luminosity` are not. `PlusLighter` is the Level 2 additive operator.
#[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,
    /// Premultiplied source plus backdrop, color and alpha clamped to 1.
    PlusLighter,
}

impl BlendMode {
    /// Every mode: Level 1 in specification order, then `PlusLighter`.
    pub const ALL: [Self; 17] = [
        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,
        Self::PlusLighter,
    ];

    /// 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,
            Self::PlusLighter => 16.0,
        }
    }
}