-
-
Notifications
You must be signed in to change notification settings - Fork 808
Add Color Constructor Nodes #2777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Adds a function to convert CMYKA values into RGBA.
Adds nodes to construct colors in the following formats: RGBA, HSLA, Grayscale, CMYKA
Fixed duplicated text in documentation
Updated a bunch of whole number floats to match style guide
node-graph/gmath-nodes/src/lib.rs
Outdated
@@ -462,6 +462,30 @@ fn dot_product(_: impl Ctx, vector_a: DVec2, vector_b: DVec2) -> f64 { | |||
vector_a.dot(vector_b) | |||
} | |||
|
|||
/// Constructs a color from RGBA components. Clamped to 0 -> 1. | |||
#[node_macro::node(category("Color"))] | |||
fn construct_color_rgba(_: impl Ctx, _primary: (), red: f32, green: f32, blue: f32, alpha: f32) -> Color { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"RGBA to Color" would be my preferred name for this node, and I think that would fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"RGBA to Color" would be my preferred name for this node, and I think that would fit.
I have updated the node names to 'RGBA to Color', 'HSLA to Color', 'Gray to Color', and 'CMYKA to Color'.
Would it be preferable to swap to a single 'Create Color' node? I now know how to make enums appear as dropdowns/buttons/etc, but I'm not sure if the following is possible:
- Create five generic f64 inputs
- Rename them in the UI based on the currently-selected color formula. IE if RGBA is selected, input 1 is R. If HSLA is selected, input 1 is H
- Hide any inputs that aren't needed for the current formula
Alternatively, we could have R, G, B, H, S, V, L, C, M, Y, K, A inputs and then show/hide the ones not relevant to the current formula.
I'll mark this as a draft for the moment while awaiting the requested code review changes for the naming scheme and parameter types. Please mark it as ready for review once resolved, thanks! |
Made nodes accept f64 arguments and convert them to f32 internally so that node properties work.
Changed names from 'construct_color_xxx' to 'xxx_to_color'
ec51271
to
e025103
Compare
!build |
|
I see there is a conflict, can you please resolve it? And once this is fully ready for review, please mark it as such so it's not a draft (I ignore drafts when working through my review queue). |
Resolves #2774
Adds the following:
color crate function:
from_cmyka() function to convert CMYKA to RGBA
Nodes:
All nodes clamp input to 0 -> 1 before passing to matching function in color crate
construct_color_rgba() accepts f32 inputs in RGBA format and outputs a color
construct_color_hsla() accepts f32 inputs in HSLA format and outputs a color
ConstructColorDemo.zip
construct_color_grayscale() accepts a single f32 luminance input and outputs a color
construct_color_cmyka() accepts f32 inputs in CMYKA format and outputs a color
I am struggling to understand more complex node construction. These could likely get merged, but I couldn't figure out how to create options that swap out inputs.
Demo: ConstructColorDemo.zip
The squares in the background test the four nodes in order from the center out. The dots in the foreground demonstrate a more practical use, deriving color from the instance index in a way that can't be done with a simple gradient.