瀏覽代碼

Add alpha equation override

Popov72 4 年之前
父節點
當前提交
0197985bb2
共有 1 個文件被更改,包括 36 次插入0 次删除
  1. 36 0
      src/Engines/webgpuEngine.ts

+ 36 - 0
src/Engines/webgpuEngine.ts

@@ -3519,6 +3519,38 @@ export class WebGPUEngine extends Engine {
         this._alphaMode = mode;
     }
 
+    /**
+     * Sets the current alpha equation
+     * @param equation defines the equation to use (one of the Engine.ALPHA_EQUATION_XXX)
+     */
+    public setAlphaEquation(equation: number): void {
+        if (this._alphaEquation === equation) {
+            return;
+        }
+
+        switch (equation) {
+            case Constants.ALPHA_EQUATION_ADD:
+                this._alphaState.setAlphaEquationParameters(this._gl.FUNC_ADD, this._gl.FUNC_ADD);
+                break;
+            case Constants.ALPHA_EQUATION_SUBSTRACT:
+                this._alphaState.setAlphaEquationParameters(this._gl.FUNC_SUBTRACT, this._gl.FUNC_SUBTRACT);
+                break;
+            case Constants.ALPHA_EQUATION_REVERSE_SUBTRACT:
+                this._alphaState.setAlphaEquationParameters(this._gl.FUNC_REVERSE_SUBTRACT, this._gl.FUNC_REVERSE_SUBTRACT);
+                break;
+            case Constants.ALPHA_EQUATION_MAX:
+                this._alphaState.setAlphaEquationParameters(this._gl.MAX, this._gl.MAX);
+                break;
+            case Constants.ALPHA_EQUATION_MIN:
+                this._alphaState.setAlphaEquationParameters(this._gl.MIN, this._gl.MIN);
+                break;
+            case Constants.ALPHA_EQUATION_DARKEN:
+                this._alphaState.setAlphaEquationParameters(this._gl.MIN, this._gl.FUNC_ADD);
+                break;
+        }
+        this._alphaEquation = equation;
+    }
+
     private _getAphaBlendOperation(operation: Nullable<number>): GPUBlendOperation {
         switch (operation) {
             case 0x8006:
@@ -3527,6 +3559,10 @@ export class WebGPUEngine extends Engine {
                 return WebGPUConstants.BlendOperation.Subtract;
             case 0x800B:
                 return WebGPUConstants.BlendOperation.ReverseSubtract;
+            case 0x8007:
+                return WebGPUConstants.BlendOperation.Min;
+            case 0x8008:
+                return WebGPUConstants.BlendOperation.Max;
             default:
                 return WebGPUConstants.BlendOperation.Add;
         }