Un-premultiply extracted drawables

This commit is contained in:
adroitwhiz
2020-02-04 22:32:04 -05:00
parent d0d98de38f
commit 90b8f15d8c
3 changed files with 12 additions and 1 deletions

View File

@@ -1124,7 +1124,8 @@ class RenderWebGL extends EventEmitter {
gl.clear(gl.COLOR_BUFFER_BIT);
try {
gl.disable(gl.BLEND);
this._drawThese([drawableID], ShaderManager.DRAW_MODE.default, projection,
// ImageData objects store alpha un-premultiplied, so draw with the `straightAlpha` draw mode.
this._drawThese([drawableID], ShaderManager.DRAW_MODE.straightAlpha, projection,
{effectMask: ~ShaderManager.EFFECT_INFO.ghost.mask});
} finally {
gl.enable(gl.BLEND);

View File

@@ -158,6 +158,11 @@ ShaderManager.DRAW_MODE = {
*/
default: 'default',
/**
* Un-premultiply alpha. Useful for reading pixels from GL into an ImageData object.
*/
straightAlpha: 'straightAlpha',
/**
* Draw a silhouette using a solid color.
*/

View File

@@ -210,6 +210,11 @@ void main()
#endif // DRAW_MODE_colorMask
#endif // DRAW_MODE_silhouette
#ifdef DRAW_MODE_straightAlpha
// Un-premultiply alpha.
gl_FragColor.rgb /= gl_FragColor.a + epsilon;
#endif
#else // DRAW_MODE_lineSample
gl_FragColor = u_lineColor * clamp(
// Scale the capScale a little to have an aliased region.