Color3 values should support math operations

This feels like gatekeeping of a problem that doesn’t exist.

Everybody who has requested this has gone on to achieve what they needed, by writing a wrapper. The only difference is we all lost time writing the same code rather than it being built-in. If multiplying a color by 0.5 to get it “half as bright” was a use case & problem, people would still run into this with their wrappers.

Mathematical operators are technically incorrect on unit vectors too, but developers still survive because… people working with math typically understand some math!

6 Likes

IMO the built in solution should push you in the right direction though. Why not provide :Darker(alpha) / :Lighter(alpha) which are actually what people wanted in the first place and do the right thing rather than providing a math construct which makes you do more work for a worse result?

3 Likes

Going to put in my two cents, I’d be for a :Lighter and :Darker method. However, I think that if you were to implement Darker and Lighter methods, we would also need :Saturate and :Desaturate, and possibly :HueShift methods for consistency since (in my experience anyway), I’ve been in both situations (where I’ve needed to de/saturate, and where I need to darken/brighten colours).

To only have :Dark/Lighten and not desaturate/saturate would still be an inconvenience, and then you also run into the issue of needing a custom Saturate/Desaturate func but not a Dark/Lighten method which is just inconsistent, not implementing both would feel like a partial solution. I also think that implementing Dark/Lighten would give the impression that only modifying one channel feels like an arbitrary solution.

However that doesn’t take away from the fact that I do think that math operations should also be implemented, nearly every other data type that houses numbers in some form have it (Vector3, Vector2, Vector3Int16, Vector2Int16, UDim2, UDim, CFrame…, you literally work on the engine so you know this so I’m not sure why I’m listing). To not have Color3 math operations just feels like a feature that is so obvious and should be there for consistency.

To be frank I don’t really think most devs that want a darker colour really take into account the specifics, just would want the colour to be more or less saturated and they can change the number it’s multiplied by if need be. That’s just my opinion tho.

5 Likes

Sure. Fancy methods to darken and lighten a color with the correct gamma adjustment would be nice for simple use cases.

However, Roblox should not spend 4 years designing this magical API that satisfies everyone before doing the bare minimum for a simple datatype that should just be an extension of Vector3 behind the scenes anyway.

Currently, to write your own algorithms involving color transformations or moving between color spaces, you’re better off just using a Vector3 as an intermediary, or working with the RGB components as separate variables and duplicating math across all of them manually. Like a caveman.

If I recall, Vector3s have some optimization behind the scenes for mathematical operations. Where does that leave this classic gist standing in terms of performance? CIELUV Interpolator

8 Likes

I don’t see how it’d bloat API, wouldn’t shader language allow color multiplication and addition and things (tho its done via vec3, vec4, you get it). I have no idea why can’t the same be done to color. I had to multiply color few times and it’s VERY painstaking process, you’d have to extract colorvalues from one color and another color and reconstruct this Color3 value.

1 Like

You don’t see how adding functions for niche purposes bloats the API? :slightly_smiling_face:

Yeah, best not to comment on things we don’t know much about (e.g. how much effort for Roblox to support). I care more about the bloat argument.

Also it should be trivial to write helper functions for these things you need.

This is all I really wish were added. These would function using the normalized RGB values, of course.

Color3 + Color3 -- (R1 + R2, G1 + G2, B1 + B2)
Color3 - Color3 -- (R1 - R2, G1 - G2, B1 - B2)

Color3 * Color3 -- (R1 * R2, G1 * G2, B1 * B2)
Color3 * number -- (R1 * N, G2 * N, B3 * N)

Color3 / Color3 -- (R1 / R2, G1 / G2, B1 / B2)
Color3 / number -- (R1 / N, G1 / N, B1 / N)

Color3:ToRGB -- 0-255 Tuple
Color3:ToNormal -- 0-1 Tuple

All the other stuff about :Lighter/Darker and :HueShift would be cool also, but these above are my main pain points. I shouldn’t have to create a wrapper just to add two colors together.

6 Likes

Having math operations on Color3 would be extremely good and much faster than trying to treat Vector3 values as a Color value to do math on, and then convert said Vector3 value back into a Color3 value.

If Color3 could handle all math operations that Vector3 could do, it’d be perfect:

Color:Dot(Color)
Color:Cross(Color)
Color *= 0.5
etc
6 Likes

Bumping. Honestly surprised this isn’t a thing. You can add/subtract/divide/multiply Vector3s, both Vector3s and Color3s are compatible with TweenService, so it’s very odd that you cannot do math operations with Color3 values.

6 Likes

My full support

4 Likes