Skip to content

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

phailhaus
Copy link

@phailhaus phailhaus commented Jun 28, 2025

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.

ConstructColorDemo

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
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of these nodes is too long so that the actual colour system doesn't appear in the node graph:
Node 'Construct Colo...`

Perhaps they could be shortened e.g. RGBA Colour. To change the capitalisation of the name, you can use:

#[node_macro::node(category("Colour"), name("RGBA Colour"))]

Copy link
Member

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.

Copy link
Author

@phailhaus phailhaus Jul 9, 2025

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'.

image

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:

  1. Create five generic f64 inputs
  2. 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
  3. 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.

@Keavon
Copy link
Member

Keavon commented Jul 6, 2025

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!

@Keavon Keavon marked this pull request as draft July 6, 2025 04:22
phailhaus added 2 commits July 8, 2025 18:51
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'
@Keavon Keavon force-pushed the master branch 4 times, most recently from ec51271 to e025103 Compare July 10, 2025 05:48
@Keavon
Copy link
Member

Keavon commented Jul 12, 2025

!build

Copy link

📦 Build Complete for 541ec14
https://0938a41a.graphite.pages.dev

@Keavon
Copy link
Member

Keavon commented Jul 12, 2025

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Color from Component Values
3 participants