-
I've been using this crate to avoid some boilerplate for a project involving a fairly common LED strip. Currently, as you might expect by me asking this question, the colours I'm getting aren't what I expect. Although there are other issues I'm having which could be the cause (like finding out which is the most appropriate form of gamma correction to use, and the fact that sRGB probably isn't the triangle I want), I'd like some clarification on what the arithmetic operators are really doing, because I have suspicions that
As I've done ray-marching and ray-tracing code before, my initial instinct was piecewise-adjacent: I did initially check out the definition, but that didn't get me far as my macro knowledge hasn't gone any farther than how to avoid Rust syntax for generating things like mathematical vectors (curse you Are they piecewise (or close enough for the difference to not matter in my case)? If so, do the elements being multiplied actually represent something like luminous intensity for the vertices of the sRGB triangle? I know I could just avoid this problem entirely by properly using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi, I can give more details a bit later, but all the arithmetic operators are just simple operations on each component/channel separately. So multiplying RGB would be like |
Beta Was this translation helpful? Give feedback.
-
Nice that you found the cause! And you're welcome, I'm happy to help. 😁 I was going to say that I don't think you need to reach for WASM just for parsing hex values, so good that it wasn't that part that was problematic.
Right, it was just a wild assumption from my part and can be ignored if it works anyway.
Exactly what you send is an agreement between the client and server, it could be either format that works with the rest of the pipeline. You could potentially also push those conversions into the update functions, so they only do it when/if necessary. It all depends on what they need to do and how you structure them. |
Beta Was this translation helpful? Give feedback.
Alright, I'm able to expand on my response a bit, but I hope it was the answer to the main question.
Yes. Your initial assumption was entirely correct, and if you stick to
Srgb
,LinSrgb
and similar aliases without thea
at the end, you shouldn't get any problems with alpha either, since those don't have theAlpha
wrapper involved anywhere. But even with it, the multiplication operator doesn't mix the alpha values into the color values on its own. Here's what the macro expands to in the case ofRgb
, for multiplying two colors: