diff --git a/node-graph/gcore-shaders/src/shaders/buffer_struct/graphite.rs b/node-graph/gcore-shaders/src/shaders/buffer_struct/graphite.rs new file mode 100644 index 0000000000..748f5be46d --- /dev/null +++ b/node-graph/gcore-shaders/src/shaders/buffer_struct/graphite.rs @@ -0,0 +1,29 @@ +//! custom BufferStruct impl for graphite + +use crate::color::Color; +use crate::shaders::buffer_struct::BufferStruct; +use bytemuck::{Pod, Zeroable}; + +#[repr(C)] +#[derive(Copy, Clone, Zeroable, Pod)] +pub struct OptionalColorBuffer(u32, ::Buffer); + +unsafe impl BufferStruct for Option { + type Buffer = OptionalColorBuffer; + + #[inline] + fn write(from: Self) -> Self::Buffer { + match from { + None => OptionalColorBuffer(0, Color::write(Color::default())), + Some(t) => OptionalColorBuffer(1, Color::write(t)), + } + } + + #[inline] + fn read(from: Self::Buffer) -> Self { + match from.0 { + 1 => Some(Color::read(from.1)), + _ => None, + } + } +} diff --git a/node-graph/gcore-shaders/src/shaders/buffer_struct/mod.rs b/node-graph/gcore-shaders/src/shaders/buffer_struct/mod.rs index 07fca85e46..f17b7e9d88 100644 --- a/node-graph/gcore-shaders/src/shaders/buffer_struct/mod.rs +++ b/node-graph/gcore-shaders/src/shaders/buffer_struct/mod.rs @@ -6,6 +6,7 @@ use bytemuck::Pod; mod glam; +mod graphite; mod primitive; /// A BufferStruct is a "parallel representation" of the original struct with some fundamental types remapped. This diff --git a/node-graph/graster-nodes/src/adjustments.rs b/node-graph/graster-nodes/src/adjustments.rs index e8b6e57bed..5f0c0a5d63 100644 --- a/node-graph/graster-nodes/src/adjustments.rs +++ b/node-graph/graster-nodes/src/adjustments.rs @@ -341,7 +341,7 @@ fn black_and_white>( )] #[gpu_image] mut image: T, - #[default(Color::BLACK)] tint: Color, + #[default(Color::BLACK)] tint: Option, #[default(40.)] #[range((-200., 300.))] reds: PercentageF32, @@ -361,6 +361,8 @@ fn black_and_white>( #[range((-200., 300.))] magentas: PercentageF32, ) -> T { + let tint = tint.unwrap_or(Color::BLACK); + image.adjust(|color| { let color = color.to_gamma_srgb(); diff --git a/node-graph/graster-nodes/src/blending_nodes.rs b/node-graph/graster-nodes/src/blending_nodes.rs index 13f93773d4..409c9bfa25 100644 --- a/node-graph/graster-nodes/src/blending_nodes.rs +++ b/node-graph/graster-nodes/src/blending_nodes.rs @@ -169,11 +169,12 @@ fn color_overlay>( )] #[gpu_image] mut image: T, - #[default(Color::BLACK)] color: Color, + #[default(Color::BLACK)] color: Option, blend_mode: BlendMode, #[default(100.)] opacity: PercentageF32, ) -> T { let opacity = (opacity as f32 / 100.).clamp(0., 1.); + let color = color.unwrap_or(Color::BLACK); image.adjust(|pixel| { let image = pixel.map_rgb(|channel| channel * (1. - opacity)); @@ -206,7 +207,7 @@ mod test { // 100% of the output should come from the multiplied value let opacity = 100.; - let result = super::color_overlay((), Table::new_from_element(Raster::new_cpu(image.clone())), overlay_color, BlendMode::Multiply, opacity); + let result = super::color_overlay((), Table::new_from_element(Raster::new_cpu(image.clone())), Some(overlay_color), BlendMode::Multiply, opacity); let result = result.iter().next().unwrap().element; // The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0) diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 2f90dca139..acc61d41e5 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -51,6 +51,7 @@ fn node_registry() -> HashMap>, to: Table), // into_node!(from: Table>, to: Table>), + into_node!(from: Table, to: Option), #[cfg(feature = "gpu")] into_node!(from: &WasmEditorApi, to: &WgpuExecutor), // =============