mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
New node: Noise Pattern (#1518)
Add the Noise Pattern node Closes #1517
This commit is contained in:
@@ -611,20 +611,178 @@ impl core::fmt::Display for RedGreenBlue {
|
||||
#[cfg_attr(feature = "std", derive(specta::Type))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
|
||||
pub enum NoiseType {
|
||||
Perlin,
|
||||
OpenSimplex2,
|
||||
OpenSimplex2S,
|
||||
Cellular,
|
||||
ValueCubic,
|
||||
Value,
|
||||
WhiteNoise,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for NoiseType {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
NoiseType::Perlin => write!(f, "Perlin"),
|
||||
NoiseType::OpenSimplex2 => write!(f, "OpenSimplex2"),
|
||||
NoiseType::OpenSimplex2S => write!(f, "OpenSimplex2S"),
|
||||
NoiseType::Cellular => write!(f, "Cellular"),
|
||||
NoiseType::ValueCubic => write!(f, "Value Cubic"),
|
||||
NoiseType::Value => write!(f, "Value"),
|
||||
NoiseType::WhiteNoise => write!(f, "White Noise"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NoiseType {
|
||||
pub fn list() -> [NoiseType; 1] {
|
||||
[NoiseType::WhiteNoise]
|
||||
pub fn list() -> &'static [NoiseType; 7] {
|
||||
&[
|
||||
NoiseType::Perlin,
|
||||
NoiseType::OpenSimplex2,
|
||||
NoiseType::OpenSimplex2S,
|
||||
NoiseType::Cellular,
|
||||
NoiseType::ValueCubic,
|
||||
NoiseType::Value,
|
||||
NoiseType::WhiteNoise,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", derive(specta::Type))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
|
||||
pub enum FractalType {
|
||||
None,
|
||||
FBm,
|
||||
Ridged,
|
||||
PingPong,
|
||||
DomainWarpProgressive,
|
||||
DomainWarpIndependent,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for FractalType {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
FractalType::None => write!(f, "None"),
|
||||
FractalType::FBm => write!(f, "Fractional Brownian Motion"),
|
||||
FractalType::Ridged => write!(f, "Ridged"),
|
||||
FractalType::PingPong => write!(f, "Ping Pong"),
|
||||
FractalType::DomainWarpProgressive => write!(f, "Progressive (Domain Warp Only)"),
|
||||
FractalType::DomainWarpIndependent => write!(f, "Independent (Domain Warp Only)"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FractalType {
|
||||
pub fn list() -> &'static [FractalType; 6] {
|
||||
&[
|
||||
FractalType::None,
|
||||
FractalType::FBm,
|
||||
FractalType::Ridged,
|
||||
FractalType::PingPong,
|
||||
FractalType::DomainWarpProgressive,
|
||||
FractalType::DomainWarpIndependent,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", derive(specta::Type))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
|
||||
pub enum CellularDistanceFunction {
|
||||
Euclidean,
|
||||
EuclideanSq,
|
||||
Manhattan,
|
||||
Hybrid,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for CellularDistanceFunction {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
CellularDistanceFunction::Euclidean => write!(f, "Euclidean"),
|
||||
CellularDistanceFunction::EuclideanSq => write!(f, "Euclidean Squared (Faster)"),
|
||||
CellularDistanceFunction::Manhattan => write!(f, "Manhattan"),
|
||||
CellularDistanceFunction::Hybrid => write!(f, "Hybrid"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CellularDistanceFunction {
|
||||
pub fn list() -> &'static [CellularDistanceFunction; 4] {
|
||||
&[
|
||||
CellularDistanceFunction::Euclidean,
|
||||
CellularDistanceFunction::EuclideanSq,
|
||||
CellularDistanceFunction::Manhattan,
|
||||
CellularDistanceFunction::Hybrid,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", derive(specta::Type))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
|
||||
pub enum CellularReturnType {
|
||||
CellValue,
|
||||
Nearest,
|
||||
NextNearest,
|
||||
Average,
|
||||
Difference,
|
||||
Product,
|
||||
Division,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for CellularReturnType {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
CellularReturnType::CellValue => write!(f, "Cell Value"),
|
||||
CellularReturnType::Nearest => write!(f, "Nearest (F1)"),
|
||||
CellularReturnType::NextNearest => write!(f, "Next Nearest (F2)"),
|
||||
CellularReturnType::Average => write!(f, "Average (F1 / 2 + F2 / 2)"),
|
||||
CellularReturnType::Difference => write!(f, "Difference (F2 - F1)"),
|
||||
CellularReturnType::Product => write!(f, "Product (F2 * F1 / 2)"),
|
||||
CellularReturnType::Division => write!(f, "Division (F1 / F2)"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CellularReturnType {
|
||||
pub fn list() -> &'static [CellularReturnType; 7] {
|
||||
&[
|
||||
CellularReturnType::CellValue,
|
||||
CellularReturnType::Nearest,
|
||||
CellularReturnType::NextNearest,
|
||||
CellularReturnType::Average,
|
||||
CellularReturnType::Difference,
|
||||
CellularReturnType::Product,
|
||||
CellularReturnType::Division,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", derive(specta::Type))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
|
||||
pub enum DomainWarpType {
|
||||
None,
|
||||
OpenSimplex2,
|
||||
OpenSimplex2Reduced,
|
||||
BasicGrid,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for DomainWarpType {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
DomainWarpType::None => write!(f, "None"),
|
||||
DomainWarpType::OpenSimplex2 => write!(f, "OpenSimplex2"),
|
||||
DomainWarpType::OpenSimplex2Reduced => write!(f, "OpenSimplex2 Reduced"),
|
||||
DomainWarpType::BasicGrid => write!(f, "Basic Grid"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DomainWarpType {
|
||||
pub fn list() -> &'static [DomainWarpType; 4] {
|
||||
&[DomainWarpType::None, DomainWarpType::OpenSimplex2, DomainWarpType::OpenSimplex2Reduced, DomainWarpType::BasicGrid]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use graphene_core::{Color, Node, Type};
|
||||
|
||||
use dyn_any::DynAny;
|
||||
pub use dyn_any::StaticType;
|
||||
pub use glam::{DAffine2, DVec2};
|
||||
pub use glam::{DAffine2, DVec2, UVec2};
|
||||
use std::hash::Hash;
|
||||
pub use std::sync::Arc;
|
||||
|
||||
@@ -23,6 +23,7 @@ pub enum TaggedValue {
|
||||
F32(f32),
|
||||
F64(f64),
|
||||
Bool(bool),
|
||||
UVec2(UVec2),
|
||||
DVec2(DVec2),
|
||||
OptionalDVec2(Option<DVec2>),
|
||||
DAffine2(DAffine2),
|
||||
@@ -45,6 +46,10 @@ pub enum TaggedValue {
|
||||
VecDVec2(Vec<DVec2>),
|
||||
RedGreenBlue(graphene_core::raster::RedGreenBlue),
|
||||
NoiseType(graphene_core::raster::NoiseType),
|
||||
FractalType(graphene_core::raster::FractalType),
|
||||
CellularDistanceFunction(graphene_core::raster::CellularDistanceFunction),
|
||||
CellularReturnType(graphene_core::raster::CellularReturnType),
|
||||
DomainWarpType(graphene_core::raster::DomainWarpType),
|
||||
RelativeAbsolute(graphene_core::raster::RelativeAbsolute),
|
||||
SelectiveColorChoice(graphene_core::raster::SelectiveColorChoice),
|
||||
LineCap(graphene_core::vector::style::LineCap),
|
||||
@@ -76,70 +81,75 @@ impl Hash for TaggedValue {
|
||||
core::mem::discriminant(self).hash(state);
|
||||
match self {
|
||||
Self::None => {}
|
||||
Self::String(s) => s.hash(state),
|
||||
Self::U32(u) => u.hash(state),
|
||||
Self::F32(f) => f.to_bits().hash(state),
|
||||
Self::F64(f) => f.to_bits().hash(state),
|
||||
Self::Bool(b) => b.hash(state),
|
||||
Self::DVec2(v) => v.to_array().iter().for_each(|x| x.to_bits().hash(state)),
|
||||
Self::String(x) => x.hash(state),
|
||||
Self::U32(x) => x.hash(state),
|
||||
Self::F32(x) => x.to_bits().hash(state),
|
||||
Self::F64(x) => x.to_bits().hash(state),
|
||||
Self::Bool(x) => x.hash(state),
|
||||
Self::UVec2(x) => x.to_array().iter().for_each(|x| x.hash(state)),
|
||||
Self::DVec2(x) => x.to_array().iter().for_each(|x| x.to_bits().hash(state)),
|
||||
Self::OptionalDVec2(None) => 0.hash(state),
|
||||
Self::OptionalDVec2(Some(v)) => {
|
||||
Self::OptionalDVec2(Some(x)) => {
|
||||
1.hash(state);
|
||||
Self::DVec2(*v).hash(state)
|
||||
Self::DVec2(*x).hash(state)
|
||||
}
|
||||
Self::DAffine2(m) => m.to_cols_array().iter().for_each(|x| x.to_bits().hash(state)),
|
||||
Self::Image(i) => i.hash(state),
|
||||
Self::ImaginateCache(i) => i.hash(state),
|
||||
Self::Color(c) => c.hash(state),
|
||||
Self::Subpaths(s) => s.iter().for_each(|subpath| subpath.hash(state)),
|
||||
Self::RcSubpath(s) => s.hash(state),
|
||||
Self::BlendMode(b) => b.hash(state),
|
||||
Self::LuminanceCalculation(l) => l.hash(state),
|
||||
Self::ImaginateSamplingMethod(m) => m.hash(state),
|
||||
Self::ImaginateMaskStartingFill(f) => f.hash(state),
|
||||
Self::ImaginateController(s) => s.hash(state),
|
||||
Self::LayerPath(p) => p.hash(state),
|
||||
Self::ImageFrame(i) => i.hash(state),
|
||||
Self::VectorData(vector_data) => vector_data.hash(state),
|
||||
Self::Fill(fill) => fill.hash(state),
|
||||
Self::Stroke(stroke) => stroke.hash(state),
|
||||
Self::VecF32(vec_f32) => vec_f32.iter().for_each(|val| val.to_bits().hash(state)),
|
||||
Self::VecDVec2(vec_dvec2) => vec_dvec2.iter().for_each(|val| val.to_array().iter().for_each(|x| x.to_bits().hash(state))),
|
||||
Self::RedGreenBlue(red_green_blue) => red_green_blue.hash(state),
|
||||
Self::NoiseType(noise_type) => noise_type.hash(state),
|
||||
Self::RelativeAbsolute(relative_absolute) => relative_absolute.hash(state),
|
||||
Self::SelectiveColorChoice(selective_color_choice) => selective_color_choice.hash(state),
|
||||
Self::LineCap(line_cap) => line_cap.hash(state),
|
||||
Self::LineJoin(line_join) => line_join.hash(state),
|
||||
Self::FillType(fill_type) => fill_type.hash(state),
|
||||
Self::GradientType(gradient_type) => gradient_type.hash(state),
|
||||
Self::GradientPositions(gradient_positions) => {
|
||||
gradient_positions.len().hash(state);
|
||||
for (position, color) in gradient_positions {
|
||||
Self::DAffine2(x) => x.to_cols_array().iter().for_each(|x| x.to_bits().hash(state)),
|
||||
Self::Image(x) => x.hash(state),
|
||||
Self::ImaginateCache(x) => x.hash(state),
|
||||
Self::Color(x) => x.hash(state),
|
||||
Self::Subpaths(x) => x.iter().for_each(|subpath| subpath.hash(state)),
|
||||
Self::RcSubpath(x) => x.hash(state),
|
||||
Self::BlendMode(x) => x.hash(state),
|
||||
Self::LuminanceCalculation(x) => x.hash(state),
|
||||
Self::ImaginateSamplingMethod(x) => x.hash(state),
|
||||
Self::ImaginateMaskStartingFill(x) => x.hash(state),
|
||||
Self::ImaginateController(x) => x.hash(state),
|
||||
Self::LayerPath(x) => x.hash(state),
|
||||
Self::ImageFrame(x) => x.hash(state),
|
||||
Self::VectorData(x) => x.hash(state),
|
||||
Self::Fill(x) => x.hash(state),
|
||||
Self::Stroke(x) => x.hash(state),
|
||||
Self::VecF32(x) => x.iter().for_each(|val| val.to_bits().hash(state)),
|
||||
Self::VecDVec2(x) => x.iter().for_each(|val| val.to_array().iter().for_each(|x| x.to_bits().hash(state))),
|
||||
Self::RedGreenBlue(x) => x.hash(state),
|
||||
Self::NoiseType(x) => x.hash(state),
|
||||
Self::FractalType(x) => x.hash(state),
|
||||
Self::CellularDistanceFunction(x) => x.hash(state),
|
||||
Self::CellularReturnType(x) => x.hash(state),
|
||||
Self::DomainWarpType(x) => x.hash(state),
|
||||
Self::RelativeAbsolute(x) => x.hash(state),
|
||||
Self::SelectiveColorChoice(x) => x.hash(state),
|
||||
Self::LineCap(x) => x.hash(state),
|
||||
Self::LineJoin(x) => x.hash(state),
|
||||
Self::FillType(x) => x.hash(state),
|
||||
Self::GradientType(x) => x.hash(state),
|
||||
Self::GradientPositions(x) => {
|
||||
x.len().hash(state);
|
||||
for (position, color) in x {
|
||||
position.to_bits().hash(state);
|
||||
color.hash(state);
|
||||
}
|
||||
}
|
||||
Self::Quantization(quantized_image) => quantized_image.hash(state),
|
||||
Self::OptionalColor(color) => color.hash(state),
|
||||
Self::ManipulatorGroupIds(mirror) => mirror.hash(state),
|
||||
Self::Font(font) => font.hash(state),
|
||||
Self::BrushStrokes(brush_strokes) => brush_strokes.hash(state),
|
||||
Self::BrushCache(brush_cache) => brush_cache.hash(state),
|
||||
Self::Segments(segments) => {
|
||||
for segment in segments {
|
||||
Self::Quantization(x) => x.hash(state),
|
||||
Self::OptionalColor(x) => x.hash(state),
|
||||
Self::ManipulatorGroupIds(x) => x.hash(state),
|
||||
Self::Font(x) => x.hash(state),
|
||||
Self::BrushStrokes(x) => x.hash(state),
|
||||
Self::BrushCache(x) => x.hash(state),
|
||||
Self::Segments(x) => {
|
||||
for segment in x {
|
||||
segment.hash(state)
|
||||
}
|
||||
}
|
||||
Self::DocumentNode(document_node) => document_node.hash(state),
|
||||
Self::GraphicGroup(graphic_group) => graphic_group.hash(state),
|
||||
Self::Artboard(artboard) => artboard.hash(state),
|
||||
Self::Curve(curve) => curve.hash(state),
|
||||
Self::IVec2(v) => v.hash(state),
|
||||
Self::SurfaceFrame(surface_id) => surface_id.hash(state),
|
||||
Self::Footprint(footprint) => footprint.hash(state),
|
||||
Self::RenderOutput(render_output) => render_output.hash(state),
|
||||
Self::Palette(palette) => palette.hash(state),
|
||||
Self::DocumentNode(x) => x.hash(state),
|
||||
Self::GraphicGroup(x) => x.hash(state),
|
||||
Self::Artboard(x) => x.hash(state),
|
||||
Self::Curve(x) => x.hash(state),
|
||||
Self::IVec2(x) => x.hash(state),
|
||||
Self::SurfaceFrame(x) => x.hash(state),
|
||||
Self::Footprint(x) => x.hash(state),
|
||||
Self::RenderOutput(x) => x.hash(state),
|
||||
Self::Palette(x) => x.hash(state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,6 +164,7 @@ impl<'a> TaggedValue {
|
||||
TaggedValue::F32(x) => Box::new(x),
|
||||
TaggedValue::F64(x) => Box::new(x),
|
||||
TaggedValue::Bool(x) => Box::new(x),
|
||||
TaggedValue::UVec2(x) => Box::new(x),
|
||||
TaggedValue::DVec2(x) => Box::new(x),
|
||||
TaggedValue::OptionalDVec2(x) => Box::new(x),
|
||||
TaggedValue::DAffine2(x) => Box::new(x),
|
||||
@@ -176,6 +187,10 @@ impl<'a> TaggedValue {
|
||||
TaggedValue::VecDVec2(x) => Box::new(x),
|
||||
TaggedValue::RedGreenBlue(x) => Box::new(x),
|
||||
TaggedValue::NoiseType(x) => Box::new(x),
|
||||
TaggedValue::FractalType(x) => Box::new(x),
|
||||
TaggedValue::CellularDistanceFunction(x) => Box::new(x),
|
||||
TaggedValue::CellularReturnType(x) => Box::new(x),
|
||||
TaggedValue::DomainWarpType(x) => Box::new(x),
|
||||
TaggedValue::RelativeAbsolute(x) => Box::new(x),
|
||||
TaggedValue::SelectiveColorChoice(x) => Box::new(x),
|
||||
TaggedValue::LineCap(x) => Box::new(x),
|
||||
@@ -210,8 +225,8 @@ impl<'a> TaggedValue {
|
||||
TaggedValue::F32(x) => x.to_string() + "_f32",
|
||||
TaggedValue::F64(x) => x.to_string() + "_f64",
|
||||
TaggedValue::Bool(x) => x.to_string(),
|
||||
TaggedValue::BlendMode(blend_mode) => "BlendMode::".to_string() + &blend_mode.to_string(),
|
||||
TaggedValue::Color(color) => format!("Color {color:?}"),
|
||||
TaggedValue::BlendMode(x) => "BlendMode::".to_string() + &x.to_string(),
|
||||
TaggedValue::Color(x) => format!("Color {x:?}"),
|
||||
_ => panic!("Cannot convert to primitive string"),
|
||||
}
|
||||
}
|
||||
@@ -224,6 +239,7 @@ impl<'a> TaggedValue {
|
||||
TaggedValue::F32(_) => concrete!(f32),
|
||||
TaggedValue::F64(_) => concrete!(f64),
|
||||
TaggedValue::Bool(_) => concrete!(bool),
|
||||
TaggedValue::UVec2(_) => concrete!(UVec2),
|
||||
TaggedValue::DVec2(_) => concrete!(DVec2),
|
||||
TaggedValue::OptionalDVec2(_) => concrete!(Option<DVec2>),
|
||||
TaggedValue::Image(_) => concrete!(graphene_core::raster::Image<Color>),
|
||||
@@ -246,6 +262,10 @@ impl<'a> TaggedValue {
|
||||
TaggedValue::VecDVec2(_) => concrete!(Vec<DVec2>),
|
||||
TaggedValue::RedGreenBlue(_) => concrete!(graphene_core::raster::RedGreenBlue),
|
||||
TaggedValue::NoiseType(_) => concrete!(graphene_core::raster::NoiseType),
|
||||
TaggedValue::FractalType(_) => concrete!(graphene_core::raster::FractalType),
|
||||
TaggedValue::CellularDistanceFunction(_) => concrete!(graphene_core::raster::CellularDistanceFunction),
|
||||
TaggedValue::CellularReturnType(_) => concrete!(graphene_core::raster::CellularReturnType),
|
||||
TaggedValue::DomainWarpType(_) => concrete!(graphene_core::raster::DomainWarpType),
|
||||
TaggedValue::RelativeAbsolute(_) => concrete!(graphene_core::raster::RelativeAbsolute),
|
||||
TaggedValue::SelectiveColorChoice(_) => concrete!(graphene_core::raster::SelectiveColorChoice),
|
||||
TaggedValue::LineCap(_) => concrete!(graphene_core::vector::style::LineCap),
|
||||
@@ -283,6 +303,7 @@ impl<'a> TaggedValue {
|
||||
x if x == TypeId::of::<f32>() => Ok(TaggedValue::F32(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<f64>() => Ok(TaggedValue::F64(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<bool>() => Ok(TaggedValue::Bool(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<UVec2>() => Ok(TaggedValue::UVec2(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<DVec2>() => Ok(TaggedValue::DVec2(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<Option<DVec2>>() => Ok(TaggedValue::OptionalDVec2(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::Image<Color>>() => Ok(TaggedValue::Image(*downcast(input).unwrap())),
|
||||
@@ -305,6 +326,10 @@ impl<'a> TaggedValue {
|
||||
x if x == TypeId::of::<Vec<DVec2>>() => Ok(TaggedValue::VecDVec2(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::RedGreenBlue>() => Ok(TaggedValue::RedGreenBlue(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::NoiseType>() => Ok(TaggedValue::NoiseType(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::FractalType>() => Ok(TaggedValue::FractalType(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::CellularDistanceFunction>() => Ok(TaggedValue::CellularDistanceFunction(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::CellularReturnType>() => Ok(TaggedValue::CellularReturnType(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::DomainWarpType>() => Ok(TaggedValue::DomainWarpType(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::RelativeAbsolute>() => Ok(TaggedValue::RelativeAbsolute(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::raster::SelectiveColorChoice>() => Ok(TaggedValue::SelectiveColorChoice(*downcast(input).unwrap())),
|
||||
x if x == TypeId::of::<graphene_core::vector::style::LineCap>() => Ok(TaggedValue::LineCap(*downcast(input).unwrap())),
|
||||
|
||||
@@ -27,6 +27,7 @@ resvg = ["dep:resvg"]
|
||||
wayland = []
|
||||
|
||||
[dependencies]
|
||||
fastnoise-lite = { workspace = true }
|
||||
rand = { workspace = true, features = [
|
||||
"alloc",
|
||||
"small_rng",
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
use crate::wasm_application_io::WasmEditorApi;
|
||||
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
use glam::{DAffine2, DVec2, Vec2};
|
||||
use graph_craft::imaginate_input::{ImaginateController, ImaginateMaskStartingFill, ImaginateSamplingMethod};
|
||||
use graph_craft::proto::DynFuture;
|
||||
use graphene_core::raster::{Alpha, Bitmap, BitmapMut, BlendMode, BlendNode, Image, ImageFrame, Linear, LinearChannel, Luminance, NoiseType, Pixel, RGBMut, RedGreenBlue, Sample};
|
||||
use graphene_core::transform::{Footprint, Transform};
|
||||
|
||||
use crate::wasm_application_io::WasmEditorApi;
|
||||
use graphene_core::raster::bbox::{AxisAlignedBbox, Bbox};
|
||||
use graphene_core::raster::{
|
||||
Alpha, Bitmap, BitmapMut, BlendMode, BlendNode, CellularDistanceFunction, CellularReturnType, DomainWarpType, FractalType, Image, ImageFrame, Linear, LinearChannel, Luminance, NoiseType, Pixel,
|
||||
RGBMut, RedGreenBlue, Sample,
|
||||
};
|
||||
use graphene_core::transform::{Footprint, Transform};
|
||||
use graphene_core::value::CopiedNode;
|
||||
use graphene_core::{AlphaBlending, Color, Node};
|
||||
|
||||
use fastnoise_lite;
|
||||
use glam::{DAffine2, DVec2, UVec2, Vec2};
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::Path;
|
||||
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
|
||||
#[derive(Debug, DynAny)]
|
||||
pub enum Error {
|
||||
IO(std::io::Error),
|
||||
@@ -192,7 +195,7 @@ pub struct MaskImageNode<P, S, Stencil> {
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(MaskImageNode<_P, _S>)]
|
||||
fn mask_imge<
|
||||
fn mask_image<
|
||||
// _P is the color of the input image. It must have an alpha channel because that is going to
|
||||
// be modified by the mask
|
||||
_P: Copy + Alpha,
|
||||
@@ -405,7 +408,7 @@ fn extend_image_to_bounds_node(image: ImageFrame<Color>, bounds: DAffine2) -> Im
|
||||
let new_end = bounds_in_image_space.end.ceil().max(orig_image_scale);
|
||||
let new_scale = new_end - new_start;
|
||||
|
||||
// Copy over original image into embiggened image.
|
||||
// Copy over original image into enlarged image.
|
||||
let mut new_img = Image::new(new_scale.x as u32, new_scale.y as u32, Color::TRANSPARENT);
|
||||
let offset_in_new_image = (-new_start).as_uvec2();
|
||||
for y in 0..image.image.height {
|
||||
@@ -553,25 +556,155 @@ fn image_frame<_P: Pixel>(image: Image<_P>, transform: DAffine2) -> graphene_cor
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PixelNoiseNode<Height, Seed, NoiseType> {
|
||||
height: Height,
|
||||
pub struct NoisePatternNode<
|
||||
Dimensions,
|
||||
Seed,
|
||||
Scale,
|
||||
NoiseType,
|
||||
DomainWarpType,
|
||||
DomainWarpAmplitude,
|
||||
FractalType,
|
||||
FractalOctaves,
|
||||
FractalLacunarity,
|
||||
FractalGain,
|
||||
FractalWeightedStrength,
|
||||
FractalPingPongStrength,
|
||||
CellularDistanceFunction,
|
||||
CellularReturnType,
|
||||
CellularJitter,
|
||||
> {
|
||||
dimensions: Dimensions,
|
||||
seed: Seed,
|
||||
scale: Scale,
|
||||
noise_type: NoiseType,
|
||||
domain_warp_type: DomainWarpType,
|
||||
domain_warp_amplitude: DomainWarpAmplitude,
|
||||
fractal_type: FractalType,
|
||||
fractal_octaves: FractalOctaves,
|
||||
fractal_lacunarity: FractalLacunarity,
|
||||
fractal_gain: FractalGain,
|
||||
fractal_weighted_strength: FractalWeightedStrength,
|
||||
fractal_ping_pong_strength: FractalPingPongStrength,
|
||||
cellular_distance_function: CellularDistanceFunction,
|
||||
cellular_return_type: CellularReturnType,
|
||||
cellular_jitter: CellularJitter,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(PixelNoiseNode)]
|
||||
fn pixel_noise(width: u32, height: u32, seed: u32, noise_type: NoiseType) -> graphene_core::raster::ImageFrame<Color> {
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(seed as u64);
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[node_macro::node_fn(NoisePatternNode)]
|
||||
fn noise_pattern(
|
||||
_no_primary_input: (),
|
||||
dimensions: UVec2,
|
||||
seed: u32,
|
||||
scale: f32,
|
||||
noise_type: NoiseType,
|
||||
domain_warp_type: DomainWarpType,
|
||||
domain_warp_amplitude: f32,
|
||||
fractal_type: FractalType,
|
||||
fractal_octaves: u32,
|
||||
fractal_lacunarity: f32,
|
||||
fractal_gain: f32,
|
||||
fractal_weighted_strength: f32,
|
||||
fractal_ping_pong_strength: f32,
|
||||
cellular_distance_function: CellularDistanceFunction,
|
||||
cellular_return_type: CellularReturnType,
|
||||
cellular_jitter: f32,
|
||||
) -> graphene_core::raster::ImageFrame<Color> {
|
||||
// All
|
||||
let [width, height] = dimensions.to_array();
|
||||
let mut image = Image::new(width, height, Color::from_luminance(0.5));
|
||||
let mut noise = fastnoise_lite::FastNoiseLite::with_seed(seed as i32);
|
||||
noise.set_frequency(Some(scale / 1000.));
|
||||
|
||||
// Domain Warp
|
||||
let domain_warp_type = match domain_warp_type {
|
||||
DomainWarpType::None => None,
|
||||
DomainWarpType::OpenSimplex2 => Some(fastnoise_lite::DomainWarpType::OpenSimplex2),
|
||||
DomainWarpType::OpenSimplex2Reduced => Some(fastnoise_lite::DomainWarpType::OpenSimplex2Reduced),
|
||||
DomainWarpType::BasicGrid => Some(fastnoise_lite::DomainWarpType::BasicGrid),
|
||||
};
|
||||
let domain_warp_active = domain_warp_type.is_some();
|
||||
noise.set_domain_warp_type(domain_warp_type);
|
||||
noise.set_domain_warp_amp(Some(domain_warp_amplitude));
|
||||
|
||||
// Fractal
|
||||
let noise_type = match noise_type {
|
||||
NoiseType::Perlin => fastnoise_lite::NoiseType::Perlin,
|
||||
NoiseType::OpenSimplex2 => fastnoise_lite::NoiseType::OpenSimplex2,
|
||||
NoiseType::OpenSimplex2S => fastnoise_lite::NoiseType::OpenSimplex2S,
|
||||
NoiseType::Cellular => fastnoise_lite::NoiseType::Cellular,
|
||||
NoiseType::ValueCubic => fastnoise_lite::NoiseType::ValueCubic,
|
||||
NoiseType::Value => fastnoise_lite::NoiseType::Value,
|
||||
NoiseType::WhiteNoise => {
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(seed as u64);
|
||||
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let pixel = image.get_pixel_mut(x, y).unwrap();
|
||||
let luminance = rng.gen_range(0.0..1.) as f32;
|
||||
*pixel = Color::from_luminance(luminance);
|
||||
}
|
||||
}
|
||||
|
||||
return ImageFrame::<Color> {
|
||||
image,
|
||||
transform: DAffine2::from_scale(DVec2::new(width as f64, height as f64)),
|
||||
alpha_blending: AlphaBlending::default(),
|
||||
};
|
||||
}
|
||||
};
|
||||
noise.set_noise_type(Some(noise_type));
|
||||
let fractal_type = match fractal_type {
|
||||
FractalType::None => fastnoise_lite::FractalType::None,
|
||||
FractalType::FBm => fastnoise_lite::FractalType::FBm,
|
||||
FractalType::Ridged => fastnoise_lite::FractalType::Ridged,
|
||||
FractalType::PingPong => fastnoise_lite::FractalType::PingPong,
|
||||
FractalType::DomainWarpProgressive => fastnoise_lite::FractalType::DomainWarpProgressive,
|
||||
FractalType::DomainWarpIndependent => fastnoise_lite::FractalType::DomainWarpIndependent,
|
||||
};
|
||||
noise.set_fractal_type(Some(fractal_type));
|
||||
noise.set_fractal_octaves(Some(fractal_octaves as i32));
|
||||
noise.set_fractal_lacunarity(Some(fractal_lacunarity));
|
||||
noise.set_fractal_gain(Some(fractal_gain));
|
||||
noise.set_fractal_weighted_strength(Some(fractal_weighted_strength));
|
||||
noise.set_fractal_ping_pong_strength(Some(fractal_ping_pong_strength));
|
||||
|
||||
// Cellular
|
||||
let cellular_distance_function = match cellular_distance_function {
|
||||
CellularDistanceFunction::Euclidean => fastnoise_lite::CellularDistanceFunction::Euclidean,
|
||||
CellularDistanceFunction::EuclideanSq => fastnoise_lite::CellularDistanceFunction::EuclideanSq,
|
||||
CellularDistanceFunction::Manhattan => fastnoise_lite::CellularDistanceFunction::Manhattan,
|
||||
CellularDistanceFunction::Hybrid => fastnoise_lite::CellularDistanceFunction::Hybrid,
|
||||
};
|
||||
let cellular_return_type = match cellular_return_type {
|
||||
CellularReturnType::CellValue => fastnoise_lite::CellularReturnType::CellValue,
|
||||
CellularReturnType::Nearest => fastnoise_lite::CellularReturnType::Distance,
|
||||
CellularReturnType::NextNearest => fastnoise_lite::CellularReturnType::Distance2,
|
||||
CellularReturnType::Average => fastnoise_lite::CellularReturnType::Distance2Add,
|
||||
CellularReturnType::Difference => fastnoise_lite::CellularReturnType::Distance2Sub,
|
||||
CellularReturnType::Product => fastnoise_lite::CellularReturnType::Distance2Mul,
|
||||
CellularReturnType::Division => fastnoise_lite::CellularReturnType::Distance2Div,
|
||||
};
|
||||
noise.set_cellular_distance_function(Some(cellular_distance_function));
|
||||
noise.set_cellular_return_type(Some(cellular_return_type));
|
||||
noise.set_cellular_jitter(Some(cellular_jitter));
|
||||
|
||||
// Calculate the noise for every pixel
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let pixel = image.get_pixel_mut(x, y).unwrap();
|
||||
let luminance = match noise_type {
|
||||
NoiseType::WhiteNoise => rng.gen_range(0.0..1.0) as f32,
|
||||
};
|
||||
|
||||
let (mut x, mut y) = (x as f32, y as f32);
|
||||
if domain_warp_active && domain_warp_amplitude > 0. {
|
||||
(x, y) = noise.domain_warp_2d(x, y);
|
||||
}
|
||||
|
||||
let luminance = (noise.get_noise_2d(x, y) + 1.) * 0.5;
|
||||
*pixel = Color::from_luminance(luminance);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the coherent noise image
|
||||
ImageFrame::<Color> {
|
||||
image,
|
||||
transform: DAffine2::from_scale(DVec2::new(width as f64, height as f64)),
|
||||
|
||||
@@ -26,7 +26,7 @@ use graphene_std::wasm_application_io::WasmEditorApi;
|
||||
use wgpu_executor::WgpuExecutor;
|
||||
|
||||
use dyn_any::StaticType;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use glam::{DAffine2, DVec2, UVec2};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -655,7 +655,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: RenderOutput, params: [RenderOutput]),
|
||||
register_node!(graphene_core::structural::ConsNode<_, _>, input: Image<Color>, params: [&str]),
|
||||
register_node!(graphene_std::raster::ImageFrameNode<_, _>, input: Image<Color>, params: [DAffine2]),
|
||||
register_node!(graphene_std::raster::PixelNoiseNode<_, _, _>, input: u32, params: [u32, u32, NoiseType]),
|
||||
register_node!(graphene_std::raster::NoisePatternNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _>, input: (), params: [UVec2, u32, f32, NoiseType, DomainWarpType, f32, FractalType, u32, f32, f32, f32, f32, CellularDistanceFunction, CellularReturnType, f32]),
|
||||
#[cfg(feature = "quantization")]
|
||||
register_node!(graphene_std::quantization::GenerateQuantizationNode<_, _>, input: ImageFrame<Color>, params: [u32, u32]),
|
||||
register_node!(graphene_core::quantization::QuantizeNode<_>, input: Color, params: [QuantizationChannels]),
|
||||
|
||||
Reference in New Issue
Block a user