Compare commits
11 Commits
greenkeepe
...
greenkeepe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ba438a7b8 | ||
|
|
58bd9cbe19 | ||
|
|
bf43ef363a | ||
|
|
a94f238ea1 | ||
|
|
4a521509da | ||
|
|
d17066b745 | ||
|
|
6cde82d33d | ||
|
|
4958bb5c69 | ||
|
|
a427461467 | ||
|
|
90b8f15d8c | ||
|
|
b194394cfd |
@@ -51,7 +51,7 @@
|
||||
"ify-loader": "1.0.4",
|
||||
"linebreak": "0.3.0",
|
||||
"minilog": "3.1.0",
|
||||
"raw-loader": "^0.5.1",
|
||||
"raw-loader": "^4.0.1",
|
||||
"scratch-storage": "^1.0.0",
|
||||
"scratch-svg-renderer": "0.2.0-prerelease.20200205003400",
|
||||
"twgl.js": "4.4.0"
|
||||
|
||||
@@ -109,6 +109,12 @@ class PenSkin extends Skin {
|
||||
/** @type {boolean} */
|
||||
this._silhouetteDirty = false;
|
||||
|
||||
/** @type {Uint8Array} */
|
||||
this._silhouettePixels = null;
|
||||
|
||||
/** @type {ImageData} */
|
||||
this._silhouetteImageData = null;
|
||||
|
||||
/** @type {object} */
|
||||
this._lineOnBufferDrawRegionId = {
|
||||
enter: () => this._enterDrawLineOnBuffer(),
|
||||
@@ -597,6 +603,9 @@ class PenSkin extends Skin {
|
||||
gl.clearColor(0, 0, 0, 0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
|
||||
this._silhouettePixels = new Uint8Array(Math.floor(width * height * 4));
|
||||
this._silhouetteImageData = this._canvas.getContext('2d').createImageData(width, height);
|
||||
|
||||
this._silhouetteDirty = true;
|
||||
}
|
||||
|
||||
@@ -634,24 +643,17 @@ class PenSkin extends Skin {
|
||||
// Render export texture to another framebuffer
|
||||
const gl = this._renderer.gl;
|
||||
|
||||
const bounds = this._bounds;
|
||||
|
||||
this._renderer.enterDrawRegion(this._toBufferDrawRegionId);
|
||||
|
||||
// Sample the framebuffer's pixels into the silhouette instance
|
||||
const skinPixels = new Uint8Array(Math.floor(this._canvas.width * this._canvas.height * 4));
|
||||
gl.readPixels(0, 0, this._canvas.width, this._canvas.height, gl.RGBA, gl.UNSIGNED_BYTE, skinPixels);
|
||||
gl.readPixels(
|
||||
0, 0,
|
||||
this._canvas.width, this._canvas.height,
|
||||
gl.RGBA, gl.UNSIGNED_BYTE, this._silhouettePixels
|
||||
);
|
||||
|
||||
const skinCanvas = this._canvas;
|
||||
skinCanvas.width = bounds.width;
|
||||
skinCanvas.height = bounds.height;
|
||||
|
||||
const skinContext = skinCanvas.getContext('2d');
|
||||
const skinImageData = skinContext.createImageData(bounds.width, bounds.height);
|
||||
skinImageData.data.set(skinPixels);
|
||||
skinContext.putImageData(skinImageData, 0, 0);
|
||||
|
||||
this._silhouette.update(this._canvas, true /* isPremultiplied */);
|
||||
this._silhouetteImageData.data.set(this._silhouettePixels);
|
||||
this._silhouette.update(this._silhouetteImageData, true /* isPremultiplied */);
|
||||
|
||||
this._silhouetteDirty = false;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -154,10 +154,15 @@ ShaderManager.EFFECTS = Object.keys(ShaderManager.EFFECT_INFO);
|
||||
*/
|
||||
ShaderManager.DRAW_MODE = {
|
||||
/**
|
||||
* Draw normally.
|
||||
* Draw normally. Its output will use premultiplied alpha.
|
||||
*/
|
||||
default: 'default',
|
||||
|
||||
/**
|
||||
* Draw with non-premultiplied alpha. Useful for reading pixels from GL into an ImageData object.
|
||||
*/
|
||||
straightAlpha: 'straightAlpha',
|
||||
|
||||
/**
|
||||
* Draw a silhouette using a solid color.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user