@vfx-js/effects 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/cjs/_figma-common.d.ts +8 -0
- package/lib/cjs/_figma-common.js +46 -0
- package/lib/cjs/_figma-common.js.map +1 -0
- package/lib/cjs/_pad.d.ts +2 -0
- package/lib/cjs/_pad.js +12 -0
- package/lib/cjs/_pad.js.map +1 -0
- package/lib/cjs/_particle-common.d.ts +0 -1
- package/lib/cjs/_particle-common.js +1 -6
- package/lib/cjs/_particle-common.js.map +1 -1
- package/lib/cjs/ascii.d.ts +137 -0
- package/lib/cjs/ascii.js +482 -0
- package/lib/cjs/ascii.js.map +1 -0
- package/lib/cjs/bloom.d.ts +2 -2
- package/lib/cjs/bloom.js +2 -7
- package/lib/cjs/bloom.js.map +1 -1
- package/lib/cjs/chromatic.d.ts +15 -0
- package/lib/cjs/chromatic.js +70 -0
- package/lib/cjs/chromatic.js.map +1 -0
- package/lib/cjs/colored-edges.d.ts +23 -0
- package/lib/cjs/colored-edges.js +88 -0
- package/lib/cjs/colored-edges.js.map +1 -0
- package/lib/cjs/datamosh.d.ts +11 -0
- package/lib/cjs/datamosh.js +28 -6
- package/lib/cjs/datamosh.js.map +1 -1
- package/lib/cjs/dither.d.ts +24 -0
- package/lib/cjs/dither.js +120 -0
- package/lib/cjs/dither.js.map +1 -0
- package/lib/cjs/duotone.d.ts +17 -0
- package/lib/cjs/duotone.js +62 -0
- package/lib/cjs/duotone.js.map +1 -0
- package/lib/cjs/fluid.js +1 -6
- package/lib/cjs/fluid.js.map +1 -1
- package/lib/cjs/glitch.d.ts +13 -0
- package/lib/cjs/glitch.js +108 -0
- package/lib/cjs/glitch.js.map +1 -0
- package/lib/cjs/gradient-map.d.ts +25 -0
- package/lib/cjs/gradient-map.js +154 -0
- package/lib/cjs/gradient-map.js.map +1 -0
- package/lib/cjs/hue-shift.d.ts +11 -0
- package/lib/cjs/hue-shift.js +65 -0
- package/lib/cjs/hue-shift.js.map +1 -0
- package/lib/cjs/index.d.ts +21 -0
- package/lib/cjs/index.js +45 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/light-streak.d.ts +91 -0
- package/lib/cjs/light-streak.js +385 -0
- package/lib/cjs/light-streak.js.map +1 -0
- package/lib/cjs/matrix.d.ts +135 -0
- package/lib/cjs/matrix.js +593 -0
- package/lib/cjs/matrix.js.map +1 -0
- package/lib/cjs/package.json +6 -6
- package/lib/cjs/particle-explode.d.ts +2 -2
- package/lib/cjs/particle-explode.js +4 -4
- package/lib/cjs/particle-explode.js.map +1 -1
- package/lib/cjs/particle.d.ts +2 -2
- package/lib/cjs/particle.js +1 -1
- package/lib/cjs/particle.js.map +1 -1
- package/lib/cjs/pattern-refraction.d.ts +31 -0
- package/lib/cjs/pattern-refraction.js +190 -0
- package/lib/cjs/pattern-refraction.js.map +1 -0
- package/lib/cjs/pixel-stretch.d.ts +21 -0
- package/lib/cjs/pixel-stretch.js +78 -0
- package/lib/cjs/pixel-stretch.js.map +1 -0
- package/lib/cjs/rainbow.d.ts +13 -0
- package/lib/cjs/rainbow.js +79 -0
- package/lib/cjs/rainbow.js.map +1 -0
- package/lib/cjs/rgb-glitch.d.ts +13 -0
- package/lib/cjs/rgb-glitch.js +79 -0
- package/lib/cjs/rgb-glitch.js.map +1 -0
- package/lib/cjs/rgb-shift.d.ts +13 -0
- package/lib/cjs/rgb-shift.js +76 -0
- package/lib/cjs/rgb-shift.js.map +1 -0
- package/lib/cjs/sinewave.d.ts +17 -0
- package/lib/cjs/sinewave.js +76 -0
- package/lib/cjs/sinewave.js.map +1 -0
- package/lib/cjs/slice-shift.d.ts +21 -0
- package/lib/cjs/slice-shift.js +75 -0
- package/lib/cjs/slice-shift.js.map +1 -0
- package/lib/cjs/tile-pixelate.d.ts +28 -0
- package/lib/cjs/tile-pixelate.js +168 -0
- package/lib/cjs/tile-pixelate.js.map +1 -0
- package/lib/cjs/tritone.d.ts +18 -0
- package/lib/cjs/tritone.js +67 -0
- package/lib/cjs/tritone.js.map +1 -0
- package/lib/cjs/vignette.d.ts +15 -0
- package/lib/cjs/vignette.js +59 -0
- package/lib/cjs/vignette.js.map +1 -0
- package/lib/cjs/warp.d.ts +22 -0
- package/lib/cjs/warp.js +92 -0
- package/lib/cjs/warp.js.map +1 -0
- package/lib/esm/_figma-common.d.ts +8 -0
- package/lib/esm/_figma-common.js +42 -0
- package/lib/esm/_figma-common.js.map +1 -0
- package/lib/esm/_pad.d.ts +2 -0
- package/lib/esm/_pad.js +9 -0
- package/lib/esm/_pad.js.map +1 -0
- package/lib/esm/_particle-common.d.ts +0 -1
- package/lib/esm/_particle-common.js +0 -5
- package/lib/esm/_particle-common.js.map +1 -1
- package/lib/esm/ascii.d.ts +137 -0
- package/lib/esm/ascii.js +478 -0
- package/lib/esm/ascii.js.map +1 -0
- package/lib/esm/bloom.d.ts +2 -2
- package/lib/esm/bloom.js +2 -7
- package/lib/esm/bloom.js.map +1 -1
- package/lib/esm/chromatic.d.ts +15 -0
- package/lib/esm/chromatic.js +66 -0
- package/lib/esm/chromatic.js.map +1 -0
- package/lib/esm/colored-edges.d.ts +23 -0
- package/lib/esm/colored-edges.js +84 -0
- package/lib/esm/colored-edges.js.map +1 -0
- package/lib/esm/datamosh.d.ts +11 -0
- package/lib/esm/datamosh.js +28 -6
- package/lib/esm/datamosh.js.map +1 -1
- package/lib/esm/dither.d.ts +24 -0
- package/lib/esm/dither.js +116 -0
- package/lib/esm/dither.js.map +1 -0
- package/lib/esm/duotone.d.ts +17 -0
- package/lib/esm/duotone.js +58 -0
- package/lib/esm/duotone.js.map +1 -0
- package/lib/esm/fluid.js +1 -6
- package/lib/esm/fluid.js.map +1 -1
- package/lib/esm/glitch.d.ts +13 -0
- package/lib/esm/glitch.js +104 -0
- package/lib/esm/glitch.js.map +1 -0
- package/lib/esm/gradient-map.d.ts +25 -0
- package/lib/esm/gradient-map.js +150 -0
- package/lib/esm/gradient-map.js.map +1 -0
- package/lib/esm/hue-shift.d.ts +11 -0
- package/lib/esm/hue-shift.js +61 -0
- package/lib/esm/hue-shift.js.map +1 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/light-streak.d.ts +91 -0
- package/lib/esm/light-streak.js +381 -0
- package/lib/esm/light-streak.js.map +1 -0
- package/lib/esm/matrix.d.ts +135 -0
- package/lib/esm/matrix.js +589 -0
- package/lib/esm/matrix.js.map +1 -0
- package/lib/esm/package.json +6 -6
- package/lib/esm/particle-explode.d.ts +2 -2
- package/lib/esm/particle-explode.js +5 -5
- package/lib/esm/particle-explode.js.map +1 -1
- package/lib/esm/particle.d.ts +2 -2
- package/lib/esm/particle.js +2 -2
- package/lib/esm/particle.js.map +1 -1
- package/lib/esm/pattern-refraction.d.ts +31 -0
- package/lib/esm/pattern-refraction.js +186 -0
- package/lib/esm/pattern-refraction.js.map +1 -0
- package/lib/esm/pixel-stretch.d.ts +21 -0
- package/lib/esm/pixel-stretch.js +74 -0
- package/lib/esm/pixel-stretch.js.map +1 -0
- package/lib/esm/rainbow.d.ts +13 -0
- package/lib/esm/rainbow.js +75 -0
- package/lib/esm/rainbow.js.map +1 -0
- package/lib/esm/rgb-glitch.d.ts +13 -0
- package/lib/esm/rgb-glitch.js +75 -0
- package/lib/esm/rgb-glitch.js.map +1 -0
- package/lib/esm/rgb-shift.d.ts +13 -0
- package/lib/esm/rgb-shift.js +72 -0
- package/lib/esm/rgb-shift.js.map +1 -0
- package/lib/esm/sinewave.d.ts +17 -0
- package/lib/esm/sinewave.js +72 -0
- package/lib/esm/sinewave.js.map +1 -0
- package/lib/esm/slice-shift.d.ts +21 -0
- package/lib/esm/slice-shift.js +71 -0
- package/lib/esm/slice-shift.js.map +1 -0
- package/lib/esm/tile-pixelate.d.ts +28 -0
- package/lib/esm/tile-pixelate.js +164 -0
- package/lib/esm/tile-pixelate.js.map +1 -0
- package/lib/esm/tritone.d.ts +18 -0
- package/lib/esm/tritone.js +63 -0
- package/lib/esm/tritone.js.map +1 -0
- package/lib/esm/vignette.d.ts +15 -0
- package/lib/esm/vignette.js +55 -0
- package/lib/esm/vignette.js.map +1 -0
- package/lib/esm/warp.d.ts +22 -0
- package/lib/esm/warp.js +88 -0
- package/lib/esm/warp.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const FRAG_GLITCH = `#version 300 es
|
|
2
|
+
precision highp float;
|
|
3
|
+
in vec2 uvContent;
|
|
4
|
+
out vec4 outColor;
|
|
5
|
+
uniform sampler2D src;
|
|
6
|
+
uniform vec4 srcRectUv;
|
|
7
|
+
uniform float time;
|
|
8
|
+
uniform float intensity;
|
|
9
|
+
|
|
10
|
+
// Sample src at a content-space UV (0..1 over the element), remapped
|
|
11
|
+
// into the padded src buffer via srcRectUv.
|
|
12
|
+
vec4 sampleSrc(vec2 c) {
|
|
13
|
+
return texture(src, srcRectUv.xy + c * srcRectUv.zw);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Like sampleSrc but transparent outside the content rect (preset autoCrop).
|
|
17
|
+
vec4 readTex(vec2 c) {
|
|
18
|
+
if (c.x < 0.0 || c.x > 1.0 || c.y < 0.0 || c.y > 1.0) return vec4(0.0);
|
|
19
|
+
return sampleSrc(c);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
float nn(float y, float t) {
|
|
23
|
+
float n = (
|
|
24
|
+
sin(y * .07 + t * 8. + sin(y * .5 + t * 10.)) +
|
|
25
|
+
sin(y * .7 + t * 2. + sin(y * .3 + t * 8.)) * .7 +
|
|
26
|
+
sin(y * 1.1 + t * 2.8) * .4
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
n += sin(y * 124. + t * 100.7) * sin(y * 877. - t * 38.8) * .3;
|
|
30
|
+
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void main (void) {
|
|
35
|
+
vec2 uv = uvContent;
|
|
36
|
+
vec4 color = readTex(uv);
|
|
37
|
+
|
|
38
|
+
float t = mod(time, 3.14 * 10.);
|
|
39
|
+
|
|
40
|
+
// Seed value
|
|
41
|
+
float v = fract(sin(t * 2.) * 700.);
|
|
42
|
+
|
|
43
|
+
if (abs(nn(uv.y, t)) < 1.2) {
|
|
44
|
+
v *= 0.01;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Prepare for chromatic aberration
|
|
48
|
+
vec2 focus = vec2(0.5);
|
|
49
|
+
float d = v * 0.6 * intensity;
|
|
50
|
+
vec2 ruv = focus + (uv - focus) * (1. - d);
|
|
51
|
+
vec2 guv = focus + (uv - focus) * (1. - 2. * d);
|
|
52
|
+
vec2 buv = focus + (uv - focus) * (1. - 3. * d);
|
|
53
|
+
|
|
54
|
+
// Random Glitch
|
|
55
|
+
if (v > 0.1) {
|
|
56
|
+
// Randomize y
|
|
57
|
+
float y = floor(uv.y * 13. * sin(35. * t)) + 1.;
|
|
58
|
+
if (sin(36. * y * v) > 0.9) {
|
|
59
|
+
ruv.x = uv.x + sin(76. * y) * 0.1 * intensity;
|
|
60
|
+
guv.x = uv.x + sin(34. * y) * 0.1 * intensity;
|
|
61
|
+
buv.x = uv.x + sin(59. * y) * 0.1 * intensity;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// RGB Shift
|
|
65
|
+
v = pow(v * 1.5, 2.) * 0.15 * intensity;
|
|
66
|
+
color.rgb *= 0.3;
|
|
67
|
+
color.r += readTex(vec2(uv.x + sin(t * 123.45) * v, uv.y)).r;
|
|
68
|
+
color.g += readTex(vec2(uv.x + sin(t * 157.67) * v, uv.y)).g;
|
|
69
|
+
color.b += readTex(vec2(uv.x + sin(t * 143.67) * v, uv.y)).b;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Compose chromatic aberration
|
|
73
|
+
if (abs(nn(uv.y, t)) > 1.1) {
|
|
74
|
+
color.r = color.r * 0.5 + color.r * sampleSrc(ruv).r;
|
|
75
|
+
color.g = color.g * 0.5 + color.g * sampleSrc(guv).g;
|
|
76
|
+
color.b = color.b * 0.5 + color.b * sampleSrc(buv).b;
|
|
77
|
+
color *= 2.;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
outColor = color;
|
|
81
|
+
outColor.a = smoothstep(0.0, 0.8, max(color.r, max(color.g, color.b)));
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
const DEFAULT_PARAMS = { speed: 1, intensity: 1 };
|
|
85
|
+
export class GlitchEffect {
|
|
86
|
+
constructor(initial = {}) {
|
|
87
|
+
this.params = { ...DEFAULT_PARAMS, ...initial };
|
|
88
|
+
}
|
|
89
|
+
setParams(updates) {
|
|
90
|
+
Object.assign(this.params, updates);
|
|
91
|
+
}
|
|
92
|
+
render(ctx) {
|
|
93
|
+
ctx.draw({
|
|
94
|
+
frag: FRAG_GLITCH,
|
|
95
|
+
uniforms: {
|
|
96
|
+
src: ctx.src,
|
|
97
|
+
time: ctx.time * this.params.speed,
|
|
98
|
+
intensity: this.params.intensity,
|
|
99
|
+
},
|
|
100
|
+
target: ctx.target,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=glitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glitch.js","sourceRoot":"","sources":["../../src/glitch.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFnB,CAAC;AASF,MAAM,cAAc,GAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;AAEhE,MAAM,OAAO,YAAY;IAGrB,YAAY,UAAiC,EAAE;QAC3C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAA8B;QACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAkB;QACrB,GAAG,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;gBAClC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;aACnC;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Effect, EffectContext } from "@vfx-js/core";
|
|
2
|
+
export type GradientMapRepeat = "none" | "repeat" | "mirror";
|
|
3
|
+
export type GradientMapMixSpace = "srgb" | "linear" | "oklab";
|
|
4
|
+
export type GradientMapParams = {
|
|
5
|
+
/** Gradient color stops (2–8), evenly spaced over the luminance range. */
|
|
6
|
+
colors: string[];
|
|
7
|
+
/** Random luminance jitter before the lookup, in [0, 1]. */
|
|
8
|
+
scatter: number;
|
|
9
|
+
/** Shift the lookup position along the gradient, in [0, 1]. */
|
|
10
|
+
offset: number;
|
|
11
|
+
/** How the lookup folds back when out of range (none = clamp). */
|
|
12
|
+
repeat: GradientMapRepeat;
|
|
13
|
+
/** How many times the gradient repeats across the luminance range. */
|
|
14
|
+
frequency: number;
|
|
15
|
+
/** Color space used to interpolate the gradient. */
|
|
16
|
+
mixSpace: GradientMapMixSpace;
|
|
17
|
+
/** Animate the offset over time, in [-1, 1] (0 = static). */
|
|
18
|
+
speed: number;
|
|
19
|
+
};
|
|
20
|
+
export declare class GradientMapEffect implements Effect {
|
|
21
|
+
params: GradientMapParams;
|
|
22
|
+
constructor(initial?: Partial<GradientMapParams>);
|
|
23
|
+
setParams(updates: Partial<GradientMapParams>): void;
|
|
24
|
+
render(ctx: EffectContext): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { parseHexColor } from "./_figma-common";
|
|
2
|
+
const MAX_STOPS = 8;
|
|
3
|
+
const FRAG_GRADIENT_MAP = `#version 300 es
|
|
4
|
+
precision highp float;
|
|
5
|
+
in vec2 uvContent;
|
|
6
|
+
out vec4 outColor;
|
|
7
|
+
uniform sampler2D src;
|
|
8
|
+
uniform vec4 srcRectUv;
|
|
9
|
+
uniform vec3 colors[${MAX_STOPS}];
|
|
10
|
+
uniform int colorCount;
|
|
11
|
+
uniform float scatter;
|
|
12
|
+
uniform float offset;
|
|
13
|
+
uniform int repeatType;
|
|
14
|
+
uniform float frequency;
|
|
15
|
+
uniform int mixSpace;
|
|
16
|
+
uniform float time;
|
|
17
|
+
|
|
18
|
+
float hash12(vec2 p) {
|
|
19
|
+
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
|
20
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
21
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
vec3 srgb2lin(vec3 c) { return pow(max(c, 0.0), vec3(2.2)); }
|
|
25
|
+
// Clamp first: OKLab interpolation can leave the gamut, and pow() of a
|
|
26
|
+
// negative value is NaN (renders as garbage/magenta).
|
|
27
|
+
vec3 lin2srgb(vec3 c) { return pow(max(c, 0.0), vec3(1.0 / 2.2)); }
|
|
28
|
+
|
|
29
|
+
vec3 lin2oklab(vec3 c) {
|
|
30
|
+
float l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
|
|
31
|
+
float m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
|
|
32
|
+
float s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
|
|
33
|
+
vec3 lms = pow(max(vec3(l, m, s), 0.0), vec3(1.0 / 3.0));
|
|
34
|
+
return vec3(
|
|
35
|
+
0.2104542553 * lms.x + 0.7936177850 * lms.y - 0.0040720468 * lms.z,
|
|
36
|
+
1.9779984951 * lms.x - 2.4285922050 * lms.y + 0.4505937099 * lms.z,
|
|
37
|
+
0.0259040371 * lms.x + 0.7827717662 * lms.y - 0.8086757660 * lms.z
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
vec3 oklab2lin(vec3 lab) {
|
|
41
|
+
float l_ = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;
|
|
42
|
+
float m_ = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;
|
|
43
|
+
float s_ = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;
|
|
44
|
+
vec3 lms = vec3(l_, m_, s_);
|
|
45
|
+
lms = lms * lms * lms;
|
|
46
|
+
return vec3(
|
|
47
|
+
4.0767416621 * lms.x - 3.3077115913 * lms.y + 0.2309699292 * lms.z,
|
|
48
|
+
-1.2684380046 * lms.x + 2.6097574011 * lms.y - 0.3413193965 * lms.z,
|
|
49
|
+
-0.0041960863 * lms.x - 0.7034186147 * lms.y + 1.7076147010 * lms.z
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Interpolate two sRGB colors in the selected space, returning sRGB.
|
|
54
|
+
vec3 mixColor(vec3 a, vec3 b, float t) {
|
|
55
|
+
if (mixSpace == 1) {
|
|
56
|
+
return lin2srgb(mix(srgb2lin(a), srgb2lin(b), t));
|
|
57
|
+
} else if (mixSpace == 2) {
|
|
58
|
+
vec3 oa = lin2oklab(srgb2lin(a));
|
|
59
|
+
vec3 ob = lin2oklab(srgb2lin(b));
|
|
60
|
+
return lin2srgb(oklab2lin(mix(oa, ob, t)));
|
|
61
|
+
}
|
|
62
|
+
return mix(a, b, t);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Fold t into [0, 1] per the repeat mode (none = clamp).
|
|
66
|
+
float applyRepeat(float t) {
|
|
67
|
+
if (repeatType == 1) return fract(t);
|
|
68
|
+
if (repeatType == 2) return 1.0 - abs(1.0 - fract(t * 0.5) * 2.0);
|
|
69
|
+
return clamp(t, 0.0, 1.0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
vec3 sampleGradient(float t) {
|
|
73
|
+
float f = t * float(colorCount - 1);
|
|
74
|
+
int i = int(floor(f));
|
|
75
|
+
i = clamp(i, 0, colorCount - 2);
|
|
76
|
+
float frac = clamp(f - float(i), 0.0, 1.0);
|
|
77
|
+
return clamp(mixColor(colors[i], colors[i + 1], frac), 0.0, 1.0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void main(void) {
|
|
81
|
+
vec4 tex = texture(src, srcRectUv.xy + uvContent * srcRectUv.zw);
|
|
82
|
+
float l = dot(tex.rgb, vec3(0.299, 0.587, 0.114));
|
|
83
|
+
// Hash in pixel space (gl_FragCoord); hash12 degenerates on tiny
|
|
84
|
+
// [0,1] uv inputs.
|
|
85
|
+
l += scatter * (hash12(gl_FragCoord.xy) - 0.5);
|
|
86
|
+
|
|
87
|
+
// offset (and time drift) advance one full cycle per unit, so a 0->1
|
|
88
|
+
// offset sweep runs (frequency) cycles.
|
|
89
|
+
float t = applyRepeat((l + offset + time) * frequency);
|
|
90
|
+
// Premultiply: the final blit is premultiplied, so non-zero rgb in
|
|
91
|
+
// transparent areas would add to the background as stray color.
|
|
92
|
+
outColor = vec4(sampleGradient(t) * tex.a, tex.a);
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
95
|
+
const REPEAT_TYPES = {
|
|
96
|
+
none: 0,
|
|
97
|
+
repeat: 1,
|
|
98
|
+
mirror: 2,
|
|
99
|
+
};
|
|
100
|
+
const MIX_SPACES = {
|
|
101
|
+
srgb: 0,
|
|
102
|
+
linear: 1,
|
|
103
|
+
oklab: 2,
|
|
104
|
+
};
|
|
105
|
+
const DEFAULT_PARAMS = {
|
|
106
|
+
colors: ["#bbee00", "#3aa0ff", "#000000"],
|
|
107
|
+
scatter: 0,
|
|
108
|
+
offset: 0,
|
|
109
|
+
repeat: "mirror",
|
|
110
|
+
frequency: 1,
|
|
111
|
+
mixSpace: "srgb",
|
|
112
|
+
speed: 0,
|
|
113
|
+
};
|
|
114
|
+
export class GradientMapEffect {
|
|
115
|
+
constructor(initial = {}) {
|
|
116
|
+
this.params = { ...DEFAULT_PARAMS, ...initial };
|
|
117
|
+
}
|
|
118
|
+
setParams(updates) {
|
|
119
|
+
Object.assign(this.params, updates);
|
|
120
|
+
}
|
|
121
|
+
render(ctx) {
|
|
122
|
+
const p = this.params;
|
|
123
|
+
const stops = p.colors.length >= 2 ? p.colors : DEFAULT_PARAMS.colors;
|
|
124
|
+
const count = Math.min(MAX_STOPS, stops.length);
|
|
125
|
+
// Flatten the stops to a vec3[MAX_STOPS] array, padding with the last.
|
|
126
|
+
const flat = new Float32Array(MAX_STOPS * 3);
|
|
127
|
+
for (let i = 0; i < MAX_STOPS; i++) {
|
|
128
|
+
const [r, g, b] = parseHexColor(stops[Math.min(i, count - 1)]);
|
|
129
|
+
flat[i * 3] = r;
|
|
130
|
+
flat[i * 3 + 1] = g;
|
|
131
|
+
flat[i * 3 + 2] = b;
|
|
132
|
+
}
|
|
133
|
+
ctx.draw({
|
|
134
|
+
frag: FRAG_GRADIENT_MAP,
|
|
135
|
+
uniforms: {
|
|
136
|
+
src: ctx.src,
|
|
137
|
+
colors: flat,
|
|
138
|
+
colorCount: count,
|
|
139
|
+
scatter: Math.max(0, p.scatter),
|
|
140
|
+
offset: p.offset,
|
|
141
|
+
repeatType: REPEAT_TYPES[p.repeat] ?? 0,
|
|
142
|
+
frequency: p.frequency,
|
|
143
|
+
mixSpace: MIX_SPACES[p.mixSpace] ?? 0,
|
|
144
|
+
time: ctx.time * p.speed,
|
|
145
|
+
},
|
|
146
|
+
target: ctx.target,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=gradient-map.js.map
|
|
@@ -0,0 +1 @@
|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,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Effect, EffectContext } from "@vfx-js/core";
|
|
2
|
+
export type HueShiftParams = {
|
|
3
|
+
/** Hue rotation amount; `0..1` covers a full revolution. */
|
|
4
|
+
shift: number;
|
|
5
|
+
};
|
|
6
|
+
export declare class HueShiftEffect implements Effect {
|
|
7
|
+
params: HueShiftParams;
|
|
8
|
+
constructor(initial?: Partial<HueShiftParams>);
|
|
9
|
+
setParams(updates: Partial<HueShiftParams>): void;
|
|
10
|
+
render(ctx: EffectContext): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const FRAG_HUE_SHIFT = `#version 300 es
|
|
2
|
+
precision highp float;
|
|
3
|
+
in vec2 uvContent;
|
|
4
|
+
out vec4 outColor;
|
|
5
|
+
uniform sampler2D src;
|
|
6
|
+
uniform vec4 srcRectUv;
|
|
7
|
+
uniform float shift;
|
|
8
|
+
|
|
9
|
+
vec4 readTex(vec2 c) {
|
|
10
|
+
if (c.x < 0.0 || c.x > 1.0 || c.y < 0.0 || c.y > 1.0) return vec4(0.0);
|
|
11
|
+
return texture(src, srcRectUv.xy + c * srcRectUv.zw);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
vec3 hsv2rgb(vec3 c) {
|
|
15
|
+
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
16
|
+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
17
|
+
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
vec3 rgb2hsv(vec3 c) {
|
|
21
|
+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
22
|
+
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
23
|
+
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
|
24
|
+
|
|
25
|
+
float d = q.x - min(q.w, q.y);
|
|
26
|
+
float e = 1.0e-10;
|
|
27
|
+
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
vec3 hueShift(vec3 rgb, float t) {
|
|
31
|
+
vec3 hsv = rgb2hsv(rgb);
|
|
32
|
+
hsv.x = fract(hsv.x + t);
|
|
33
|
+
return hsv2rgb(hsv);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void main (void) {
|
|
37
|
+
vec4 color = readTex(uvContent);
|
|
38
|
+
color.rgb = hueShift(color.rgb, shift);
|
|
39
|
+
outColor = color;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
const DEFAULT_PARAMS = { shift: 0.5 };
|
|
43
|
+
export class HueShiftEffect {
|
|
44
|
+
constructor(initial = {}) {
|
|
45
|
+
this.params = { ...DEFAULT_PARAMS, ...initial };
|
|
46
|
+
}
|
|
47
|
+
setParams(updates) {
|
|
48
|
+
Object.assign(this.params, updates);
|
|
49
|
+
}
|
|
50
|
+
render(ctx) {
|
|
51
|
+
ctx.draw({
|
|
52
|
+
frag: FRAG_HUE_SHIFT,
|
|
53
|
+
uniforms: {
|
|
54
|
+
src: ctx.src,
|
|
55
|
+
shift: this.params.shift,
|
|
56
|
+
},
|
|
57
|
+
target: ctx.target,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=hue-shift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hue-shift.js","sourceRoot":"","sources":["../../src/hue-shift.ts"],"names":[],"mappings":"AAIA,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCtB,CAAC;AAOF,MAAM,cAAc,GAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAEtD,MAAM,OAAO,cAAc;IAGvB,YAAY,UAAmC,EAAE;QAC7C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAAgC;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAkB;QACrB,GAAG,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;aAC3B;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
+
export { ASCII_PRESETS, type AsciiCharRamp, type AsciiColor, AsciiEffect, type AsciiImageSource, type AsciiParams, type AsciiPresetName, } from "./ascii";
|
|
1
2
|
export { BadJpegEffect, type BadJpegEffectOptions } from "./bad-jpeg";
|
|
2
3
|
export { BloomEffect } from "./bloom";
|
|
4
|
+
export { ChromaticEffect, type ChromaticParams } from "./chromatic";
|
|
5
|
+
export { ColoredEdgesEffect, type ColoredEdgesParams, } from "./colored-edges";
|
|
3
6
|
export { type DatamoshColorSpace, DatamoshEffect, type DatamoshParams, type DatamoshView, } from "./datamosh";
|
|
7
|
+
export { DitherEffect, type DitherParams, type DitherStyle } from "./dither";
|
|
8
|
+
export { DuotoneEffect, type DuotoneParams, type Rgba } from "./duotone";
|
|
4
9
|
export { FluidEffect } from "./fluid";
|
|
10
|
+
export { GlitchEffect, type GlitchParams } from "./glitch";
|
|
11
|
+
export { GradientMapEffect, type GradientMapMixSpace, type GradientMapParams, type GradientMapRepeat, } from "./gradient-map";
|
|
5
12
|
export { HalftoneEffect, type HalftoneInkPresetName } from "./halftone";
|
|
13
|
+
export { HueShiftEffect, type HueShiftParams } from "./hue-shift";
|
|
6
14
|
export { JPEGGlitchEffect, type JPEGGlitchParams } from "./jpeg-glitch";
|
|
15
|
+
export { LightStreakEffect, type LightStreakParams } from "./light-streak";
|
|
16
|
+
export { MATRIX_GLYPHS, type MatrixColor, MatrixEffect, type MatrixGlyphs, type MatrixParams, } from "./matrix";
|
|
7
17
|
export { ParticleEffect } from "./particle";
|
|
8
18
|
export { ParticleExplodeEffect } from "./particle-explode";
|
|
19
|
+
export { PatternRefractionEffect, type PatternRefractionParams, type RefractionEdgeWrap, type RefractionPattern, } from "./pattern-refraction";
|
|
20
|
+
export { PixelStretchEffect, type PixelStretchParams, } from "./pixel-stretch";
|
|
9
21
|
export { PixelateEffect } from "./pixelate";
|
|
10
22
|
export { type PixelSortDirection, PixelSortEffect, type PixelSortKey, type PixelSortParams, } from "./pixelsort";
|
|
23
|
+
export { RainbowEffect, type RainbowParams } from "./rainbow";
|
|
24
|
+
export { RgbGlitchEffect, type RgbGlitchParams } from "./rgb-glitch";
|
|
25
|
+
export { RgbShiftEffect, type RgbShiftParams } from "./rgb-shift";
|
|
11
26
|
export { ScanlineEffect } from "./scanline";
|
|
27
|
+
export { SinewaveEffect, type SinewaveParams } from "./sinewave";
|
|
28
|
+
export { SliceShiftEffect, type SliceShiftParams } from "./slice-shift";
|
|
29
|
+
export { TilePixelateEffect, type TilePixelateParams, type TilePixelateShape, } from "./tile-pixelate";
|
|
30
|
+
export { TritoneEffect, type TritoneParams } from "./tritone";
|
|
31
|
+
export { VignetteEffect, type VignetteParams } from "./vignette";
|
|
12
32
|
export { VoronoiEffect } from "./voronoi";
|
|
33
|
+
export { WarpEffect, type WarpParams, type WarpType } from "./warp";
|
package/lib/esm/index.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
+
export { ASCII_PRESETS, AsciiEffect, } from "./ascii";
|
|
1
2
|
export { BadJpegEffect } from "./bad-jpeg";
|
|
2
3
|
export { BloomEffect } from "./bloom";
|
|
4
|
+
export { ChromaticEffect } from "./chromatic";
|
|
5
|
+
export { ColoredEdgesEffect, } from "./colored-edges";
|
|
3
6
|
export { DatamoshEffect, } from "./datamosh";
|
|
7
|
+
export { DitherEffect } from "./dither";
|
|
8
|
+
export { DuotoneEffect } from "./duotone";
|
|
4
9
|
export { FluidEffect } from "./fluid";
|
|
10
|
+
export { GlitchEffect } from "./glitch";
|
|
11
|
+
export { GradientMapEffect, } from "./gradient-map";
|
|
5
12
|
export { HalftoneEffect } from "./halftone";
|
|
13
|
+
export { HueShiftEffect } from "./hue-shift";
|
|
6
14
|
export { JPEGGlitchEffect } from "./jpeg-glitch";
|
|
15
|
+
export { LightStreakEffect } from "./light-streak";
|
|
16
|
+
export { MATRIX_GLYPHS, MatrixEffect, } from "./matrix";
|
|
7
17
|
export { ParticleEffect } from "./particle";
|
|
8
18
|
export { ParticleExplodeEffect } from "./particle-explode";
|
|
19
|
+
export { PatternRefractionEffect, } from "./pattern-refraction";
|
|
20
|
+
export { PixelStretchEffect, } from "./pixel-stretch";
|
|
9
21
|
export { PixelateEffect } from "./pixelate";
|
|
10
22
|
export { PixelSortEffect, } from "./pixelsort";
|
|
23
|
+
export { RainbowEffect } from "./rainbow";
|
|
24
|
+
export { RgbGlitchEffect } from "./rgb-glitch";
|
|
25
|
+
export { RgbShiftEffect } from "./rgb-shift";
|
|
11
26
|
export { ScanlineEffect } from "./scanline";
|
|
27
|
+
export { SinewaveEffect } from "./sinewave";
|
|
28
|
+
export { SliceShiftEffect } from "./slice-shift";
|
|
29
|
+
export { TilePixelateEffect, } from "./tile-pixelate";
|
|
30
|
+
export { TritoneEffect } from "./tritone";
|
|
31
|
+
export { VignetteEffect } from "./vignette";
|
|
12
32
|
export { VoronoiEffect } from "./voronoi";
|
|
33
|
+
export { WarpEffect } from "./warp";
|
|
13
34
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6B,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAEH,cAAc,GAGjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,cAAc,EAA8B,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAEH,eAAe,GAGlB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAGb,WAAW,GAId,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAA6B,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AACpE,OAAO,EACH,kBAAkB,GAErB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEH,cAAc,GAGjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAuC,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAiC,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,YAAY,EAAqB,MAAM,UA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{ Effect, EffectContext, EffectDims } from "@vfx-js/core";
|
|
2
|
+
export type LightStreakParams = {
|
|
3
|
+
/**
|
|
4
|
+
* Number of rays. `2` → a single horizontal axis (anamorphic flare);
|
|
5
|
+
* `n` → an n-pointed aperture starburst.
|
|
6
|
+
*/
|
|
7
|
+
streaks: number;
|
|
8
|
+
/** Base rotation of the ray fan, in degrees. */
|
|
9
|
+
angle: number;
|
|
10
|
+
/** Max streak length in CSS (logical) px. */
|
|
11
|
+
length: number;
|
|
12
|
+
/**
|
|
13
|
+
* Streak width in CSS (logical) px — the gaussian cross-section of
|
|
14
|
+
* each streak. Thinner than the sampling grid cell and the streak
|
|
15
|
+
* breaks into stripes; raise `density` for thin-yet-continuous streaks.
|
|
16
|
+
*/
|
|
17
|
+
width: number;
|
|
18
|
+
/**
|
|
19
|
+
* Exponential length fade decay rate. Higher concentrates the
|
|
20
|
+
* brightness into a tighter core near the source and trails a fainter
|
|
21
|
+
* tail; lower flattens toward an even streak.
|
|
22
|
+
*/
|
|
23
|
+
falloff: number;
|
|
24
|
+
/** Highlight cutoff in [0,1]. Only highlights above this throw streaks. */
|
|
25
|
+
threshold: number;
|
|
26
|
+
/**
|
|
27
|
+
* Upper clamp on source highlight brightness (Blender's highlight
|
|
28
|
+
* "Maximum"), so blown-out sources don't dominate the accumulation.
|
|
29
|
+
* Floored to just above `threshold`; lower values have no extra effect.
|
|
30
|
+
*/
|
|
31
|
+
highlightClamp: number;
|
|
32
|
+
/**
|
|
33
|
+
* Streak brightness. Drives a soft-saturating tone map
|
|
34
|
+
* (`1 - exp(-acc * intensity)`), so raising it brightens without
|
|
35
|
+
* clipping accumulated highlights to white.
|
|
36
|
+
*/
|
|
37
|
+
intensity: number;
|
|
38
|
+
/** Per-channel multiplier on the streak colour. */
|
|
39
|
+
tint: readonly [number, number, number];
|
|
40
|
+
/**
|
|
41
|
+
* Chromatic dispersion, -1..1. Gives each channel a different reach so
|
|
42
|
+
* the streak fringes through colour toward its tip. `+1` lets red
|
|
43
|
+
* persist furthest (warm tip, like aperture diffraction); `-1` lets blue
|
|
44
|
+
* persist (cool tip, refractive look); `0` is achromatic.
|
|
45
|
+
*/
|
|
46
|
+
dispersion: number;
|
|
47
|
+
/**
|
|
48
|
+
* Diffraction fringe contrast, 0..1. Periodic brightness modulation
|
|
49
|
+
* along the streak whose period scales with wavelength, so bands
|
|
50
|
+
* converge to white at the source and separate into rainbow further
|
|
51
|
+
* out. Distinct from `dispersion` (a monotone tip-ward shift); `0`
|
|
52
|
+
* disables it.
|
|
53
|
+
*/
|
|
54
|
+
fringe: number;
|
|
55
|
+
/** Fringes along the streak (green channel reference); fractional. */
|
|
56
|
+
fringeCount: number;
|
|
57
|
+
/**
|
|
58
|
+
* Source sampling grid dimension (instance count = `density²`).
|
|
59
|
+
* Higher resolves finer highlights, lets streaks be thinner without
|
|
60
|
+
* banding, and costs more vertex work (most instances are culled, so
|
|
61
|
+
* fragment cost stays tied to highlight count).
|
|
62
|
+
*/
|
|
63
|
+
density: number;
|
|
64
|
+
/**
|
|
65
|
+
* Accumulation buffer resolution relative to the output, 0..1.
|
|
66
|
+
* Streaks are soft, so `0.5` looks nearly identical and cuts GPU
|
|
67
|
+
* bandwidth to a quarter. `1` accumulates at full resolution.
|
|
68
|
+
*/
|
|
69
|
+
resolution: number;
|
|
70
|
+
/**
|
|
71
|
+
* Extra pad around the element in CSS px so streaks aren't clipped at
|
|
72
|
+
* the element edge. Should be ≥ `length`. `"fullscreen"` reaches the
|
|
73
|
+
* viewport edges.
|
|
74
|
+
*/
|
|
75
|
+
pad: number | "fullscreen";
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Light-streak effect (anamorphic flare / aperture starburst) built from
|
|
79
|
+
* instanced streak sprites. Mutate `params` directly or via `setParams`;
|
|
80
|
+
* uniforms are read live each frame, so a reactive UI (e.g. Tweakpane)
|
|
81
|
+
* can bind straight to `effect.params`.
|
|
82
|
+
*/
|
|
83
|
+
export declare class LightStreakEffect implements Effect {
|
|
84
|
+
#private;
|
|
85
|
+
params: LightStreakParams;
|
|
86
|
+
constructor(initial?: Partial<LightStreakParams>);
|
|
87
|
+
setParams(updates: Partial<LightStreakParams>): void;
|
|
88
|
+
render(ctx: EffectContext): void;
|
|
89
|
+
outputRect(dims: EffectDims): readonly [number, number, number, number];
|
|
90
|
+
dispose(): void;
|
|
91
|
+
}
|