Skip to content

KTX2Loader: Add support for BC4, BC5 #31713

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

Merged
merged 1 commit into from
Aug 24, 2025

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented Aug 22, 2025

Adds KTX2Loader support for BC4 (R) and BC5 (RG). Fixes a typo in WebGLRenderer previously causing BC4 textures to fail. Adds samples for both in webgl_loader_texture_ktx2.html.

I'm a little confused why the BC5 source image below...

bc4 bc5

... appears in compressed form with green text, rather than black text. But I tried two tools with the same result, so I'm guessing there's something about the format itself I don't understand. A common use case for BC5 would be RG normal maps, as in #31695.

// TODO: Merge the TYPE_MAP warning into the thrown error above, after r190.
if ( TYPE_MAP[ vkFormat ] === undefined ) {

console.warn( 'THREE.KTX2Loader: Missing ".type" for vkFormat: ' + vkFormat );
Copy link
Collaborator Author

@donmccurdy donmccurdy Aug 22, 2025

Choose a reason for hiding this comment

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

Not strictly related but TYPE_MAP was missing many of the entries, causing texture.type to be undefined — surprisingly, nothing broke with undefined .type for compressed textures? But just in case, I've added a check here, and reordered FORMAT_MAP and TYPE_MAP to make it easier to keep them in sync in the future.

Copy link

github-actions bot commented Aug 22, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.1
338.91
79.11
+0 B
+1 B
WebGPU 578.07
159.22
578.07
159.22
+0 B
+0 B
WebGPU Nodes 576.68
158.98
576.68
158.98
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.7
113.91
470.71
113.89
+3 B
-19 B
WebGPU 648.61
175.26
648.61
175.26
+0 B
+0 B
WebGPU Nodes 602.71
164.39
602.71
164.39
+0 B
+0 B

@donmccurdy donmccurdy force-pushed the feat/ktx2loader-bc4-bc5 branch from dd411ce to 96d9e45 Compare August 24, 2025 19:42
@donmccurdy donmccurdy merged commit 503b410 into mrdoob:dev Aug 24, 2025
9 checks passed
@donmccurdy donmccurdy deleted the feat/ktx2loader-bc4-bc5 branch August 24, 2025 19:57
@donmccurdy donmccurdy added this to the r180 milestone Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant