@vfx-js/effects 1.2.0 → 1.3.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.
Files changed (136) hide show
  1. package/README.md +2 -0
  2. package/lib/cjs/_figma-common.d.ts +8 -0
  3. package/lib/cjs/_figma-common.js +46 -0
  4. package/lib/cjs/_figma-common.js.map +1 -0
  5. package/lib/cjs/ascii.d.ts +137 -0
  6. package/lib/cjs/ascii.js +482 -0
  7. package/lib/cjs/ascii.js.map +1 -0
  8. package/lib/cjs/chromatic.d.ts +15 -0
  9. package/lib/cjs/chromatic.js +70 -0
  10. package/lib/cjs/chromatic.js.map +1 -0
  11. package/lib/cjs/colored-edges.d.ts +23 -0
  12. package/lib/cjs/colored-edges.js +88 -0
  13. package/lib/cjs/colored-edges.js.map +1 -0
  14. package/lib/cjs/dither.d.ts +24 -0
  15. package/lib/cjs/dither.js +120 -0
  16. package/lib/cjs/dither.js.map +1 -0
  17. package/lib/cjs/duotone.d.ts +17 -0
  18. package/lib/cjs/duotone.js +62 -0
  19. package/lib/cjs/duotone.js.map +1 -0
  20. package/lib/cjs/glitch.d.ts +13 -0
  21. package/lib/cjs/glitch.js +108 -0
  22. package/lib/cjs/glitch.js.map +1 -0
  23. package/lib/cjs/gradient-map.d.ts +25 -0
  24. package/lib/cjs/gradient-map.js +154 -0
  25. package/lib/cjs/gradient-map.js.map +1 -0
  26. package/lib/cjs/hue-shift.d.ts +11 -0
  27. package/lib/cjs/hue-shift.js +65 -0
  28. package/lib/cjs/hue-shift.js.map +1 -0
  29. package/lib/cjs/index.d.ts +20 -0
  30. package/lib/cjs/index.js +43 -1
  31. package/lib/cjs/index.js.map +1 -1
  32. package/lib/cjs/matrix.d.ts +135 -0
  33. package/lib/cjs/matrix.js +593 -0
  34. package/lib/cjs/matrix.js.map +1 -0
  35. package/lib/cjs/package.json +1 -1
  36. package/lib/cjs/pattern-refraction.d.ts +31 -0
  37. package/lib/cjs/pattern-refraction.js +190 -0
  38. package/lib/cjs/pattern-refraction.js.map +1 -0
  39. package/lib/cjs/pixel-stretch.d.ts +21 -0
  40. package/lib/cjs/pixel-stretch.js +78 -0
  41. package/lib/cjs/pixel-stretch.js.map +1 -0
  42. package/lib/cjs/rainbow.d.ts +13 -0
  43. package/lib/cjs/rainbow.js +79 -0
  44. package/lib/cjs/rainbow.js.map +1 -0
  45. package/lib/cjs/rgb-glitch.d.ts +13 -0
  46. package/lib/cjs/rgb-glitch.js +79 -0
  47. package/lib/cjs/rgb-glitch.js.map +1 -0
  48. package/lib/cjs/rgb-shift.d.ts +13 -0
  49. package/lib/cjs/rgb-shift.js +76 -0
  50. package/lib/cjs/rgb-shift.js.map +1 -0
  51. package/lib/cjs/sinewave.d.ts +17 -0
  52. package/lib/cjs/sinewave.js +76 -0
  53. package/lib/cjs/sinewave.js.map +1 -0
  54. package/lib/cjs/slice-shift.d.ts +21 -0
  55. package/lib/cjs/slice-shift.js +75 -0
  56. package/lib/cjs/slice-shift.js.map +1 -0
  57. package/lib/cjs/tile-pixelate.d.ts +28 -0
  58. package/lib/cjs/tile-pixelate.js +168 -0
  59. package/lib/cjs/tile-pixelate.js.map +1 -0
  60. package/lib/cjs/tritone.d.ts +18 -0
  61. package/lib/cjs/tritone.js +67 -0
  62. package/lib/cjs/tritone.js.map +1 -0
  63. package/lib/cjs/vignette.d.ts +15 -0
  64. package/lib/cjs/vignette.js +59 -0
  65. package/lib/cjs/vignette.js.map +1 -0
  66. package/lib/cjs/warp.d.ts +22 -0
  67. package/lib/cjs/warp.js +92 -0
  68. package/lib/cjs/warp.js.map +1 -0
  69. package/lib/esm/_figma-common.d.ts +8 -0
  70. package/lib/esm/_figma-common.js +42 -0
  71. package/lib/esm/_figma-common.js.map +1 -0
  72. package/lib/esm/ascii.d.ts +137 -0
  73. package/lib/esm/ascii.js +478 -0
  74. package/lib/esm/ascii.js.map +1 -0
  75. package/lib/esm/chromatic.d.ts +15 -0
  76. package/lib/esm/chromatic.js +66 -0
  77. package/lib/esm/chromatic.js.map +1 -0
  78. package/lib/esm/colored-edges.d.ts +23 -0
  79. package/lib/esm/colored-edges.js +84 -0
  80. package/lib/esm/colored-edges.js.map +1 -0
  81. package/lib/esm/dither.d.ts +24 -0
  82. package/lib/esm/dither.js +116 -0
  83. package/lib/esm/dither.js.map +1 -0
  84. package/lib/esm/duotone.d.ts +17 -0
  85. package/lib/esm/duotone.js +58 -0
  86. package/lib/esm/duotone.js.map +1 -0
  87. package/lib/esm/glitch.d.ts +13 -0
  88. package/lib/esm/glitch.js +104 -0
  89. package/lib/esm/glitch.js.map +1 -0
  90. package/lib/esm/gradient-map.d.ts +25 -0
  91. package/lib/esm/gradient-map.js +150 -0
  92. package/lib/esm/gradient-map.js.map +1 -0
  93. package/lib/esm/hue-shift.d.ts +11 -0
  94. package/lib/esm/hue-shift.js +61 -0
  95. package/lib/esm/hue-shift.js.map +1 -0
  96. package/lib/esm/index.d.ts +20 -0
  97. package/lib/esm/index.js +20 -0
  98. package/lib/esm/index.js.map +1 -1
  99. package/lib/esm/matrix.d.ts +135 -0
  100. package/lib/esm/matrix.js +589 -0
  101. package/lib/esm/matrix.js.map +1 -0
  102. package/lib/esm/package.json +1 -1
  103. package/lib/esm/pattern-refraction.d.ts +31 -0
  104. package/lib/esm/pattern-refraction.js +186 -0
  105. package/lib/esm/pattern-refraction.js.map +1 -0
  106. package/lib/esm/pixel-stretch.d.ts +21 -0
  107. package/lib/esm/pixel-stretch.js +74 -0
  108. package/lib/esm/pixel-stretch.js.map +1 -0
  109. package/lib/esm/rainbow.d.ts +13 -0
  110. package/lib/esm/rainbow.js +75 -0
  111. package/lib/esm/rainbow.js.map +1 -0
  112. package/lib/esm/rgb-glitch.d.ts +13 -0
  113. package/lib/esm/rgb-glitch.js +75 -0
  114. package/lib/esm/rgb-glitch.js.map +1 -0
  115. package/lib/esm/rgb-shift.d.ts +13 -0
  116. package/lib/esm/rgb-shift.js +72 -0
  117. package/lib/esm/rgb-shift.js.map +1 -0
  118. package/lib/esm/sinewave.d.ts +17 -0
  119. package/lib/esm/sinewave.js +72 -0
  120. package/lib/esm/sinewave.js.map +1 -0
  121. package/lib/esm/slice-shift.d.ts +21 -0
  122. package/lib/esm/slice-shift.js +71 -0
  123. package/lib/esm/slice-shift.js.map +1 -0
  124. package/lib/esm/tile-pixelate.d.ts +28 -0
  125. package/lib/esm/tile-pixelate.js +164 -0
  126. package/lib/esm/tile-pixelate.js.map +1 -0
  127. package/lib/esm/tritone.d.ts +18 -0
  128. package/lib/esm/tritone.js +63 -0
  129. package/lib/esm/tritone.js.map +1 -0
  130. package/lib/esm/vignette.d.ts +15 -0
  131. package/lib/esm/vignette.js +55 -0
  132. package/lib/esm/vignette.js.map +1 -0
  133. package/lib/esm/warp.d.ts +22 -0
  134. package/lib/esm/warp.js +88 -0
  135. package/lib/esm/warp.js.map +1 -0
  136. package/package.json +1 -1
