Skip to content

Commit

Permalink
WebGPUTextures: Support more depth texture types. (mrdoob#25886)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored and emmanueljl committed Apr 28, 2023
1 parent 42339e3 commit 1ac0e98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
23 changes: 21 additions & 2 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension }
import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping, RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthTexture,
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
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType
} from 'three';
import WebGPUTextureUtils from './WebGPUTextureUtils.js';

Expand Down Expand Up @@ -806,7 +806,26 @@ class WebGPUTextures {
break;

case DepthFormat:
formatGPU = GPUTextureFormat.Depth32Float;

switch ( type ) {

case UnsignedShortType:
formatGPU = GPUTextureFormat.Depth16Unorm;
break;

case UnsignedIntType:
formatGPU = GPUTextureFormat.Depth24Plus;
break;

case FloatType:
formatGPU = GPUTextureFormat.Depth32Float;
break;

default:
console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type );

}

break;

default:
Expand Down
12 changes: 4 additions & 8 deletions examples/jsm/renderers/webgpu/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export const GPUTextureFormat = {
Depth24PlusStencil8: 'depth24plus-stencil8',
Depth32Float: 'depth32float',

// 'depth32float-stencil8' extension

Depth32FloatStencil8: 'depth32float-stencil8',

// BC compressed formats usable if 'texture-compression-bc' is both
// supported by the device/user agent and enabled in requestDevice.

Expand Down Expand Up @@ -202,14 +206,6 @@ export const GPUTextureFormat = {
ASTC12x12Unorm: 'astc-12x12-unorm',
ASTC12x12UnormSRGB: 'astc-12x12-unorm-srgb',

// 'depth24unorm-stencil8' extension

Depth24UnormStencil8: 'depth24unorm-stencil8',

// 'depth32float-stencil8' extension

Depth32FloatStencil8: 'depth32float-stencil8',

};

export const GPUAddressMode = {
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_depth_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script type="module">

import * as THREE from 'three';
import { smoothstep, positionView, texture, MeshBasicNodeMaterial } from 'three/nodes';
import { texture, MeshBasicNodeMaterial } from 'three/nodes';

import WebGPU from 'three/addons/capabilities/WebGPU.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
Expand Down

0 comments on commit 1ac0e98

Please sign in to comment.