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

KTX2: unsupported pixel formats R/RG/RGB linear/srgb #4592

Closed
inodentry opened this issue Apr 25, 2022 · 2 comments
Closed

KTX2: unsupported pixel formats R/RG/RGB linear/srgb #4592

inodentry opened this issue Apr 25, 2022 · 2 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@inodentry
Copy link
Contributor

Bevy version: Current main: 989fb8a7

What you did

Created some KTX2 files from source png files (grayscale, grayscale+alpha, RGB) using the toktx tool. No gpu/block texture compression, data is uncompressed (just zstd, but that's irrelevant). Tried to load them in Bevy.

I created a little test project for reproducing the issue: https://github.com/inodentry/bevy_ktx2_test

It contains KTX2 files in a variety of formats. I also created linear versions in addition to sRGB, for good measure.

What you expected to happen

The textures can load and be used for rendering. The spawned sprites appear on-screen.

What actually happened

WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_bevy.ktx2: unsupported texture format: R8_SRGB, this is an error in `bevy_render`.
WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_bevy_linear.ktx2: unsupported texture format: R8_UNORM, this is an error in `bevy_render`.
WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_rust_grey.ktx2: unsupported texture format: R8G8_SRGB, this is an error in `bevy_render`.
WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_rust_grey_linear.ktx2: unsupported texture format: R8G8_UNORM, this is an error in `bevy_render`.
WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_rust_linear.ktx2: unsupported texture format: R8G8B8_UNORM, this is an error in `bevy_render`.
WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file logo_rust.ktx2: unsupported texture format: R8G8B8_SRGB, this is an error in `bevy_render`.
@inodentry inodentry added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Assets Load files from disk to use for things like images, models, and sounds labels Apr 25, 2022
@superdump
Copy link
Contributor

Perfect, thanks for doing this!

@superdump
Copy link
Contributor

So:

  • R8_SRGB would have to be converted to linear and use R8Unorm
  • R8_UNORM should be possible to load as R8Unorm but for some reason I chose to respect the is_srgb flag which is set to true for sprite textures.
  • R8G8_SRGB would have to manually convert it to linear and use Rg8Unorm.
  • R8G8_UNORM should be possible to load as Rg8Unorm but for some reason I chose to respect the is_srgb flag which is set to true for sprite textures.
  • R8G8B8_SRGB would have to have an alpha channel added and use Rgba8UnormSrgb
  • R8G8B8_UNORM would have to have an alpha channel added and use Rgba8Unorm

@bors bors bot closed this as completed in c9a53bf Jan 30, 2023
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
…8_UNORM support (bevyengine#4594)

# Objective

- Fixes bevyengine#4592

## Solution

- Implement `SrgbColorSpace` for `u8` via `f32`
- Convert KTX2 R8 and R8G8 non-linear sRGB to wgpu `R8Unorm` and `Rg8Unorm` as non-linear sRGB are not supported by wgpu for these formats
- Convert KTX2 R8G8B8 formats to `Rgba8Unorm` and `Rgba8UnormSrgb` by adding an alpha channel as the Rgb variants don't exist in wgpu

---

## Changelog

- Added: Support for KTX2 `R8_SRGB`, `R8_UNORM`, `R8G8_SRGB`, `R8G8_UNORM`, `R8G8B8_SRGB`, `R8G8B8_UNORM` formats by converting to supported wgpu formats as appropriate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
Status: Done
2 participants