Skip to content

Commit e9b3145

Browse files
authored
KTX2Loader: Support RGB9E5 (#31611)
1 parent 67b9093 commit e9b3145

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

examples/jsm/loaders/KTX2Loader.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import {
2626
RGB_ETC2_Format,
2727
RGB_PVRTC_4BPPV1_Format,
2828
RGB_S3TC_DXT1_Format,
29+
RGBFormat,
2930
RGFormat,
3031
RedFormat,
3132
SRGBColorSpace,
32-
UnsignedByteType
33+
UnsignedByteType,
34+
UnsignedInt5999Type
3335
} from 'three';
3436
import { WorkerPool } from '../utils/WorkerPool.js';
3537
import {
@@ -70,6 +72,7 @@ import {
7072
VK_FORMAT_R8G8_UNORM,
7173
VK_FORMAT_R8_SRGB,
7274
VK_FORMAT_R8_UNORM,
75+
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
7376
VK_FORMAT_UNDEFINED
7477
} from '../libs/ktx-parse.module.js';
7578
import { ZSTDDecoder } from '../libs/zstddec.module.js';
@@ -918,7 +921,7 @@ KTX2Loader.BasisWorker = function () {
918921
// Parsing for non-Basis textures. These textures may have supercompression
919922
// like Zstd, but they do not require transcoding.
920923

921-
const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGFormat, RedFormat ] );
924+
const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGBFormat, RGFormat, RedFormat ] );
922925

923926
const FORMAT_MAP = {
924927

@@ -937,6 +940,8 @@ const FORMAT_MAP = {
937940
[ VK_FORMAT_R8_SRGB ]: RedFormat,
938941
[ VK_FORMAT_R8_UNORM ]: RedFormat,
939942

943+
[ VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 ]: RGBFormat,
944+
940945
[ VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK ]: RGB_ETC2_Format,
941946
[ VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK ]: RGBA_ETC2_EAC_Format,
942947

@@ -979,6 +984,8 @@ const TYPE_MAP = {
979984
[ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
980985
[ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
981986

987+
[ VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 ]: UnsignedInt5999Type,
988+
982989
[ VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK ]: UnsignedByteType,
983990
[ VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK ]: UnsignedByteType,
984991

@@ -1071,6 +1078,16 @@ async function createRawTexture( container ) {
10711078

10721079
);
10731080

1081+
} else if ( TYPE_MAP[ vkFormat ] === UnsignedInt5999Type ) {
1082+
1083+
data = new Uint32Array(
1084+
1085+
levelData.buffer,
1086+
levelData.byteOffset,
1087+
levelData.byteLength / Uint32Array.BYTES_PER_ELEMENT
1088+
1089+
);
1090+
10741091
} else {
10751092

10761093
data = levelData;
8.71 KB
Binary file not shown.

examples/webgl_loader_texture_ktx2.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
{ path: '2d_rgba8_linear.ktx2' },
101101
{ path: '2d_rgba16_linear.ktx2' },
102102
{ path: '2d_rgba32_linear.ktx2' },
103+
{ path: '2d_rgb9e5_linear.ktx2' },
103104
]
104105
},
105106
{

0 commit comments

Comments
 (0)