Skip to content

Commit c9c780a

Browse files
authored
Merge pull request #418 from peabrainiac/develop
pen transparency fix
2 parents 590c2ca + fe01fea commit c9c780a

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/PenSkin.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ class PenSkin extends Skin {
154154
return true;
155155
}
156156

157+
/**
158+
* @returns {boolean} true if alpha is premultiplied, false otherwise
159+
*/
160+
get hasPremultipliedAlpha () {
161+
return true;
162+
}
163+
157164
/**
158165
* @return {Array<number>} the "native" size, in texels, of this skin. [width, height]
159166
*/
@@ -181,8 +188,9 @@ class PenSkin extends Skin {
181188
clear () {
182189
const gl = this._renderer.gl;
183190
twgl.bindFramebufferInfo(gl, this._framebuffer);
184-
185-
gl.clearColor(1, 1, 1, 0);
191+
192+
/* Reset framebuffer to transparent black */
193+
gl.clearColor(0, 0, 0, 0);
186194
gl.clear(gl.COLOR_BUFFER_BIT);
187195

188196
const ctx = this._canvas.getContext('2d');
@@ -598,7 +606,7 @@ class PenSkin extends Skin {
598606
this._silhouetteBuffer = twgl.createFramebufferInfo(gl, [{format: gl.RGBA}], width, height);
599607
}
600608

601-
gl.clearColor(1, 1, 1, 0);
609+
gl.clearColor(0, 0, 0, 0);
602610
gl.clear(gl.COLOR_BUFFER_BIT);
603611

604612
this._silhouetteDirty = true;

src/RenderWebGL.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,14 @@ class RenderWebGL extends EventEmitter {
16201620
}
16211621

16221622
twgl.setUniforms(currentShader, uniforms);
1623-
1623+
1624+
/* adjust blend function for this skin */
1625+
if (drawable.skin.hasPremultipliedAlpha){
1626+
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
1627+
} else {
1628+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
1629+
}
1630+
16241631
twgl.drawBufferInfo(gl, this._bufferInfo, gl.TRIANGLES);
16251632
}
16261633

src/Skin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class Skin extends EventEmitter {
7676
return false;
7777
}
7878

79+
/**
80+
* @returns {boolean} true if alpha is premultiplied, false otherwise
81+
*/
82+
get hasPremultipliedAlpha () {
83+
return false;
84+
}
85+
7986
/**
8087
* @return {int} the unique ID for this Skin.
8188
*/

src/shaders/sprite.frag

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ void main()
194194
discard;
195195
}
196196
#endif // DRAW_MODE_colorMask
197-
198-
// WebGL defaults to premultiplied alpha
199-
#ifndef DRAW_MODE_stamp
200-
gl_FragColor.rgb *= gl_FragColor.a;
201-
#endif // DRAW_MODE_stamp
202-
203197
#endif // DRAW_MODE_silhouette
204198

205199
#else // DRAW_MODE_lineSample

0 commit comments

Comments
 (0)