Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color::INDIGO is not indigo #1193

Closed
SeanMcLoughlin opened this issue Jan 2, 2021 · 7 comments
Closed

Color::INDIGO is not indigo #1193

SeanMcLoughlin opened this issue Jan 2, 2021 · 7 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Milestone

Comments

@SeanMcLoughlin
Copy link

SeanMcLoughlin commented Jan 2, 2021

Bevy version

Bevy 4.0.0

Operating system & version

Ubuntu 20.04

What you did

Was looking at the breakout example where a ClearColor resource was added. I noticed the Color struct has some constant values to choose from, including the value INDIGO. When using that value on a simple default app, the color generated is much more purple than indigo. A simple reproducible example:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_resource(ClearColor(Color::INDIGO))
        .run();
}

What you expected to happen

The background color to be indigo.

What actually happened

The background color was purple.

Additional information

My initial search of a hex value for indigo led to #4B0082, which appears to be the programming for Color::INDIGO. Color pickers seem to show that as more of a purple. However I don't want this issue to get heated over the definition of indigo, so do with this info what you will.

Below is what I see when using Color::INDIGO:

Screenshot from 2021-01-02 12-36-44

From a quick Google search, indigo more closely resembles the color below.
image

@mockersf
Copy link
Member

mockersf commented Jan 2, 2021

The colours where added in #859, and should be the HTML colours, so #4B0082 for indigo (how nice of GitHub to render the colour! Seems to be between the two colours in your issue)
In #616, there was a difference made between rbg and rgb_linear

Color::INDIGO is set up using rgb_linear

pub const INDIGO: Color = Color::rgb_linear(0.29, 0.0, 0.51);

If I take the same values and use them as rgb, I get the expected colour:

  .add_resource(ClearColor(Color::rgb(0.29, 0.0, 0.51)))

I'm not very fluent in colour spaces, so would be great if someone that knows those better could take a look at it

@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Jan 4, 2021
@TheZalli
Copy link

TheZalli commented Jan 4, 2021

I've read some on color spaces, but to spare you the details (although I do believe every game programmer should understand the basics about sRGB and gamma correction), when describing colors you most often want to avoid using the linear colors that haven't been gamma corrected. They are used only when mixing and blending colors, and when sending them to the screen (most often done automatically by the GPU in a shader).

When giving color values, they should always be in sRGB (the standard RGB space, aka gamma corrected), and this is the colorspace that all programs use when interfacing with users (the values they give, and what you give).

TLDR:

change it from linear to srbg, which is the Color::rgb function.

Edit: actually looking at it, I guess you can't since Color::rgb_linear is a const function, and Color::rgb isn't, and looking at Rust reference it can't be since it has float operations. I guess just convert the value from sRGB to linear by-hand, and change the function's parameters. And check the other color constants as well, doing the same operation if they're likewise weird looking.

@sburris0
Copy link
Contributor

sburris0 commented Jan 13, 2021

I noticed this and did some testing, rgb_linear() seems to always produce much lighter colors than expected
Color::MIDNIGHT_BLUE is pretty light.

@tigregalis
Copy link
Contributor

tigregalis commented Jan 16, 2021

I grabbed the list of 148 (139*) "named colours" in CSS to generate this code using bevy's own Color functions. Do we want this full list?

This is Indigo:

use bevy::prelude::*;

#[allow(clippy::excessive_precision)]
/// #4B0082 Indigo
pub const INDIGO: Color =
    Color::rgb_linear(0.07036010921001434326171875, 0., 0.223227977752685546875);

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_resource(ClearColor(INDIGO))
        .run();
}

image
image

*duplicates are:

"#00FFFF": [
    "Aqua",
    "Cyan",
],
"#FF00FF": [
    "Fuchsia",
    "Magenta",
],
"#778899": [
    "Light Slate Gray",
    "Light Slate Grey",
],
"#708090": [
    "Slate Gray",
    "Slate Grey",
],
"#808080": [
    "Gray",
    "Grey",
],
"#A9A9A9": [
    "Dark Gray",
    "Dark Grey",
],
"#D3D3D3": [
    "Light Gray",
    "Light Grey",
],
"#696969": [
    "Dim Gray",
    "Dim Grey",
],
"#2F4F4F": [
    "Dark Slate Gray",
    "Dark Slate Grey",
],

@mockersf
Copy link
Member

Do we want this full list?

Yes... and no 😃

The full fix would be to have a const function to create colours with standard rgb hex. To do that, this TODO should be done

// TODO: Separate types for non-linear sRGB and linear sRGB, with conversions between

But fixing the colours to have the correct value in linear until this is done is better than what we have now.

@tigregalis
Copy link
Contributor

tigregalis commented Jan 18, 2021

Do we want this full list?

Yes... and no 😃

So the list that's currently in Bevy is a smaller subset of that.
I'll submit a PR later for all of the CSS colours using the generated values. I personally think it's worth having.

The full fix would be to have a const function to create colours with standard rgb hex. To do that, this TODO should be done

// TODO: Separate types for non-linear sRGB and linear sRGB, with conversions between

But fixing the colours to have the correct value in linear until this is done is better than what we have now.

Maybe I'll have a go at this a bit later on. What should these types be called?

Relevant discussion: #688

@mockersf
Copy link
Member

Maybe I'll have a go at this a bit later on. What should these types be called?

I would go with Color for the standard one that everybody is used to, and LinearColor for the linear variant, that is the one we have currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants