Skip to content

Commit 1ac0e98

Browse files
Mugen87emmanueljl
authored andcommitted
WebGPUTextures: Support more depth texture types. (mrdoob#25886)
1 parent 42339e3 commit 1ac0e98

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

examples/jsm/renderers/webgpu/WebGPUTextures.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension }
22
import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping, RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
33
RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthTexture,
44
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,
5-
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format
5+
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType
66
} from 'three';
77
import WebGPUTextureUtils from './WebGPUTextureUtils.js';
88

@@ -806,7 +806,26 @@ class WebGPUTextures {
806806
break;
807807

808808
case DepthFormat:
809-
formatGPU = GPUTextureFormat.Depth32Float;
809+
810+
switch ( type ) {
811+
812+
case UnsignedShortType:
813+
formatGPU = GPUTextureFormat.Depth16Unorm;
814+
break;
815+
816+
case UnsignedIntType:
817+
formatGPU = GPUTextureFormat.Depth24Plus;
818+
break;
819+
820+
case FloatType:
821+
formatGPU = GPUTextureFormat.Depth32Float;
822+
break;
823+
824+
default:
825+
console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type );
826+
827+
}
828+
810829
break;
811830

812831
default:

examples/jsm/renderers/webgpu/constants.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export const GPUTextureFormat = {
138138
Depth24PlusStencil8: 'depth24plus-stencil8',
139139
Depth32Float: 'depth32float',
140140

141+
// 'depth32float-stencil8' extension
142+
143+
Depth32FloatStencil8: 'depth32float-stencil8',
144+
141145
// BC compressed formats usable if 'texture-compression-bc' is both
142146
// supported by the device/user agent and enabled in requestDevice.
143147

@@ -202,14 +206,6 @@ export const GPUTextureFormat = {
202206
ASTC12x12Unorm: 'astc-12x12-unorm',
203207
ASTC12x12UnormSRGB: 'astc-12x12-unorm-srgb',
204208

205-
// 'depth24unorm-stencil8' extension
206-
207-
Depth24UnormStencil8: 'depth24unorm-stencil8',
208-
209-
// 'depth32float-stencil8' extension
210-
211-
Depth32FloatStencil8: 'depth32float-stencil8',
212-
213209
};
214210

215211
export const GPUAddressMode = {

examples/webgpu_depth_texture.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<script type="module">
2727

2828
import * as THREE from 'three';
29-
import { smoothstep, positionView, texture, MeshBasicNodeMaterial } from 'three/nodes';
29+
import { texture, MeshBasicNodeMaterial } from 'three/nodes';
3030

3131
import WebGPU from 'three/addons/capabilities/WebGPU.js';
3232
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';

0 commit comments

Comments
 (0)