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

Write release note for PR 10392 (CPU Drawing) #1854

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions release-content/0.15/release-notes/10392_CPU_Drawing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
There are many situations where you might want to just set the color of pixels
from CPU code. Procedural assets, certain art styles, or simply because
it is easier. No need to bother with shaders and materials, when you just want
to change a few specific pixels!

In previous versions of Bevy, this was difficult and tedious. Bevy gives you
access to the raw data bytes of an [`Image`], but you had to compute the byte
offset corresponding to your desired pixel coordinate, make sure to encode your
bytes with respect to the [`TextureFormat`], etc. Very low level!

In Bevy 0.15, there are now user-friendly APIs for reading and writing the
colors of pixels in an [`Image`]. The tricky low-level details are dealt with
for you! You can even use `bevy_color`'s fancy color space APIs!

```rust
fn my_system(mut images: ResMut<Assets<Image>>, mut commands: Commands) {
// Create a new image.
let mut image = Image::new_fill(
// 64x64 size
Extent3d {
width: 64,
height: 64,
depth_or_array_layers: 1,
},
TextureDimension::D2,
&Srgba::WHITE.to_u8_array(),
TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::all(),
);

// This is new:

// Make the pixel at x: 23, y: 32 magenta
image.set_color_at(23, 32, Color::srgb(1.0, 0.0, 1.0))
.expect("Error writing color");

// Set the pixel at 10,10 to a color specified using the Oklch color space:
image.set_color_at(10, 10, Color::oklch(0.3, 0.2, 0.5))
.expect("Error writing color");

// read the bytes of the pixel we just wrote:
let bytes = image.pixel_bytes(UVec3::new(10, 10, 0)).unwrap();

// read the (approximate) color back (as sRGB):
let color = image.get_color_at(10, 10);

// We could add our new image to Bevy's assets
// and spawn a sprite to display it:
commands.spawn(Sprite {
image: images.add(image),
..default()
});
}
```

Note: The [`Color`]-based methods are lossy. They have to convert to/from the
[`Image`]'s [`TextureFormat`]. If you read back the color you wrote, it will be slightly different.

[`Image`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/prelude/struct.Image.html
[`TextureFormat`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/render/render_resource/enum.TextureFormat.html
[`Color`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/color/enum.Color.html
7 changes: 7 additions & 0 deletions release-content/0.15/release-notes/_release-notes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ contributors = ["@kristoff3r", "@tychedelia", "@JMS55"]
prs = [14876]
file_name = "14876_Add_Order_Independent_Transparency.md"

[[release_notes]]
Copy link
Member

Choose a reason for hiding this comment

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

We should probably move this down (it's not the most important change), but we need to do a reordering pass anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's up to you.

I just put it at the end of the graphics/rendering related stuff. The order: "Required components (most important change) -> a bunch of graphics/visual related stuff -> this PR (vaguely related to drawing/visuals) -> other stuff" made sense to me. :)

But feel free to reorder it wherever you like.

title = "User-Friendly CPU Drawing"
authors = ["@inodentry"]
contributors = []
prs = [10392]
file_name = "10392_CPU_Drawing.md"

[[release_notes]]
title = "Entity Picking / Selection"
authors = ["@aevyrie", "@NthTensor", "@TotalKrill", "@jnhyatt", "@Jondolf"]
Expand Down