bevy_color: Unclamp with_luminance and fix the Laba to Lcha conversion - #25394
Open
stuartparmenter wants to merge 6 commits into
Open
bevy_color: Unclamp with_luminance and fix the Laba to Lcha conversion#25394stuartparmenter wants to merge 6 commits into
stuartparmenter wants to merge 6 commits into
Conversation
…the Laba to Lcha conversion
beicause
reviewed
Aug 13, 2026
beicause
reviewed
Aug 14, 2026
| /// but will be within a given space. | ||
| pub trait Luminance: Sized { | ||
| /// Return the luminance of this color (0.0 - 1.0). | ||
| /// Return the luminance of this color (0.0 - 1.0 for SDR colors, higher for HDR). |
Member
There was a problem hiding this comment.
The comment is wrong. Even if luminance is within 1.0, components can be greater than 1.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
LinearRgba::with_luminanceclamps its result to[0.0, 1.0], so it destroys HDR and wide-gamut values, and the clamped result does not have the requested luminance. TheLabatoLchaconversion clamps chroma, which cuts off wide-gamut colors. Several channel docs also claim a[0, 1]range that HDR colors already exceed.Solution
LinearRgba::with_luminancea pure scale with no clamp.lighteranddarkerkeep their SDR clamps, and their docs now say so and point HDR users atwith_luminance.From<Laba> for Lchaconversion.LinearRgba,SrgbaandXyza. The stated ranges only apply to SDR colors, as discussed in bevy_color: LinearRec2020 #25373.Behavior notes
SDR colors come out the same, with three exceptions:
with_luminanceon a saturated color can now return components above 1.0 instead of clamping, and the result has the requested luminance exactly.with_luminanceinstead of clamping to 0.From<Laba> for Lchadrops a strayto_radians()on the Cartesian a and b components. Equal in maths, not bit for bit, so hue can move by a rounding step. It also drops thechroma.clamp(0.0, 1.5)limit.Migration
See
_release-content/migration-guides/bevy_color_hdr_clamps.md.Testing
Lchaconversion.bevy_colortests pass.This PR was built by me with the assistance of Claude Code w/ Fable 5