From eb40c69fb463e151883c589859b712e3ee75df40 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Mon, 25 Aug 2025 13:35:04 +0200 Subject: [PATCH] WebGPURenderer: Add support for BC4 and BC5 texture compression. --- examples/webgpu_loader_texture_ktx2.html | 3 ++- .../webgl-fallback/utils/WebGLUtils.js | 2 +- .../webgpu/utils/WebGPUTextureUtils.js | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/webgpu_loader_texture_ktx2.html b/examples/webgpu_loader_texture_ktx2.html index 9cf0fa3499b45f..e4c8fc307a6c59 100644 --- a/examples/webgpu_loader_texture_ktx2.html +++ b/examples/webgpu_loader_texture_ktx2.html @@ -117,7 +117,8 @@ { path: '2d_etc2.ktx2' }, { path: '2d_bc1.ktx2' }, { path: '2d_bc3.ktx2' }, - // { path: '2d_bc5.ktx2' }, + { path: '2d_bc4.ktx2' }, + { path: '2d_bc5.ktx2' }, { path: '2d_bc7.ktx2' }, ] }, diff --git a/src/renderers/webgl-fallback/utils/WebGLUtils.js b/src/renderers/webgl-fallback/utils/WebGLUtils.js index ace9be5229c004..b3c06225c309c4 100644 --- a/src/renderers/webgl-fallback/utils/WebGLUtils.js +++ b/src/renderers/webgl-fallback/utils/WebGLUtils.js @@ -232,7 +232,7 @@ class WebGLUtils { if ( extension !== null ) { - if ( p === RGBA_BPTC_Format ) return extension.COMPRESSED_RED_RGTC1_EXT; + if ( p === RED_RGTC1_Format ) return extension.COMPRESSED_RED_RGTC1_EXT; if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT; if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT; if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT; diff --git a/src/renderers/webgpu/utils/WebGPUTextureUtils.js b/src/renderers/webgpu/utils/WebGPUTextureUtils.js index 5f1426ef372989..a8a6ad8a23badc 100644 --- a/src/renderers/webgpu/utils/WebGPUTextureUtils.js +++ b/src/renderers/webgpu/utils/WebGPUTextureUtils.js @@ -14,7 +14,7 @@ import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedInt5999Type, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat, - UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format + UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format } from '../../../constants.js'; import { CubeTexture } from '../../../textures/CubeTexture.js'; import { DepthTexture } from '../../../textures/DepthTexture.js'; @@ -1140,6 +1140,22 @@ export function getFormat( texture, device = null ) { formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm; break; + case RED_RGTC1_Format: + formatGPU = GPUTextureFormat.BC4RUnorm; + break; + + case SIGNED_RED_RGTC1_Format: + formatGPU = GPUTextureFormat.BC4RSnorm; + break; + + case RED_GREEN_RGTC2_Format: + formatGPU = GPUTextureFormat.BC5RGUnorm; + break; + + case SIGNED_RED_GREEN_RGTC2_Format: + formatGPU = GPUTextureFormat.BC5RGSnorm; + break; + case RGBA_BPTC_Format: formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC7RGBAUnormSRGB : GPUTextureFormat.BC7RGBAUnorm; break;