-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Convert colors from srgb to linear srgb automatically #585
Copy link
Copy link
Closed
Labels
A-RenderingDrawing game state to the screenDrawing game state to the screenC-FeatureA new feature, making something new possibleA new feature, making something new possible
Description
As per this Discord conversation and #419 (comment), assume people are providing raw color values in the non-linear srgb colorspace. Bevy should then convert the provided colors to linear srgb for internal use, for example in the constructors in bevy_render/src/color.rs), and automatically convert the colors to linear srgb when it makes sense under the hood.
We could have constructors for both non-linear and linear sources as long as we document them wherever there could be ambiguity.
Workaround
Right now this can be worked around by manually converting the colors to linear srgb colorspace before using them with the engine like this:
// # Cargo.toml
// [dependencies]
// palette = "0.5.0"
use palette::Srgb;
use bevy::prelude::Color;
fn some_function() {
// (0.592, 0.337, 0.157) is a dark brown in the non-linear srgb colorspace
// Use `palette` to convert from non-linear to linear
let color_intermediate = Srgb::new(0.592, 0.337, 0.157).into_linear();
// Convert to Bevy's `Color` struct
let color_linear = Color::rgb(color_intermediate.red, color_intermediate.green, color_intermediate.blue) ;
// Now use `color_linear` with Bevy
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-RenderingDrawing game state to the screenDrawing game state to the screenC-FeatureA new feature, making something new possibleA new feature, making something new possible