Skip to content

WIP: Add SpectralColor type#24447

Draft
coreh wants to merge 2 commits into
bevyengine:mainfrom
coreh:spectral-color
Draft

WIP: Add SpectralColor type#24447
coreh wants to merge 2 commits into
bevyengine:mainfrom
coreh:spectral-color

Conversation

@coreh
Copy link
Copy Markdown
Contributor

@coreh coreh commented May 26, 2026

Note: This PR has been extracted from #14822


Objective

  • Add a special type for representing and working with spectral colors (composed of single wavelength light)

Solution

  • Introduces a new SpectralColor type, along with a CIE 1931 lookup table for 2-deg XYZ color matching function for conversion to tristimulus color spaces

Testing

  • Did you test these changes? If so, how?
  • Are there any parts that need more testing?
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test? macOS

@coreh coreh added C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes A-Color Color spaces and color math labels May 26, 2026
Copy link
Copy Markdown
Contributor

@amtep amtep left a comment

Choose a reason for hiding this comment

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

Hope you don't mind that I reviewed a draft :) I have some doc fixes and one question.

#[cfg(feature = "bevy_reflect")]
use bevy_reflect::prelude::*;

/// A color produced by monochromatic light. (of a single wavelength)
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.

Suggested change
/// A color produced by monochromatic light. (of a single wavelength)
/// A color produced by monochromatic light (which is light of a single wavelength).

luminance: 1.0,
};

/// Create a new spectral color with the given wavelength, luminance.
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.

Suggested change
/// Create a new spectral color with the given wavelength, luminance.
/// Create a new spectral color with the given wavelength and luminance.


let xyza = Xyza::new(x, y, z, 1.0);

let mut linear = Color::from(xyza).to_linear();
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.

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants