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

Why does Color::rgb use f32 instead of u8? #364

Closed
wyhaya opened this issue Aug 27, 2020 · 5 comments · Fixed by #381
Closed

Why does Color::rgb use f32 instead of u8? #364

wyhaya opened this issue Aug 27, 2020 · 5 comments · Fixed by #381
Labels
A-Rendering Drawing game state to the screen

Comments

@wyhaya
Copy link
Contributor

wyhaya commented Aug 27, 2020

u8:

Color::rgb(0, 0, 0);
Color::rgb(255, 255, 255);
Color::rgb(3, 169, 244);

In many cases, rgb uses numbers from 0-255, and using u8 will not appear invalid colors

f32:

Color::rgb(312312321.312, 312312.0, 654645.1231);

f32 cannot verify the correctness of the value

@karroffel karroffel added question A-Rendering Drawing game state to the screen labels Aug 27, 2020
@karroffel
Copy link
Contributor

What values are useful depends on the situation. HDR rendering and HDR images for example (high dynamic range) need to be able to go above 1.0, so going with f32 means you can have higher dynamic range than when using a normalised u8.

@wyhaya
Copy link
Contributor Author

wyhaya commented Aug 27, 2020

@karroffel Thank you for your reply.

This is a very common one. Is it necessary to add Color:from_u8(255, 255, 255) or similar methods? It should be more convenient to use rgb in this way.

@karroffel
Copy link
Contributor

I'm sure a function like that can be added, I wouldn't think that should be a problem :)

I personally don't use normalised u8s often to describe colour values, to me a range from 0.0 to 1.0 is more intuitive, unless you are dealing with serialisation code or direct image formats. But if a from_u8 methods makes code clearer in some cases then I would expect that to be a welcome addition

@cart
Copy link
Member

cart commented Aug 27, 2020

Yeah we do need floats in some cases. But from_u8 would be very welcome!

@ncallaway
Copy link
Contributor

I'd suggest normalizing with the Color::rgb and Color::rgba functions, so something like Color::rgb_u8() and Color::rgba_u8()

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants