New node: Pixel Noise (#1267)

Add Pixel Noise Node

Currently only White Noise is implemented, but the Code is written so that other's can be added easily
This commit is contained in:
isiko
2023-08-19 20:30:03 +02:00
committed by GitHub
parent 185106132d
commit a566331f1c
8 changed files with 117 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ use graph_craft::NodeIdentifier;
#[cfg(feature = "gpu")]
use graphene_core::application_io::SurfaceHandle;
use graphene_core::raster::brush_cache::BrushCache;
use graphene_core::raster::{BlendMode, Color, Image, ImageFrame, LuminanceCalculation, RedGreenBlue, RelativeAbsolute, SelectiveColorChoice};
use graphene_core::raster::{BlendMode, Color, Image, ImageFrame, LuminanceCalculation, NoiseType, RedGreenBlue, RelativeAbsolute, SelectiveColorChoice};
use graphene_core::text::Font;
use graphene_core::vector::VectorData;
use graphene_core::*;
@@ -547,6 +547,20 @@ fn static_nodes() -> Vec<DocumentNodeType> {
properties: |_document_node, _node_id, _context| node_properties::string_properties("Creates an embedded image with the given transform"),
..Default::default()
},
DocumentNodeType {
name: "Pixel Noise",
category: "General",
identifier: NodeImplementation::proto("graphene_std::raster::PixelNoiseNode<_, _, _>"),
inputs: vec![
DocumentInputType::value("Width", TaggedValue::U32(100), false),
DocumentInputType::value("Height", TaggedValue::U32(100), false),
DocumentInputType::value("Seed", TaggedValue::U32(0), false),
DocumentInputType::value("Noise Type", TaggedValue::NoiseType(NoiseType::WhiteNoise), false),
],
outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)],
properties: node_properties::pixel_noise_properties,
..Default::default()
},
DocumentNodeType {
name: "Mask",
category: "Image Adjustments",

View File

@@ -10,7 +10,7 @@ use graph_craft::concrete;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{DocumentNode, NodeId, NodeInput};
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod, ImaginateServerStatus, ImaginateStatus};
use graphene_core::raster::{BlendMode, Color, ImageFrame, LuminanceCalculation, RedGreenBlue, RelativeAbsolute, SelectiveColorChoice};
use graphene_core::raster::{BlendMode, Color, ImageFrame, LuminanceCalculation, NoiseType, RedGreenBlue, RelativeAbsolute, SelectiveColorChoice};
use graphene_core::text::Font;
use graphene_core::vector::style::{FillType, GradientType, LineCap, LineJoin};
use graphene_core::{Cow, Type, TypeDescriptor};
@@ -316,6 +316,29 @@ fn color_channel(document_node: &DocumentNode, node_id: u64, index: usize, name:
LayoutGroup::Row { widgets }.with_tooltip("Color Channel")
}
//TODO Use generalized Version of this as soon as it's available
fn noise_type(document_node: &DocumentNode, node_id: u64, index: usize, name: &str, blank_assist: bool) -> LayoutGroup {
let mut widgets = start_widgets(document_node, node_id, index, name, FrontendGraphDataType::General, blank_assist);
if let &NodeInput::Value {
tagged_value: TaggedValue::NoiseType(calculation),
exposed: false,
} = &document_node.inputs[index]
{
let calculation_modes = NoiseType::list();
let mut entries = Vec::with_capacity(calculation_modes.len());
for method in calculation_modes {
entries.push(DropdownEntryData::new(method.to_string()).on_update(update_value(move |_| TaggedValue::NoiseType(method), node_id, index)));
}
let entries = vec![entries];
widgets.extend_from_slice(&[
Separator::new(SeparatorType::Unrelated).widget_holder(),
DropdownInput::new(entries).selected_index(Some(calculation as u32)).widget_holder(),
]);
}
LayoutGroup::Row { widgets }.with_tooltip("Type of Noise")
}
//TODO Use generalized Version of this as soon as it's available
fn blend_mode(document_node: &DocumentNode, node_id: u64, index: usize, name: &str, blank_assist: bool) -> LayoutGroup {
let mut widgets = start_widgets(document_node, node_id, index, name, FrontendGraphDataType::General, blank_assist);
@@ -772,6 +795,22 @@ pub fn extract_channel_properties(document_node: &DocumentNode, node_id: NodeId,
vec![color_channel]
}
// Noise Type is commented out for now as ther is only one type of noise (White Noise).
// As soon as there are more types of noise, this should be uncommented.
pub fn pixel_noise_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let width = number_widget(document_node, node_id, 0, "Width", NumberInput::default().unit("px").min(1.), true);
let height = number_widget(document_node, node_id, 1, "Height", NumberInput::default().unit("px").min(1.), true);
let seed = number_widget(document_node, node_id, 2, "Seed", NumberInput::default().min(0.), true);
let _noise_type = noise_type(document_node, node_id, 3, "Noise Type", true);
vec![
LayoutGroup::Row { widgets: width },
LayoutGroup::Row { widgets: height },
LayoutGroup::Row { widgets: seed },
//_noise_type
]
}
pub fn adjust_hsl_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let hue_shift = number_widget(document_node, node_id, 1, "Hue Shift", NumberInput::default().min(-180.).max(180.).unit("°"), true);
let saturation_shift = number_widget(document_node, node_id, 2, "Saturation Shift", NumberInput::default().min(-100.).max(100.).unit("%"), true);