mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Add the "Perceptual" and "Classic" families of gradient spaces with OkLab as the new default (#4415)
* Add an OkLab gradient interpolation space and make it the new default * Fix the Properties panel fill row resetting the gradient interpolation space to the default * Add OkLch, Lab, LCh, and HSL gradient interpolation spaces * Add a hue direction attribute and picker choice for polar gradient interpolation spaces * Add an HSV gradient interpolation space * Rename the sRGB Linear and sRGB Gamma gradient spaces to RGB Linear and RGB Gamma * Divide the gradient interpolation dropdown between absolute and relative color spaces * Rename the OkLch gradient interpolation space to OkLCh for channel-notation capitalization * Shorten the color picker popover's hue direction row label to Arc * Call the Gradient Interpolation node's parameter Space and extend the picker tooltip title to match * Rename the gradient interpolation attribute and type family to gradient space * Rename the gradient tool's gradient space transform to gradient to viewport transform * Add serde aliases and a node replacement covering the gradient space renames * Give the gradient space choices artist-facing labels and reorder the dropdown sections * Add a Gradient Hue Direction node and its attribute read node * Say interpolate instead of blend for gradient stop color traversal in docs and tooltips * Label the polar perceptual gradient spaces as Perceptual Hue and group the dropdown sections by geometry * Add a migration alias covering the gradient space attribute reader rename * Carry the gradient hue direction attribute through boolean operations * Register GradientHueDirection wire types in the node registry
This commit is contained in:
committed by
Dennis Kobert
parent
11dfc27645
commit
a35143586a
@@ -14,7 +14,7 @@ use graphic_types::graphic::{Graphic, GraphicLevel, RowStep, TryFromGraphic, wal
|
||||
use graphic_types::markers::{EditorMergedLayers, Fill, Stroke as StrokeAttr};
|
||||
use graphic_types::{ATTR_FILL, ATTR_STROKE, Vector};
|
||||
use raster_types::{CPU, GPU, Raster};
|
||||
use vector_types::gradient::{GradientForm as GradientFormValue, GradientSpread};
|
||||
use vector_types::gradient::{GradientForm as GradientFormValue, GradientHueDirection, GradientSpace, GradientSpread};
|
||||
use vector_types::{Gradient, ReferencePoint};
|
||||
|
||||
fn arena_exhausted() -> Interrupt {
|
||||
@@ -257,6 +257,10 @@ attribute_reads! {
|
||||
read_gradient_form_attribute: GradientFormValue => GradientFormValue;
|
||||
/// Reads a named gradient-spread attribute, such as `gradient_spread`.
|
||||
read_gradient_spread_attribute: GradientSpread => GradientSpread;
|
||||
/// Reads a named gradient-space attribute, such as `gradient_space`.
|
||||
read_gradient_space_attribute: GradientSpace => GradientSpace;
|
||||
/// Reads a named gradient-hue-direction attribute, such as `gradient_hue_direction`.
|
||||
read_gradient_hue_direction_attribute: GradientHueDirection => GradientHueDirection;
|
||||
}
|
||||
|
||||
/// Nests the input graphical content in a wrapper graphic. This essentially "groups" the input.
|
||||
|
||||
@@ -11,7 +11,7 @@ use math_parser::value::{Number, Value};
|
||||
use rand::{Rng, SeedableRng};
|
||||
use std::ops::{Add, Mul, Rem, Sub};
|
||||
use vector_types::Gradient;
|
||||
use vector_types::markers::{GradientForm as GradientFormAttr, GradientInterpolation as GradientInterpolationAttr, GradientSpread as GradientSpreadAttr};
|
||||
use vector_types::markers::{GradientForm as GradientFormAttr, GradientHueDirection as GradientHueDirectionAttr, GradientSpace as GradientSpaceAttr, GradientSpread as GradientSpreadAttr};
|
||||
|
||||
/// The struct that stores the context for the maths parser.
|
||||
/// This is currently just limited to supplying `a` and `b` until we add better node graph support and UI for variadic inputs.
|
||||
@@ -1214,18 +1214,24 @@ fn gradient_spread(_: impl Ctx, gradient: Gradient, gradient_spread: vector_type
|
||||
(gradient, Attr(gradient_spread))
|
||||
}
|
||||
|
||||
/// Sets the color space each gradient in the input list blends between its stops with: linear light or gamma-encoded sRGB.
|
||||
/// Sets the color space in which each gradient in the input list interpolates between its stops.
|
||||
#[node_macro::node(category("Gradient"))]
|
||||
fn gradient_interpolation(_: impl Ctx, gradient: Gradient, gradient_interpolation: vector_types::GradientInterpolation) -> (Gradient, Attr<GradientInterpolationAttr>) {
|
||||
(gradient, Attr(gradient_interpolation))
|
||||
fn gradient_space(_: impl Ctx, gradient: Gradient, gradient_space: vector_types::GradientSpace) -> (Gradient, Attr<GradientSpaceAttr>) {
|
||||
(gradient, Attr(gradient_space))
|
||||
}
|
||||
|
||||
/// Sets the hue path each gradient in the input list interpolates along in polar color spaces.
|
||||
#[node_macro::node(category("Gradient"))]
|
||||
fn gradient_hue_direction(_: impl Ctx, gradient: Gradient, gradient_hue_direction: vector_types::GradientHueDirection) -> (Gradient, Attr<GradientHueDirectionAttr>) {
|
||||
(gradient, Attr(gradient_hue_direction))
|
||||
}
|
||||
|
||||
/// Sets the position of each of a gradient's stops, a factor from 0 to 1 along the gradient.
|
||||
///
|
||||
/// A list shorter than the stop count repeats its last value, a longer list is truncated, and an empty list sets each stop to its default evenly spaced position.
|
||||
#[node_macro::node(category("Gradient"))]
|
||||
fn gradient_positions(_: impl Ctx, mut gradient: Gradient, positions: List<f64>) -> Gradient {
|
||||
let positions: Vec<f64> = positions.iter_element_values().copied().collect();
|
||||
fn gradient_positions(_: impl Ctx, mut gradient: Gradient, positions: IList<f64>) -> Gradient {
|
||||
let positions: Vec<f64> = positions.iter().collect();
|
||||
gradient.set_positions(&positions);
|
||||
gradient
|
||||
}
|
||||
@@ -1236,13 +1242,13 @@ fn gradient_positions(_: impl Ctx, mut gradient: Gradient, positions: List<f64>)
|
||||
///
|
||||
/// A list shorter than the stop count repeats its last value, a longer list is truncated, and an empty list sets each midpoint to its default of 0.5.
|
||||
#[node_macro::node(category("Gradient"))]
|
||||
fn gradient_midpoints(_: impl Ctx, mut gradient: Gradient, midpoints: List<f64>) -> Gradient {
|
||||
let midpoints: Vec<f64> = midpoints.iter_element_values().copied().collect();
|
||||
fn gradient_midpoints(_: impl Ctx, mut gradient: Gradient, midpoints: IList<f64>) -> Gradient {
|
||||
let midpoints: Vec<f64> = midpoints.iter().collect();
|
||||
gradient.set_midpoints(&midpoints);
|
||||
gradient
|
||||
}
|
||||
|
||||
/// Evaluates the color at the specified position along the gradient, given a position from 0 (left) to 1 (right). Positions beyond that range follow the gradient's `gradient_spread` attribute: Pad (default), Reflect, Repeat, or Clear. Colors between stops blend in the gradient's `gradient_interpolation` color space.
|
||||
/// Evaluates the color at the specified position along the gradient, given a position from 0 (left) to 1 (right). Positions beyond that range follow the gradient's `gradient_spread` attribute: Pad (default), Reflect, Repeat, or Clear. Colors between stops interpolate in the gradient's `gradient_space` color space.
|
||||
#[node_macro::node(category("Color"))]
|
||||
fn sample_gradient(
|
||||
ctx: impl Ctx + ExtractIndex + InjectIndex + Copy,
|
||||
@@ -1256,8 +1262,9 @@ fn sample_gradient(
|
||||
}
|
||||
|
||||
let gradient_spread = gradient.lane(0).attr::<GradientSpreadAttr>();
|
||||
let gradient_interpolation = gradient.lane(0).attr::<GradientInterpolationAttr>();
|
||||
Ok(gradient.element_ref(0).evaluate(position, gradient_spread, gradient_interpolation))
|
||||
let gradient_space = gradient.lane(0).attr::<GradientSpaceAttr>();
|
||||
let gradient_hue_direction = gradient.lane(0).attr::<GradientHueDirectionAttr>();
|
||||
Ok(gradient.element_ref(0).evaluate(position, gradient_spread, gradient_space, gradient_hue_direction))
|
||||
}
|
||||
|
||||
/// Constructs a footprint value which may be set to any transformation of a unit square describing a render area, and a render resolution at least 1x1 integer pixels.
|
||||
|
||||
@@ -38,15 +38,15 @@ mod blend_std {
|
||||
|
||||
impl Blend<Color> for Gradient {
|
||||
// TODO: This joining is unfaithful in several ways: it samples only at stop positions so midpoint curves flatten away;
|
||||
// it evaluates both sources with the default spread and interpolation rather than their own attributes (which this
|
||||
// it evaluates both sources with the default spread and space rather than their own attributes (which this
|
||||
// element-level impl cannot read); and the output keeps over's attributes despite being sampled in the default space
|
||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||
let mut combined_stops = self.positions().into_iter().chain(under.positions()).collect::<Vec<_>>();
|
||||
combined_stops.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
|
||||
combined_stops.dedup_by(|a, b| (*a - *b).abs() < 1e-6);
|
||||
let stops = combined_stops.into_iter().map(|position| {
|
||||
let over_color = self.evaluate(position, Default::default(), Default::default());
|
||||
let under_color = under.evaluate(position, Default::default(), Default::default());
|
||||
let over_color = self.evaluate(position, Default::default(), Default::default(), Default::default());
|
||||
let under_color = under.evaluate(position, Default::default(), Default::default(), Default::default());
|
||||
let color = blend_fn(over_color, under_color);
|
||||
GradientStop { position, midpoint: 0.5, color }
|
||||
});
|
||||
|
||||
@@ -24,13 +24,14 @@ fn gradient_map<T: Adjust<Color> + Clone + Send + Sync + core_types::CacheHash +
|
||||
return image;
|
||||
}
|
||||
let gradient_spread = gradient.lane(0).attr::<vector_types::markers::GradientSpread>();
|
||||
let gradient_interpolation = gradient.lane(0).attr::<vector_types::markers::GradientInterpolation>();
|
||||
let gradient_space = gradient.lane(0).attr::<vector_types::markers::GradientSpace>();
|
||||
let gradient_hue_direction = gradient.lane(0).attr::<vector_types::markers::GradientHueDirection>();
|
||||
let gradient = gradient.element_ref(0);
|
||||
|
||||
image.adjust(|color| {
|
||||
let intensity = color.luminance_rec_709();
|
||||
let intensity = if reverse { 1. - intensity } else { intensity };
|
||||
gradient.evaluate(intensity as f64, gradient_spread, gradient_interpolation)
|
||||
gradient.evaluate(intensity as f64, gradient_spread, gradient_space, gradient_hue_direction)
|
||||
});
|
||||
|
||||
image
|
||||
|
||||
@@ -39,13 +39,22 @@ use vector_types::vector::misc::{
|
||||
CentroidType, ExtrudeJoiningAlgorithm, HandleId, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns, bezpath_from_manipulator_groups,
|
||||
bezpath_to_manipulator_groups, handles_to_segment, is_linear, point_to_dvec2, segment_to_handles,
|
||||
};
|
||||
use vector_types::vector::style::{DashPattern, Gradient, GradientInterpolation, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use vector_types::vector::style::{DashPattern, Gradient, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use vector_types::vector::{FillId, PointId, RegionId, SegmentDomain, SegmentId, StrokeId, VectorExt};
|
||||
use vector_types::vector::{PointDomain, RegionDomain};
|
||||
|
||||
/// The gradient color for one assign-colors position, replaying the
|
||||
/// randomized draws up to it.
|
||||
fn assign_color_at(gradient: &Gradient, gradient_interpolation: vector_types::GradientInterpolation, position: usize, length: usize, randomize: bool, seed: SeedValue, repeat_every: u32) -> Color {
|
||||
fn assign_color_at(
|
||||
gradient: &Gradient,
|
||||
gradient_space: vector_types::GradientSpace,
|
||||
gradient_hue_direction: vector_types::GradientHueDirection,
|
||||
position: usize,
|
||||
length: usize,
|
||||
randomize: bool,
|
||||
seed: SeedValue,
|
||||
repeat_every: u32,
|
||||
) -> Color {
|
||||
let factor = match randomize {
|
||||
true => {
|
||||
let mut rng = rand::rngs::StdRng::seed_from_u64(seed.into());
|
||||
@@ -61,7 +70,7 @@ fn assign_color_at(gradient: &Gradient, gradient_interpolation: vector_types::Gr
|
||||
_ => position as f64 % repeat_every as f64 / (repeat_every - 1) as f64,
|
||||
},
|
||||
};
|
||||
gradient.evaluate(factor, Default::default(), gradient_interpolation)
|
||||
gradient.evaluate(factor, Default::default(), gradient_space, gradient_hue_direction)
|
||||
}
|
||||
|
||||
/// Uniquely sets the fill and/or stroke style of every vector element to individual colors sampled along a chosen gradient.
|
||||
@@ -104,7 +113,8 @@ fn assign_colors<'e>(
|
||||
if gradient.is_empty() {
|
||||
return Ok((content.lane(lane).map_element(element), Attr(existing_fill), Attr(existing_stroke)));
|
||||
}
|
||||
let gradient_interpolation = gradient.lane(0).attr::<vector_types::markers::GradientInterpolation>();
|
||||
let gradient_space = gradient.lane(0).attr::<vector_types::markers::GradientSpace>();
|
||||
let gradient_hue_direction = gradient.lane(0).attr::<vector_types::markers::GradientHueDirection>();
|
||||
let gradient_element = gradient.element_ref(0);
|
||||
let reversed;
|
||||
let gradient_element = match reverse {
|
||||
@@ -115,7 +125,7 @@ fn assign_colors<'e>(
|
||||
false => gradient_element,
|
||||
};
|
||||
|
||||
let color = assign_color_at(gradient_element, gradient_interpolation, lane, content.len(), randomize, seed, repeat_every);
|
||||
let color = assign_color_at(gradient_element, gradient_space, gradient_hue_direction, lane, content.len(), randomize, seed, repeat_every);
|
||||
let paint = List::new_from_element(color).into_graphic_list();
|
||||
let parked = park_paint(ctx.arena(), paint)?;
|
||||
|
||||
@@ -173,7 +183,8 @@ fn assign_colors_graphic<'e>(
|
||||
if gradient.is_empty() {
|
||||
return Ok(content.lane(lane).map_element(original.clone()));
|
||||
}
|
||||
let gradient_interpolation = gradient.lane(0).attr::<vector_types::markers::GradientInterpolation>();
|
||||
let gradient_space = gradient.lane(0).attr::<vector_types::markers::GradientSpace>();
|
||||
let gradient_hue_direction = gradient.lane(0).attr::<vector_types::markers::GradientHueDirection>();
|
||||
let gradient_element = gradient.element_ref(0);
|
||||
let reversed;
|
||||
let gradient_element = match reverse {
|
||||
@@ -219,7 +230,7 @@ fn assign_colors_graphic<'e>(
|
||||
Some(mut rows) => {
|
||||
for row in 0..rows.len() {
|
||||
let has_stroke = rows.element(row).is_some_and(|vector| vector.stroke.is_some());
|
||||
let color = assign_color_at(gradient_element, gradient_interpolation, position + row, length, randomize, seed, repeat_every);
|
||||
let color = assign_color_at(gradient_element, gradient_space, gradient_hue_direction, position + row, length, randomize, seed, repeat_every);
|
||||
let paint = List::new_from_element(color).into_graphic_list();
|
||||
if fill {
|
||||
set_paint_attribute_at(&mut rows, row, ATTR_FILL, paint.clone());
|
||||
|
||||
Reference in New Issue
Block a user