Skip to content

Commit

Permalink
Don't apply ghost to "touching color" drawables
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitwhiz committed Mar 22, 2020
1 parent 5188113 commit 969fd7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Drawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,10 @@ class Drawable {
* @param {twgl.v3} vec The scratch space [x,y] vector
* @param {Drawable} drawable The drawable to sample the texture from
* @param {Uint8ClampedArray} dst The "color4b" representation of the texture at point.
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
* @returns {Uint8ClampedArray} The dst object filled with the color4b
*/
static sampleColor4b (vec, drawable, dst) {
static sampleColor4b (vec, drawable, dst, effectMask) {
const localPosition = getLocalPosition(drawable, vec);
if (localPosition[0] < 0 || localPosition[1] < 0 ||
localPosition[0] > 1 || localPosition[1] > 1) {
Expand All @@ -696,7 +697,7 @@ class Drawable {
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);

if (drawable.enabledEffects === 0) return textColor;
return EffectTransform.transformColor(drawable, textColor);
return EffectTransform.transformColor(drawable, textColor, effectMask);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/EffectTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ class EffectTransform {
* Ghost and Color and Brightness effects.
* @param {Drawable} drawable The drawable to get uniforms from.
* @param {Uint8ClampedArray} inOutColor The color to transform.
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
* @returns {Uint8ClampedArray} dst filled with the transformed color
*/
static transformColor (drawable, inOutColor) {

static transformColor (drawable, inOutColor, effectMask) {
// If the color is fully transparent, don't bother attempting any transformations.
if (inOutColor[3] === 0) {
return inOutColor;
}

const effects = drawable.enabledEffects;
let effects = drawable.enabledEffects;
if (typeof effectMask === 'number') effects &= effectMask;
const uniforms = drawable.getUniforms();

const enableColor = (effects & ShaderManager.EFFECT_INFO.color.mask) !== 0;
Expand Down
5 changes: 4 additions & 1 deletion src/RenderWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ class RenderWebGL extends EventEmitter {
const color = __touchingColor;
const hasMask = Boolean(mask3b);

// "touching color" ignores ghost effect
const effectMask = ~ShaderManager.EFFECT_INFO.ghost.mask;

// Scratch Space - +y is top
for (let y = 0; y < bounds.height; ++y) {
if (bounds.width * y * (candidates.length + 1) >= maxPixelsForCPU) {
Expand All @@ -775,7 +778,7 @@ class RenderWebGL extends EventEmitter {
point[1] = bounds.top - y; // bounds.bottom < point[1] <= bounds.top ("flipped")
// if we use a mask, check our sample color...
if (hasMask ?
maskMatches(Drawable.sampleColor4b(point, drawable, color), mask3b) :
maskMatches(Drawable.sampleColor4b(point, drawable, color, effectMask), mask3b) :
drawable.isTouching(point)) {
RenderWebGL.sampleColor3b(point, candidates, color);
if (debugCanvasContext) {
Expand Down

0 comments on commit 969fd7a

Please sign in to comment.