Skip to content

Conversation

@alice-i-cecile
Copy link
Member

@alice-i-cecile alice-i-cecile commented Feb 26, 2024

Objective

Solution

  • Port all uses of LegacyColor in the bevy_core_pipeline to LinearRgba
  • LinearRgba is the correct type to use for internal rendering types
  • Added LinearRgba::BLACK and WHITE (used during migration)
  • Add LinearRgba::grey to more easily construct balanced grey colors (used during migration)
  • Add a conversion from LinearRgba to wgpu::Color. The converse was not done at this time, as this is typically a user error.

I did not change the field type of the clear color on the cameras: as this is user-facing, this should be done in concert with the other configurable fields.

Migration Guide

ColorAttachment now stores a LinearRgba color, rather than a Bevy 0.13 Color.
set_blend_constant now takes a LinearRgba argument, rather than a Bevy 0.13 Color.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Feb 26, 2024
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

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

One really great thing about having this baked into the type system is that we're not paying for the cost of conversion or the branches within the color itself inside the renderer.

Copy link
Contributor

@viridia viridia left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Look good to me! I'm glad we can start being more explicit through the type system around what colour spaces certain areas of Bevy want/need.

Comment on lines +231 to +240
impl From<LinearRgba> for wgpu::Color {
fn from(color: LinearRgba) -> Self {
wgpu::Color {
r: color.red as f64,
g: color.green as f64,
b: color.blue as f64,
a: color.alpha as f64,
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since bevy_color is our new color management library specifically for Bevy, would it be worth moving to f64 internally to avoid this casting? The extra precision will eat up more memory, but also expose the full precision of wgpu to end users.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question. I think that should be investigated after migration: then we can get both benchmark results and see if there's meaningfully improved color fidelity or numerical stability.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably won't make a big difference on the code-path where wgpu almost immediately casts the color back to a f32 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, at this rate I guess we're getting bevy_wgpu

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 26, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 26, 2024
Merged via the queue into bevyengine:main with commit 8ec6552 Feb 26, 2024
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- We should move towards a consistent use of the new `bevy_color` crate.
- As discussed in bevyengine#12089, splitting this work up into small pieces makes
it easier to review.

## Solution

- Port all uses of `LegacyColor` in the `bevy_core_pipeline` to
`LinearRgba`
- `LinearRgba` is the correct type to use for internal rendering types
- Added `LinearRgba::BLACK` and `WHITE` (used during migration)
- Add `LinearRgba::grey` to more easily construct balanced grey colors
(used during migration)
- Add a conversion from `LinearRgba` to `wgpu::Color`. The converse was
not done at this time, as this is typically a user error.

I did not change the field type of the clear color on the cameras: as
this is user-facing, this should be done in concert with the other
configurable fields.

## Migration Guide

`ColorAttachment` now stores a `LinearRgba` color, rather than a Bevy
0.13 `Color`.
`set_blend_constant` now takes a `LinearRgba` argument, rather than a
Bevy 0.13 `Color`.

---------

Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- We should move towards a consistent use of the new `bevy_color` crate.
- As discussed in bevyengine#12089, splitting this work up into small pieces makes
it easier to review.

## Solution

- Port all uses of `LegacyColor` in the `bevy_core_pipeline` to
`LinearRgba`
- `LinearRgba` is the correct type to use for internal rendering types
- Added `LinearRgba::BLACK` and `WHITE` (used during migration)
- Add `LinearRgba::grey` to more easily construct balanced grey colors
(used during migration)
- Add a conversion from `LinearRgba` to `wgpu::Color`. The converse was
not done at this time, as this is typically a user error.

I did not change the field type of the clear color on the cameras: as
this is user-facing, this should be done in concert with the other
configurable fields.

## Migration Guide

`ColorAttachment` now stores a `LinearRgba` color, rather than a Bevy
0.13 `Color`.
`set_blend_constant` now takes a `LinearRgba` argument, rather than a
Bevy 0.13 `Color`.

---------

Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
@BD103 BD103 added the A-Color Color spaces and color math label May 3, 2024
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 A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants