|
@@ -23,6 +23,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
|
|
|
var currentBlendEquationAlpha = null;
|
|
|
var currentBlendSrcAlpha = null;
|
|
|
var currentBlendDstAlpha = null;
|
|
|
+ var currentPremultipledAlpha = false;
|
|
|
|
|
|
var currentDepthFunc = null;
|
|
|
var currentDepthWrite = null;
|
|
@@ -197,7 +198,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
|
|
|
+ this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
|
|
|
|
if ( blending === THREE.NoBlending ) {
|
|
|
|
|
@@ -209,59 +210,72 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( blending !== currentBlending ) {
|
|
|
+ if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
|
|
|
|
|
|
if ( blending === THREE.AdditiveBlending ) {
|
|
|
|
|
|
- gl.blendEquation( gl.FUNC_ADD );
|
|
|
- gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
|
|
|
- } else if ( blending === THREE.SubtractiveBlending ) {
|
|
|
+ gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+ gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
|
|
|
|
|
|
- // TODO: Find blendFuncSeparate() combination
|
|
|
+ } else {
|
|
|
|
|
|
- gl.blendEquation( gl.FUNC_ADD );
|
|
|
- gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
|
|
|
+ gl.blendEquation( gl.FUNC_ADD );
|
|
|
+ gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
|
|
|
|
|
|
- } else if ( blending === THREE.MultiplyBlending ) {
|
|
|
+ }
|
|
|
|
|
|
- // TODO: Find blendFuncSeparate() combination
|
|
|
+ } else if ( blending === THREE.SubtractiveBlending ) {
|
|
|
|
|
|
- gl.blendEquation( gl.FUNC_ADD );
|
|
|
- gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
|
|
|
- } else if( blending === THREE.PremultipliedAlphaNormalBlending ) {
|
|
|
+ gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+ gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
|
- gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
- gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ gl.blendEquation( gl.FUNC_ADD );
|
|
|
+ gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- } else if( blending === THREE.PremultipliedAlphaAdditiveBlending ) {
|
|
|
+ } else if ( blending === THREE.MultiplyBlending ) {
|
|
|
|
|
|
- gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
- gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
|
|
|
- } else if( blending === THREE.PremultipliedAlphaSubtractiveBlending ) {
|
|
|
+ gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+ gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.SRC_COLOR, gl.SRC_ALPHA );
|
|
|
|
|
|
- gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
- gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ } else {
|
|
|
|
|
|
- } else if( blending === THREE.PremultipliedAlphaMultiplyBlending ) {
|
|
|
+ gl.blendEquation( gl.FUNC_ADD );
|
|
|
+ gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
|
|
|
|
|
|
- gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
- gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.SRC_COLOR, gl.SRC_ALPHA );
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
- gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+ if ( premultipliedAlpha ) {
|
|
|
+
|
|
|
+ gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+ gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
|
|
|
+ gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
currentBlending = blending;
|
|
|
+ currentPremultipledAlpha = premultipliedAlpha;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( blending === THREE.CustomBlending || blending === THREE.PremultipliedAlphaCustomBlending ) {
|
|
|
+ if ( blending === THREE.CustomBlending ) {
|
|
|
|
|
|
blendEquationAlpha = blendEquationAlpha || blendEquation;
|
|
|
blendSrcAlpha = blendSrcAlpha || blendSrc;
|