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 +163 -16
- package/dist/textmode.filters.esm.js +22 -214
- package/dist/textmode.filters.umd.js +15 -208
- package/dist/types/index.d.ts +73 -13
- package/dist/types/types.d.ts +1017 -0
- package/package.json +15 -5
|
@@ -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 u=Array(128).fill(.5),i={name:"textmode.filters",version:"1.1.1",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]}),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")}},n=()=>i;typeof window<"u"&&(window.FiltersPlugin=i,window.createFiltersPlugin=n),r.FiltersPlugin=i,r.createFiltersPlugin=n,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,32 +1,92 @@
|
|
|
1
|
-
import type { TextmodePlugin } from 'textmode.js';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* GPU-accelerated image filters plugin for textmode.js.
|
|
5
|
+
*
|
|
6
|
+
* This plugin provides customizable visual effects that run entirely on the GPU
|
|
7
|
+
* via WebGL2 fragment shaders for maximum performance.
|
|
8
|
+
*
|
|
9
|
+
* ## Available filters
|
|
10
|
+
*
|
|
11
|
+
* ### Color adjustment
|
|
12
|
+
* - {@link BrightnessOptions | brightness} - Adjust image brightness
|
|
13
|
+
* - {@link ContrastOptions | contrast} - Adjust image contrast
|
|
14
|
+
* - {@link SaturationOptions | saturation} - Adjust color intensity
|
|
15
|
+
* - {@link HueRotateOptions | hueRotate} - Rotate colors around the color wheel
|
|
16
|
+
* - {@link PosterizeOptions | posterize} - Reduce color levels
|
|
17
|
+
*
|
|
18
|
+
* ### Distortion
|
|
19
|
+
* - {@link ChromaticAberrationOptions | chromaticAberration} - RGB channel separation
|
|
20
|
+
* - {@link PixelateOptions | pixelate} - Pixelation/mosaic effect
|
|
21
|
+
* - {@link GridDistortionOptions | gridDistortion} - Custom grid warping
|
|
4
22
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
23
|
+
* ### Stylization
|
|
24
|
+
* - {@link GlitchOptions | glitch} - Digital glitch effect
|
|
25
|
+
* - {@link CrtMattiasOptions | crtMattias} - CRT monitor emulation
|
|
26
|
+
* - {@link ScanlinesOptions | scanlines} - Customizable scanlines
|
|
27
|
+
* - {@link VignetteOptions | vignette} - Darkened edges effect
|
|
28
|
+
* - {@link BloomOptions | bloom} - Glow around bright areas
|
|
29
|
+
* - {@link FilmGrainOptions | filmGrain} - Animated film grain overlay
|
|
30
|
+
*
|
|
31
|
+
* @module textmode.filters.js
|
|
32
|
+
*/
|
|
33
|
+
import type { TextmodePlugin } from 'textmode.js/plugins';
|
|
34
|
+
export type { BrightnessOptions, ContrastOptions, SaturationOptions, HueRotateOptions, PosterizeOptions, ChromaticAberrationOptions, PixelateOptions, GridDistortionOptions, GlitchOptions, CrtMattiasOptions, ScanlinesOptions, VignetteOptions, BloomOptions, FilmGrainOptions, } from './types';
|
|
35
|
+
/**
|
|
36
|
+
* GPU-accelerated image filters plugin for textmode.js.
|
|
37
|
+
*
|
|
38
|
+
* Add this plugin to your textmode.js instance to enable additional customizable
|
|
39
|
+
* visual effects that run entirely on the GPU via WebGL2 fragment shaders.
|
|
12
40
|
*
|
|
13
41
|
* @example
|
|
14
42
|
* ```javascript
|
|
15
43
|
* import { textmode } from 'textmode.js';
|
|
16
|
-
* import {
|
|
44
|
+
* import { FiltersPlugin } from 'textmode.filters.js';
|
|
17
45
|
*
|
|
18
46
|
* const t = textmode.create({
|
|
19
|
-
* plugins: [
|
|
47
|
+
* plugins: [FiltersPlugin]
|
|
20
48
|
* });
|
|
21
49
|
*
|
|
50
|
+
* let frame = 0;
|
|
22
51
|
* t.draw(() => {
|
|
52
|
+
* // Simple filter with shorthand value
|
|
23
53
|
* t.layers.base.filter('brightness', 1.2);
|
|
24
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* // Filter with options object
|
|
56
|
+
* t.layers.base.filter('bloom', {
|
|
57
|
+
* threshold: 0.5,
|
|
58
|
+
* intensity: 1.5,
|
|
59
|
+
* radius: 8
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Animated filter
|
|
63
|
+
* t.layers.base.filter('filmGrain', {
|
|
64
|
+
* intensity: 0.2,
|
|
65
|
+
* time: frame * 0.016
|
|
66
|
+
* });
|
|
25
67
|
*
|
|
26
68
|
* t.background(0);
|
|
27
|
-
*
|
|
69
|
+
* frame++;
|
|
28
70
|
* });
|
|
29
71
|
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const FiltersPlugin: TextmodePlugin;
|
|
74
|
+
/**
|
|
75
|
+
* Creates the `textmode.filters.js` plugin for textmode.js.
|
|
76
|
+
*
|
|
77
|
+
* @deprecated Use {@link FiltersPlugin} directly instead.
|
|
78
|
+
* This function is provided for backwards compatibility only.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```javascript
|
|
82
|
+
* // Old way (deprecated)
|
|
83
|
+
* import { createFiltersPlugin } from 'textmode.filters.js';
|
|
84
|
+
* const t = textmode.create({ plugins: [createFiltersPlugin()] });
|
|
85
|
+
*
|
|
86
|
+
* // New way (recommended)
|
|
87
|
+
* import { FiltersPlugin } from 'textmode.filters.js';
|
|
88
|
+
* const t = textmode.create({ plugins: [FiltersPlugin] });
|
|
89
|
+
* ```
|
|
30
90
|
*
|
|
31
91
|
* @returns A textmode.js plugin instance.
|
|
32
92
|
*/
|