Skip to content

Commit ec83308

Browse files
committed
Simplify EffectTransform call signatures
1 parent 07d0d48 commit ec83308

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/Drawable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class Drawable {
691691
// : drawable.skin._silhouette.colorAtLinear(localPosition, dst);
692692

693693
if (drawable.enabledEffects === 0) return textColor;
694-
return EffectTransform.transformColor(drawable, textColor, textColor);
694+
return EffectTransform.transformColor(drawable, textColor);
695695
}
696696
}
697697

src/EffectTransform.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,33 @@ const hslToRgb = ([h, s, l]) => {
114114
class EffectTransform {
115115

116116
/**
117-
* Transform a color given the drawables effect uniforms. Will apply
117+
* Transform a color in-place given the drawable's effect uniforms. Will apply
118118
* Ghost and Color and Brightness effects.
119119
* @param {Drawable} drawable The drawable to get uniforms from.
120-
* @param {Uint8ClampedArray} color4b The initial color.
121-
* @param {Uint8ClampedArary} [dst] Working space to save the color in (is returned)
122-
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
120+
* @param {Uint8ClampedArray} inOutColor The color to transform.
123121
* @returns {Uint8ClampedArray} dst filled with the transformed color
124122
*/
125-
static transformColor (drawable, color4b, dst, effectMask) {
126-
if (typeof effectMask === 'undefined') effectMask = 0xffffffff;
127-
if (typeof dst === 'undefined') dst = new Uint8ClampedArray(4);
128-
129-
dst.set(color4b);
123+
static transformColor (drawable, inOutColor) {
124+
130125
// If the color is fully transparent, don't bother attempting any transformations.
131-
if (dst[3] === 0) {
132-
return dst;
126+
if (inOutColor[3] === 0) {
127+
return inOutColor;
133128
}
134129

135-
const effects = drawable.enabledEffects & effectMask;
130+
const effects = drawable.enabledEffects;
136131
const uniforms = drawable.getUniforms();
137132

138133
if ((effects & ShaderManager.EFFECT_INFO.ghost.mask) !== 0) {
139134
// gl_FragColor.a *= u_ghost
140-
dst[3] *= uniforms.u_ghost;
135+
inOutColor[3] *= uniforms.u_ghost;
141136
}
142137

143138
const enableColor = (effects & ShaderManager.EFFECT_INFO.color.mask) !== 0;
144139
const enableBrightness = (effects & ShaderManager.EFFECT_INFO.brightness.mask) !== 0;
145140

146141
if (enableColor || enableBrightness) {
147142
// vec3 hsl = convertRGB2HSL(gl_FragColor.xyz);
148-
const hsl = rgbToHsl(dst);
143+
const hsl = rgbToHsl(inOutColor);
149144

150145
if (enableColor) {
151146
// this code forces grayscale values to be slightly saturated
@@ -175,21 +170,20 @@ class EffectTransform {
175170
hsl[2] = Math.min(1, hsl[2] + uniforms.u_brightness);
176171
}
177172
// gl_FragColor.rgb = convertHSL2RGB(hsl);
178-
dst.set(hslToRgb(hsl));
173+
inOutColor.set(hslToRgb(hsl));
179174
}
180175

181-
return dst;
176+
return inOutColor;
182177
}
183178

184179
/**
185180
* Transform a texture coordinate to one that would be select after applying shader effects.
186181
* @param {Drawable} drawable The drawable whose effects to emulate.
187182
* @param {twgl.v3} vec The texture coordinate to transform.
188-
* @param {?twgl.v3} dst A place to store the output coordinate.
183+
* @param {twgl.v3} dst A place to store the output coordinate.
189184
* @return {twgl.v3} dst - The coordinate after being transform by effects.
190185
*/
191186
static transformPoint (drawable, vec, dst) {
192-
if (typeof dst === 'undefined') dst = twgl.v3.create();
193187
twgl.v3.copy(vec, dst);
194188

195189
const effects = drawable.enabledEffects;

0 commit comments

Comments
 (0)