Skip to content

Commit 2e0ab70

Browse files
Mugen87RuthySheffi
authored andcommitted
WebGPURenderer: Honor Texture.premultiplyAlpha in WebGPU backend. (mrdoob#31157)
1 parent 568fc43 commit 2e0ab70

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

src/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
RGBAFormat, RGBFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBTransfer, DepthFormat, DepthStencilFormat,
1414
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,
1515
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedInt5999Type,
16-
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat,
17-
CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping
16+
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat
1817
} from '../../../constants.js';
1918
import { CubeTexture } from '../../../textures/CubeTexture.js';
2019
import { DepthTexture } from '../../../textures/DepthTexture.js';
@@ -479,7 +478,7 @@ class WebGPUTextureUtils {
479478

480479
} else if ( texture.isCubeTexture ) {
481480

482-
this._copyCubeMapToTexture( options.images, textureData.texture, textureDescriptorGPU, texture.flipY );
481+
this._copyCubeMapToTexture( options.images, textureData.texture, textureDescriptorGPU, texture.flipY, texture.premultiplyAlpha );
483482

484483
} else if ( texture.isVideoTexture ) {
485484

@@ -489,7 +488,7 @@ class WebGPUTextureUtils {
489488

490489
} else {
491490

492-
this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY );
491+
this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
493492

494493
}
495494

@@ -562,21 +561,6 @@ class WebGPUTextureUtils {
562561

563562
}
564563

565-
/**
566-
* Returns `true` if the given texture is an environment map.
567-
*
568-
* @private
569-
* @param {Texture} texture - The texture.
570-
* @return {boolean} Whether the given texture is an environment map or not.
571-
*/
572-
_isEnvironmentTexture( texture ) {
573-
574-
const mapping = texture.mapping;
575-
576-
return ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) || ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
577-
578-
}
579-
580564
/**
581565
* Returns the default GPU texture for the given format.
582566
*
@@ -666,8 +650,9 @@ class WebGPUTextureUtils {
666650
* @param {GPUTexture} textureGPU - The GPU texture.
667651
* @param {Object} textureDescriptorGPU - The GPU texture descriptor.
668652
* @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
653+
* @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
669654
*/
670-
_copyCubeMapToTexture( images, textureGPU, textureDescriptorGPU, flipY ) {
655+
_copyCubeMapToTexture( images, textureGPU, textureDescriptorGPU, flipY, premultiplyAlpha ) {
671656

672657
for ( let i = 0; i < 6; i ++ ) {
673658

@@ -681,7 +666,7 @@ class WebGPUTextureUtils {
681666

682667
} else {
683668

684-
this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY );
669+
this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY, premultiplyAlpha );
685670

686671
}
687672

@@ -698,8 +683,9 @@ class WebGPUTextureUtils {
698683
* @param {Object} textureDescriptorGPU - The GPU texture descriptor.
699684
* @param {number} originDepth - The origin depth.
700685
* @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
686+
* @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
701687
*/
702-
_copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY ) {
688+
_copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha ) {
703689

704690
const device = this.backend.device;
705691

@@ -710,7 +696,8 @@ class WebGPUTextureUtils {
710696
}, {
711697
texture: textureGPU,
712698
mipLevel: 0,
713-
origin: { x: 0, y: 0, z: originDepth }
699+
origin: { x: 0, y: 0, z: originDepth },
700+
premultipliedAlpha: premultiplyAlpha
714701
}, {
715702
width: image.width,
716703
height: image.height,

0 commit comments

Comments
 (0)