textmode.filters.js 1.0.1 → 1.1.1

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 CHANGED
@@ -1,23 +1,23 @@
1
+ # textmode.filters.js
2
+
1
3
  <div align="center">
2
4
 
3
- # 🎨 textmode.filters.js
5
+ <!-- Add your banner image here when ready -->
6
+ <!-- <img alt="textmode_filters_banner" src="YOUR_BANNER_IMAGE_URL" /> -->
7
+
8
+ | [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![WebGL](https://img.shields.io/badge/WebGL2-990000?logo=webgl&logoColor=white)](https://www.khronos.org/webgl/) [![Vite](https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white)](https://vitejs.dev/) | [![npm version](https://img.shields.io/npm/v/textmode.filters.js.svg)](https://www.npmjs.com/package/textmode.filters.js) [![license](https://img.shields.io/npm/l/textmode.filters.js.svg)](https://github.com/humanbydefinition/textmode.filters.js/blob/main/LICENSE) | [![Discord](https://img.shields.io/discord/1357070706181017691?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/sjrw8QXNks) [![ko-fi](https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi)](https://ko-fi.com/V7V8JG2FY) [![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/humanbydefinition) |
9
+ |:-------------|:-------------|:-------------|
4
10
 
5
- **GPU-accelerated image filters plugin for [textmode.js](https://code.textmode.art/)**
11
+ </div>
6
12
 
7
- [![npm version](https://img.shields.io/npm/v/textmode.filters.js.svg?style=flat-square)](https://www.npmjs.com/package/textmode.filters.js)
8
- [![license](https://img.shields.io/npm/l/textmode.filters.js.svg?style=flat-square)](https://github.com/humanbydefinition/textmode.filters.js/blob/main/LICENSE)
9
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/humanbydefinition/textmode.filters.js/blob/main/CONTRIBUTING.md)
13
+ textmode.filters.js is a GPU-accelerated image filters plugin for [textmode.js](https://code.textmode.art/). Built with [`WebGL2`](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext) fragment shaders, it provides a collection of customizable visual effects that run entirely on the GPU for maximum performance.
10
14
 
11
15
  [Installation](#installation) •
12
16
  [Usage](#usage) •
13
17
  [Filters](#filters) •
14
18
  [Contributing](#contributing)
15
19
 
16
- </div>
17
-
18
- ---
19
-
20
- ## ✨ Features
20
+ ## Features
21
21
 
22
22
  - 🚀 **GPU-accelerated** - All filters run on the GPU via WebGL2 fragment shaders
23
23
  - 🎛️ **Customizable parameters** - Fine-tune each filter to your needs
@@ -30,8 +30,6 @@
30
30
  npm install textmode.filters.js
31
31
  ```
32
32
 
33
- > **Note:** Make sure `textmode.js` is also installed in your project. This add-on declares it as a peer dependency.
34
-
35
33
  You can also use it via CDN:
36
34
 
37
35
  ```html
@@ -50,12 +48,12 @@ You can also use it via CDN:
50
48
 
51
49
  ```javascript
52
50
  import { textmode } from 'textmode.js';
53
- import { createFiltersPlugin } from 'textmode.filters.js';
51
+ import { FiltersPlugin } from 'textmode.filters.js';
54
52
 
55
53
  const t = textmode.create({
56
54
  width: 800,
57
55
  height: 600,
58
- plugins: [createFiltersPlugin()],
56
+ plugins: [FiltersPlugin],
59
57
  });
60
58
 
61
59
  t.draw(() => {
@@ -75,7 +73,7 @@ t.draw(() => {
75
73
  <script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
76
74
  <script>
77
75
  const t = textmode.create({
78
- plugins: [createFiltersPlugin()],
76
+ plugins: [FiltersPlugin],
79
77
  });
80
78
 
81
79
  t.draw(() => {
@@ -160,6 +158,135 @@ Reduce image resolution to create a mosaic/pixelated effect
160
158
 
161
159
  ---
162
160
 
161
+ ### `gridDistortion`
162
+
163
+ Distort a monospaced character grid by varying the width and height of individual cells. Create wave effects, perspective distortions, or other grid warping effects by providing custom factor arrays.
164
+
165
+ **Parameters:**
166
+ - `gridSize` - Grid dimensions as `[columns, rows]`
167
+ Default: `[80, 40]` | Maximum: `[128, 128]`
168
+ - `widthFactors` - Array of distortion values (0-1) for each column
169
+ Must contain at least as many elements as columns (max 128)
170
+ - `heightFactors` - Array of distortion values (0-1) for each row
171
+ Must contain at least as many elements as rows (max 128)
172
+ - `widthVariationScale` - Intensity multiplier for width distortion
173
+ Default: `0.5` | Range: `0.0` - `∞`
174
+ - `heightVariationScale` - Intensity multiplier for height distortion
175
+ Default: `0.5` | Range: `0.0` - `∞`
176
+
177
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
178
+
179
+ ---
180
+
181
+ ### `crtMattias`
182
+
183
+ CRT monitor emulation effect with screen curvature, animated scanlines, blur, vignette, and film grain noise.
184
+
185
+ **Parameters:**
186
+ - `curvature` - Amount of screen curvature/barrel distortion
187
+ Default: `0.5` | Range: `0.0` - `1.0`
188
+ - `scanSpeed` - Speed of the scrolling scanline effect
189
+ Default: `1.0` | Range: `0.0` - `10.0`
190
+ - `time` - Animation time
191
+ Default: `0.0`
192
+
193
+ **Author:** [@mattiasgustavsson](https://github.com/mattiasgustavsson)
194
+ **Source:** https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-mattias.glsl
195
+
196
+ ---
197
+ ### `scanlines`
198
+
199
+ A standalone scanline effect that adds horizontal lines to the image to simulate a CRT display or old monitor. Adjustable density, thickness, and movement speed.
200
+
201
+ **Parameters:**
202
+ - `count` - Number of scanlines
203
+ Default: `300.0` | Range: `10.0` - `∞`
204
+ - `lineWidth` - Width of the lines relative to the spacing
205
+ Default: `0.5` | Range: `0.0` - `1.0`
206
+ - `intensity` - Opacity of the scanlines
207
+ Default: `0.75` | Range: `0.0` - `1.0`
208
+ - `speed` - Scrolling speed of the lines
209
+ Default: `1.0` | Range: `0.0` - `∞`
210
+ - `time` - Animation time
211
+ Default: `0.0`
212
+
213
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
214
+
215
+ ---
216
+
217
+ ### `vignette`
218
+
219
+ Darkens the edges and corners of the image, drawing focus to the center. Useful for creating a cinematic look or highlighting central content.
220
+
221
+ **Parameters:**
222
+ - `amount` - Intensity of the darkening effect
223
+ Default: `0.5` | Range: `0.0` - `1.0`
224
+ - `softness` - Falloff gradient softness (0 = hard edge, 1 = very soft)
225
+ Default: `0.5` | Range: `0.0` - `1.0`
226
+ - `roundness` - Shape of the vignette (0 = rectangular, 1 = circular)
227
+ Default: `0.5` | Range: `0.0` - `1.0`
228
+
229
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
230
+
231
+ ---
232
+
233
+ ### `bloom`
234
+
235
+ Creates a glow effect around bright areas of the image. Pixels above the brightness threshold emit a soft glow that spreads outward, perfect for creating neon, glowing text, or dreamy effects.
236
+
237
+ **Parameters:**
238
+ - `threshold` - Brightness level above which pixels will glow
239
+ Default: `0.5` | Range: `0.0` - `1.0`
240
+ - `intensity` - Strength of the glow effect
241
+ Default: `1.0` | Range: `0.0` - `∞`
242
+ - `radius` - Size of the glow spread in pixels
243
+ Default: `4.0` | Range: `1.0` - `∞`
244
+
245
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
246
+
247
+ ---
248
+
249
+ ### `filmGrain`
250
+
251
+ Adds an animated film grain/noise texture overlay to simulate vintage film stock or analog video. The multi-layered noise creates an organic, moving grain pattern that's less visible in darker areas, mimicking real film characteristics.
252
+
253
+ **Parameters:**
254
+ - `intensity` - Strength of the grain effect
255
+ Default: `0.2` | Range: `0.0` - `1.0`
256
+ - `size` - Size of grain particles
257
+ Default: `2.0` | Range: `1.0` - `10.0`
258
+ - `speed` - Animation speed of the grain
259
+ Default: `1.0` | Range: `0.0` - `∞`
260
+ - `time` - Animation time parameter
261
+ Default: `0.0`
262
+
263
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
264
+
265
+ ---
266
+
267
+ ### `saturation`
268
+
269
+ Adjust color intensity without affecting luminance. Perfect for creating vivid, oversaturated looks or desaturating to grayscale.
270
+
271
+ **Parameters:**
272
+ - `amount` - Saturation multiplier
273
+ Default: `1.0` | Range: `0.0` (grayscale) - `∞` (vivid)
274
+
275
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
276
+
277
+ ---
278
+ ### `posterize`
279
+
280
+ Reduces the color palette to a limited number of bands, creating a retro quantized look.
281
+
282
+ **Parameters:**
283
+ - `levels` - Number of color levels per channel
284
+ Default: `4.0` | Range: `1.0` - `∞`
285
+
286
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
287
+
288
+ ---
289
+
163
290
  ### Usage examples
164
291
 
165
292
  ```javascript
@@ -181,6 +308,26 @@ t.layers.base.filter('chromaticAberration', { amount: 10, direction: [1, 1] });
181
308
 
182
309
  // Pixelate effect
183
310
  t.layers.base.filter('pixelate', 8);
311
+
312
+ // Vignette with custom shape
313
+ t.layers.base.filter('vignette', { amount: 0.7, softness: 0.4, roundness: 1.0 });
314
+
315
+ // Bloom for glowing bright areas
316
+ t.layers.base.filter('bloom', { threshold: 0.6, intensity: 1.5, radius: 8 });
317
+
318
+ // Film grain with animation
319
+ let time = 0;
320
+ t.draw(() => {
321
+ t.layers.base.filter('filmGrain', { intensity: 0.3, size: 2, speed: 1.0, time: time });
322
+ time += 0.016;
323
+ });
324
+
325
+ // Saturation adjustments
326
+ t.layers.base.filter('saturation', 0); // Grayscale
327
+ t.layers.base.filter('saturation', 1.5); // Vivid colors
328
+
329
+ // Posterize effect (quantize colors)
330
+ t.layers.base.filter('posterize', { levels: 4 });
184
331
  ```
185
332
 
186
333
  ## Adding custom filters
@@ -234,6 +381,6 @@ Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
234
381
 
235
382
  <br />
236
383
 
237
- **[↑ Back to Top](#-textmodefiltersjs)**
384
+ **[↑ back to top](#-textmodefiltersjs)**
238
385
 
239
386
  </div>
@@ -1,216 +1,24 @@
1
- const n = () => ({ name: "textmode.filters", version: "1.0.0", async install(r) {
2
- r.filters.register("brightness", `#version 300 es\r
3
- precision highp float;\r
4
- \r
5
- uniform sampler2D u_texture;\r
6
- uniform vec2 u_resolution;\r
7
- uniform float u_amount;\r
8
- \r
9
- in vec2 v_uv;\r
10
- out vec4 fragColor;\r
11
- \r
12
- void main() {\r
13
- vec4 color = texture(u_texture, v_uv);\r
14
- \r
15
- // Multiply RGB by brightness amount\r
16
- vec3 result = color.rgb * u_amount;\r
17
- \r
18
- fragColor = vec4(result, color.a);\r
19
- }`, { u_amount: ["amount", 1] }), r.filters.register("contrast", `#version 300 es\r
20
- precision highp float;\r
21
- \r
22
- uniform sampler2D u_texture;\r
23
- uniform vec2 u_resolution;\r
24
- uniform float u_amount;\r
25
- \r
26
- in vec2 v_uv;\r
27
- out vec4 fragColor;\r
28
- \r
29
- void main() {\r
30
- vec4 color = texture(u_texture, v_uv);\r
31
- \r
32
- // Adjust contrast around midpoint (0.5)\r
33
- vec3 result = (color.rgb - 0.5) * u_amount + 0.5;\r
34
- \r
35
- fragColor = vec4(result, color.a);\r
36
- }`, { u_amount: ["amount", 1] }), r.filters.register("hueRotate", `#version 300 es\r
37
- precision highp float;\r
38
- \r
39
- uniform sampler2D u_texture;\r
40
- uniform vec2 u_resolution;\r
41
- uniform float u_angle;\r
42
- \r
43
- in vec2 v_uv;\r
44
- out vec4 fragColor;\r
45
- \r
46
- // Helper function for HSL to RGB conversion\r
47
- float hue2rgb(float p, float q, float t) {\r
48
- if (t < 0.0) t += 1.0;\r
49
- if (t > 1.0) t -= 1.0;\r
50
- if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;\r
51
- if (t < 1.0 / 2.0) return q;\r
52
- if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;\r
53
- return p;\r
54
- }\r
55
- \r
56
- // Convert RGB to HSL\r
57
- vec3 rgb2hsl(vec3 color) {\r
58
- float maxC = max(max(color.r, color.g), color.b);\r
59
- float minC = min(min(color.r, color.g), color.b);\r
60
- float delta = maxC - minC;\r
61
- \r
62
- vec3 hsl = vec3(0.0);\r
63
- hsl.z = (maxC + minC) / 2.0; // Lightness\r
64
- \r
65
- if (delta == 0.0) {\r
66
- hsl.x = 0.0; // Hue\r
67
- hsl.y = 0.0; // Saturation\r
68
- } else {\r
69
- hsl.y = hsl.z < 0.5 ? delta / (maxC + minC) : delta / (2.0 - maxC - minC); // Saturation\r
70
- \r
71
- if (color.r == maxC) {\r
72
- hsl.x = (color.g - color.b) / delta + (color.g < color.b ? 6.0 : 0.0);\r
73
- } else if (color.g == maxC) {\r
74
- hsl.x = (color.b - color.r) / delta + 2.0;\r
75
- } else {\r
76
- hsl.x = (color.r - color.g) / delta + 4.0;\r
77
- }\r
78
- hsl.x /= 6.0;\r
79
- }\r
80
- \r
81
- return hsl;\r
82
- }\r
83
- \r
84
- // Convert HSL to RGB\r
85
- vec3 hsl2rgb(vec3 hsl) {\r
86
- float h = hsl.x;\r
87
- float s = hsl.y;\r
88
- float l = hsl.z;\r
89
- \r
90
- if (s == 0.0) {\r
91
- return vec3(l);\r
92
- }\r
93
- \r
94
- float q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;\r
95
- float p = 2.0 * l - q;\r
96
- \r
97
- float r = hue2rgb(p, q, h + 1.0 / 3.0);\r
98
- float g = hue2rgb(p, q, h);\r
99
- float b = hue2rgb(p, q, h - 1.0 / 3.0);\r
100
- \r
101
- return vec3(r, g, b);\r
102
- }\r
103
- \r
104
- void main() {\r
105
- vec4 color = texture(u_texture, v_uv);\r
106
- \r
107
- // Convert to HSL\r
108
- vec3 hsl = rgb2hsl(color.rgb);\r
109
- \r
110
- // Rotate hue (angle is in degrees, convert to 0-1 range)\r
111
- hsl.x = fract(hsl.x + u_angle / 360.0);\r
112
- \r
113
- // Convert back to RGB\r
114
- vec3 result = hsl2rgb(hsl);\r
115
- \r
116
- fragColor = vec4(result, color.a);\r
117
- }\r
118
- `, { u_angle: ["angle", 0] }), r.filters.register("glitch", `#version 300 es\r
119
- precision highp float;\r
120
- \r
121
- uniform sampler2D u_texture;\r
122
- uniform vec2 u_resolution;\r
123
- uniform float u_amount;\r
124
- \r
125
- in vec2 v_uv;\r
126
- out vec4 fragColor;\r
127
- \r
128
- // Random function\r
129
- float random(vec2 co) {\r
130
- return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\r
131
- }\r
132
- \r
133
- void main() {\r
134
- vec2 uv = v_uv;\r
135
- \r
136
- // Create glitch effect based on amount\r
137
- float glitchStrength = u_amount * 0.1;\r
138
- \r
139
- // Horizontal displacement\r
140
- float block = floor(uv.y * 20.0);\r
141
- float noise = random(vec2(block, floor(u_amount * 100.0)));\r
142
- \r
143
- if (noise > 0.7) {\r
144
- uv.x += (noise - 0.7) * glitchStrength * 2.0;\r
145
- }\r
146
- \r
147
- // RGB channel separation (chromatic aberration)\r
148
- float separation = glitchStrength * 0.02;\r
149
- vec2 uvR = uv + vec2(separation, 0.0);\r
150
- vec2 uvG = uv;\r
151
- vec2 uvB = uv - vec2(separation, 0.0);\r
152
- \r
153
- float r = texture(u_texture, uvR).r;\r
154
- float g = texture(u_texture, uvG).g;\r
155
- float b = texture(u_texture, uvB).b;\r
156
- float a = texture(u_texture, uv).a;\r
157
- \r
158
- vec3 color = vec3(r, g, b);\r
159
- \r
160
- // Add scanlines\r
161
- float scanline = sin(uv.y * u_resolution.y * 2.0) * 0.1 * u_amount;\r
162
- color -= scanline;\r
163
- \r
164
- // Add random noise\r
165
- float noiseAmount = random(uv + fract(u_amount)) * 0.1 * u_amount;\r
166
- color += noiseAmount;\r
167
- \r
168
- fragColor = vec4(color, a);\r
169
- }\r
170
- `, { u_amount: ["amount", 0] }), r.filters.register("chromaticAberration", `#version 300 es\r
171
- precision highp float;\r
172
- \r
173
- uniform sampler2D u_texture;\r
174
- uniform vec2 u_resolution;\r
175
- uniform float u_amount;\r
176
- uniform vec2 u_direction;\r
177
- \r
178
- in vec2 v_uv;\r
179
- out vec4 fragColor;\r
180
- \r
181
- void main() {\r
182
- vec2 texelSize = 1.0 / u_resolution;\r
183
- vec2 offset = u_direction * u_amount * texelSize;\r
184
- \r
185
- // Sample each color channel with different offsets\r
186
- float r = texture(u_texture, v_uv + offset).r;\r
187
- float g = texture(u_texture, v_uv).g;\r
188
- float b = texture(u_texture, v_uv - offset).b;\r
189
- float a = texture(u_texture, v_uv).a;\r
190
- \r
191
- fragColor = vec4(r, g, b, a);\r
192
- }\r
193
- `, { u_amount: ["amount", 5], u_direction: ["direction", [1, 0]] }), r.filters.register("pixelate", `#version 300 es\r
194
- precision highp float;\r
195
- \r
196
- uniform sampler2D u_texture;\r
197
- uniform vec2 u_resolution;\r
198
- uniform float u_pixelSize;\r
199
- \r
200
- in vec2 v_uv;\r
201
- out vec4 fragColor;\r
202
- \r
203
- void main() {\r
204
- vec2 pixelSize = vec2(u_pixelSize) / u_resolution;\r
205
- vec2 pixelatedUV = floor(v_uv / pixelSize) * pixelSize + pixelSize * 0.5;\r
206
- \r
207
- fragColor = texture(u_texture, pixelatedUV);\r
208
- }\r
209
- `, { u_pixelSize: ["pixelSize", 4] });
210
- }, async uninstall(r) {
211
- r.filters.unregister("brightness"), r.filters.unregister("contrast"), r.filters.unregister("hueRotate"), r.filters.unregister("glitch"), r.filters.unregister("chromaticAberration"), r.filters.unregister("pixelate");
212
- } });
213
- typeof window < "u" && (window.createFiltersPlugin = n);
1
+ const t = Array(128).fill(0.5), r = { name: "textmode.filters", version: "1.1.1", async install(e) {
2
+ e.filters.register("brightness", `#version 300 es
3
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=A.rgb*u_amount;fragColor=vec4(B,A.a);}`, { u_amount: ["amount", 1] }), e.filters.register("contrast", `#version 300 es
4
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=(A.rgb-0.5)*u_amount+0.5;fragColor=vec4(B,A.a);}`, { u_amount: ["amount", 1] }), e.filters.register("hueRotate", `#version 300 es
5
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_angle;in vec2 v_uv;out vec4 fragColor;float A(float B,float C,float D){if(D<0.)D+=1.;if(D>1.)D-=1.;if(D<1./6.)return B+(C-B)*6.*D;if(D<1./2.)return C;if(D<2./3.)return B+(C-B)*(2./3.-D)*6.;return B;}vec3 E(vec3 F){float G=max(max(F.r,F.g),F.b);float H=min(min(F.r,F.g),F.b);float I=G-H;vec3 J=vec3(0.);J.z=(G+H)/2.;if(I==0.){J.x=0.;J.y=0.;}else{J.y=J.z<0.5?I/(G+H):I/(2.-G-H);if(F.r==G){J.x=(F.g-F.b)/I+(F.g<F.b?6.:0.);}else if(F.g==G){J.x=(F.b-F.r)/I+2.;}else{J.x=(F.r-F.g)/I+4.;}J.x/=6.;}return J;}vec3 K(vec3 J){float L=J.x;float M=J.y;float N=J.z;if(M==0.){return vec3(N);}float C=N<0.5?N*(1.+M):N+M-N*M;float B=2.*N-C;float O=A(B,C,L+1./3.);float P=A(B,C,L);float Q=A(B,C,L-1./3.);return vec3(O,P,Q);}void main(){vec4 F=texture(u_texture,v_uv);vec3 J=E(F.rgb);J.x=fract(J.x+u_angle/360.);vec3 R=K(J);fragColor=vec4(R,F.a);}`, { u_angle: ["angle", 0] }), e.filters.register("glitch", `#version 300 es
6
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;in vec2 v_uv;out vec4 fragColor;float A(vec2 B){return fract(sin(dot(B.xy,vec2(12.9898,78.233)))*43758.5453);}void main(){vec2 C=v_uv;float D=u_amount*0.1;float E=floor(C.y*20.);float F=A(vec2(E,floor(u_amount*100.)));if(F>0.7){C.x+=(F-0.7)*D*2.;}float G=D*0.02;vec2 H=C+vec2(G,0.);vec2 I=C;vec2 J=C-vec2(G,0.);float K=texture(u_texture,H).r;float L=texture(u_texture,I).g;float M=texture(u_texture,J).b;float N=texture(u_texture,C).a;vec3 O=vec3(K,L,M);float P=sin(C.y*u_resolution.y*2.)*0.1*u_amount;O-=P;float Q=A(C+fract(u_amount))*0.1*u_amount;O+=Q;fragColor=vec4(O,N);}`, { u_amount: ["amount", 0] }), e.filters.register("chromaticAberration", `#version 300 es
7
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;uniform vec2 u_direction;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=u_direction*u_amount*A;float C=texture(u_texture,v_uv+B).r;vec4 D=texture(u_texture,v_uv);float E=D.g;float F=texture(u_texture,v_uv-B).b;float G=D.a;fragColor=vec4(C,E,F,G);}`, { u_amount: ["amount", 5], u_direction: ["direction", [1, 0]] }), e.filters.register("pixelate", `#version 300 es
8
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_pixelSize;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(u_pixelSize)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}`, { u_pixelSize: ["pixelSize", 4] }), e.filters.register("gridDistortion", `#version 300 es
9
+ precision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetDimensions;uniform float u_widthFactors[128];uniform float u_heightFactors[128];uniform float u_widthVariationScale;uniform float u_heightVariationScale;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-u_gridOffsetDimensions)/u_gridPixelDimensions;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(u_gridCellDimensions.x);int F=int(u_gridCellDimensions.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=u_widthFactors[H];G+=0.1+I*u_widthVariationScale;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=u_heightFactors[K];J+=0.1+L*u_heightVariationScale;}}float M=D.x;float N=D.y;float O=0.;float P=0.;float Q=M*G;for(int H=0;H<A;H++){if(H<E){float I=u_widthFactors[H];float R=0.1+I*u_widthVariationScale;if(Q<P+R){float S=(Q-P)/R;O=(float(H)+S)/float(E);break;}P+=R;}}float T=0.;float U=0.;float V=N*J;for(int K=0;K<B;K++){if(K<F){float L=u_heightFactors[K];float W=0.1+L*u_heightVariationScale;if(V<U+W){float S=(V-U)/W;T=(float(K)+S)/float(F);break;}U+=W;}}vec2 X=vec2(O,T);fragColor=texture(u_texture,X);}`, { u_gridCellDimensions: ["gridCellDimensions", [80, 40]], u_gridPixelDimensions: ["gridPixelDimensions", [640, 320]], u_gridOffsetDimensions: ["gridOffsetDimensions", [0, 0]], u_widthFactors: ["widthFactors", t], u_heightFactors: ["heightFactors", t], u_widthVariationScale: ["widthVariationScale", 0.5], u_heightVariationScale: ["heightVariationScale", 0.5] }), e.filters.register("crtMattias", `#version 300 es
10
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_time;uniform float u_curvature;uniform float u_scanSpeed;in vec2 v_uv;out vec4 fragColor;vec3 A(vec2 B){vec3 C=pow(texture(u_texture,B).rgb,vec3(2.2));return C;}vec3 D(vec2 B,float E){vec4 F=E*vec4(-2.,-1.,1.,2.)/u_resolution.x;vec4 G=E*vec4(-2.,-1.,1.,2.)/u_resolution.y;vec3 H=vec3(0.);H+=A(B+vec2(F.x,G.x))*0.00366;H+=A(B+vec2(F.y,G.x))*0.01465;H+=A(B+vec2(0.,G.x))*0.02564;H+=A(B+vec2(F.z,G.x))*0.01465;H+=A(B+vec2(F.w,G.x))*0.00366;H+=A(B+vec2(F.x,G.y))*0.01465;H+=A(B+vec2(F.y,G.y))*0.05861;H+=A(B+vec2(0.,G.y))*0.09524;H+=A(B+vec2(F.z,G.y))*0.05861;H+=A(B+vec2(F.w,G.y))*0.01465;H+=A(B+vec2(F.x,0.))*0.02564;H+=A(B+vec2(F.y,0.))*0.09524;H+=A(B+vec2(0.,0.))*0.15018;H+=A(B+vec2(F.z,0.))*0.09524;H+=A(B+vec2(F.w,0.))*0.02564;H+=A(B+vec2(F.x,G.z))*0.01465;H+=A(B+vec2(F.y,G.z))*0.05861;H+=A(B+vec2(0.,G.z))*0.09524;H+=A(B+vec2(F.z,G.z))*0.05861;H+=A(B+vec2(F.w,G.z))*0.01465;H+=A(B+vec2(F.x,G.w))*0.00366;H+=A(B+vec2(F.y,G.w))*0.01465;H+=A(B+vec2(0.,G.w))*0.02564;H+=A(B+vec2(F.z,G.w))*0.01465;H+=A(B+vec2(F.w,G.w))*0.00366;return H;}float I(vec2 J){float K=12.9898;float L=78.233;float M=43758.5453;float N=dot(J.xy,vec2(K,L));float O=mod(N,3.14);return fract(sin(O)*M);}vec2 P(vec2 Q){Q=(Q-0.5)*2.;Q*=1.1;Q.x*=1.+pow((abs(Q.y)/5.),2.);Q.y*=1.+pow((abs(Q.x)/4.),2.);Q=(Q/2.)+0.5;Q=Q*0.92+0.04;return Q;}void main(){vec2 R=gl_FragCoord.xy;vec2 S=v_uv;vec2 Q=S;Q=mix(Q,P(Q),u_curvature);vec3 T;float U=sin(0.1*u_time+Q.y*21.)*sin(0.23*u_time+Q.y*29.)*sin(0.3+0.11*u_time+Q.y*31.)*0.0017;float V=2.*mod(R.y,2.)/u_resolution.x;U+=V;T.r=1.*D(vec2(Q.x+0.0009,Q.y+0.0009),1.2).x+0.005;T.g=1.*D(vec2(Q.x+0.000,Q.y-0.0015),1.2).y+0.005;T.b=1.*D(vec2(Q.x-0.0015,Q.y+0.000),1.2).z+0.005;T.r+=0.2*D(vec2(Q.x+0.0009,Q.y+0.0009),2.25).x-0.005;T.g+=0.2*D(vec2(Q.x+0.000,Q.y-0.0015),1.75).y-0.005;T.b+=0.2*D(vec2(Q.x-0.0015,Q.y+0.000),1.25).z-0.005;float W=0.05;T.r+=W*(1.-0.299)*D(0.75*vec2(0.01,-0.027)+vec2(Q.x+0.001,Q.y+0.001),7.).x;T.g+=W*(1.-0.587)*D(0.75*vec2(-0.022,-0.02)+vec2(Q.x+0.000,Q.y-0.002),5.).y;T.b+=W*(1.-0.114)*D(0.75*vec2(-0.02,-0.)+vec2(Q.x-0.002,Q.y+0.000),3.).z;T=clamp(T*0.4+0.6*T*T*1.,0.,1.);float X=(0.+1.*16.*Q.x*Q.y*(1.-Q.x)*(1.-Q.y));X=pow(X,0.3);T*=vec3(X);T*=vec3(0.95,1.05,0.95);T=mix(T,T*T,0.3)*3.8;float Y=clamp(0.35+0.15*sin(3.5*(u_time*u_scanSpeed)+Q.y*u_resolution.y*1.5),0.,1.);float C=pow(Y,0.9);T=T*vec3(C);T*=1.+0.0015*sin(300.*u_time);T*=1.-0.15*vec3(clamp((mod(R.x+V,2.)-1.)*2.,0.,1.));T*=vec3(1.)-0.25*vec3(I(Q+0.0001*u_time),I(Q+0.0001*u_time+0.3),I(Q+0.0001*u_time+0.5));T=pow(T,vec3(0.45));if(Q.x<0.||Q.x>1.)T*=0.;if(Q.y<0.||Q.y>1.)T*=0.;fragColor=vec4(T,1.);}`, { u_curvature: ["curvature", 0.5], u_scanSpeed: ["scanSpeed", 1], u_time: ["time", 0] }), e.filters.register("scanlines", `#version 300 es
11
+ precision highp float;uniform sampler2D u_texture;uniform float u_time;uniform float u_count;uniform float u_intensity;uniform float u_speed;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*u_count-u_time*u_speed)*3.141592*2.);B=B*0.5+0.5;float C=1.-(u_intensity*(1.-B));fragColor=vec4(A.rgb*C,A.a);}`, { u_count: ["count", 300], u_lineWidth: ["lineWidth", 0.5], u_intensity: ["intensity", 0.75], u_speed: ["speed", 1], u_time: ["time", 0] }), e.filters.register("vignette", `#version 300 es
12
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;uniform float u_softness;uniform float u_roundness;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec2 B=v_uv*2.-1.;float C=u_resolution.x/u_resolution.y;B.x*=C;float D=max(abs(B.x),abs(B.y));float E=length(B);float F=mix(D,E,u_roundness);float G=mix(max(C,1.),length(vec2(C,1.)),u_roundness);F/=G;float H=1.-u_amount;float I=H+u_softness*0.5+0.01;float J=1.-smoothstep(H,I,F);vec3 K=A.rgb*J;fragColor=vec4(K,A.a);}`, { u_amount: ["amount", 0.5], u_softness: ["softness", 0.5], u_roundness: ["roundness", 0.5] }), e.filters.register("bloom", `#version 300 es
13
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_threshold;uniform float u_intensity;uniform float u_radius;in vec2 v_uv;out vec4 fragColor;float A(vec3 B){return dot(B,vec3(0.299,0.587,0.114));}vec3 C(vec3 B,float D){float E=A(B);float F=max(0.,E-D)/max(E,0.001);return B*F;}void main(){vec4 G=texture(u_texture,v_uv);vec2 H=1./u_resolution;vec3 I=vec3(0.);float J=0.;float K[7];K[0]=0.227027;K[1]=0.194594;K[2]=0.121621;K[3]=0.054054;K[4]=0.016216;K[5]=0.006216;K[6]=0.002216;for(int L=-6;L<=6;L++){float M=K[abs(L)];vec2 N=vec2(float(L)*u_radius*H.x,0.);vec2 O=vec2(0.,float(L)*u_radius*H.y);vec3 P=texture(u_texture,v_uv+N).rgb;I+=C(P,u_threshold)*M;if(L!=0){vec3 Q=texture(u_texture,v_uv+O).rgb;I+=C(Q,u_threshold)*M;J+=M;}J+=M;}float R=0.1;for(int L=1;L<=4;L++){float S=float(L)*u_radius;vec2 T=vec2(S,S)*H;vec2 U=vec2(S,-S)*H;vec3 V=texture(u_texture,v_uv+T).rgb;vec3 W=texture(u_texture,v_uv-T).rgb;vec3 X=texture(u_texture,v_uv+U).rgb;vec3 Y=texture(u_texture,v_uv-U).rgb;float Z=R/float(L);I+=C(V,u_threshold)*Z;I+=C(W,u_threshold)*Z;I+=C(X,u_threshold)*Z;I+=C(Y,u_threshold)*Z;J+=Z*4.;}I/=J;vec3 a=G.rgb+I*u_intensity;fragColor=vec4(a,G.a);}`, { u_threshold: ["threshold", 0.5], u_intensity: ["intensity", 1], u_radius: ["radius", 4] }), e.filters.register("filmGrain", `#version 300 es
14
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_intensity;uniform float u_size;uniform float u_speed;uniform float u_time;in vec2 v_uv;out vec4 fragColor;float A(vec2 B){return fract(sin(dot(B,vec2(12.9898,78.233)))*43758.5453);}float C(vec2 D){vec2 E=floor(D);vec2 F=fract(D);vec2 G=F*F*(3.-2.*F);float H=A(E);float I=A(E+vec2(1.,0.));float J=A(E+vec2(0.,1.));float K=A(E+vec2(1.,1.));return mix(mix(H,I,G.x),mix(J,K,G.x),G.y);}void main(){vec4 L=texture(u_texture,v_uv);vec2 M=v_uv*u_resolution/u_size;M+=vec2(u_time*u_speed*0.1);float N=C(M);float O=C(M*2.+vec2(100.));float P=C(M*4.+vec2(200.));float Q=N*0.6+O*0.3+P*0.1;Q=(Q-0.5)*u_intensity;float R=dot(L.rgb,vec3(0.299,0.587,0.114));float S=Q*(0.5+R*0.5);vec3 T=L.rgb+S;fragColor=vec4(T,L.a);}`, { u_intensity: ["intensity", 0.2], u_size: ["size", 2], u_speed: ["speed", 1], u_time: ["time", 0] }), e.filters.register("saturation", `#version 300 es
15
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_amount;in vec2 v_uv;out vec4 fragColor;float A(float B,float C,float D){if(D<0.)D+=1.;if(D>1.)D-=1.;if(D<1./6.)return B+(C-B)*6.*D;if(D<1./2.)return C;if(D<2./3.)return B+(C-B)*(2./3.-D)*6.;return B;}vec3 E(vec3 F){float G=max(max(F.r,F.g),F.b);float H=min(min(F.r,F.g),F.b);float I=G-H;vec3 J=vec3(0.);J.z=(G+H)/2.;if(I==0.){J.x=0.;J.y=0.;}else{J.y=J.z<0.5?I/(G+H):I/(2.-G-H);if(F.r==G){J.x=(F.g-F.b)/I+(F.g<F.b?6.:0.);}else if(F.g==G){J.x=(F.b-F.r)/I+2.;}else{J.x=(F.r-F.g)/I+4.;}J.x/=6.;}return J;}vec3 K(vec3 J){float L=J.x;float M=J.y;float N=J.z;if(M==0.){return vec3(N);}float C=N<0.5?N*(1.+M):N+M-N*M;float B=2.*N-C;float O=A(B,C,L+1./3.);float P=A(B,C,L);float Q=A(B,C,L-1./3.);return vec3(O,P,Q);}void main(){vec4 F=texture(u_texture,v_uv);vec3 J=E(F.rgb);J.y=clamp(J.y*u_amount,0.,1.);vec3 R=K(J);fragColor=vec4(R,F.a);}`, { u_amount: ["amount", 1] }), e.filters.register("posterize", `#version 300 es
16
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_levels;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*u_levels)/u_levels;fragColor=vec4(B,A.a);}`, { u_levels: ["levels", 4] });
17
+ }, async uninstall(e) {
18
+ e.filters.unregister("brightness"), e.filters.unregister("contrast"), e.filters.unregister("hueRotate"), e.filters.unregister("glitch"), e.filters.unregister("chromaticAberration"), e.filters.unregister("pixelate"), e.filters.unregister("gridDistortion"), e.filters.unregister("crtMattias"), e.filters.unregister("scanlines"), e.filters.unregister("vignette"), e.filters.unregister("bloom"), e.filters.unregister("filmGrain"), e.filters.unregister("saturation"), e.filters.unregister("posterize");
19
+ } }, o = () => r;
20
+ typeof window < "u" && (window.FiltersPlugin = r, window.createFiltersPlugin = o);
214
21
  export {
215
- n as createFiltersPlugin
22
+ r as FiltersPlugin,
23
+ o as createFiltersPlugin
216
24
  };