diff --git a/src/PenSkin.js b/src/PenSkin.js index fb0b0d999..1e500ba44 100644 --- a/src/PenSkin.js +++ b/src/PenSkin.js @@ -154,6 +154,13 @@ class PenSkin extends Skin { return true; } + /** + * @returns {boolean} true if alpha is premultiplied, false otherwise + */ + get hasPremultipliedAlpha () { + return true; + } + /** * @return {Array} the "native" size, in texels, of this skin. [width, height] */ @@ -181,8 +188,9 @@ class PenSkin extends Skin { clear () { const gl = this._renderer.gl; twgl.bindFramebufferInfo(gl, this._framebuffer); - - gl.clearColor(1, 1, 1, 0); + + /* Reset framebuffer to transparent black */ + gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); const ctx = this._canvas.getContext('2d'); @@ -598,7 +606,7 @@ class PenSkin extends Skin { this._silhouetteBuffer = twgl.createFramebufferInfo(gl, [{format: gl.RGBA}], width, height); } - gl.clearColor(1, 1, 1, 0); + gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); this._silhouetteDirty = true; diff --git a/src/RenderWebGL.js b/src/RenderWebGL.js index 05b35e2ea..f16b02d45 100644 --- a/src/RenderWebGL.js +++ b/src/RenderWebGL.js @@ -1620,7 +1620,14 @@ class RenderWebGL extends EventEmitter { } twgl.setUniforms(currentShader, uniforms); - + + /* adjust blend function for this skin */ + if (drawable.skin.hasPremultipliedAlpha){ + gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + } else { + gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + } + twgl.drawBufferInfo(gl, this._bufferInfo, gl.TRIANGLES); } diff --git a/src/Skin.js b/src/Skin.js index d5fcbb3a8..e0e741357 100644 --- a/src/Skin.js +++ b/src/Skin.js @@ -76,6 +76,13 @@ class Skin extends EventEmitter { return false; } + /** + * @returns {boolean} true if alpha is premultiplied, false otherwise + */ + get hasPremultipliedAlpha () { + return false; + } + /** * @return {int} the unique ID for this Skin. */ diff --git a/src/shaders/sprite.frag b/src/shaders/sprite.frag index 055e9a219..a781baff5 100644 --- a/src/shaders/sprite.frag +++ b/src/shaders/sprite.frag @@ -194,12 +194,6 @@ void main() discard; } #endif // DRAW_MODE_colorMask - - // WebGL defaults to premultiplied alpha - #ifndef DRAW_MODE_stamp - gl_FragColor.rgb *= gl_FragColor.a; - #endif // DRAW_MODE_stamp - #endif // DRAW_MODE_silhouette #else // DRAW_MODE_lineSample