Add SpectralColor type#24447
Conversation
amtep
left a comment
There was a problem hiding this comment.
Hope you don't mind that I reviewed a draft :) I have some doc fixes and one question.
|
|
||
| let xyza = Xyza::new(x, y, z, 1.0); | ||
|
|
||
| let mut linear = Color::from(xyza).to_linear(); |
There was a problem hiding this comment.
I checked, and for rows 43 to 57 this generates a linear color with the red value above 1.0, with a max of 2.5166698. Is that okay? LinearRgba says [0.0, 1.0] in its docs for the fields.
There was a problem hiding this comment.
I think so? Internally the shaders support and heavily use colors above 1 for highlights, etc, and for things like highlights, emissive, etc. Might be more of a convention than a strict rule? The conversion of LinearRgba to u8 channel values clamps it to 0..=255 per channel, which might be the one real downside here as hue can shift.
Some examples currently use use values > 1.0 directly, so this would not be introducing anything unusual:
Line 43 in 01cc975
| / SpectralColor::CIE_1931_NM_CMF_LOOKUP_TABLE_INCREMENT) | ||
| .floor() as usize; | ||
|
|
||
| let lerp = (value.wavelength - SpectralColor::CIE_1931_NM_CMF_LOOKUP_TABLE_START) |
There was a problem hiding this comment.
as a fan of spec colors just looking through the lookup table interpolation here... wouldn't it be a bit cleaner to avoid the floating point modulo (%) and redundant math by leveraging .fract()? I use the same CIE 1931 table in a WGSL shader and ended up with this form (an experiment): 🙂
https://github.com/altunenes/cuneus/blob/main/examples/shaders/buddhabrot.wgsl
There was a problem hiding this comment.
Hmm yeah. I ended up using .floor(), storing an intermediate result and dropping the extra operation entirely.
There's also apparently a closed formula approximation (without lookup table) that @valaphee had mentioned on the original PR, but the link is now gone.
Note: This PR has been extracted from #14822
Objective
Solution
SpectralColortype, along with a CIE 1931 lookup table for 2-deg XYZ color matching function for conversion to tristimulus color spacesTesting