Skip to content

Convert colors from srgb to linear srgb automatically #585

@CleanCut

Description

@CleanCut

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions