textmode.filters.js 1.1.1 → 1.2.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,386 +1,403 @@
1
- # textmode.filters.js
2
-
3
- <div align="center">
4
-
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
- |:-------------|:-------------|:-------------|
10
-
11
- </div>
12
-
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.
14
-
15
- [Installation](#installation) •
16
- [Usage](#usage) •
17
- [Filters](#filters) •
18
- [Contributing](#contributing)
19
-
20
- ## Features
21
-
22
- - 🚀 **GPU-accelerated** - All filters run on the GPU via WebGL2 fragment shaders
23
- - 🎛️ **Customizable parameters** - Fine-tune each filter to your needs
24
- - 📦 **Lightweight** - Minimal footprint, no external dependencies
25
- - 🤝 **Open to contributions** - Easy to add your own custom filters!
26
-
27
- ## Installation
28
-
29
- ```bash
30
- npm install textmode.filters.js
31
- ```
32
-
33
- You can also use it via CDN:
34
-
35
- ```html
36
- <!-- ESM -->
37
- <script type="module" src="https://unpkg.com/textmode.js/dist/textmode.esm.js"></script>
38
- <script type="module" src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.esm.js"></script>
39
-
40
- <!-- UMD -->
41
- <script src="https://unpkg.com/textmode.js/dist/textmode.umd.js"></script>
42
- <script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
43
- ```
44
-
45
- ## Usage
46
-
47
- ### ESM
48
-
49
- ```javascript
50
- import { textmode } from 'textmode.js';
51
- import { FiltersPlugin } from 'textmode.filters.js';
52
-
53
- const t = textmode.create({
54
- width: 800,
55
- height: 600,
56
- plugins: [FiltersPlugin],
57
- });
58
-
59
- t.draw(() => {
60
- // Apply filters to layers
61
- t.layers.base.filter('brightness', 1.2);
62
- t.layers.base.filter('contrast', { amount: 1.5 });
63
-
64
- t.background(0);
65
- // ... draw something ...
66
- });
67
- ```
68
-
69
- ### UMD
70
-
71
- ```html
72
- <script src="https://unpkg.com/textmode.js/dist/textmode.umd.js"></script>
73
- <script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
74
- <script>
75
- const t = textmode.create({
76
- plugins: [FiltersPlugin],
77
- });
78
-
79
- t.draw(() => {
80
- t.layers.base.filter('brightness', 1.3);
81
- });
82
- </script>
83
- ```
84
-
85
- ## Filters
86
-
87
- ### `brightness`
88
-
89
- Adjust image brightness *(1.0 = normal, >1 = brighter, <1 = darker)*
90
-
91
- **Parameters:**
92
- - `amount` - Brightness multiplier
93
- Default: `1.0` | Range: `0.0` - `∞`
94
-
95
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
96
-
97
- ---
98
-
99
- ### `contrast`
100
-
101
- Adjust image contrast *(1.0 = normal, >1 = more contrast, <1 = less)*
102
-
103
- **Parameters:**
104
- - `amount` - Contrast multiplier
105
- Default: `1.0` | Range: `0.0` - `∞`
106
-
107
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
108
-
109
- ---
110
-
111
- ### `hueRotate`
112
-
113
- Shift colors around the color wheel
114
-
115
- **Parameters:**
116
- - `angle` - Rotation angle in degrees
117
- Default: `0.0` | Range: `0.0` - `360.0`
118
-
119
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
120
-
121
- ---
122
-
123
- ### `glitch`
124
-
125
- Digital glitch effect with RGB channel separation, scanlines, and noise
126
-
127
- **Parameters:**
128
- - `amount` - Glitch intensity
129
- Default: `0.0` | Range: `0.0` - `∞`
130
-
131
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
132
-
133
- ---
134
-
135
- ### `chromaticAberration`
136
-
137
- RGB color channel separation effect that simulates lens distortion
138
-
139
- **Parameters:**
140
- - `amount` - Offset amount in pixels
141
- Default: `5.0` | Range: `0.0` - `∞`
142
- - `direction` - Direction of the color separation as `[x, y]`
143
- Default: `[1.0, 0.0]` (horizontal)
144
-
145
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
146
-
147
- ---
148
-
149
- ### `pixelate`
150
-
151
- Reduce image resolution to create a mosaic/pixelated effect
152
-
153
- **Parameters:**
154
- - `pixelSize` - Size of each pixel block in pixels
155
- Default: `4.0` | Range: `1.0` - `∞`
156
-
157
- **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
158
-
159
- ---
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
-
290
- ### Usage examples
291
-
292
- ```javascript
293
- // Using a single value (shorthand)
294
- t.layers.base.filter('brightness', 1.5);
295
- t.layers.base.filter('hueRotate', 180);
296
-
297
- // Using an options object
298
- t.layers.base.filter('contrast', { amount: 0.8 });
299
- t.layers.base.filter('glitch', { amount: 2.0 });
300
-
301
- // Chaining multiple filters in sequence
302
- t.layers.base.filter('brightness', 1.2);
303
- t.layers.base.filter('contrast', 1.3);
304
- t.layers.base.filter('hueRotate', 90);
305
-
306
- // Chromatic aberration with custom direction
307
- t.layers.base.filter('chromaticAberration', { amount: 10, direction: [1, 1] });
308
-
309
- // Pixelate effect
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 });
331
- ```
332
-
333
- ## Adding custom filters
334
-
335
- Want to create your own filter? Check out the [Contributing Guide](CONTRIBUTING.md) for detailed instructions on how to add new filters to this library!
336
-
337
- The basic structure of a filter shader:
338
-
339
- ```glsl
340
- #version 300 es
341
- precision highp float;
342
-
343
- uniform sampler2D u_texture; // Input texture
344
- uniform vec2 u_resolution; // Canvas resolution
345
- uniform float u_yourParam; // Your custom parameter
346
-
347
- in vec2 v_uv;
348
- out vec4 fragColor;
349
-
350
- void main() {
351
- vec4 color = texture(u_texture, v_uv);
352
-
353
- // Your filter logic here
354
- vec3 result = color.rgb; // Modify this!
355
-
356
- fragColor = vec4(result, color.a);
357
- }
358
- ```
359
-
360
- ## Contributing
361
-
362
- Contributions are welcome and greatly appreciated! 🎉
363
-
364
- Whether you want to:
365
- - 🐛 Report a bug
366
- - 💡 Suggest a new filter
367
- - 🔧 Submit a pull request
368
- - 📖 Improve documentation
369
-
370
- Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
371
-
372
- ## Related projects
373
-
374
- - **[textmode.js](https://github.com/humanbydefinition/textmode.js)** - The main textmode.js library
375
- - **[code.textmode.art](https://code.textmode.art/)** - Documentation & examples
376
- - **[editor.textmode.art](https://editor.textmode.art/)** - textmode.js web editor
377
-
378
- ---
379
-
380
- <div align="center">
381
-
382
- <br />
383
-
384
- **[↑ back to top](#-textmodefiltersjs)**
385
-
386
- </div>
1
+ # textmode.filters.js
2
+
3
+ <div align="center">
4
+
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
+ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
10
+
11
+ </div>
12
+
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.
14
+
15
+ [Installation](#installation) •
16
+ [Usage](#usage) •
17
+ [Filters](#filters) •
18
+ [Contributing](#contributing)
19
+
20
+ ## Features
21
+
22
+ - 🚀 **GPU-accelerated** - All filters run on the GPU via WebGL2 fragment shaders
23
+ - 🎛️ **Customizable parameters** - Fine-tune each filter to your needs
24
+ - 📦 **Lightweight** - Minimal footprint, no external dependencies
25
+ - 🤝 **Open to contributions** - Easy to add your own custom filters!
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install textmode.filters.js
31
+ ```
32
+
33
+ You can also use it via CDN:
34
+
35
+ ```html
36
+ <!-- ESM -->
37
+ <script type="module" src="https://unpkg.com/textmode.js/dist/textmode.esm.js"></script>
38
+ <script type="module" src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.esm.js"></script>
39
+
40
+ <!-- UMD -->
41
+ <script src="https://unpkg.com/textmode.js/dist/textmode.umd.js"></script>
42
+ <script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### ESM
48
+
49
+ ```javascript
50
+ import { textmode } from 'textmode.js';
51
+ import { FiltersPlugin } from 'textmode.filters.js';
52
+
53
+ const t = textmode.create({
54
+ width: 800,
55
+ height: 600,
56
+ plugins: [FiltersPlugin],
57
+ });
58
+
59
+ t.draw(() => {
60
+ // Apply filters to layers
61
+ t.layers.base.filter('brightness', 1.2);
62
+ t.layers.base.filter('contrast', { amount: 1.5 });
63
+
64
+ t.background(0);
65
+ // ... draw something ...
66
+ });
67
+ ```
68
+
69
+ ### UMD
70
+
71
+ ```html
72
+ <script src="https://unpkg.com/textmode.js/dist/textmode.umd.js"></script>
73
+ <script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
74
+ <script>
75
+ const t = textmode.create({
76
+ plugins: [FiltersPlugin],
77
+ });
78
+
79
+ t.draw(() => {
80
+ t.layers.base.filter('brightness', 1.3);
81
+ });
82
+ </script>
83
+ ```
84
+
85
+ ## Filters
86
+
87
+ ### `brightness`
88
+
89
+ Adjust image brightness *(1.0 = normal, >1 = brighter, <1 = darker)*
90
+
91
+ **Parameters:**
92
+
93
+ - `amount` - Brightness multiplier
94
+ Default: `1.0` | Range: `0.0` - `∞`
95
+
96
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
97
+
98
+ ---
99
+
100
+ ### `contrast`
101
+
102
+ Adjust image contrast *(1.0 = normal, >1 = more contrast, <1 = less)*
103
+
104
+ **Parameters:**
105
+
106
+ - `amount` - Contrast multiplier
107
+ Default: `1.0` | Range: `0.0` - `∞`
108
+
109
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
110
+
111
+ ---
112
+
113
+ ### `hueRotate`
114
+
115
+ Shift colors around the color wheel
116
+
117
+ **Parameters:**
118
+
119
+ - `angle` - Rotation angle in degrees
120
+ Default: `0.0` | Range: `0.0` - `360.0`
121
+
122
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
123
+
124
+ ---
125
+
126
+ ### `glitch`
127
+
128
+ Digital glitch effect with RGB channel separation, scanlines, and noise
129
+
130
+ **Parameters:**
131
+
132
+ - `amount` - Glitch intensity
133
+ Default: `0.0` | Range: `0.0` - `∞`
134
+
135
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
136
+
137
+ ---
138
+
139
+ ### `chromaticAberration`
140
+
141
+ RGB color channel separation effect that simulates lens distortion
142
+
143
+ **Parameters:**
144
+
145
+ - `amount` - Offset amount in pixels
146
+ Default: `5.0` | Range: `0.0` - `∞`
147
+ - `direction` - Direction of the color separation as `[x, y]`
148
+ Default: `[1.0, 0.0]` (horizontal)
149
+
150
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
151
+
152
+ ---
153
+
154
+ ### `pixelate`
155
+
156
+ Reduce image resolution to create a mosaic/pixelated effect
157
+
158
+ **Parameters:**
159
+
160
+ - `pixelSize` - Size of each pixel block in pixels
161
+ Default: `4.0` | Range: `1.0` - `∞`
162
+
163
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
164
+
165
+ ---
166
+
167
+ ### `gridDistortion`
168
+
169
+ 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.
170
+
171
+ **Parameters:**
172
+
173
+ - `gridSize` - Grid dimensions as `[columns, rows]`
174
+ Default: `[80, 40]` | Maximum: `[128, 128]`
175
+ - `widthFactors` - Array of distortion values (0-1) for each column
176
+ Must contain at least as many elements as columns (max 128)
177
+ - `heightFactors` - Array of distortion values (0-1) for each row
178
+ Must contain at least as many elements as rows (max 128)
179
+ - `widthVariationScale` - Intensity multiplier for width distortion
180
+ Default: `0.5` | Range: `0.0` - `∞`
181
+ - `heightVariationScale` - Intensity multiplier for height distortion
182
+ Default: `0.5` | Range: `0.0` - `∞`
183
+
184
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
185
+
186
+ ---
187
+
188
+ ### `crtMattias`
189
+
190
+ CRT monitor emulation effect with screen curvature, animated scanlines, blur, vignette, and film grain noise.
191
+
192
+ **Parameters:**
193
+
194
+ - `curvature` - Amount of screen curvature/barrel distortion
195
+ Default: `0.5` | Range: `0.0` - `1.0`
196
+ - `scanSpeed` - Speed of the scrolling scanline effect
197
+ Default: `1.0` | Range: `0.0` - `10.0`
198
+ - `time` - Animation time
199
+ Default: `0.0`
200
+
201
+ **Author:** [@mattiasgustavsson](https://github.com/mattiasgustavsson)
202
+ **Source:** https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-mattias.glsl
203
+
204
+ ---
205
+
206
+ ### `scanlines`
207
+
208
+ 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.
209
+
210
+ **Parameters:**
211
+
212
+ - `count` - Number of scanlines
213
+ Default: `300.0` | Range: `10.0` - `∞`
214
+ - `lineWidth` - Width of the lines relative to the spacing
215
+ Default: `0.5` | Range: `0.0` - `1.0`
216
+ - `intensity` - Opacity of the scanlines
217
+ Default: `0.75` | Range: `0.0` - `1.0`
218
+ - `speed` - Scrolling speed of the lines
219
+ Default: `1.0` | Range: `0.0` - `∞`
220
+ - `time` - Animation time
221
+ Default: `0.0`
222
+
223
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
224
+
225
+ ---
226
+
227
+ ### `vignette`
228
+
229
+ Darkens the edges and corners of the image, drawing focus to the center. Useful for creating a cinematic look or highlighting central content.
230
+
231
+ **Parameters:**
232
+
233
+ - `amount` - Intensity of the darkening effect
234
+ Default: `0.5` | Range: `0.0` - `1.0`
235
+ - `softness` - Falloff gradient softness (0 = hard edge, 1 = very soft)
236
+ Default: `0.5` | Range: `0.0` - `1.0`
237
+ - `roundness` - Shape of the vignette (0 = rectangular, 1 = circular)
238
+ Default: `0.5` | Range: `0.0` - `1.0`
239
+
240
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
241
+
242
+ ---
243
+
244
+ ### `bloom`
245
+
246
+ 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.
247
+
248
+ **Parameters:**
249
+
250
+ - `threshold` - Brightness level above which pixels will glow
251
+ Default: `0.5` | Range: `0.0` - `1.0`
252
+ - `intensity` - Strength of the glow effect
253
+ Default: `1.0` | Range: `0.0` - `∞`
254
+ - `radius` - Size of the glow spread in pixels
255
+ Default: `4.0` | Range: `1.0` - `∞`
256
+
257
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
258
+
259
+ ---
260
+
261
+ ### `filmGrain`
262
+
263
+ 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.
264
+
265
+ **Parameters:**
266
+
267
+ - `intensity` - Strength of the grain effect
268
+ Default: `0.2` | Range: `0.0` - `1.0`
269
+ - `size` - Size of grain particles
270
+ Default: `2.0` | Range: `1.0` - `10.0`
271
+ - `speed` - Animation speed of the grain
272
+ Default: `1.0` | Range: `0.0` - `∞`
273
+ - `time` - Animation time parameter
274
+ Default: `0.0`
275
+
276
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
277
+
278
+ ---
279
+
280
+ ### `saturation`
281
+
282
+ Adjust color intensity without affecting luminance. Perfect for creating vivid, oversaturated looks or desaturating to grayscale.
283
+
284
+ **Parameters:**
285
+
286
+ - `amount` - Saturation multiplier
287
+ Default: `1.0` | Range: `0.0` (grayscale) - `∞` (vivid)
288
+
289
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
290
+
291
+ ---
292
+
293
+ ### `posterize`
294
+
295
+ Reduces the color palette to a limited number of bands, creating a retro quantized look.
296
+
297
+ **Parameters:**
298
+
299
+ - `levels` - Number of color levels per channel
300
+ Default: `4.0` | Range: `1.0` - `∞`
301
+
302
+ **Author:** [@humanbydefinition](https://github.com/humanbydefinition)
303
+
304
+ ---
305
+
306
+ ### Usage examples
307
+
308
+ ```javascript
309
+ // Using a single value (shorthand)
310
+ t.layers.base.filter('brightness', 1.5);
311
+ t.layers.base.filter('hueRotate', 180);
312
+
313
+ // Using an options object
314
+ t.layers.base.filter('contrast', { amount: 0.8 });
315
+ t.layers.base.filter('glitch', { amount: 2.0 });
316
+
317
+ // Chaining multiple filters in sequence
318
+ t.layers.base.filter('brightness', 1.2);
319
+ t.layers.base.filter('contrast', 1.3);
320
+ t.layers.base.filter('hueRotate', 90);
321
+
322
+ // Chromatic aberration with custom direction
323
+ t.layers.base.filter('chromaticAberration', { amount: 10, direction: [1, 1] });
324
+
325
+ // Pixelate effect
326
+ t.layers.base.filter('pixelate', 8);
327
+
328
+ // Vignette with custom shape
329
+ t.layers.base.filter('vignette', { amount: 0.7, softness: 0.4, roundness: 1.0 });
330
+
331
+ // Bloom for glowing bright areas
332
+ t.layers.base.filter('bloom', { threshold: 0.6, intensity: 1.5, radius: 8 });
333
+
334
+ // Film grain with animation
335
+ let time = 0;
336
+ t.draw(() => {
337
+ t.layers.base.filter('filmGrain', { intensity: 0.3, size: 2, speed: 1.0, time: time });
338
+ time += 0.016;
339
+ });
340
+
341
+ // Saturation adjustments
342
+ t.layers.base.filter('saturation', 0); // Grayscale
343
+ t.layers.base.filter('saturation', 1.5); // Vivid colors
344
+
345
+ // Posterize effect (quantize colors)
346
+ t.layers.base.filter('posterize', { levels: 4 });
347
+ ```
348
+
349
+ ## Adding custom filters
350
+
351
+ Want to create your own filter? Check out the [Contributing Guide](CONTRIBUTING.md) for detailed instructions on how to add new filters to this library!
352
+
353
+ The basic structure of a filter shader:
354
+
355
+ ```glsl
356
+ #version 300 es
357
+ precision highp float;
358
+
359
+ uniform sampler2D u_texture; // Input texture
360
+ uniform vec2 u_resolution; // Canvas resolution
361
+ uniform float u_yourParam; // Your custom parameter
362
+
363
+ in vec2 v_uv;
364
+ out vec4 fragColor;
365
+
366
+ void main() {
367
+ vec4 color = texture(u_texture, v_uv);
368
+
369
+ // Your filter logic here
370
+ vec3 result = color.rgb; // Modify this!
371
+
372
+ fragColor = vec4(result, color.a);
373
+ }
374
+ ```
375
+
376
+ ## Contributing
377
+
378
+ Contributions are welcome and greatly appreciated! 🎉
379
+
380
+ Whether you want to:
381
+
382
+ - 🐛 Report a bug
383
+ - 💡 Suggest a new filter
384
+ - 🔧 Submit a pull request
385
+ - 📖 Improve documentation
386
+
387
+ Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
388
+
389
+ ## Related projects
390
+
391
+ - **[textmode.js](https://github.com/humanbydefinition/textmode.js)** - The main textmode.js library
392
+ - **[code.textmode.art](https://code.textmode.art/)** - Documentation & examples
393
+ - **[editor.textmode.art](https://editor.textmode.art/)** - textmode.js web editor
394
+
395
+ ---
396
+
397
+ <div align="center">
398
+
399
+ <br />
400
+
401
+ **[↑ back to top](#textmodefiltersjs)**
402
+
403
+ </div>