|
@@ -1,4 +1,4 @@
|
|
|
-import { GPUPrimitiveTopology, GPUIndexFormat, GPUTextureFormat, GPUCompareFunction, GPUFrontFace, GPUCullMode, GPUVertexFormat, GPUBlendFactor, GPUBlendOperation, BlendColorFactor, OneMinusBlendColorFactor } from './constants.js';
|
|
|
+import { GPUPrimitiveTopology, GPUIndexFormat, GPUTextureFormat, GPUCompareFunction, GPUFrontFace, GPUCullMode, GPUVertexFormat, GPUBlendFactor, GPUBlendOperation, BlendColorFactor, OneMinusBlendColorFactor, GPUColorWriteFlags } from './constants.js';
|
|
|
import {
|
|
|
FrontSide, BackSide, DoubleSide,
|
|
|
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth,
|
|
@@ -148,6 +148,7 @@ class WebGPURenderPipelines {
|
|
|
const primitiveTopology = this._getPrimitiveTopology( object );
|
|
|
const rasterizationState = this._getRasterizationStateDescriptor( object );
|
|
|
const depthCompare = this._getDepthCompare( material );
|
|
|
+ const colorWriteMask = this._getColorWriteMask( material );
|
|
|
|
|
|
pipeline = device.createRenderPipeline( {
|
|
|
layout: layout,
|
|
@@ -158,7 +159,8 @@ class WebGPURenderPipelines {
|
|
|
colorStates: [ {
|
|
|
format: GPUTextureFormat.BRGA8Unorm,
|
|
|
alphaBlend: alphaBlend,
|
|
|
- colorBlend: colorBlend
|
|
|
+ colorBlend: colorBlend,
|
|
|
+ writeMask: colorWriteMask
|
|
|
} ],
|
|
|
depthStencilState: {
|
|
|
depthWriteEnabled: material.depthWrite,
|
|
@@ -303,58 +305,6 @@ class WebGPURenderPipelines {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _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.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;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
_getBlendFactor( blend ) {
|
|
|
|
|
|
let blendFactor;
|
|
@@ -458,6 +408,64 @@ class WebGPURenderPipelines {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ _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.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;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _getColorWriteMask( material ) {
|
|
|
+
|
|
|
+ return ( material.colorWrite === true ) ? GPUColorWriteFlags.All : GPUColorWriteFlags.None;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
_getDepthCompare( material ) {
|
|
|
|
|
|
let depthCompare;
|