@@ -0,0 +1,66 @@
1
+ const FRAG_CHROMATIC = `#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 aspect;
8
+ uniform float intensity;
9
+ uniform float radius;
10
+ uniform float power;
11
+
12
+ // Sample at a content-space UV mirror-wrapped into [0, 1], remapped into
13
+ // the padded src buffer via srcRectUv.
14
+ vec4 mirrorTex(vec2 uv) {
15
+ vec2 uv2 = 1. - abs(1. - mod(uv, 2.0));
16
+ return texture(src, srcRectUv.xy + uv2 * srcRectUv.zw);
17
+ }
18
+
19
+ void main() {
20
+ vec2 uv = uvContent;
21
+
22
+ vec2 p = uv * 2.0 - 1.0;
23
+ p.x *= aspect;
24
+
25
+ float l = max(length(p) - radius, 0.);
26
+ float d = pow(l, power) * (intensity * 0.1);
27
+
28
+ vec2 uvR = (uv - .5) / (1.0 + d * 1.) + 0.5;
29
+ vec2 uvG = (uv - .5) / (1.0 + d * 2.) + 0.5;
30
+ vec2 uvB = (uv - .5) / (1.0 + d * 3.) + 0.5;
31
+
32
+ vec4 cr = mirrorTex(uvR);
33
+ vec4 cg = mirrorTex(uvG);
34
+ vec4 cb = mirrorTex(uvB);
35
+
36
+ outColor = vec4(cr.r, cg.g, cb.b, (cr.a + cg.a + cb.a) / 3.0);
37
+ }
38
+ `;
39
+ const DEFAULT_PARAMS = {
40
+ intensity: 0.3,
41
+ radius: 0.0,
42
+ power: 2.0,
43
+ };
44
+ export class ChromaticEffect {
45
+ constructor(initial = {}) {
46
+ this.params = { ...DEFAULT_PARAMS, ...initial };
47
+ }
48
+ setParams(updates) {
49
+ Object.assign(this.params, updates);
50
+ }
51
+ render(ctx) {
52
+ const [w, h] = ctx.dims.element;
53
+ ctx.draw({
54
+ frag: FRAG_CHROMATIC,
55
+ uniforms: {
56
+ src: ctx.src,
57
+ aspect: (w || 1) / (h || 1),
58
+ intensity: this.params.intensity,
59
+ radius: this.params.radius,
60
+ power: this.params.power,
61
+ },
62
+ target: ctx.target,
63
+ });
64
+ }
65
+ }
66
+ //# sourceMappingURL=chromatic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chromatic.js","sourceRoot":"","sources":["../../src/chromatic.ts"],"names":[],"mappings":"AAKA,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCtB,CAAC;AAWF,MAAM,cAAc,GAAoB;IACpC,SAAS,EAAE,GAAG;IACd,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,GAAG;CACb,CAAC;AAEF,MAAM,OAAO,eAAe;IAGxB,YAAY,UAAoC,EAAE;QAC9C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAAiC;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAkB;QACrB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;QAChC,GAAG,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC3B,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;gBAChC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;aAC3B;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,23 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ export type ColoredEdgesParams = {
3
+ /** Edge detection threshold, in [0, 1]. */
4
+ threshold: number;
5
+ /** Sampling radius for the Sobel kernel, in px. */
6
+ thickness: number;
7
+ /** Edge contrast multiplier. */
8
+ intensity: number;
9
+ /** Blend the source back in over the edges, in [0, 1]. */
10
+ opacity: number;
11
+ /** Gradient start color. Accepts a hex string. */
12
+ color1: string;
13
+ /** Gradient end color. Accepts a hex string. */
14
+ color2: string;
15
+ /** Background color for non-edge areas. Accepts a hex string. */
16
+ background: string;
17
+ };
18
+ export declare class ColoredEdgesEffect implements Effect {
19
+ params: ColoredEdgesParams;
20
+ constructor(initial?: Partial<ColoredEdgesParams>);
21
+ setParams(updates: Partial<ColoredEdgesParams>): void;
22
+ render(ctx: EffectContext): void;
23
+ }
@@ -0,0 +1,84 @@
1
+ import { parseHexColor } from "./_figma-common";
2
+ const FRAG_COLORED_EDGES = `#version 300 es
3
+ precision highp float;
4
+ in vec2 uvContent;
5
+ out vec4 outColor;
6
+ uniform sampler2D src;
7
+ uniform vec4 srcRectUv;
8
+ uniform vec2 resolution;
9
+ uniform float threshold;
10
+ uniform float thickness;
11
+ uniform float intensity;
12
+ uniform float opacity;
13
+ uniform vec4 color1;
14
+ uniform vec4 color2;
15
+ uniform vec4 background;
16
+
17
+ vec3 sampleSrc(vec2 uv) {
18
+ return texture(src, srcRectUv.xy + uv * srcRectUv.zw).rgb;
19
+ }
20
+
21
+ float lum(vec3 c) { return dot(c, vec3(0.299, 0.587, 0.114)); }
22
+
23
+ void main(void) {
24
+ vec2 d = thickness / resolution;
25
+ // Sobel gradient on luminance.
26
+ float tl = lum(sampleSrc(uvContent + vec2(-d.x, d.y)));
27
+ float tc = lum(sampleSrc(uvContent + vec2(0.0, d.y)));
28
+ float tr = lum(sampleSrc(uvContent + vec2(d.x, d.y)));
29
+ float ml = lum(sampleSrc(uvContent + vec2(-d.x, 0.0)));
30
+ float mr = lum(sampleSrc(uvContent + vec2(d.x, 0.0)));
31
+ float bl = lum(sampleSrc(uvContent + vec2(-d.x, -d.y)));
32
+ float bc = lum(sampleSrc(uvContent + vec2(0.0, -d.y)));
33
+ float br = lum(sampleSrc(uvContent + vec2(d.x, -d.y)));
34
+
35
+ float gx = (tr + 2.0 * mr + br) - (tl + 2.0 * ml + bl);
36
+ float gy = (tl + 2.0 * tc + tr) - (bl + 2.0 * bc + br);
37
+ float g = length(vec2(gx, gy));
38
+
39
+ float e = clamp(g * intensity - threshold, 0.0, 1.0);
40
+ vec3 edgeCol = mix(color1.rgb, color2.rgb, clamp(g, 0.0, 1.0));
41
+ vec3 base = mix(background.rgb, edgeCol, e);
42
+
43
+ // Opacity blends the untouched source back in over the edge render.
44
+ vec3 orig = sampleSrc(uvContent);
45
+ outColor = vec4(mix(base, orig, opacity), 1.0);
46
+ }
47
+ `;
48
+ const DEFAULT_PARAMS = {
49
+ threshold: 0.2,
50
+ thickness: 3,
51
+ intensity: 4,
52
+ opacity: 0,
53
+ color1: "#ff0000",
54
+ color2: "#0000ff",
55
+ background: "#000000",
56
+ };
57
+ export class ColoredEdgesEffect {
58
+ constructor(initial = {}) {
59
+ this.params = { ...DEFAULT_PARAMS, ...initial };
60
+ }
61
+ setParams(updates) {
62
+ Object.assign(this.params, updates);
63
+ }
64
+ render(ctx) {
65
+ const p = this.params;
66
+ const [w, h] = ctx.dims.elementPixel;
67
+ ctx.draw({
68
+ frag: FRAG_COLORED_EDGES,
69
+ uniforms: {
70
+ src: ctx.src,
71
+ resolution: [Math.max(1, w), Math.max(1, h)],
72
+ threshold: p.threshold,
73
+ thickness: Math.max(0.5, p.thickness),
74
+ intensity: Math.max(0, p.intensity),
75
+ opacity: Math.min(1, Math.max(0, p.opacity)),
76
+ color1: parseHexColor(p.color1),
77
+ color2: parseHexColor(p.color2),
78
+ background: parseHexColor(p.background),
79
+ },
80
+ target: ctx.target,
81
+ });
82
+ }
83
+ }
84
+ //# sourceMappingURL=colored-edges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colored-edges.js","sourceRoot":"","sources":["../../src/colored-edges.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6C1B,CAAC;AAmBF,MAAM,cAAc,GAAuB;IACvC,SAAS,EAAE,GAAG;IACd,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,SAAS;CACxB,CAAC;AAEF,MAAM,OAAO,kBAAkB;IAG3B,YAAY,UAAuC,EAAE;QACjD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAAoC;QAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAkB;QACrB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;QACrC,GAAG,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,kBAAkB;YACxB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC5C,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC;gBACrC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;gBACnC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;gBAC5C,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC/B,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC;aAC1C;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,24 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ export type DitherStyle = "bayer2" | "bayer4" | "bayer8" | "bayer16" | "blueNoise" | "threshold";
3
+ export type DitherParams = {
4
+ /** Dither pattern. */
5
+ style: DitherStyle;
6
+ /** Pattern scale, in px per dither cell. */
7
+ size: number;
8
+ /** Quantization steps per channel. */
9
+ levels: number;
10
+ /** Brightness applied before quantization (1 = unchanged). */
11
+ brightness: number;
12
+ /** Contrast applied before quantization (1 = unchanged). */
13
+ contrast: number;
14
+ /** Output a single tinted channel instead of RGB. */
15
+ mono: boolean;
16
+ /** Foreground tint for mono mode. Accepts a hex string. */
17
+ monoColor: string;
18
+ };
19
+ export declare class DitherEffect implements Effect {
20
+ params: DitherParams;
21
+ constructor(initial?: Partial<DitherParams>);
22
+ setParams(updates: Partial<DitherParams>): void;
23
+ render(ctx: EffectContext): void;
24
+ }
@@ -0,0 +1,116 @@
1
+ import { parseHexColor } from "./_figma-common";
2
+ const FRAG_DITHER = `#version 300 es
3
+ precision highp float;
4
+ in vec2 uvContent;
5
+ out vec4 outColor;
6
+ uniform sampler2D src;
7
+ uniform vec4 srcRectUv;
8
+ uniform vec2 resolution;
9
+ uniform int style;
10
+ uniform float size;
11
+ uniform float levels;
12
+ uniform float brightness;
13
+ uniform float contrast;
14
+ uniform float mono;
15
+ uniform vec4 monoColor;
16
+
17
+ // Recursive Bayer ordered-dither thresholds, in [0, 1).
18
+ float bayer2(vec2 a) {
19
+ a = floor(a);
20
+ return fract(a.x / 2.0 + a.y * a.y * 0.75);
21
+ }
22
+ float bayer4(vec2 a) { return bayer2(0.5 * a) * 0.25 + bayer2(a); }
23
+ float bayer8(vec2 a) { return bayer4(0.5 * a) * 0.25 + bayer2(a); }
24
+ float bayer16(vec2 a) { return bayer8(0.5 * a) * 0.25 + bayer2(a); }
25
+
26
+ float hash12(vec2 p) {
27
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
28
+ p3 += dot(p3, p3.yzx + 33.33);
29
+ return fract((p3.x + p3.y) * p3.z);
30
+ }
31
+
32
+ float threshold(vec2 cell) {
33
+ if (style == 0) return bayer2(cell);
34
+ if (style == 1) return bayer4(cell);
35
+ if (style == 2) return bayer8(cell);
36
+ if (style == 3) return bayer16(cell);
37
+ // Blue noise: approximated by a per-cell hash (not a true blue spectrum).
38
+ if (style == 4) return hash12(cell);
39
+ return 0.5; // Threshold: no pattern, hard quantization.
40
+ }
41
+
42
+ void main(void) {
43
+ float cellSize = max(1.0, size);
44
+ // Content origin in fragment px (constant across the element). Bucketing
45
+ // on the integer fragment grid keeps cells square; anchoring to this
46
+ // origin (not raw gl_FragCoord) ties the pattern to the src rect, not
47
+ // the screen.
48
+ vec2 originPx = floor(gl_FragCoord.xy - uvContent * resolution + 0.5);
49
+ // Pixel position measured from the src-rect center.
50
+ vec2 centerPx = gl_FragCoord.xy - originPx - 0.5 * resolution;
51
+ vec2 cell = floor(centerPx / cellSize);
52
+ // Sample once per cell so each cell is a single flat color.
53
+ vec2 cellUv = ((cell + 0.5) * cellSize) / resolution + 0.5;
54
+ vec4 tex = texture(src, srcRectUv.xy + cellUv * srcRectUv.zw);
55
+ vec3 c = tex.rgb;
56
+ c = (c - 0.5) * contrast + 0.5;
57
+ c *= brightness;
58
+
59
+ float th = threshold(cell);
60
+ float steps = max(1.0, levels - 1.0);
61
+
62
+ if (mono > 0.5) {
63
+ float l = dot(c, vec3(0.299, 0.587, 0.114));
64
+ float q = clamp(floor(l * steps + th) / steps, 0.0, 1.0);
65
+ outColor = vec4(monoColor.rgb * q, tex.a * monoColor.a);
66
+ } else {
67
+ vec3 q = clamp(floor(c * steps + th) / steps, 0.0, 1.0);
68
+ outColor = vec4(q, tex.a);
69
+ }
70
+ }
71
+ `;
72
+ const DITHER_STYLES = {
73
+ bayer2: 0,
74
+ bayer4: 1,
75
+ bayer8: 2,
76
+ bayer16: 3,
77
+ blueNoise: 4,
78
+ threshold: 5,
79
+ };
80
+ const DEFAULT_PARAMS = {
81
+ style: "bayer16",
82
+ size: 2,
83
+ levels: 3,
84
+ brightness: 1,
85
+ contrast: 1,
86
+ mono: false,
87
+ monoColor: "#ffffff",
88
+ };
89
+ export class DitherEffect {
90
+ constructor(initial = {}) {
91
+ this.params = { ...DEFAULT_PARAMS, ...initial };
92
+ }
93
+ setParams(updates) {
94
+ Object.assign(this.params, updates);
95
+ }
96
+ render(ctx) {
97
+ const p = this.params;
98
+ const [w, h] = ctx.dims.elementPixel;
99
+ ctx.draw({
100
+ frag: FRAG_DITHER,
101
+ uniforms: {
102
+ src: ctx.src,
103
+ resolution: [Math.max(1, w), Math.max(1, h)],
104
+ style: DITHER_STYLES[p.style] ?? 5,
105
+ size: Math.max(1, p.size),
106
+ levels: Math.max(2, p.levels),
107
+ brightness: p.brightness,
108
+ contrast: p.contrast,
109
+ mono: p.mono ? 1 : 0,
110
+ monoColor: parseHexColor(p.monoColor),
111
+ },
112
+ target: ctx.target,
113
+ });
114
+ }
115
+ }
116
+ //# sourceMappingURL=dither.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dither.js","sourceRoot":"","sources":["../../src/dither.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqEnB,CAAC;AAUF,MAAM,aAAa,GAAgC;IAC/C,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;CACf,CAAC;AAmBF,MAAM,cAAc,GAAiB;IACjC,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,UAAU,EAAE,CAAC;IACb,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,KAAK;IACX,SAAS,EAAE,SAAS;CACvB,CAAC;AAEF,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,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;QACrC,GAAG,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC5C,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBAClC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;gBACzB,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC;gBAC7B,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;aACxC;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,17 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ /** RGBA colour, each channel in [0, 1]. */
3
+ export type Rgba = [number, number, number, number];
4
+ export type DuotoneParams = {
5
+ /** First tone (shadows). */
6
+ color1: Rgba;
7
+ /** Second tone (highlights). */
8
+ color2: Rgba;
9
+ /** Gradient cycling speed. `0` keeps the mapping static. */
10
+ speed: number;
11
+ };
12
+ export declare class DuotoneEffect implements Effect {
13
+ params: DuotoneParams;
14
+ constructor(initial?: Partial<DuotoneParams>);
15
+ setParams(updates: Partial<DuotoneParams>): void;
16
+ render(ctx: EffectContext): void;
17
+ }
@@ -0,0 +1,58 @@
1
+ const FRAG_DUOTONE = `#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 vec4 color1;
9
+ uniform vec4 color2;
10
+ uniform float speed;
11
+
12
+ vec4 readTex(vec2 c) {
13
+ if (c.x < 0.0 || c.x > 1.0 || c.y < 0.0 || c.y > 1.0) return vec4(0.0);
14
+ return texture(src, srcRectUv.xy + c * srcRectUv.zw);
15
+ }
16
+
17
+ void main (void) {
18
+ vec4 color = readTex(uvContent);
19
+
20
+ float gray = dot(color.rgb, vec3(0.2, 0.7, 0.08));
21
+ float t = mod(gray * 2.0 + time * speed, 2.0);
22
+
23
+ if (t < 1.) {
24
+ outColor = mix(color1, color2, fract(t));
25
+ } else {
26
+ outColor = mix(color2, color1, fract(t));
27
+ }
28
+
29
+ outColor.a *= color.a;
30
+ }
31
+ `;
32
+ const DEFAULT_PARAMS = {
33
+ color1: [1, 0, 0, 1],
34
+ color2: [0, 0, 1, 1],
35
+ speed: 0.2,
36
+ };
37
+ export class DuotoneEffect {
38
+ constructor(initial = {}) {
39
+ this.params = { ...DEFAULT_PARAMS, ...initial };
40
+ }
41
+ setParams(updates) {
42
+ Object.assign(this.params, updates);
43
+ }
44
+ render(ctx) {
45
+ ctx.draw({
46
+ frag: FRAG_DUOTONE,
47
+ uniforms: {
48
+ src: ctx.src,
49
+ time: ctx.time,
50
+ color1: this.params.color1,
51
+ color2: this.params.color2,
52
+ speed: this.params.speed,
53
+ },
54
+ target: ctx.target,
55
+ });
56
+ }
57
+ }
58
+ //# sourceMappingURL=duotone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duotone.js","sourceRoot":"","sources":["../../src/duotone.ts"],"names":[],"mappings":"AAQA,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BpB,CAAC;AAWF,MAAM,cAAc,GAAkB;IAClC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG;CACb,CAAC;AAEF,MAAM,OAAO,aAAa;IAGtB,YAAY,UAAkC,EAAE;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAA+B;QACrC,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,YAAY;YAClB,QAAQ,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;aAC3B;YACD,MAAM,EAAE,GAAG,CAAC,MAAM;SACrB,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,13 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ export type GlitchParams = {
3
+ /** Time scale applied to the animation. */
4
+ speed: number;
5
+ /** Overall glitch strength — scales shift and aberration amounts. */
6
+ intensity: number;
7
+ };
8
+ export declare class GlitchEffect implements Effect {
9
+ params: GlitchParams;
10
+ constructor(initial?: Partial<GlitchParams>);
11
+ setParams(updates: Partial<GlitchParams>): void;
12
+ render(ctx: EffectContext): void;
13
+ }
@@ -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
+ }