Skip to content

Commit

Permalink
convert grayscale images to rgb (#1524)
Browse files Browse the repository at this point in the history
Fixes #1518 

Issue was that images loaded as [`ImageLumaA8`](https://docs.rs/image/0.23.13/image/enum.DynamicImage.html#variant.ImageLumaA8) (grayscale with alpha channel) from `image` were considered as [`Rg8Unorm`](https://docs.rs/wgpu/0.7.0/wgpu/enum.TextureFormat.html#variant.Rg8Unorm) (red green channels) from `wgpu`.
Same for `ImageLuma8` (grayscale) that was converted to `R8Unorm` (only red channel).

As `wgpu` doesn't seem to have grayscale texture formats, I converted the grayscale textures to rgba.
  • Loading branch information
mockersf committed Mar 3, 2021
1 parent 319e75c commit 6a0968b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/bevy_render/src/texture/image_texture_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ pub(crate) fn image_to_texture(dyn_img: image::DynamicImage) -> Texture {

match dyn_img {
image::DynamicImage::ImageLuma8(i) => {
let i = image::DynamicImage::ImageLuma8(i).into_rgba8();
width = i.width();
height = i.height();
format = TextureFormat::R8Unorm;
format = TextureFormat::Rgba8UnormSrgb;

data = i.into_raw();
}
image::DynamicImage::ImageLumaA8(i) => {
let i = image::DynamicImage::ImageLumaA8(i).into_rgba8();
width = i.width();
height = i.height();
format = TextureFormat::Rg8Unorm;
format = TextureFormat::Rgba8UnormSrgb;

data = i.into_raw();
}
Expand Down

0 comments on commit 6a0968b

Please sign in to comment.