Skip to content

CompressedImageSaver revamp redux#24223

Open
JMS55 wants to merge 55 commits intobevyengine:mainfrom
JMS55:compressed-image-saver3
Open

CompressedImageSaver revamp redux#24223
JMS55 wants to merge 55 commits intobevyengine:mainfrom
JMS55:compressed-image-saver3

Conversation

@JMS55
Copy link
Copy Markdown
Contributor

@JMS55 JMS55 commented May 9, 2026

Redo of #23567 but with:

  • Better normal map handling
  • Better mipmap generation
  • Web assets
  • Fixed docs

@JMS55 JMS55 changed the title Compressed image saver3 CompressedImageSaver revamp redux May 9, 2026
@JMS55 JMS55 added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels May 9, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Assets May 9, 2026
@JMS55 JMS55 added this to the 0.19 milestone May 9, 2026
Comment thread examples/asset/compressed_image_saver.rs
@JMS55 JMS55 added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label May 10, 2026
@JMS55 JMS55 requested a review from andriyDev May 10, 2026 00:02
>>("png");
>>(crate::CompressedImageSaver::default().into());

for file_extension in ["png", "jpeg", "jpg"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's leave that for a followup. Rn exr and hdr textures go through an entirely separate image loader, so processing them would be a little complicated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At least ImageLoader::SUPPORTED_FILE_EXTENSIONS can be used by the processor.

}
// ASTC has no dedicated 2-channel block format; all ASTC blocks are
// RGBA-shaped. Since `compressed_image_saver` writes 2-component normal maps
// when using the ASTC backend, assume ASTC normal maps are 2-component.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code smells.

Astc from users isn't necessarily 2 components, and what about Bc7?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BC7 is 3 channel, not 2 channel.

We're assuming ASTC normal maps are all two channel, because that's what bevy's own asset processor will produce. This should be fine for 99% of users.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BC7 is 4 channels, too. Using less channels can help with compression but VRAM usage doesn't reduce.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

VRAM does reduce with less channels?

But also it's irrelevant for this code. If you use BC7 normal maps, it'll work fine, because StandardMaterialFlags::TWO_COMPONENT_NORMAL_MAP won't get set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does BC7 normal map benefit from 2-components, too?

Copy link
Copy Markdown
Member

@beicause beicause May 10, 2026

Choose a reason for hiding this comment

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

Note the shader is wrong for Astc normal map.

Astc recommends to store normal map as rrrg, but our shader samples .rg, not .ga

(Actually Astc can store 3 components normal, just less precise ARM-software/astc-encoder#278)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Astc recommends to store normal map as rrrg, but our shader samples .rg, not .ga

We don't use rrrg, we do rg01.

Comment thread crates/bevy_image/src/compressed_image_saver/ctt.rs
@JMS55 JMS55 modified the milestones: 0.19, 0.20 May 10, 2026
/// edges. See the field docs for details.
#[derive(TypePath, Default)]
#[expect(clippy::doc_markdown, reason = "clippy does not like unquoted BCn")]
pub struct CompressedImageSaver {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still dislike wrapping two saver in one and making ctt saver and basisu saver exclusive:

  1. Each AssetSaver should be independent. Both ctt saver and basisu saver can be used by plugins.
  2. Asset processor is exclusive for the same file but users can choose the processor by meta file.

I think ctt and basisu should be split into two processors.

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 C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants