|
|
@@ -4,7 +4,8 @@ import {
|
|
|
AdditiveBlending, SubtractiveBlending, MultiplyBlending, SubtractEquation, ReverseSubtractEquation,
|
|
|
ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor,
|
|
|
OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
|
|
|
- NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
|
|
|
+ NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth,
|
|
|
+ MaterialBlending
|
|
|
} from '../../../constants.js';
|
|
|
import { Vector4 } from '../../../math/Vector4.js';
|
|
|
import { error } from '../../../utils.js';
|
|
|
@@ -270,17 +271,140 @@ class WebGLState {
|
|
|
|
|
|
}
|
|
|
|
|
|
- setMRTBlending( textures ) {
|
|
|
+ setMRTBlending( textures, mrt, material ) {
|
|
|
|
|
|
const gl = this.gl;
|
|
|
const drawBuffersIndexedExt = this.backend.drawBuffersIndexedExt;
|
|
|
|
|
|
if ( ! drawBuffersIndexedExt ) return;
|
|
|
|
|
|
- for ( let i = 1; i < textures.length; i ++ ) {
|
|
|
+ for ( let i = 0; i < textures.length; i ++ ) {
|
|
|
|
|
|
- // use opaque blending for additional render targets
|
|
|
- drawBuffersIndexedExt.blendFuncSeparateiOES( i, gl.ONE, gl.ZERO, gl.ONE, gl.ZERO );
|
|
|
+ const texture = textures[ i ];
|
|
|
+
|
|
|
+ let blending = null;
|
|
|
+
|
|
|
+ if ( mrt !== null ) {
|
|
|
+
|
|
|
+ const blendMode = mrt.getBlendMode( texture.name );
|
|
|
+
|
|
|
+ if ( blendMode.blending === MaterialBlending ) {
|
|
|
+
|
|
|
+ // use material blending
|
|
|
+ blending = material;
|
|
|
+
|
|
|
+ } else if ( blendMode.blending !== NoBlending ) {
|
|
|
+
|
|
|
+ blending = blendMode;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // use material blending
|
|
|
+ blending = material;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( blending !== null ) {
|
|
|
+
|
|
|
+ this._setMRTBlendingIndex( i, blending );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // use opaque blending (no blending)
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( i, gl.ONE, gl.ZERO, gl.ONE, gl.ZERO );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Applies blending configuration for a specific draw buffer index.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {number} index - The draw buffer index.
|
|
|
+ * @param {Object} blending - The blending configuration (material or BlendMode).
|
|
|
+ */
|
|
|
+ _setMRTBlendingIndex( index, blending ) {
|
|
|
+
|
|
|
+ const { gl } = this;
|
|
|
+ const drawBuffersIndexedExt = this.backend.drawBuffersIndexedExt;
|
|
|
+
|
|
|
+ const blendingType = blending.blending;
|
|
|
+ const blendSrc = blending.blendSrc;
|
|
|
+ const blendDst = blending.blendDst;
|
|
|
+ const blendEquation = blending.blendEquation;
|
|
|
+ const premultipliedAlpha = blending.premultipliedAlpha;
|
|
|
+
|
|
|
+ if ( blendingType === CustomBlending ) {
|
|
|
+
|
|
|
+ const blendSrcAlpha = blending.blendSrcAlpha !== null ? blending.blendSrcAlpha : blendSrc;
|
|
|
+ const blendDstAlpha = blending.blendDstAlpha !== null ? blending.blendDstAlpha : blendDst;
|
|
|
+ const blendEquationAlpha = blending.blendEquationAlpha !== null ? blending.blendEquationAlpha : blendEquation;
|
|
|
+
|
|
|
+ drawBuffersIndexedExt.blendEquationSeparateiOES( index, equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ drawBuffersIndexedExt.blendEquationSeparateiOES( index, gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
+
|
|
|
+ switch ( blendingType ) {
|
|
|
+
|
|
|
+ case NormalBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case AdditiveBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.ONE, gl.ONE, gl.ONE, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SubtractiveBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case MultiplyBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ switch ( blendingType ) {
|
|
|
+
|
|
|
+ case NormalBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case AdditiveBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SubtractiveBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case MultiplyBlending:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ drawBuffersIndexedExt.blendFuncSeparateiOES( index, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|