diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs index dd9b5904..db09412b 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs @@ -393,7 +393,7 @@ fn static_nodes() -> Vec { identifier: NodeImplementation::proto("graphene_core::raster::LuminanceNode<_>"), inputs: vec![ DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), true), - DocumentInputType::value("Luma Calculation", TaggedValue::LuminanceCalculation(LuminanceCalculation::SRGB), false), + DocumentInputType::value("Luminance Calc", TaggedValue::LuminanceCalculation(LuminanceCalculation::SRGB), false), ], outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)], properties: node_properties::luminance_properties, @@ -590,11 +590,12 @@ fn static_nodes() -> Vec { DocumentNodeType { name: "Threshold", category: "Image Adjustments", - identifier: NodeImplementation::proto("graphene_core::raster::ThresholdNode<_, _>"), + identifier: NodeImplementation::proto("graphene_core::raster::ThresholdNode<_, _, _>"), inputs: vec![ DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), true), - DocumentInputType::value("Luma Calculation", TaggedValue::LuminanceCalculation(LuminanceCalculation::SRGB), false), - DocumentInputType::value("Threshold", TaggedValue::F64(50.), false), + DocumentInputType::value("Min Luminance", TaggedValue::F64(50.), false), + DocumentInputType::value("Max Luminance", TaggedValue::F64(100.), false), + DocumentInputType::value("Luminance Calc", TaggedValue::LuminanceCalculation(LuminanceCalculation::SRGB), false), ], outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)], properties: node_properties::adjust_threshold_properties, diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/node_properties.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/node_properties.rs index 9c776788..67ee2251 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/node_properties.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/node_properties.rs @@ -478,9 +478,9 @@ pub fn blend_properties(document_node: &DocumentNode, node_id: NodeId, _context: } pub fn luminance_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec { - let luma_calculation = luminance_calculation(document_node, node_id, 1, "Luma Calculation", true); + let luminance_calc = luminance_calculation(document_node, node_id, 1, "Luminance Calc", true); - vec![luma_calculation] + vec![luminance_calc] } pub fn adjust_hsl_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec { @@ -510,10 +510,11 @@ pub fn blur_image_properties(document_node: &DocumentNode, node_id: NodeId, _con } pub fn adjust_threshold_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec { - let luma_calculation = luminance_calculation(document_node, node_id, 1, "Luma Calculation", true); - let thereshold = number_widget(document_node, node_id, 2, "Threshold", NumberInput::default().min(0.).max(100.).unit("%"), true); + let thereshold_min = number_widget(document_node, node_id, 1, "Min Luminance", NumberInput::default().min(0.).max(100.).unit("%"), true); + let thereshold_max = number_widget(document_node, node_id, 2, "Max Luminance", NumberInput::default().min(0.).max(100.).unit("%"), true); + let luminance_calc = luminance_calculation(document_node, node_id, 3, "Luminance Calc", true); - vec![luma_calculation, LayoutGroup::Row { widgets: thereshold }] + vec![LayoutGroup::Row { widgets: thereshold_min }, LayoutGroup::Row { widgets: thereshold_max }, luminance_calc] } pub fn adjust_vibrance_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec { diff --git a/node-graph/gcore/src/raster/adjustments.rs b/node-graph/gcore/src/raster/adjustments.rs index 53ce5b89..2ee7dbec 100644 --- a/node-graph/gcore/src/raster/adjustments.rs +++ b/node-graph/gcore/src/raster/adjustments.rs @@ -161,15 +161,15 @@ impl core::fmt::Display for BlendMode { #[derive(Debug, Clone, Copy, Default)] pub struct LuminanceNode { - luma_calculation: LuminanceCalculation, + luminance_calc: LuminanceCalculation, } #[node_macro::node_fn(LuminanceNode)] -fn luminance_color_node(color: Color, luma_calculation: LuminanceCalculation) -> Color { +fn luminance_color_node(color: Color, luminance_calc: LuminanceCalculation) -> Color { // TODO: Remove conversion to linear when the whole node graph uses linear color let color = color.to_linear_srgb(); - let luminance = match luma_calculation { + let luminance = match luminance_calc { LuminanceCalculation::SRGB => color.luminance_srgb(), LuminanceCalculation::Perceptual => color.luminance_perceptual(), LuminanceCalculation::AverageChannels => color.average_rgb_channels(), @@ -304,19 +304,21 @@ fn invert_image(color: Color) -> Color { } #[derive(Debug, Clone, Copy)] -pub struct ThresholdNode { - luma_calculation: LuminanceCalculation, - threshold: Threshold, +pub struct ThresholdNode { + min_luminance: MinLuminance, + max_luminance: MaxLuminance, + luminance_calc: LuminanceCalc, } #[node_macro::node_fn(ThresholdNode)] -fn threshold_node(color: Color, luma_calculation: LuminanceCalculation, threshold: f64) -> Color { - let threshold = Color::srgb_to_linear(threshold as f32 / 100.); +fn threshold_node(color: Color, min_luminance: f64, max_luminance: f64, luminance_calc: LuminanceCalculation) -> Color { + let min_luminance = Color::srgb_to_linear(min_luminance as f32 / 100.); + let max_luminance = Color::srgb_to_linear(max_luminance as f32 / 100.); // TODO: Remove conversion to linear when the whole node graph uses linear color let color = color.to_linear_srgb(); - let luminance = match luma_calculation { + let luminance = match luminance_calc { LuminanceCalculation::SRGB => color.luminance_srgb(), LuminanceCalculation::Perceptual => color.luminance_perceptual(), LuminanceCalculation::AverageChannels => color.average_rgb_channels(), @@ -324,7 +326,7 @@ fn threshold_node(color: Color, luma_calculation: LuminanceCalculation, threshol LuminanceCalculation::MaximumChannels => color.maximum_rgb_channels(), }; - if luminance >= threshold { + if luminance >= min_luminance && luminance <= max_luminance { Color::WHITE } else { Color::BLACK diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 2050ac88..59d968ad 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -171,7 +171,7 @@ fn node_registry() -> HashMap, params: [Color, f64, f64, f64, f64, f64, f64]), raster_node!(graphene_core::raster::HueSaturationNode<_, _, _>, params: [f64, f64, f64]), raster_node!(graphene_core::raster::InvertRGBNode, params: []), - raster_node!(graphene_core::raster::ThresholdNode<_, _>, params: [LuminanceCalculation, f64]), + raster_node!(graphene_core::raster::ThresholdNode<_, _, _>, params: [f64, f64, LuminanceCalculation]), raster_node!(graphene_core::raster::VibranceNode<_>, params: [f64]), raster_node!(graphene_core::raster::BrightnessContrastNode< _, _>, params: [f64, f64]), raster_node!(graphene_core::raster::OpacityNode<_>, params: [f64]),