textmode.filters.js 1.0.0 → 1.1.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 +160 -16
- package/dist/textmode.filters.esm.js +22 -213
- package/dist/textmode.filters.umd.js +15 -208
- package/dist/types/index.d.ts +30 -3
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
+
# textmode.filters.js
|
|
2
|
+
|
|
1
3
|
<div align="center">
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<!-- Add your banner image here when ready -->
|
|
6
|
+
<!-- <img alt="textmode_filters_banner" src="YOUR_BANNER_IMAGE_URL" /> -->
|
|
7
|
+
|
|
8
|
+
| [](https://www.typescriptlang.org/) [](https://www.khronos.org/webgl/) [](https://vitejs.dev/) | [](https://www.npmjs.com/package/textmode.filters.js) [](https://github.com/humanbydefinition/textmode.filters.js/blob/main/LICENSE) | [](https://discord.gg/sjrw8QXNks) [](https://ko-fi.com/V7V8JG2FY) [](https://github.com/sponsors/humanbydefinition) |
|
|
9
|
+
|:-------------|:-------------|:-------------|
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
</div>
|
|
6
12
|
|
|
7
|
-
[
|
|
8
|
-
[](https://github.com/humanbydefinition/textmode.filters.js/blob/main/LICENSE)
|
|
9
|
-
[](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
|
-
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
> [!NOTE]
|
|
21
|
-
> 🚧 **Work in Progress** - The required textmode.js version (0.7.0-beta.2+) is not yet publicly released.
|
|
22
|
-
|
|
23
|
-
## ✨ Features
|
|
20
|
+
## Features
|
|
24
21
|
|
|
25
22
|
- 🚀 **GPU-accelerated** - All filters run on the GPU via WebGL2 fragment shaders
|
|
26
23
|
- 🎛️ **Customizable parameters** - Fine-tune each filter to your needs
|
|
@@ -33,8 +30,6 @@
|
|
|
33
30
|
npm install textmode.filters.js
|
|
34
31
|
```
|
|
35
32
|
|
|
36
|
-
> **Note:** Make sure `textmode.js` is also installed in your project. This add-on declares it as a peer dependency.
|
|
37
|
-
|
|
38
33
|
You can also use it via CDN:
|
|
39
34
|
|
|
40
35
|
```html
|
|
@@ -163,6 +158,135 @@ Reduce image resolution to create a mosaic/pixelated effect
|
|
|
163
158
|
|
|
164
159
|
---
|
|
165
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
|
+
|
|
166
290
|
### Usage examples
|
|
167
291
|
|
|
168
292
|
```javascript
|
|
@@ -184,6 +308,26 @@ t.layers.base.filter('chromaticAberration', { amount: 10, direction: [1, 1] });
|
|
|
184
308
|
|
|
185
309
|
// Pixelate effect
|
|
186
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 });
|
|
187
331
|
```
|
|
188
332
|
|
|
189
333
|
## Adding custom filters
|
|
@@ -237,6 +381,6 @@ Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
|
|
|
237
381
|
|
|
238
382
|
<br />
|
|
239
383
|
|
|
240
|
-
**[↑
|
|
384
|
+
**[↑ back to top](#-textmodefiltersjs)**
|
|
241
385
|
|
|
242
386
|
</div>
|
|
@@ -1,216 +1,25 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
precision highp float
|
|
4
|
-
|
|
5
|
-
uniform sampler2D u_texture
|
|
6
|
-
uniform vec2 u_resolution
|
|
7
|
-
uniform float u_amount
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
void main() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
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");
|
|
1
|
+
const o = () => ({ name: "textmode.filters", version: "1.0.0", 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] });
|
|
9
|
+
const t = Array(128).fill(0.5);
|
|
10
|
+
e.filters.register("gridDistortion", `#version 300 es
|
|
11
|
+
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
|
|
12
|
+
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
|
|
13
|
+
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
|
|
14
|
+
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
|
|
15
|
+
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
|
|
16
|
+
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
|
|
17
|
+
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
|
|
18
|
+
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] });
|
|
19
|
+
}, async uninstall(e) {
|
|
20
|
+
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");
|
|
212
21
|
} });
|
|
213
|
-
typeof window < "u" && (window.createFiltersPlugin =
|
|
22
|
+
typeof window < "u" && (window.createFiltersPlugin = o);
|
|
214
23
|
export {
|
|
215
|
-
|
|
24
|
+
o as createFiltersPlugin
|
|
216
25
|
};
|
|
@@ -1,208 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
precision highp float
|
|
3
|
-
|
|
4
|
-
uniform sampler2D u_texture
|
|
5
|
-
uniform vec2 u_resolution
|
|
6
|
-
uniform float u_amount
|
|
7
|
-
|
|
8
|
-
in vec2 v_uv
|
|
9
|
-
out vec4 fragColor
|
|
10
|
-
|
|
11
|
-
void main() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
\r
|
|
17
|
-
fragColor = vec4(result, color.a);\r
|
|
18
|
-
}`,{u_amount:["amount",1]}),e.filters.register("contrast",`#version 300 es\r
|
|
19
|
-
precision highp float;\r
|
|
20
|
-
\r
|
|
21
|
-
uniform sampler2D u_texture;\r
|
|
22
|
-
uniform vec2 u_resolution;\r
|
|
23
|
-
uniform float u_amount;\r
|
|
24
|
-
\r
|
|
25
|
-
in vec2 v_uv;\r
|
|
26
|
-
out vec4 fragColor;\r
|
|
27
|
-
\r
|
|
28
|
-
void main() {\r
|
|
29
|
-
vec4 color = texture(u_texture, v_uv);\r
|
|
30
|
-
\r
|
|
31
|
-
// Adjust contrast around midpoint (0.5)\r
|
|
32
|
-
vec3 result = (color.rgb - 0.5) * u_amount + 0.5;\r
|
|
33
|
-
\r
|
|
34
|
-
fragColor = vec4(result, color.a);\r
|
|
35
|
-
}`,{u_amount:["amount",1]}),e.filters.register("hueRotate",`#version 300 es\r
|
|
36
|
-
precision highp float;\r
|
|
37
|
-
\r
|
|
38
|
-
uniform sampler2D u_texture;\r
|
|
39
|
-
uniform vec2 u_resolution;\r
|
|
40
|
-
uniform float u_angle;\r
|
|
41
|
-
\r
|
|
42
|
-
in vec2 v_uv;\r
|
|
43
|
-
out vec4 fragColor;\r
|
|
44
|
-
\r
|
|
45
|
-
// Helper function for HSL to RGB conversion\r
|
|
46
|
-
float hue2rgb(float p, float q, float t) {\r
|
|
47
|
-
if (t < 0.0) t += 1.0;\r
|
|
48
|
-
if (t > 1.0) t -= 1.0;\r
|
|
49
|
-
if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;\r
|
|
50
|
-
if (t < 1.0 / 2.0) return q;\r
|
|
51
|
-
if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;\r
|
|
52
|
-
return p;\r
|
|
53
|
-
}\r
|
|
54
|
-
\r
|
|
55
|
-
// Convert RGB to HSL\r
|
|
56
|
-
vec3 rgb2hsl(vec3 color) {\r
|
|
57
|
-
float maxC = max(max(color.r, color.g), color.b);\r
|
|
58
|
-
float minC = min(min(color.r, color.g), color.b);\r
|
|
59
|
-
float delta = maxC - minC;\r
|
|
60
|
-
\r
|
|
61
|
-
vec3 hsl = vec3(0.0);\r
|
|
62
|
-
hsl.z = (maxC + minC) / 2.0; // Lightness\r
|
|
63
|
-
\r
|
|
64
|
-
if (delta == 0.0) {\r
|
|
65
|
-
hsl.x = 0.0; // Hue\r
|
|
66
|
-
hsl.y = 0.0; // Saturation\r
|
|
67
|
-
} else {\r
|
|
68
|
-
hsl.y = hsl.z < 0.5 ? delta / (maxC + minC) : delta / (2.0 - maxC - minC); // Saturation\r
|
|
69
|
-
\r
|
|
70
|
-
if (color.r == maxC) {\r
|
|
71
|
-
hsl.x = (color.g - color.b) / delta + (color.g < color.b ? 6.0 : 0.0);\r
|
|
72
|
-
} else if (color.g == maxC) {\r
|
|
73
|
-
hsl.x = (color.b - color.r) / delta + 2.0;\r
|
|
74
|
-
} else {\r
|
|
75
|
-
hsl.x = (color.r - color.g) / delta + 4.0;\r
|
|
76
|
-
}\r
|
|
77
|
-
hsl.x /= 6.0;\r
|
|
78
|
-
}\r
|
|
79
|
-
\r
|
|
80
|
-
return hsl;\r
|
|
81
|
-
}\r
|
|
82
|
-
\r
|
|
83
|
-
// Convert HSL to RGB\r
|
|
84
|
-
vec3 hsl2rgb(vec3 hsl) {\r
|
|
85
|
-
float h = hsl.x;\r
|
|
86
|
-
float s = hsl.y;\r
|
|
87
|
-
float l = hsl.z;\r
|
|
88
|
-
\r
|
|
89
|
-
if (s == 0.0) {\r
|
|
90
|
-
return vec3(l);\r
|
|
91
|
-
}\r
|
|
92
|
-
\r
|
|
93
|
-
float q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;\r
|
|
94
|
-
float p = 2.0 * l - q;\r
|
|
95
|
-
\r
|
|
96
|
-
float r = hue2rgb(p, q, h + 1.0 / 3.0);\r
|
|
97
|
-
float g = hue2rgb(p, q, h);\r
|
|
98
|
-
float b = hue2rgb(p, q, h - 1.0 / 3.0);\r
|
|
99
|
-
\r
|
|
100
|
-
return vec3(r, g, b);\r
|
|
101
|
-
}\r
|
|
102
|
-
\r
|
|
103
|
-
void main() {\r
|
|
104
|
-
vec4 color = texture(u_texture, v_uv);\r
|
|
105
|
-
\r
|
|
106
|
-
// Convert to HSL\r
|
|
107
|
-
vec3 hsl = rgb2hsl(color.rgb);\r
|
|
108
|
-
\r
|
|
109
|
-
// Rotate hue (angle is in degrees, convert to 0-1 range)\r
|
|
110
|
-
hsl.x = fract(hsl.x + u_angle / 360.0);\r
|
|
111
|
-
\r
|
|
112
|
-
// Convert back to RGB\r
|
|
113
|
-
vec3 result = hsl2rgb(hsl);\r
|
|
114
|
-
\r
|
|
115
|
-
fragColor = vec4(result, color.a);\r
|
|
116
|
-
}\r
|
|
117
|
-
`,{u_angle:["angle",0]}),e.filters.register("glitch",`#version 300 es\r
|
|
118
|
-
precision highp float;\r
|
|
119
|
-
\r
|
|
120
|
-
uniform sampler2D u_texture;\r
|
|
121
|
-
uniform vec2 u_resolution;\r
|
|
122
|
-
uniform float u_amount;\r
|
|
123
|
-
\r
|
|
124
|
-
in vec2 v_uv;\r
|
|
125
|
-
out vec4 fragColor;\r
|
|
126
|
-
\r
|
|
127
|
-
// Random function\r
|
|
128
|
-
float random(vec2 co) {\r
|
|
129
|
-
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\r
|
|
130
|
-
}\r
|
|
131
|
-
\r
|
|
132
|
-
void main() {\r
|
|
133
|
-
vec2 uv = v_uv;\r
|
|
134
|
-
\r
|
|
135
|
-
// Create glitch effect based on amount\r
|
|
136
|
-
float glitchStrength = u_amount * 0.1;\r
|
|
137
|
-
\r
|
|
138
|
-
// Horizontal displacement\r
|
|
139
|
-
float block = floor(uv.y * 20.0);\r
|
|
140
|
-
float noise = random(vec2(block, floor(u_amount * 100.0)));\r
|
|
141
|
-
\r
|
|
142
|
-
if (noise > 0.7) {\r
|
|
143
|
-
uv.x += (noise - 0.7) * glitchStrength * 2.0;\r
|
|
144
|
-
}\r
|
|
145
|
-
\r
|
|
146
|
-
// RGB channel separation (chromatic aberration)\r
|
|
147
|
-
float separation = glitchStrength * 0.02;\r
|
|
148
|
-
vec2 uvR = uv + vec2(separation, 0.0);\r
|
|
149
|
-
vec2 uvG = uv;\r
|
|
150
|
-
vec2 uvB = uv - vec2(separation, 0.0);\r
|
|
151
|
-
\r
|
|
152
|
-
float r = texture(u_texture, uvR).r;\r
|
|
153
|
-
float g = texture(u_texture, uvG).g;\r
|
|
154
|
-
float b = texture(u_texture, uvB).b;\r
|
|
155
|
-
float a = texture(u_texture, uv).a;\r
|
|
156
|
-
\r
|
|
157
|
-
vec3 color = vec3(r, g, b);\r
|
|
158
|
-
\r
|
|
159
|
-
// Add scanlines\r
|
|
160
|
-
float scanline = sin(uv.y * u_resolution.y * 2.0) * 0.1 * u_amount;\r
|
|
161
|
-
color -= scanline;\r
|
|
162
|
-
\r
|
|
163
|
-
// Add random noise\r
|
|
164
|
-
float noiseAmount = random(uv + fract(u_amount)) * 0.1 * u_amount;\r
|
|
165
|
-
color += noiseAmount;\r
|
|
166
|
-
\r
|
|
167
|
-
fragColor = vec4(color, a);\r
|
|
168
|
-
}\r
|
|
169
|
-
`,{u_amount:["amount",0]}),e.filters.register("chromaticAberration",`#version 300 es\r
|
|
170
|
-
precision highp float;\r
|
|
171
|
-
\r
|
|
172
|
-
uniform sampler2D u_texture;\r
|
|
173
|
-
uniform vec2 u_resolution;\r
|
|
174
|
-
uniform float u_amount;\r
|
|
175
|
-
uniform vec2 u_direction;\r
|
|
176
|
-
\r
|
|
177
|
-
in vec2 v_uv;\r
|
|
178
|
-
out vec4 fragColor;\r
|
|
179
|
-
\r
|
|
180
|
-
void main() {\r
|
|
181
|
-
vec2 texelSize = 1.0 / u_resolution;\r
|
|
182
|
-
vec2 offset = u_direction * u_amount * texelSize;\r
|
|
183
|
-
\r
|
|
184
|
-
// Sample each color channel with different offsets\r
|
|
185
|
-
float r = texture(u_texture, v_uv + offset).r;\r
|
|
186
|
-
float g = texture(u_texture, v_uv).g;\r
|
|
187
|
-
float b = texture(u_texture, v_uv - offset).b;\r
|
|
188
|
-
float a = texture(u_texture, v_uv).a;\r
|
|
189
|
-
\r
|
|
190
|
-
fragColor = vec4(r, g, b, a);\r
|
|
191
|
-
}\r
|
|
192
|
-
`,{u_amount:["amount",5],u_direction:["direction",[1,0]]}),e.filters.register("pixelate",`#version 300 es\r
|
|
193
|
-
precision highp float;\r
|
|
194
|
-
\r
|
|
195
|
-
uniform sampler2D u_texture;\r
|
|
196
|
-
uniform vec2 u_resolution;\r
|
|
197
|
-
uniform float u_pixelSize;\r
|
|
198
|
-
\r
|
|
199
|
-
in vec2 v_uv;\r
|
|
200
|
-
out vec4 fragColor;\r
|
|
201
|
-
\r
|
|
202
|
-
void main() {\r
|
|
203
|
-
vec2 pixelSize = vec2(u_pixelSize) / u_resolution;\r
|
|
204
|
-
vec2 pixelatedUV = floor(v_uv / pixelSize) * pixelSize + pixelSize * 0.5;\r
|
|
205
|
-
\r
|
|
206
|
-
fragColor = texture(u_texture, pixelatedUV);\r
|
|
207
|
-
}\r
|
|
208
|
-
`,{u_pixelSize:["pixelSize",4]})},async uninstall(e){e.filters.unregister("brightness"),e.filters.unregister("contrast"),e.filters.unregister("hueRotate"),e.filters.unregister("glitch"),e.filters.unregister("chromaticAberration"),e.filters.unregister("pixelate")}});typeof window<"u"&&(window.createFiltersPlugin=o),t.createFiltersPlugin=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):n((r=typeof globalThis<"u"?globalThis:r||self).textmodeFilters={});
|
|
1
|
+
var e,o;e=this,o=function(r){const i=()=>({name:"textmode.filters",version:"1.0.0",async install(t){t.filters.register("brightness",`#version 300 es
|
|
2
|
+
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]}),t.filters.register("contrast",`#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-0.5)*u_amount+0.5;fragColor=vec4(B,A.a);}`,{u_amount:["amount",1]}),t.filters.register("hueRotate",`#version 300 es
|
|
4
|
+
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]}),t.filters.register("glitch",`#version 300 es
|
|
5
|
+
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]}),t.filters.register("chromaticAberration",`#version 300 es
|
|
6
|
+
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]]}),t.filters.register("pixelate",`#version 300 es
|
|
7
|
+
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]});const u=Array(128).fill(.5);t.filters.register("gridDistortion",`#version 300 es
|
|
8
|
+
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",u],u_heightFactors:["heightFactors",u],u_widthVariationScale:["widthVariationScale",.5],u_heightVariationScale:["heightVariationScale",.5]}),t.filters.register("crtMattias",`#version 300 es
|
|
9
|
+
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",.5],u_scanSpeed:["scanSpeed",1],u_time:["time",0]}),t.filters.register("scanlines",`#version 300 es
|
|
10
|
+
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",.5],u_intensity:["intensity",.75],u_speed:["speed",1],u_time:["time",0]}),t.filters.register("vignette",`#version 300 es
|
|
11
|
+
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",.5],u_softness:["softness",.5],u_roundness:["roundness",.5]}),t.filters.register("bloom",`#version 300 es
|
|
12
|
+
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",.5],u_intensity:["intensity",1],u_radius:["radius",4]}),t.filters.register("filmGrain",`#version 300 es
|
|
13
|
+
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",.2],u_size:["size",2],u_speed:["speed",1],u_time:["time",0]}),t.filters.register("saturation",`#version 300 es
|
|
14
|
+
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]}),t.filters.register("posterize",`#version 300 es
|
|
15
|
+
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]})},async uninstall(t){t.filters.unregister("brightness"),t.filters.unregister("contrast"),t.filters.unregister("hueRotate"),t.filters.unregister("glitch"),t.filters.unregister("chromaticAberration"),t.filters.unregister("pixelate"),t.filters.unregister("gridDistortion"),t.filters.unregister("crtMattias"),t.filters.unregister("scanlines"),t.filters.unregister("vignette"),t.filters.unregister("bloom"),t.filters.unregister("filmGrain"),t.filters.unregister("saturation"),t.filters.unregister("posterize")}});typeof window<"u"&&(window.createFiltersPlugin=i),r.createFiltersPlugin=i,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):o((e=typeof globalThis<"u"?globalThis:e||self).textmodeFilters={});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TextmodePlugin } from 'textmode.js';
|
|
1
|
+
import type { TextmodePlugin } from 'textmode.js/plugins';
|
|
2
2
|
/**
|
|
3
3
|
* Creates the `textmode.filters.js` plugin for textmode.js.
|
|
4
4
|
*
|
|
@@ -9,6 +9,14 @@ import type { TextmodePlugin } from 'textmode.js';
|
|
|
9
9
|
* - `glitch` - Digital glitch effect (amount: 0.0 = none, higher values = more intense)
|
|
10
10
|
* - `chromaticAberration` - RGB channel separation effect (amount: offset in pixels, direction: vec2 for offset direction)
|
|
11
11
|
* - `pixelate` - Pixelation effect (pixelSize: size of pixels in pixels)
|
|
12
|
+
* - `gridDistortion` - Distort a monospaced grid with custom patterns (widthFactors/heightFactors: arrays of values 0-1)
|
|
13
|
+
* - `crtMattias` - CRT monitor emulation with curvature, scanlines, blur, and noise (by Mattias)
|
|
14
|
+
* - `scanlines` - Customizable scanlines effect (count, lineWidth, intensity, speed)
|
|
15
|
+
* - `vignette` - Darkened edges/corners effect (amount, softness, roundness)
|
|
16
|
+
* - `bloom` - Glow effect around bright areas (threshold, intensity, radius)
|
|
17
|
+
* - `filmGrain` - Animated film grain/noise overlay (intensity, size, speed)
|
|
18
|
+
* - `saturation` - Adjust color intensity (amount: 0 = grayscale, 1 = normal, >1 = vivid)
|
|
19
|
+
* - `posterize` - Reduce color levels (levels: number of color bands, default 4.0)
|
|
12
20
|
*
|
|
13
21
|
* @example
|
|
14
22
|
* ```javascript
|
|
@@ -19,12 +27,31 @@ import type { TextmodePlugin } from 'textmode.js';
|
|
|
19
27
|
* plugins: [createFiltersPlugin()]
|
|
20
28
|
* });
|
|
21
29
|
*
|
|
30
|
+
* let frame = 0;
|
|
22
31
|
* t.draw(() => {
|
|
23
32
|
* t.layers.base.filter('brightness', 1.2);
|
|
24
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* // Grid distortion with custom sine wave pattern
|
|
35
|
+
* const widthFactors = [];
|
|
36
|
+
* const heightFactors = [];
|
|
37
|
+
* for (let i = 0; i < 80; i++) {
|
|
38
|
+
* widthFactors.push((Math.sin(i * 0.1 + frame * 0.05) + 1) / 2);
|
|
39
|
+
* }
|
|
40
|
+
* for (let j = 0; j < 40; j++) {
|
|
41
|
+
* heightFactors.push((Math.sin(j * 0.15 + frame * 0.03) + 1) / 2);
|
|
42
|
+
* }
|
|
43
|
+
* t.layers.base.filter('gridDistortion', {
|
|
44
|
+
* gridCellDimensions: [80, 40],
|
|
45
|
+
* gridPixelDimensions: [t.grid.cols * t.grid.cellWidth, t.grid.rows * t.grid.cellHeight],
|
|
46
|
+
* gridOffsetDimensions: [t.grid.offsetX, t.grid.offsetY],
|
|
47
|
+
* widthFactors,
|
|
48
|
+
* heightFactors,
|
|
49
|
+
* widthVariationScale: 0.5,
|
|
50
|
+
* heightVariationScale: 0.5
|
|
51
|
+
* });
|
|
25
52
|
*
|
|
26
53
|
* t.background(0);
|
|
27
|
-
*
|
|
54
|
+
* frame++;
|
|
28
55
|
* });
|
|
29
56
|
* ```
|
|
30
57
|
*
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.filters.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Image filters plugin for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/textmode.filters.umd.js",
|
|
7
7
|
"module": "./dist/textmode.filters.esm.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"import": "./dist/textmode.filters.esm.js",
|
|
13
13
|
"require": "./dist/textmode.filters.umd.js"
|
|
14
14
|
}
|
|
@@ -18,14 +18,18 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "vite build && tsc -p tsconfig.json",
|
|
21
|
-
"dev": "vite --port 5179 --host"
|
|
21
|
+
"dev": "vite --port 5179 --host",
|
|
22
|
+
"format": "prettier --write \"src/**/*.{ts,js}\"",
|
|
23
|
+
"format:check": "prettier --check \"src/**/*.{ts,js}\""
|
|
22
24
|
},
|
|
23
|
-
"
|
|
25
|
+
"dependencies": {
|
|
24
26
|
"textmode.js": "^0.7.0"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
29
|
+
"@mapwhit/glsl-minify": "^1.0.0",
|
|
27
30
|
"@rollup/plugin-terser": "^0.4.4",
|
|
28
31
|
"@types/node": "^24.10.1",
|
|
32
|
+
"prettier": "^3.8.1",
|
|
29
33
|
"tslib": "^2.8.1",
|
|
30
34
|
"typescript": "^5.9.2",
|
|
31
35
|
"vite": "^6.3.4"
|
|
@@ -36,4 +40,4 @@
|
|
|
36
40
|
"type": "git",
|
|
37
41
|
"url": "https://github.com/humanbydefinition/textmode.filters.js"
|
|
38
42
|
}
|
|
39
|
-
}
|
|
43
|
+
}
|