Skip to content

Commit d8c9f33

Browse files
authored
Merge pull request #576 from adroitwhiz/fix-ghost-touching-color
Don't apply ghost effect to "color is touching color" drawable
2 parents a7bec3a + aaffc77 commit d8c9f33

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Drawable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,10 @@ class Drawable {
679679
* @param {twgl.v3} vec The scratch space [x,y] vector
680680
* @param {Drawable} drawable The drawable to sample the texture from
681681
* @param {Uint8ClampedArray} dst The "color4b" representation of the texture at point.
682+
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
682683
* @returns {Uint8ClampedArray} The dst object filled with the color4b
683684
*/
684-
static sampleColor4b (vec, drawable, dst) {
685+
static sampleColor4b (vec, drawable, dst, effectMask) {
685686
const localPosition = getLocalPosition(drawable, vec);
686687
if (localPosition[0] < 0 || localPosition[1] < 0 ||
687688
localPosition[0] > 1 || localPosition[1] > 1) {
@@ -698,7 +699,7 @@ class Drawable {
698699
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
699700

700701
if (drawable.enabledEffects === 0) return textColor;
701-
return EffectTransform.transformColor(drawable, textColor);
702+
return EffectTransform.transformColor(drawable, textColor, effectMask);
702703
}
703704
}
704705

src/EffectTransform.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,17 @@ class EffectTransform {
118118
* Ghost and Color and Brightness effects.
119119
* @param {Drawable} drawable The drawable to get uniforms from.
120120
* @param {Uint8ClampedArray} inOutColor The color to transform.
121+
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
121122
* @returns {Uint8ClampedArray} dst filled with the transformed color
122123
*/
123-
static transformColor (drawable, inOutColor) {
124-
124+
static transformColor (drawable, inOutColor, effectMask) {
125125
// If the color is fully transparent, don't bother attempting any transformations.
126126
if (inOutColor[3] === 0) {
127127
return inOutColor;
128128
}
129129

130-
const effects = drawable.enabledEffects;
130+
let effects = drawable.enabledEffects;
131+
if (typeof effectMask === 'number') effects &= effectMask;
131132
const uniforms = drawable.getUniforms();
132133

133134
const enableColor = (effects & ShaderManager.EFFECT_INFO.color.mask) !== 0;

src/RenderWebGL.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ class RenderWebGL extends EventEmitter {
763763
const color = __touchingColor;
764764
const hasMask = Boolean(mask3b);
765765

766+
// Masked drawable ignores ghost effect
767+
const effectMask = ~ShaderManager.EFFECT_INFO.ghost.mask;
768+
766769
// Scratch Space - +y is top
767770
for (let y = bounds.bottom; y <= bounds.top; y++) {
768771
if (bounds.width * (y - bounds.bottom) * (candidates.length + 1) >= maxPixelsForCPU) {
@@ -773,7 +776,7 @@ class RenderWebGL extends EventEmitter {
773776
point[0] = x;
774777
// if we use a mask, check our sample color...
775778
if (hasMask ?
776-
maskMatches(Drawable.sampleColor4b(point, drawable, color), mask3b) :
779+
maskMatches(Drawable.sampleColor4b(point, drawable, color, effectMask), mask3b) :
777780
drawable.isTouching(point)) {
778781
RenderWebGL.sampleColor3b(point, candidates, color);
779782
if (debugCanvasContext) {

0 commit comments

Comments
 (0)