Skip to content

KTX2Loader: Support RGBA 16-bit unsigned normalized formats#33245

Open
donmccurdy wants to merge 1 commit intomrdoob:devfrom
donmccurdy:feat/ktx2loader-rgba16unorm
Open

KTX2Loader: Support RGBA 16-bit unsigned normalized formats#33245
donmccurdy wants to merge 1 commit intomrdoob:devfrom
donmccurdy:feat/ktx2loader-rgba16unorm

Conversation

@donmccurdy
Copy link
Copy Markdown
Collaborator

Adds support for KTX2 files containing vkFormat = VK_FORMAT_R16G16B16A16_UNORM. Support for R, RG, RGB, and equivalent SNORM types is left open for PRs, as I don't have textures in these formats yet. The texture included here was produced with OpenImageIO and KTX-Software:

# convert 8-bit PNG to 16-bit PNG (for testing only)
oiiotool uint8.png --iscolorspace srgb --tocolorspace lin_rec709_srgb -d uint16 -o uint16.png

# convert 16-bit PNG to RGBA16 UNORM KTX2
ktx create --format R16G16B16A16_UNORM --assign-tf linear --assign-primaries bt709 --generate-mipmap uint16.png rgba16_unorm.ktx2

Related:

@github-actions
Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 360.01
85.46
360.07
85.47
+65 B
+17 B
WebGPU 633.22
175.54
633.22
175.54
+0 B
+0 B
WebGPU Nodes 631.34
175.25
631.34
175.25
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 492.21
120.03
492.28
120.05
+65 B
+20 B
WebGPU 705.25
190.44
705.25
190.44
+0 B
+0 B
WebGPU Nodes 654.47
177.68
654.47
177.68
+0 B
+0 B

if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = extensions.get( 'EXT_texture_norm16' ).RGBA16_EXT;
Copy link
Copy Markdown
Collaborator

@Mugen87 Mugen87 Mar 26, 2026

Choose a reason for hiding this comment

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

Do you mind adding this line in below module, too?

if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? gl.SRGB8_ALPHA8 : gl.RGBA8;
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4;

In this way, the WebGL 2 backend of WebGPURenderer support this feature as well.

The WebGPU backend should already cover this use case here:

case UnsignedShortType:
formatGPU = GPUTextureFormat.RGBA16Uint;
break;

Edit: RGBA16Uint is obviously the wrong format. Alternative suggestion: #33250 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants