Skip to content

bevy_color: Add a primaries module with chromaticities and RGB conversion matrices - #25393

Open
stuartparmenter wants to merge 4 commits into
bevyengine:mainfrom
stuartparmenter:hdr-wave1-color-primaries
Open

bevy_color: Add a primaries module with chromaticities and RGB conversion matrices#25393
stuartparmenter wants to merge 4 commits into
bevyengine:mainfrom
stuartparmenter:hdr-wave1-color-primaries

Conversation

@stuartparmenter

@stuartparmenter stuartparmenter commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Objective

bevy_color has no data about RGB primary sets and no way to derive the conversion matrices between them. The upcoming HDR output PRs need these matrices, and this PR is the first piece of that series.

Solution

  • Adds a primaries module.
  • Adds Chromaticity, a CIE 1931 xy coordinate pair.
  • Adds RgbPrimaries with constants for BT709, BT2020, DISPLAY_P3 and ACES_CG.
  • Adds rgb_to_rgb_matrix, which derives the conversion matrix between any two primary sets.

Testing

  • New tests check the derived matrices against published reference values.
  • All bevy_color tests pass.

This PR was built by me with the assistance of Claude Code w/ Fable 5

@mate-h mate-h left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work, love this new module. very much missing from bevy_color as of today, I'm completely in favor of adding this. I have some feedback about documentation, references as well as some placement /return value of functions.

Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
Comment thread crates/bevy_color/src/primaries.rs Outdated
@stuartparmenter
stuartparmenter force-pushed the hdr-wave1-color-primaries branch from 809e9aa to 6ef85b3 Compare August 13, 2026 18:40
@stuartparmenter stuartparmenter added A-Color Color spaces and color math C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 13, 2026

@mate-h mate-h left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, this looks good to me!


/// The CIE 1931 XYZ tristimulus value of this chromaticity at luminance `1.0`,
/// in `f64` precision for matrix derivation.
const fn to_dxyz(self) -> DVec3 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice solution!!

Comment on lines +149 to +158
fn rgb_to_xyz_dmat3(&self) -> DMat3 {
let primaries = DMat3::from_cols(
self.red.to_dxyz(),
self.green.to_dxyz(),
self.blue.to_dxyz(),
);
// Scale each column so that (1, 1, 1) maps to the white point at Y = 1.
let scale = primaries.inverse() * self.white.to_dxyz();
primaries * DMat3::from_diagonal(scale)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this reads much better now without that nested function

@Zeophlite Zeophlite added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 15, 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 C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants