The Wayback Machine - https://webcf.waybackmachine.org/web/20220312141237/https://github.com/mrdoob/three.js/commit/e6b67d30ba0659b1f16d8b3ef55c360a63d1eead
Skip to content
Permalink
Browse files
WebGPUTextures: Add support for RedFormat and RGFormat.
  • Loading branch information
Mugen87 committed on Sep 25, 2020
1 parent 1f4aeca commit e6b67d30ba0659b1f16d8b3ef55c360a63d1eead
Showing with 54 additions and 1 deletion.
  1. +54 −1 examples/jsm/renderers/webgpu/WebGPUTextures.js
@@ -1,6 +1,6 @@
import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js';
import { CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping,
RGBFormat, RGBAFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, sRGBEncoding
RGBFormat, RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, sRGBEncoding
} from '../../../../build/three.module.js';
import WebGPUTextureUtils from './WebGPUTextureUtils.js';

@@ -501,7 +501,13 @@ class WebGPUTextures {

_getBytesPerTexel( format ) {

if ( format === GPUTextureFormat.R8Unorm ) return 1;
if ( format === GPUTextureFormat.R16Float ) return 2;
if ( format === GPUTextureFormat.RG8Unorm ) return 2;
if ( format === GPUTextureFormat.RG16Float ) return 4;
if ( format === GPUTextureFormat.R32Float ) return 4;
if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return 4;
if ( format === GPUTextureFormat.RG32Float ) return 8;
if ( format === GPUTextureFormat.RGBA16Float ) return 8;
if ( format === GPUTextureFormat.RGBA32Float ) return 16;

@@ -571,6 +577,53 @@ class WebGPUTextures {

break;

case RedFormat:

switch ( type ) {

case UnsignedByteType:
formatGPU = GPUTextureFormat.R8Unorm;
break;

case FloatType:
formatGPU = GPUTextureFormat.R32Float;
break;

case HalfFloatType:
formatGPU = GPUTextureFormat.R16Float;
break;

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

}

break;

case RGFormat:

switch ( type ) {

case UnsignedByteType:
formatGPU = GPUTextureFormat.RG8Unorm;
break;

case FloatType:
formatGPU = GPUTextureFormat.RG32Float;
break;

case HalfFloatType:
formatGPU = GPUTextureFormat.RG16Float;
break;

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

}

break;
break;

This comment has been minimized.

Copy link
@mrdoob

mrdoob on Sep 26, 2020

Owner

Double break to make sure! 😁

This comment has been minimized.

Copy link
@Mugen87

Mugen87 on Sep 26, 2020

Author Collaborator

@Kangz I have a question about the LUMINANCE format in context of WebGPU. When using the RED format and sampling the texture in the shader, only the r color channel has a value (and not g and b). This is not how LuminanceFormat works with WebGL where you write one color value and all color channels get this value. Meaning:

RED: (r) => (r, 0, 0, 1.0)
LUMINANCE: (x) => (x, x, x, 1.0)

Is there a texture format that replaces LUMINANCE (and LUMINANCE_ALPHA)?

This comment has been minimized.

Copy link
@Kangz

Kangz on Sep 26, 2020

There isn't, maybe in the future we'll have texture component swizzling optional feature that allows doing the same thing (using swizzling (red, red, red, 0)) but not yet.


default:
console.error( 'WebGPURenderer: Unsupported texture format.', format );

0 comments on commit e6b67d3

Please sign in to comment.