Migrate from LegacyColor to bevy_color::Color#12163
Merged
alice-i-cecile merged 58 commits intobevyengine:mainfrom Feb 29, 2024
Merged
Migrate from LegacyColor to bevy_color::Color#12163alice-i-cecile merged 58 commits intobevyengine:mainfrom
LegacyColor to bevy_color::Color#12163alice-i-cecile merged 58 commits intobevyengine:mainfrom
Conversation
viridia
suggested changes
Feb 27, 2024
cart
reviewed
Feb 27, 2024
Contributor
bushrat011899
left a comment
There was a problem hiding this comment.
Looking good so far!
| arc_angle, | ||
| radius, | ||
| color, | ||
| color: color.into(), |
Contributor
There was a problem hiding this comment.
Might need to do some performance testing to confirm, but we probably need to go back over the various From implementations an annotate them with #[inline]. I'm not sure how good the Rust compiler is at inlining these tiny functions.
Member
Author
There was a problem hiding this comment.
Yeah agreed. I want to do perf testing towards the end of this process.
This was referenced Feb 27, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 28, 2024
# Objective As suggested in #12163 by @cart, we should add convenience constructors to `bevy_color::Color` to match the existing API (easing migration pain) and generally improve ergonomics. ## Solution - Add `const fn Color::rgba(red, green, blue, alpha)` and friends, which directly construct the appropriate variant. - Add `const fn Color::rgb(red, green, blue)` and friends, which impute and alpha value of 1.0. - Add `const BLACK, WHITE, NONE` to `Color`. These are stored in `LinearRgba` to reduce pointless conversion costs and inaccuracy. - Changed the default `Color` from `Srgba::WHITE` to the new linear equivalent for the same reason. --------- Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
ac56d67 to
e00b6bd
Compare
viridia
approved these changes
Feb 28, 2024
This was referenced Mar 1, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 1, 2024
# Objective - bloom is not working anymore in 3d after #12163 ## Solution - Fix a copy paste mistake and use emissive for the emissive
This was referenced Mar 2, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 2, 2024
# Objective - Copy paste error in #12163 ## Solution - Fix it
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 3, 2024
# Objective - Since #12163 example lightmaps is more dull <img width="1280" alt="Screenshot 2024-03-02 at 23 04 36" src="https://github.com/bevyengine/bevy/assets/8672791/7736f420-b9c5-4870-93f6-b5b992c4768a"> ## Solution - Use a srgba color, as it was before: https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/examples/3d/lightmaps.rs#L39 https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/crates/bevy_render/src/color/mod.rs#L132 <img width="1280" alt="Screenshot 2024-03-02 at 23 05 09" src="https://github.com/bevyengine/bevy/assets/8672791/451187ed-8612-456f-ad25-180d5f774188">
spectria-limina
pushed a commit
to spectria-limina/bevy
that referenced
this pull request
Mar 9, 2024
) # Objective - bloom is not working anymore in 3d after bevyengine#12163 ## Solution - Fix a copy paste mistake and use emissive for the emissive
spectria-limina
pushed a commit
to spectria-limina/bevy
that referenced
this pull request
Mar 9, 2024
…e#12266) # Objective - Copy paste error in bevyengine#12163 ## Solution - Fix it
spectria-limina
pushed a commit
to spectria-limina/bevy
that referenced
this pull request
Mar 9, 2024
# Objective - Since bevyengine#12163 example lightmaps is more dull <img width="1280" alt="Screenshot 2024-03-02 at 23 04 36" src="https://github.com/bevyengine/bevy/assets/8672791/7736f420-b9c5-4870-93f6-b5b992c4768a"> ## Solution - Use a srgba color, as it was before: https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/examples/3d/lightmaps.rs#L39 https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/crates/bevy_render/src/color/mod.rs#L132 <img width="1280" alt="Screenshot 2024-03-02 at 23 05 09" src="https://github.com/bevyengine/bevy/assets/8672791/451187ed-8612-456f-ad25-180d5f774188">
Merged
ChristopherBiscardi
added a commit
to ChristopherBiscardi/bevy_ecs_tilemap
that referenced
this pull request
Jun 7, 2024
[12163](bevyengine/bevy#12163) bevy_color was created and Color handling has changed. Specifically Color::as_linear_rgba_f32 has been removed. LinearRgba is now its own type that can be accessed via [`linear()`](https://docs.rs/bevy/0.14.0-rc.2/bevy/color/enum.Color.html#method.linear) and then converted.
zhaop
added a commit
to zhaop/bevy_editor_pls
that referenced
this pull request
Jun 24, 2024
Addresses Bevy [12163](bevyengine/bevy#12163)
zhaop
added a commit
to zhaop/bevy_editor_pls
that referenced
this pull request
Jun 24, 2024
Addresses Bevy [12163](bevyengine/bevy#12163)
zhaop
added a commit
to zhaop/bevy_editor_pls
that referenced
this pull request
Jun 25, 2024
Addresses Bevy [12163](bevyengine/bevy#12163)
rparrett
added a commit
to StarArawn/bevy_ecs_tilemap
that referenced
this pull request
Jul 5, 2024
* Update to 0.14.0-rc.2 * [12997](bevyengine/bevy#12997): rename `multi-threaded` to `multi_threaded` * RenderAssets<Image> is now RenderAssets<GpuImage> Implemented in [12827](bevyengine/bevy#12827) * FloatOrd is now in bevy_math implemented in [12732](bevyengine/bevy#12732) * convert Transparent2d::dynamic_offset to extra_index [12889](bevyengine/bevy#12889) Gpu Frustum Culling removed the dynamic_offset of Transparent2d and it became `extra_index` with the special value `PhaseItemExtraIndex::NONE`, which indicates the `None` that was here previously * RenderPhase<Transparent2d> -> ViewSortedRenderPhases<Transparent2d> [12453](https://github.com/StarArawn/bevy_ecs_tilemap/pull/bevyengine/bevy#12453): Render phases are now binned or sorted. Following the changes in the `mesh2d_manual` [example](https://github.com/bevyengine/bevy/blob/ecdd1624f302c5f71aaed95b0984cbbecf8880b7/examples/2d/mesh2d_manual.rs#L357-L358): use the `ViewSortedRenderPhases` resource. * get_sub_app_mut is now an Option in [9202](https://github.com/StarArawn/bevy_ecs_tilemap/pull/bevyengine/bevy/pull/9202) SubApp access has changed * GpuImage::size f32 -> u32 via UVec2 [11698](bevyengine/bevy#11698) changed `GpuImage::size` to `UVec2`. Right above this, `Extent3d` does the same thing, so I'm taking a small leap and assuming can `as`. * GpuMesh::primitive_topology -> key_bits/BaseMeshPipeline [12791](bevyengine/bevy#12791) the `primitive_topology` field on `GpuMesh` was removed in favor of `key_bits` which can be constructed using `BaseMeshPipeline::from_primitive_topology` * RenderChunk2d::prepare requires &mut MeshVertexBufferLayouts now [12216](bevyengine/bevy#12216) introduced an argument `&mut MeshVertexBufferLayouts` to `get_mesh_vertex_buffer_layout`, which bevy_ecs_tilemap calls in `RenderChunk2d::prepare` * into_linear_f32 -> color.0.linear().to_f32_array(), [12163](bevyengine/bevy#12163) bevy_color was created and Color handling has changed. Specifically Color::as_linear_rgba_f32 has been removed. LinearRgba is now its own type that can be accessed via [`linear()`](https://docs.rs/bevy/0.14.0-rc.2/bevy/color/enum.Color.html#method.linear) and then converted. * Must specify type of VisibleEntities when accessing [12582](bevyengine/bevy#12582) divided `VisibleEntities` into separate lists. So now we have to specify which kind of entity we want. I think we want the Mesh here, and I think we can get rid of the `.index` calls on Entity since Entity [already compares bits](https://docs.rs/bevy_ecs/0.14.0-rc.2/src/bevy_ecs/entity/mod.rs.html#173) for optimized codegen purposes. Waiting to do that until the other changes are in though so as to not change functionality until post-upgrade. * app.world access is functions now - [9202](bevyengine/bevy#9202) changed world access to functions. [relevent line](https://github.com/bevyengine/bevy/pull/9202/files#diff-b2fba3a0c86e496085ce7f0e3f1de5960cb754c7d215ed0f087aa556e529f97fR640) - This also surfaced [12655](bevyengine/bevy#12655) which removed `Into<AssetId<T>>` for `Handle<T>`. using a reference or .id() is the solution here. * We don't need `World::cell`, and it doesn't exist anymore In [12551](bevyengine/bevy#12551) `WorldCell` was removed. ...but it turns out we don't need it or its replacement anyway. * examples error out unless this bevy bug is addressed with these features being added bevyengine/bevy#13728 * check_visibility is required for the entity that is renderable As a result of [12582](bevyengine/bevy#12582) `check_visibility` must be implemented for the "renderable" tilemap entities. Doing this is trivial by taking advantage of the existing `check_visibility` type arguments, which accept a [`QF: QueryFilter + 'static`](https://docs.rs/bevy/0.14.0-rc.2/bevy/render/view/fn.check_visibility.html). The same `QueryFilter`` is used when checking `VisibleEntities`. I've chosen `With<TilemapRenderSettings` because presumably if the entity doesn't have a `TilemapRenderSettings` then it will not be rendering, but this could be as sophisticated or simple as we want. For example `WithLight` is currently implemented as ```rust pub type WithLight = Or<(With<PointLight>, With<SpotLight>, With<DirectionalLight>)>; ``` * view.view_proj -> view.clip_from_world [13289](bevyengine/bevy#13489) introduced matrix naming changes, including `view_proj` which becomes `clip_from_world` * color changes to make tests runnable * clippy fix * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * final clippy fixes * Update Cargo.toml Co-authored-by: Rob Parrett <robparrett@gmail.com> * Simplify async loading in ldtk/tiled helpers See Bevy #12550 * remove second allow lint * rc.3 bump * bump version for major release * remove unused features --------- Co-authored-by: Rob Parrett <robparrett@gmail.com>
5 tasks
zhaop
added a commit
to zhaop/transform-gizmo
that referenced
this pull request
Jul 6, 2024
Addresses Bevy #12163 (bevyengine/bevy#12163)
zhaop
added a commit
to zhaop/transform-gizmo
that referenced
this pull request
Jul 6, 2024
Addresses Bevy #12163 (bevyengine/bevy#12163)
zhaop
added a commit
to zhaop/bevy_editor_pls
that referenced
this pull request
Jul 7, 2024
Addresses Bevy #12163 (bevyengine/bevy#12163)
jakobhellermann
pushed a commit
to jakobhellermann/bevy_editor_pls
that referenced
this pull request
Aug 11, 2024
Addresses Bevy [12163](bevyengine/bevy#12163)
jakobhellermann
pushed a commit
to jakobhellermann/bevy_editor_pls
that referenced
this pull request
Aug 11, 2024
Addresses Bevy [12163](bevyengine/bevy#12163)
jakobhellermann
pushed a commit
to jakobhellermann/bevy_editor_pls
that referenced
this pull request
Aug 11, 2024
Addresses Bevy #12163 (bevyengine/bevy#12163)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
LegacyColorin one PR, being careful to keep a clean commit history.Solution
I've chosen to use the polymorphic
Colortype as our standard user-facing API.bevy_gizmos.impl Into<Color>in allbevy_gizmosAPIsColorMaterialMaterialMesh2DLegacyColorIncidental improvements to ease migration:
Color::srgba_u8,Color::srgba_from_arrayand friendsset_alpha,is_fully_transparentandis_fully_opaqueto theAlphatraitColor::rgband friends in favor of more explicit and consistentColor::srgbLinearRgba:Add,Sub,AddAssign,SubAssign,Mul<f32>andDiv<f32>. Multiplications and divisions do not scale alpha.AddandSubhave been cut from this PR.LinearRgbaandSrgbaRED/GREEN/BLUELinearRgba_to_f32_arrayandLinearRgba::to_u32Migration Guide
Bevy's color types have changed! Wherever you used a
bevy::render::Color, abevy::color::Coloris used instead.These are quite similar! Both are enums storing a color in a specific color space (or to be more precise, using a specific color model). However, each of the different color models now has its own type.
TODO...
Color::rgba,Color::rgb,Color::rbga_u8,Color::rgb_u8,Color::rgb_from_arrayare nowColor::srgba,Color::srgb,Color::srgba_u8,Color::srgb_u8andColor::srgb_from_array.Color::set_aandColor::ais nowColor::set_alphaandColor::alpha. These are part of theAlphatrait inbevy_color.Color::is_fully_transparentis now part of theAlphatrait inbevy_colorColor::r,Color::set_r,Color::with_rand the equivalents forg,bh,sandlhave been removed due to causing silent relatively expensive conversions. Convert yourColorinto the desired color space, perform your operations there, and then convert it back into a polymorphicColorenum.Color::hexis nowSrgba::hex. Call.intoor construct aColor::Srgbavariant manually to convert it.WireframeMaterial,ExtractedUiNode,ExtractedDirectionalLight,ExtractedPointLight,ExtractedSpotLightandExtractedSpritenow store aLinearRgba, rather than a polymorphicColorColor::rgb_linearandColor::rgba_linearare nowColor::linear_rgbandColor::linear_rgbaColor. Instead, they're defined in theSrgbacolor space, and accessed viabevy::color::palettes::css. Call.into()on them to convert them into aColorfor quick debugging use, and consider using the much prettiertailwindpalette for prototyping.LIME_GREENcolor has been renamed toLIMEGREENto comply with the standard naming.Color(add, subtract, multiply and divide by a f32) have been removed. Instead, convert your colors intoLinearRgbaspace, and perform your operations explicitly there. This is particularly relevant when working with emissive or HDR colors, whose color channel values are routinely outside of the ordinary 0 to 1 range.Color::as_linear_rgba_f32has been removed. CallLinearRgba::to_f32_arrayinstead, converting if needed.Color::as_linear_rgba_u32has been removed. CallLinearRgba::to_u32instead, converting if needed.Vectypes have been removed. Please reimplement these externally or open a PR to re-add them if you found them particularly useful.Colorsuch asrgborhslto convert the color into a specific color space have been removed. Convert intoLinearRgba, then to the color space of your choice.Colorsuch asr,g,borhhave been removed. Please convert it into the color space of your choice, then check these properties.Colorno longer implementsAsBindGroup. Store aLinearRgbainternally instead to avoid conversion costs.