|
@@ -45,10 +45,7 @@ class WebGPUPipelineUtils {
|
|
|
|
|
|
if ( material.transparent === true && material.blending !== NoBlending ) {
|
|
if ( material.transparent === true && material.blending !== NoBlending ) {
|
|
|
|
|
|
- blending = {
|
|
|
|
- alpha: this._getAlphaBlend( material ),
|
|
|
|
- color: this._getColorBlend( material )
|
|
|
|
- };
|
|
|
|
|
|
+ blending = this._getBlending( material );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -125,92 +122,108 @@ class WebGPUPipelineUtils {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- _getAlphaBlend( material ) {
|
|
|
|
|
|
+ _getBlending( material ) {
|
|
|
|
+
|
|
|
|
+ let color, alpha;
|
|
|
|
|
|
const blending = material.blending;
|
|
const blending = material.blending;
|
|
- const premultipliedAlpha = material.premultipliedAlpha;
|
|
|
|
|
|
|
|
- let alphaBlend = undefined;
|
|
|
|
|
|
+ if ( blending === CustomBlending ) {
|
|
|
|
|
|
- switch ( blending ) {
|
|
|
|
|
|
+ const blendSrcAlpha = material.blendSrcAlpha !== null ? material.blendSrcAlpha : GPUBlendFactor.One;
|
|
|
|
+ const blendDstAlpha = material.blendDstAlpha !== null ? material.blendDstAlpha : GPUBlendFactor.Zero;
|
|
|
|
+ const blendEquationAlpha = material.blendEquationAlpha !== null ? material.blendEquationAlpha : GPUBlendFactor.Add;
|
|
|
|
|
|
- case NormalBlending:
|
|
|
|
|
|
+ color = {
|
|
|
|
+ srcFactor: this._getBlendFactor( material.blendSrc ),
|
|
|
|
+ dstFactor: this._getBlendFactor( material.blendDst ),
|
|
|
|
+ operation: this._getBlendOperation( material.blendEquation )
|
|
|
|
+ };
|
|
|
|
|
|
- if ( premultipliedAlpha === false ) {
|
|
|
|
|
|
+ alpha = {
|
|
|
|
+ srcFactor: this._getBlendFactor( blendSrcAlpha ),
|
|
|
|
+ dstFactor: this._getBlendFactor( blendDstAlpha ),
|
|
|
|
+ operation: this._getBlendOperation( blendEquationAlpha )
|
|
|
|
+ };
|
|
|
|
|
|
- alphaBlend = {
|
|
|
|
- srcFactor: GPUBlendFactor.One,
|
|
|
|
- dstFactor: GPUBlendFactor.OneMinusSrcAlpha,
|
|
|
|
- operation: GPUBlendOperation.Add
|
|
|
|
- };
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const premultipliedAlpha = material.premultipliedAlpha;
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ const setBlend = ( srcRGB, dstRGB, srcAlpha, dstAlpha ) => {
|
|
|
|
|
|
- case AdditiveBlending:
|
|
|
|
|
|
+ color = {
|
|
|
|
+ srcFactor: srcRGB,
|
|
|
|
+ dstFactor: dstRGB,
|
|
|
|
+ operation: GPUBlendOperation.Add
|
|
|
|
+ };
|
|
|
|
|
|
- alphaBlend = {
|
|
|
|
- srcFactor: GPUBlendFactor.Zero,
|
|
|
|
- dstFactor: GPUBlendFactor.One,
|
|
|
|
|
|
+ alpha = {
|
|
|
|
+ srcFactor: srcAlpha,
|
|
|
|
+ dstFactor: dstAlpha,
|
|
operation: GPUBlendOperation.Add
|
|
operation: GPUBlendOperation.Add
|
|
};
|
|
};
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
|
|
|
- case SubtractiveBlending:
|
|
|
|
|
|
+ switch ( blending ) {
|
|
|
|
|
|
- if ( premultipliedAlpha === true ) {
|
|
|
|
|
|
+ case NormalBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.OneMinusSrcAlpha, GPUBlendFactor.One, GPUBlendFactor.OneMinusSrcAlpha );
|
|
|
|
+ break;
|
|
|
|
|
|
- alphaBlend = {
|
|
|
|
- srcFactor: GPUBlendFactor.OneMinusSrcColor,
|
|
|
|
- dstFactor: GPUBlendFactor.OneMinusSrcAlpha,
|
|
|
|
- operation: GPUBlendOperation.Add
|
|
|
|
- };
|
|
|
|
|
|
+ case AdditiveBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.One, GPUBlendFactor.One, GPUBlendFactor.One );
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case SubtractiveBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.Zero, GPUBlendFactor.OneMinusSrc, GPUBlendFactor.Zero, GPUBlendFactor.One );
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case MultiplyBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.Zero, GPUBlendFactor.Src, GPUBlendFactor.Zero, GPUBlendFactor.SrcAlpha );
|
|
|
|
+ break;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- case MultiplyBlending:
|
|
|
|
|
|
+ switch ( blending ) {
|
|
|
|
|
|
- if ( premultipliedAlpha === true ) {
|
|
|
|
|
|
+ case NormalBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.OneMinusSrcAlpha, GPUBlendFactor.One, GPUBlendFactor.OneMinusSrcAlpha );
|
|
|
|
+ break;
|
|
|
|
|
|
- alphaBlend = {
|
|
|
|
- srcFactor: GPUBlendFactor.Zero,
|
|
|
|
- dstFactor: GPUBlendFactor.SrcAlpha,
|
|
|
|
- operation: GPUBlendOperation.Add
|
|
|
|
- };
|
|
|
|
|
|
+ case AdditiveBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.One, GPUBlendFactor.SrcAlpha, GPUBlendFactor.One );
|
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ case SubtractiveBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.Zero, GPUBlendFactor.OneMinusSrc, GPUBlendFactor.Zero, GPUBlendFactor.One );
|
|
|
|
+ break;
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ case MultiplyBlending:
|
|
|
|
+ setBlend( GPUBlendFactor.Zero, GPUBlendFactor.Src, GPUBlendFactor.Zero, GPUBlendFactor.Src );
|
|
|
|
+ break;
|
|
|
|
|
|
- case CustomBlending:
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- const blendSrcAlpha = material.blendSrcAlpha;
|
|
|
|
- const blendDstAlpha = material.blendDstAlpha;
|
|
|
|
- const blendEquationAlpha = material.blendEquationAlpha;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( blendSrcAlpha !== null && blendDstAlpha !== null && blendEquationAlpha !== null ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- alphaBlend = {
|
|
|
|
- srcFactor: this._getBlendFactor( blendSrcAlpha ),
|
|
|
|
- dstFactor: this._getBlendFactor( blendDstAlpha ),
|
|
|
|
- operation: this._getBlendOperation( blendEquationAlpha )
|
|
|
|
- };
|
|
|
|
|
|
+ if ( color !== undefined && alpha !== undefined ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ return { color, alpha };
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- default:
|
|
|
|
- console.error( 'THREE.WebGPURenderer: Blending not supported.', blending );
|
|
|
|
|
|
+ console.error( 'THREE.WebGPURenderer: Invalid blending: ', blending );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return alphaBlend;
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
_getBlendFactor( blend ) {
|
|
_getBlendFactor( blend ) {
|
|
@@ -228,11 +241,11 @@ class WebGPUPipelineUtils {
|
|
break;
|
|
break;
|
|
|
|
|
|
case SrcColorFactor:
|
|
case SrcColorFactor:
|
|
- blendFactor = GPUBlendFactor.SrcColor;
|
|
|
|
|
|
+ blendFactor = GPUBlendFactor.Src;
|
|
break;
|
|
break;
|
|
|
|
|
|
case OneMinusSrcColorFactor:
|
|
case OneMinusSrcColorFactor:
|
|
- blendFactor = GPUBlendFactor.OneMinusSrcColor;
|
|
|
|
|
|
+ blendFactor = GPUBlendFactor.OneMinusSrc;
|
|
break;
|
|
break;
|
|
|
|
|
|
case SrcAlphaFactor:
|
|
case SrcAlphaFactor:
|
|
@@ -244,7 +257,7 @@ class WebGPUPipelineUtils {
|
|
break;
|
|
break;
|
|
|
|
|
|
case DstColorFactor:
|
|
case DstColorFactor:
|
|
- blendFactor = GPUBlendFactor.DstColor;
|
|
|
|
|
|
+ blendFactor = GPUBlendFactor.Dst;
|
|
break;
|
|
break;
|
|
|
|
|
|
case OneMinusDstColorFactor:
|
|
case OneMinusDstColorFactor:
|
|
@@ -264,11 +277,11 @@ class WebGPUPipelineUtils {
|
|
break;
|
|
break;
|
|
|
|
|
|
case BlendColorFactor:
|
|
case BlendColorFactor:
|
|
- blendFactor = GPUBlendFactor.BlendColor;
|
|
|
|
|
|
+ blendFactor = GPUBlendFactor.Constant;
|
|
break;
|
|
break;
|
|
|
|
|
|
case OneMinusBlendColorFactor:
|
|
case OneMinusBlendColorFactor:
|
|
- blendFactor = GPUBlendFactor.OneMinusBlendColor;
|
|
|
|
|
|
+ blendFactor = GPUBlendFactor.OneMinusConstant;
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -280,58 +293,6 @@ class WebGPUPipelineUtils {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- _getColorBlend( material ) {
|
|
|
|
-
|
|
|
|
- const blending = material.blending;
|
|
|
|
- const premultipliedAlpha = material.premultipliedAlpha;
|
|
|
|
-
|
|
|
|
- const colorBlend = {
|
|
|
|
- srcFactor: null,
|
|
|
|
- dstFactor: null,
|
|
|
|
- operation: null
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- switch ( blending ) {
|
|
|
|
-
|
|
|
|
- case NormalBlending:
|
|
|
|
- colorBlend.srcFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.One : GPUBlendFactor.SrcAlpha;
|
|
|
|
- colorBlend.dstFactor = GPUBlendFactor.OneMinusSrcAlpha;
|
|
|
|
- colorBlend.operation = GPUBlendOperation.Add;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case AdditiveBlending:
|
|
|
|
- colorBlend.srcFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.One : GPUBlendFactor.SrcAlpha;
|
|
|
|
- colorBlend.dstFactor = GPUBlendFactor.One;
|
|
|
|
- colorBlend.operation = GPUBlendOperation.Add;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case SubtractiveBlending:
|
|
|
|
- colorBlend.srcFactor = GPUBlendFactor.Zero;
|
|
|
|
- colorBlend.dstFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.Zero : GPUBlendFactor.OneMinusSrcColor;
|
|
|
|
- colorBlend.operation = GPUBlendOperation.Add;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case MultiplyBlending:
|
|
|
|
- colorBlend.srcFactor = GPUBlendFactor.Zero;
|
|
|
|
- colorBlend.dstFactor = GPUBlendFactor.SrcColor;
|
|
|
|
- colorBlend.operation = GPUBlendOperation.Add;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case CustomBlending:
|
|
|
|
- colorBlend.srcFactor = this._getBlendFactor( material.blendSrc );
|
|
|
|
- colorBlend.dstFactor = this._getBlendFactor( material.blendDst );
|
|
|
|
- colorBlend.operation = this._getBlendOperation( material.blendEquation );
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- console.error( 'THREE.WebGPURenderer: Blending not supported.', blending );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return colorBlend;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
_getStencilCompare( material ) {
|
|
_getStencilCompare( material ) {
|
|
|
|
|
|
let stencilCompare;
|
|
let stencilCompare;
|