Skip to content

Add Okhsla and Okhsva to bevy_color#24137

Open
beicause wants to merge 12 commits into
bevyengine:mainfrom
beicause:color-okhsl-okhsv
Open

Add Okhsla and Okhsva to bevy_color#24137
beicause wants to merge 12 commits into
bevyengine:mainfrom
beicause:color-okhsl-okhsv

Conversation

@beicause
Copy link
Copy Markdown
Member

@beicause beicause commented May 5, 2026

Objective

Fixes #17650. May help with #24118.

Solution

Implement okhsl and okhsv according to ok_color.h and add them to bevy_color.

For tests, the okhsl and okhsv values of test colors are pre-computed via colorconversion.js.zip

TODO:

  • Fix NaN and improve precision. Fix windows tests if libm isn't enabled by using libm_cbrtf

Testing

cargo test -p bevy_color

@beicause beicause force-pushed the color-okhsl-okhsv branch from 6c8ca57 to d812c36 Compare May 5, 2026 16:46
@kfc35 kfc35 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Color Color spaces and color math C-Feature A new feature, making something new possible labels May 5, 2026
@beicause beicause force-pushed the color-okhsl-okhsv branch from d812c36 to 27efc4b Compare May 5, 2026 16:56
@beicause beicause force-pushed the color-okhsl-okhsv branch from a913df2 to d6d3385 Compare May 5, 2026 18:28
@alice-i-cecile alice-i-cecile added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label May 6, 2026
@beicause beicause force-pushed the color-okhsl-okhsv branch from dadf965 to 9f36128 Compare May 6, 2026 02:27
…ting (#4)

The pre-compute results for testing is from `node colorconversion.js`
with increased Halley steps:
[colorconversion.js.zip](https://github.com/user-attachments/files/27423193/colorconversion.js.zip)

Use `libm`'s `cbrtf` implemention to fix windows testing
Comment on lines +516 to +523
// Note: This is copied from `libm` to fix precision issue on Windows CI testing.

const B1: u32 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */
const B2: u32 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
/// Cube root (f32)
///
/// Computes the cube root of the argument.
pub(crate) fn libm_cbrtf(x: f32) -> f32 {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had to use libm's cbrtf for oklab, okhsl and okhsv, otherwise the error is too large on Windows and the tests would fail. See also beicause#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Color Color spaces and color math C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Okhsl and Okhsv support for bevy_color

4 participants