Skip to content

feat: support for okhsl color space#24678

Open
zen-zap wants to merge 9 commits into
bevyengine:mainfrom
zen-zap:okhsl
Open

feat: support for okhsl color space#24678
zen-zap wants to merge 9 commits into
bevyengine:mainfrom
zen-zap:okhsl

Conversation

@zen-zap

@zen-zap zen-zap commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Added new enum variants for OKHSL called Okhsla and OkhslaLong to InterpolationColorSpace.
  • Added 'in_okhslaandin_okhsla_longmethods to theInColorSpace` trait.
  • Added OkhslHue, OkhslSaturation and OkhslLightness to ColorChannel enum in
    crates/bevy_feathers/src/controls/color_slider.rs.
  • Added okhsl_to_oklab and okhsl_to_linear_rgb methods in bevy_render/src/color_operations.wgsl along with conversion helpers.
  • Added appropriate shader flags in bevy_ui_render/src/gradients.rs and bevy_ui_render/src/gradient.wgsl.
  • Added options for cycling between color spaces in examples/ui/styling/gradients.rs

Testing

  • Not sure how to test this yet.

Notes

  • Maybe we can shift the okhsla conversion helpers to a separate module to keep things clean.
  • You might see some TODOs here. You can ignore them, I'll remove them once the working is verified.
  • Please tell me if there is anything wrong with the math here.

Showcase

There is an extra example row here - 2nd one (will remove that later).

image image

zen-zap added 4 commits June 20, 2026 03:57
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>

@beicause beicause left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the shader should prioritize speed over precision, given that render targets generally only have 8 or 16-bit precision.

return vec3<f32>(C_0, C_mid, C_max);
}

fn libm_cbrtf(x: f32) -> f32 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pow(x, 1.0 / 3.0) should be faster, and we already use it in linear_rgb_to_oklab.

let k_m = -0.105561346 * a - 0.06385417 * b;
let k_s = -0.08948418 * a - 1.2914855 * b;

for (var i = 0; i < 2; i = i + 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

1 step should be sufficient. Then the comment of this function should update.

let m_dt = dL + dC * k_m;
let s_dt = dL + dC * k_s;

for (var i = 0; i < 2; i = i + 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

zen-zap added 3 commits June 20, 2026 23:04
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
@zen-zap

zen-zap commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

@beicause I updated the functions.

@zen-zap

zen-zap commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

from examples/ui/widgets/feathers_gallery.rs:

cargo run --features="bevy_feathers" --example feathers_gallery gives me this:

screenshot-2026-06-20_23-18-55

@zen-zap zen-zap marked this pull request as ready for review June 20, 2026 17:52
@beicause

Copy link
Copy Markdown
Member

from examples/ui/widgets/feathers_gallery.rs:

cargo run --features="bevy_feathers" --example feathers_gallery gives me this:

screenshot-2026-06-20_23-18-55

The okhsl lightness slider issue and okhsla/okhsva prelude will be fixed by #24691 and #24688.

@zen-zap

zen-zap commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

from examples/ui/widgets/feathers_gallery.rs:
cargo run --features="bevy_feathers" --example feathers_gallery gives me this:
screenshot-2026-06-20_23-18-55

The okhsl lightness slider issue and okhsla/okhsva prelude will be fixed by #24691 and #24688.

Alright, then do I just cleanup the TODOs and it's good to go?

zen-zap added 2 commits June 21, 2026 14:57
Signed-off-by: zen-zap <pandaashutosh340@gmail.com>
@kfc35 kfc35 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Feature A new feature, making something new possible A-Editor Graphical tools to make Bevy games A-Color Color spaces and color math D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Shaders This code uses GPU shader languages labels Jun 21, 2026
@alice-i-cecile alice-i-cecile requested a review from beicause June 22, 2026 18:48
@alice-i-cecile alice-i-cecile added the X-Uncontroversial This work is generally agreed upon label Jun 22, 2026
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 A-Editor Graphical tools to make Bevy games C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Shaders This code uses GPU shader languages S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support OKHSL in color sliders and color plane widget

4 participants