textmode.filters.js 1.1.0 → 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 +3 -3
- package/dist/textmode.filters.esm.js +5 -6
- package/dist/textmode.filters.umd.js +3 -3
- package/dist/types/index.d.ts +68 -35
- package/dist/types/types.d.ts +1017 -0
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -48,12 +48,12 @@ You can also use it via CDN:
|
|
|
48
48
|
|
|
49
49
|
```javascript
|
|
50
50
|
import { textmode } from 'textmode.js';
|
|
51
|
-
import {
|
|
51
|
+
import { FiltersPlugin } from 'textmode.filters.js';
|
|
52
52
|
|
|
53
53
|
const t = textmode.create({
|
|
54
54
|
width: 800,
|
|
55
55
|
height: 600,
|
|
56
|
-
plugins: [
|
|
56
|
+
plugins: [FiltersPlugin],
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
t.draw(() => {
|
|
@@ -73,7 +73,7 @@ t.draw(() => {
|
|
|
73
73
|
<script src="https://unpkg.com/textmode.filters.js/dist/textmode.filters.umd.js"></script>
|
|
74
74
|
<script>
|
|
75
75
|
const t = textmode.create({
|
|
76
|
-
plugins: [
|
|
76
|
+
plugins: [FiltersPlugin],
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
t.draw(() => {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const t = Array(128).fill(0.5), r = { name: "textmode.filters", version: "1.1.1", async install(e) {
|
|
2
2
|
e.filters.register("brightness", `#version 300 es
|
|
3
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
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
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
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
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
|
|
8
|
+
precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_pixelSize;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(u_pixelSize)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}`, { u_pixelSize: ["pixelSize", 4] }), e.filters.register("gridDistortion", `#version 300 es
|
|
11
9
|
precision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetDimensions;uniform float u_widthFactors[128];uniform float u_heightFactors[128];uniform float u_widthVariationScale;uniform float u_heightVariationScale;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-u_gridOffsetDimensions)/u_gridPixelDimensions;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(u_gridCellDimensions.x);int F=int(u_gridCellDimensions.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=u_widthFactors[H];G+=0.1+I*u_widthVariationScale;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=u_heightFactors[K];J+=0.1+L*u_heightVariationScale;}}float M=D.x;float N=D.y;float O=0.;float P=0.;float Q=M*G;for(int H=0;H<A;H++){if(H<E){float I=u_widthFactors[H];float R=0.1+I*u_widthVariationScale;if(Q<P+R){float S=(Q-P)/R;O=(float(H)+S)/float(E);break;}P+=R;}}float T=0.;float U=0.;float V=N*J;for(int K=0;K<B;K++){if(K<F){float L=u_heightFactors[K];float W=0.1+L*u_heightVariationScale;if(V<U+W){float S=(V-U)/W;T=(float(K)+S)/float(F);break;}U+=W;}}vec2 X=vec2(O,T);fragColor=texture(u_texture,X);}`, { u_gridCellDimensions: ["gridCellDimensions", [80, 40]], u_gridPixelDimensions: ["gridPixelDimensions", [640, 320]], u_gridOffsetDimensions: ["gridOffsetDimensions", [0, 0]], u_widthFactors: ["widthFactors", t], u_heightFactors: ["heightFactors", t], u_widthVariationScale: ["widthVariationScale", 0.5], u_heightVariationScale: ["heightVariationScale", 0.5] }), e.filters.register("crtMattias", `#version 300 es
|
|
12
10
|
precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_time;uniform float u_curvature;uniform float u_scanSpeed;in vec2 v_uv;out vec4 fragColor;vec3 A(vec2 B){vec3 C=pow(texture(u_texture,B).rgb,vec3(2.2));return C;}vec3 D(vec2 B,float E){vec4 F=E*vec4(-2.,-1.,1.,2.)/u_resolution.x;vec4 G=E*vec4(-2.,-1.,1.,2.)/u_resolution.y;vec3 H=vec3(0.);H+=A(B+vec2(F.x,G.x))*0.00366;H+=A(B+vec2(F.y,G.x))*0.01465;H+=A(B+vec2(0.,G.x))*0.02564;H+=A(B+vec2(F.z,G.x))*0.01465;H+=A(B+vec2(F.w,G.x))*0.00366;H+=A(B+vec2(F.x,G.y))*0.01465;H+=A(B+vec2(F.y,G.y))*0.05861;H+=A(B+vec2(0.,G.y))*0.09524;H+=A(B+vec2(F.z,G.y))*0.05861;H+=A(B+vec2(F.w,G.y))*0.01465;H+=A(B+vec2(F.x,0.))*0.02564;H+=A(B+vec2(F.y,0.))*0.09524;H+=A(B+vec2(0.,0.))*0.15018;H+=A(B+vec2(F.z,0.))*0.09524;H+=A(B+vec2(F.w,0.))*0.02564;H+=A(B+vec2(F.x,G.z))*0.01465;H+=A(B+vec2(F.y,G.z))*0.05861;H+=A(B+vec2(0.,G.z))*0.09524;H+=A(B+vec2(F.z,G.z))*0.05861;H+=A(B+vec2(F.w,G.z))*0.01465;H+=A(B+vec2(F.x,G.w))*0.00366;H+=A(B+vec2(F.y,G.w))*0.01465;H+=A(B+vec2(0.,G.w))*0.02564;H+=A(B+vec2(F.z,G.w))*0.01465;H+=A(B+vec2(F.w,G.w))*0.00366;return H;}float I(vec2 J){float K=12.9898;float L=78.233;float M=43758.5453;float N=dot(J.xy,vec2(K,L));float O=mod(N,3.14);return fract(sin(O)*M);}vec2 P(vec2 Q){Q=(Q-0.5)*2.;Q*=1.1;Q.x*=1.+pow((abs(Q.y)/5.),2.);Q.y*=1.+pow((abs(Q.x)/4.),2.);Q=(Q/2.)+0.5;Q=Q*0.92+0.04;return Q;}void main(){vec2 R=gl_FragCoord.xy;vec2 S=v_uv;vec2 Q=S;Q=mix(Q,P(Q),u_curvature);vec3 T;float U=sin(0.1*u_time+Q.y*21.)*sin(0.23*u_time+Q.y*29.)*sin(0.3+0.11*u_time+Q.y*31.)*0.0017;float V=2.*mod(R.y,2.)/u_resolution.x;U+=V;T.r=1.*D(vec2(Q.x+0.0009,Q.y+0.0009),1.2).x+0.005;T.g=1.*D(vec2(Q.x+0.000,Q.y-0.0015),1.2).y+0.005;T.b=1.*D(vec2(Q.x-0.0015,Q.y+0.000),1.2).z+0.005;T.r+=0.2*D(vec2(Q.x+0.0009,Q.y+0.0009),2.25).x-0.005;T.g+=0.2*D(vec2(Q.x+0.000,Q.y-0.0015),1.75).y-0.005;T.b+=0.2*D(vec2(Q.x-0.0015,Q.y+0.000),1.25).z-0.005;float W=0.05;T.r+=W*(1.-0.299)*D(0.75*vec2(0.01,-0.027)+vec2(Q.x+0.001,Q.y+0.001),7.).x;T.g+=W*(1.-0.587)*D(0.75*vec2(-0.022,-0.02)+vec2(Q.x+0.000,Q.y-0.002),5.).y;T.b+=W*(1.-0.114)*D(0.75*vec2(-0.02,-0.)+vec2(Q.x-0.002,Q.y+0.000),3.).z;T=clamp(T*0.4+0.6*T*T*1.,0.,1.);float X=(0.+1.*16.*Q.x*Q.y*(1.-Q.x)*(1.-Q.y));X=pow(X,0.3);T*=vec3(X);T*=vec3(0.95,1.05,0.95);T=mix(T,T*T,0.3)*3.8;float Y=clamp(0.35+0.15*sin(3.5*(u_time*u_scanSpeed)+Q.y*u_resolution.y*1.5),0.,1.);float C=pow(Y,0.9);T=T*vec3(C);T*=1.+0.0015*sin(300.*u_time);T*=1.-0.15*vec3(clamp((mod(R.x+V,2.)-1.)*2.,0.,1.));T*=vec3(1.)-0.25*vec3(I(Q+0.0001*u_time),I(Q+0.0001*u_time+0.3),I(Q+0.0001*u_time+0.5));T=pow(T,vec3(0.45));if(Q.x<0.||Q.x>1.)T*=0.;if(Q.y<0.||Q.y>1.)T*=0.;fragColor=vec4(T,1.);}`, { u_curvature: ["curvature", 0.5], u_scanSpeed: ["scanSpeed", 1], u_time: ["time", 0] }), e.filters.register("scanlines", `#version 300 es
|
|
13
11
|
precision highp float;uniform sampler2D u_texture;uniform float u_time;uniform float u_count;uniform float u_intensity;uniform float u_speed;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*u_count-u_time*u_speed)*3.141592*2.);B=B*0.5+0.5;float C=1.-(u_intensity*(1.-B));fragColor=vec4(A.rgb*C,A.a);}`, { u_count: ["count", 300], u_lineWidth: ["lineWidth", 0.5], u_intensity: ["intensity", 0.75], u_speed: ["speed", 1], u_time: ["time", 0] }), e.filters.register("vignette", `#version 300 es
|
|
@@ -18,8 +16,9 @@ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;unif
|
|
|
18
16
|
precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float u_levels;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*u_levels)/u_levels;fragColor=vec4(B,A.a);}`, { u_levels: ["levels", 4] });
|
|
19
17
|
}, async uninstall(e) {
|
|
20
18
|
e.filters.unregister("brightness"), e.filters.unregister("contrast"), e.filters.unregister("hueRotate"), e.filters.unregister("glitch"), e.filters.unregister("chromaticAberration"), e.filters.unregister("pixelate"), e.filters.unregister("gridDistortion"), e.filters.unregister("crtMattias"), e.filters.unregister("scanlines"), e.filters.unregister("vignette"), e.filters.unregister("bloom"), e.filters.unregister("filmGrain"), e.filters.unregister("saturation"), e.filters.unregister("posterize");
|
|
21
|
-
} });
|
|
22
|
-
typeof window < "u" && (window.createFiltersPlugin = o);
|
|
19
|
+
} }, o = () => r;
|
|
20
|
+
typeof window < "u" && (window.FiltersPlugin = r, window.createFiltersPlugin = o);
|
|
23
21
|
export {
|
|
22
|
+
r as FiltersPlugin,
|
|
24
23
|
o as createFiltersPlugin
|
|
25
24
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var e,o;e=this,o=function(r){const
|
|
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
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
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
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
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
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]})
|
|
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
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
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
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
|
|
@@ -12,4 +12,4 @@ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;unif
|
|
|
12
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
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
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=
|
|
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,59 +1,92 @@
|
|
|
1
|
+
/**
|
|
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
|
|
22
|
+
*
|
|
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
|
+
*/
|
|
1
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';
|
|
2
35
|
/**
|
|
3
|
-
*
|
|
36
|
+
* GPU-accelerated image filters plugin for textmode.js.
|
|
4
37
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - `contrast` - Adjust image contrast (amount: 1.0 = normal, >1 = more contrast, <1 = less)
|
|
8
|
-
* - `hueRotate` - Rotate colors around the hue wheel (angle: 0-360 degrees)
|
|
9
|
-
* - `glitch` - Digital glitch effect (amount: 0.0 = none, higher values = more intense)
|
|
10
|
-
* - `chromaticAberration` - RGB channel separation effect (amount: offset in pixels, direction: vec2 for offset direction)
|
|
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)
|
|
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.
|
|
20
40
|
*
|
|
21
41
|
* @example
|
|
22
42
|
* ```javascript
|
|
23
43
|
* import { textmode } from 'textmode.js';
|
|
24
|
-
* import {
|
|
44
|
+
* import { FiltersPlugin } from 'textmode.filters.js';
|
|
25
45
|
*
|
|
26
46
|
* const t = textmode.create({
|
|
27
|
-
* plugins: [
|
|
47
|
+
* plugins: [FiltersPlugin]
|
|
28
48
|
* });
|
|
29
49
|
*
|
|
30
50
|
* let frame = 0;
|
|
31
51
|
* t.draw(() => {
|
|
52
|
+
* // Simple filter with shorthand value
|
|
32
53
|
* t.layers.base.filter('brightness', 1.2);
|
|
33
54
|
*
|
|
34
|
-
* //
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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
|
|
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
|
|
51
66
|
* });
|
|
52
67
|
*
|
|
53
68
|
* t.background(0);
|
|
54
69
|
* frame++;
|
|
55
70
|
* });
|
|
56
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
|
+
* ```
|
|
57
90
|
*
|
|
58
91
|
* @returns A textmode.js plugin instance.
|
|
59
92
|
*/
|
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for all filter options in textmode.filters.js.
|
|
3
|
+
*
|
|
4
|
+
* Each filter can be applied using either:
|
|
5
|
+
* - A single value (shorthand for the primary parameter)
|
|
6
|
+
* - An options object with named parameters
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* const t = textmode.create({
|
|
10
|
+
* width: window.innerWidth,
|
|
11
|
+
* height: window.innerHeight,
|
|
12
|
+
* plugins: [FiltersPlugin],
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* let video;
|
|
16
|
+
*
|
|
17
|
+
* t.setup(async () => {
|
|
18
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
19
|
+
* video.play();
|
|
20
|
+
* video.loop();
|
|
21
|
+
* video.characters(' .:-=+*#%@');
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* t.draw(() => {
|
|
25
|
+
* t.background(0);
|
|
26
|
+
* if (video) {
|
|
27
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
31
|
+
* t.layers.base.filter('bloom', {
|
|
32
|
+
* threshold: 0.5,
|
|
33
|
+
* intensity: 1 + wobble * 0.35,
|
|
34
|
+
* radius: 6 + wobble * 2,
|
|
35
|
+
* });
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* t.windowResized(() => {
|
|
39
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @module
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Configuration options for the `'brightness'` filter.
|
|
47
|
+
*
|
|
48
|
+
* Adjusts image brightness by multiplying pixel values.
|
|
49
|
+
* @example
|
|
50
|
+
* ```javascript
|
|
51
|
+
* const t = textmode.create({
|
|
52
|
+
* width: window.innerWidth,
|
|
53
|
+
* height: window.innerHeight,
|
|
54
|
+
* plugins: [FiltersPlugin],
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* let video;
|
|
58
|
+
*
|
|
59
|
+
* t.setup(async () => {
|
|
60
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
61
|
+
* video.play();
|
|
62
|
+
* video.loop();
|
|
63
|
+
* video.characters(' .:-=+*#%@');
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* t.draw(() => {
|
|
67
|
+
* t.background(0);
|
|
68
|
+
* if (video) {
|
|
69
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
73
|
+
* t.layers.base.filter('brightness', {
|
|
74
|
+
* amount: 1 + wobble * 0.25,
|
|
75
|
+
* });
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* t.windowResized(() => {
|
|
79
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @category Color adjustment filters
|
|
84
|
+
*/
|
|
85
|
+
export interface BrightnessOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Brightness multiplier.
|
|
88
|
+
*
|
|
89
|
+
* - `1.0` = normal brightness (no change)
|
|
90
|
+
* - `> 1.0` = brighter
|
|
91
|
+
* - `< 1.0` = darker
|
|
92
|
+
* - `0.0` = completely black
|
|
93
|
+
*
|
|
94
|
+
* @default 1.0
|
|
95
|
+
*/
|
|
96
|
+
amount: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Configuration options for the `'contrast'` filter.
|
|
100
|
+
*
|
|
101
|
+
* Adjusts image contrast by scaling pixel values around mid-gray.
|
|
102
|
+
* @example
|
|
103
|
+
* ```javascript
|
|
104
|
+
* const t = textmode.create({
|
|
105
|
+
* width: window.innerWidth,
|
|
106
|
+
* height: window.innerHeight,
|
|
107
|
+
* plugins: [FiltersPlugin],
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* let video;
|
|
111
|
+
*
|
|
112
|
+
* t.setup(async () => {
|
|
113
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
114
|
+
* video.play();
|
|
115
|
+
* video.loop();
|
|
116
|
+
* video.characters(' .:-=+*#%@');
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* t.draw(() => {
|
|
120
|
+
* t.background(0);
|
|
121
|
+
* if (video) {
|
|
122
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
126
|
+
* t.layers.base.filter('contrast', {
|
|
127
|
+
* amount: 1 + wobble * 0.35,
|
|
128
|
+
* });
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* t.windowResized(() => {
|
|
132
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @category Color adjustment filters
|
|
137
|
+
*/
|
|
138
|
+
export interface ContrastOptions {
|
|
139
|
+
/**
|
|
140
|
+
* Contrast multiplier.
|
|
141
|
+
*
|
|
142
|
+
* - `1.0` = normal contrast (no change)
|
|
143
|
+
* - `> 1.0` = more contrast (darker darks, brighter brights)
|
|
144
|
+
* - `< 1.0` = less contrast (more gray/washed out)
|
|
145
|
+
* - `0.0` = solid gray
|
|
146
|
+
*
|
|
147
|
+
* @default 1.0
|
|
148
|
+
*/
|
|
149
|
+
amount: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Configuration options for the `'saturation'` filter.
|
|
153
|
+
*
|
|
154
|
+
* Adjusts color intensity without affecting luminance.
|
|
155
|
+
* Perfect for creating vivid, oversaturated looks or desaturating to grayscale.
|
|
156
|
+
* @example
|
|
157
|
+
* ```javascript
|
|
158
|
+
* const t = textmode.create({
|
|
159
|
+
* width: window.innerWidth,
|
|
160
|
+
* height: window.innerHeight,
|
|
161
|
+
* plugins: [FiltersPlugin],
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* let video;
|
|
165
|
+
*
|
|
166
|
+
* t.setup(async () => {
|
|
167
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
168
|
+
* video.play();
|
|
169
|
+
* video.loop();
|
|
170
|
+
* video.characters(' .:-=+*#%@');
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* t.draw(() => {
|
|
174
|
+
* t.background(0);
|
|
175
|
+
* if (video) {
|
|
176
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
180
|
+
* t.layers.base.filter('saturation', {
|
|
181
|
+
* amount: 1 + wobble * 0.45,
|
|
182
|
+
* });
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* t.windowResized(() => {
|
|
186
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @category Color adjustment filters
|
|
191
|
+
*/
|
|
192
|
+
export interface SaturationOptions {
|
|
193
|
+
/**
|
|
194
|
+
* Saturation multiplier.
|
|
195
|
+
*
|
|
196
|
+
* - `0.0` = grayscale (no color)
|
|
197
|
+
* - `1.0` = normal saturation (no change)
|
|
198
|
+
* - `> 1.0` = vivid/oversaturated colors
|
|
199
|
+
*
|
|
200
|
+
* @default 1.0
|
|
201
|
+
*/
|
|
202
|
+
amount: number;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Configuration options for the `'hueRotate'` filter.
|
|
206
|
+
*
|
|
207
|
+
* Shifts all colors around the color wheel by a specified angle.
|
|
208
|
+
* Useful for color grading or creating surreal color effects.
|
|
209
|
+
* @example
|
|
210
|
+
* ```javascript
|
|
211
|
+
* const t = textmode.create({
|
|
212
|
+
* width: window.innerWidth,
|
|
213
|
+
* height: window.innerHeight,
|
|
214
|
+
* plugins: [FiltersPlugin],
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* let video;
|
|
218
|
+
*
|
|
219
|
+
* t.setup(async () => {
|
|
220
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
221
|
+
* video.play();
|
|
222
|
+
* video.loop();
|
|
223
|
+
* video.characters(' .:-=+*#%@');
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* t.draw(() => {
|
|
227
|
+
* t.background(0);
|
|
228
|
+
* if (video) {
|
|
229
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
230
|
+
* }
|
|
231
|
+
*
|
|
232
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
233
|
+
* const hue = (t.frameCount * 2 + wobble * 45) % 360;
|
|
234
|
+
* t.layers.base.filter('hueRotate', {
|
|
235
|
+
* angle: hue,
|
|
236
|
+
* });
|
|
237
|
+
* });
|
|
238
|
+
*
|
|
239
|
+
* t.windowResized(() => {
|
|
240
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* @category Color adjustment filters
|
|
245
|
+
*/
|
|
246
|
+
export interface HueRotateOptions {
|
|
247
|
+
/**
|
|
248
|
+
* Rotation angle in degrees.
|
|
249
|
+
*
|
|
250
|
+
* - `0` = no change
|
|
251
|
+
* - `180` = complementary colors
|
|
252
|
+
* - `360` = full rotation (same as 0)
|
|
253
|
+
*
|
|
254
|
+
* Values wrap around, so `370` is equivalent to `10`.
|
|
255
|
+
*
|
|
256
|
+
* @default 0.0
|
|
257
|
+
*/
|
|
258
|
+
angle: number;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Configuration options for the `'posterize'` filter.
|
|
262
|
+
*
|
|
263
|
+
* Reduces the color palette to a limited number of bands per channel,
|
|
264
|
+
* creating a retro quantized/poster-like look.
|
|
265
|
+
* @example
|
|
266
|
+
* ```javascript
|
|
267
|
+
* const t = textmode.create({
|
|
268
|
+
* width: window.innerWidth,
|
|
269
|
+
* height: window.innerHeight,
|
|
270
|
+
* plugins: [FiltersPlugin],
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* let video;
|
|
274
|
+
*
|
|
275
|
+
* t.setup(async () => {
|
|
276
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
277
|
+
* video.play();
|
|
278
|
+
* video.loop();
|
|
279
|
+
* video.characters(' .:-=+*#%@');
|
|
280
|
+
* });
|
|
281
|
+
*
|
|
282
|
+
* t.draw(() => {
|
|
283
|
+
* t.background(0);
|
|
284
|
+
* if (video) {
|
|
285
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
289
|
+
* t.layers.base.filter('posterize', {
|
|
290
|
+
* levels: Math.max(2, Math.round(5 + wobble * 3)),
|
|
291
|
+
* });
|
|
292
|
+
* });
|
|
293
|
+
*
|
|
294
|
+
* t.windowResized(() => {
|
|
295
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @category Color adjustment filters
|
|
300
|
+
*/
|
|
301
|
+
export interface PosterizeOptions {
|
|
302
|
+
/**
|
|
303
|
+
* Number of color levels per channel.
|
|
304
|
+
*
|
|
305
|
+
* Lower values create more dramatic banding effects.
|
|
306
|
+
* Higher values approach the original image quality.
|
|
307
|
+
*
|
|
308
|
+
* - `2` = extreme posterization (very few colors)
|
|
309
|
+
* - `4` = strong posterization (default)
|
|
310
|
+
* - `8+` = subtle posterization
|
|
311
|
+
*
|
|
312
|
+
* @default 4.0
|
|
313
|
+
*/
|
|
314
|
+
levels: number;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Configuration options for the `'chromaticAberration'` filter.
|
|
318
|
+
*
|
|
319
|
+
* RGB color channel separation effect that simulates lens distortion
|
|
320
|
+
* found in cheap cameras or creates stylized glitch aesthetics.
|
|
321
|
+
* @example
|
|
322
|
+
* ```javascript
|
|
323
|
+
* const t = textmode.create({
|
|
324
|
+
* width: window.innerWidth,
|
|
325
|
+
* height: window.innerHeight,
|
|
326
|
+
* plugins: [FiltersPlugin],
|
|
327
|
+
* });
|
|
328
|
+
*
|
|
329
|
+
* let video;
|
|
330
|
+
*
|
|
331
|
+
* t.setup(async () => {
|
|
332
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
333
|
+
* video.play();
|
|
334
|
+
* video.loop();
|
|
335
|
+
* video.characters(' .:-=+*#%@');
|
|
336
|
+
* });
|
|
337
|
+
*
|
|
338
|
+
* t.draw(() => {
|
|
339
|
+
* t.background(0);
|
|
340
|
+
* if (video) {
|
|
341
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
345
|
+
* t.layers.base.filter('chromaticAberration', {
|
|
346
|
+
* amount: 6 + wobble * 4,
|
|
347
|
+
* direction: [Math.sin(t.secs), Math.cos(t.secs)],
|
|
348
|
+
* });
|
|
349
|
+
* });
|
|
350
|
+
*
|
|
351
|
+
* t.windowResized(() => {
|
|
352
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
353
|
+
* });
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @category Distortion filters
|
|
357
|
+
*/
|
|
358
|
+
export interface ChromaticAberrationOptions {
|
|
359
|
+
/**
|
|
360
|
+
* Offset amount in pixels.
|
|
361
|
+
*
|
|
362
|
+
* Controls how far the red and blue channels are separated from green.
|
|
363
|
+
*
|
|
364
|
+
* @default 5.0
|
|
365
|
+
*/
|
|
366
|
+
amount: number;
|
|
367
|
+
/**
|
|
368
|
+
* Direction of the color separation as `[x, y]`.
|
|
369
|
+
*
|
|
370
|
+
* - `[1, 0]` = horizontal separation
|
|
371
|
+
* - `[0, 1]` = vertical separation
|
|
372
|
+
* - `[1, 1]` = diagonal separation
|
|
373
|
+
*
|
|
374
|
+
* The vector is normalized internally, so `[2, 0]` is the same as `[1, 0]`.
|
|
375
|
+
*
|
|
376
|
+
* @default [1.0, 0.0]
|
|
377
|
+
*/
|
|
378
|
+
direction: [number, number];
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Configuration options for the `'pixelate'` filter.
|
|
382
|
+
*
|
|
383
|
+
* Reduces image resolution to create a mosaic/pixelated effect
|
|
384
|
+
* reminiscent of retro video games or censored content.
|
|
385
|
+
* @example
|
|
386
|
+
* ```javascript
|
|
387
|
+
* const t = textmode.create({
|
|
388
|
+
* width: window.innerWidth,
|
|
389
|
+
* height: window.innerHeight,
|
|
390
|
+
* plugins: [FiltersPlugin],
|
|
391
|
+
* });
|
|
392
|
+
*
|
|
393
|
+
* let video;
|
|
394
|
+
*
|
|
395
|
+
* t.setup(async () => {
|
|
396
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
397
|
+
* video.play();
|
|
398
|
+
* video.loop();
|
|
399
|
+
* video.characters(' .:-=+*#%@');
|
|
400
|
+
* });
|
|
401
|
+
*
|
|
402
|
+
* t.draw(() => {
|
|
403
|
+
* t.background(0);
|
|
404
|
+
* if (video) {
|
|
405
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
406
|
+
* }
|
|
407
|
+
*
|
|
408
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
409
|
+
* t.layers.base.filter('pixelate', {
|
|
410
|
+
* pixelSize: 6 + wobble * 3,
|
|
411
|
+
* });
|
|
412
|
+
* });
|
|
413
|
+
*
|
|
414
|
+
* t.windowResized(() => {
|
|
415
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
416
|
+
* });
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* @category Distortion filters
|
|
420
|
+
*/
|
|
421
|
+
export interface PixelateOptions {
|
|
422
|
+
/**
|
|
423
|
+
* Size of each pixel block in pixels.
|
|
424
|
+
*
|
|
425
|
+
* Larger values create bigger, more visible pixels.
|
|
426
|
+
*
|
|
427
|
+
* Minimum value: `1.0`
|
|
428
|
+
*
|
|
429
|
+
* @default 4.0
|
|
430
|
+
*/
|
|
431
|
+
pixelSize: number;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Configuration options for the `'gridDistortion'` filter.
|
|
435
|
+
*
|
|
436
|
+
* Distorts a monospaced character grid by varying the width and height
|
|
437
|
+
* of individual cells. Create wave effects, perspective distortions,
|
|
438
|
+
* or other grid warping effects by providing custom factor arrays.
|
|
439
|
+
*
|
|
440
|
+
* This filter is designed specifically for textmode.js grids, allowing
|
|
441
|
+
* you to create dynamic text distortion effects.
|
|
442
|
+
* @example
|
|
443
|
+
* ```javascript
|
|
444
|
+
* const t = textmode.create({
|
|
445
|
+
* width: window.innerWidth,
|
|
446
|
+
* height: window.innerHeight,
|
|
447
|
+
* plugins: [FiltersPlugin],
|
|
448
|
+
* });
|
|
449
|
+
*
|
|
450
|
+
* let video;
|
|
451
|
+
*
|
|
452
|
+
* t.setup(async () => {
|
|
453
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
454
|
+
* video.play();
|
|
455
|
+
* video.loop();
|
|
456
|
+
* video.characters(' .:-=+*#%@');
|
|
457
|
+
* });
|
|
458
|
+
*
|
|
459
|
+
* t.draw(() => {
|
|
460
|
+
* t.background(0);
|
|
461
|
+
* if (video) {
|
|
462
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
463
|
+
* }
|
|
464
|
+
*
|
|
465
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
466
|
+
* const widthFactors = Array.from({ length: t.grid.cols }, (_, i) => (Math.sin(i * 0.18 + t.frameCount * 0.04) + 1) * 0.5);
|
|
467
|
+
* const heightFactors = Array.from({ length: t.grid.rows }, (_, i) => (Math.sin(i * 0.24 + t.secs * 1.5) + 1) * 0.5);
|
|
468
|
+
* t.layers.base.filter('gridDistortion', {
|
|
469
|
+
* gridCellDimensions: [t.grid.cols, t.grid.rows],
|
|
470
|
+
* gridPixelDimensions: [t.grid.width, t.grid.height],
|
|
471
|
+
* gridOffsetDimensions: [t.grid.offsetX, t.grid.offsetY],
|
|
472
|
+
* widthFactors,
|
|
473
|
+
* heightFactors,
|
|
474
|
+
* widthVariationScale: 0.35 + wobble * 0.15,
|
|
475
|
+
* heightVariationScale: 0.35 + wobble * 0.15,
|
|
476
|
+
* });
|
|
477
|
+
* });
|
|
478
|
+
*
|
|
479
|
+
* t.windowResized(() => {
|
|
480
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
481
|
+
* });
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @category Distortion filters
|
|
485
|
+
*/
|
|
486
|
+
export interface GridDistortionOptions {
|
|
487
|
+
/**
|
|
488
|
+
* Grid dimensions as `[columns, rows]`.
|
|
489
|
+
*
|
|
490
|
+
* Should match your textmode grid dimensions.
|
|
491
|
+
*
|
|
492
|
+
* Maximum value: `[128, 128]`
|
|
493
|
+
*
|
|
494
|
+
* @default [80.0, 40.0]
|
|
495
|
+
*/
|
|
496
|
+
gridCellDimensions: [number, number];
|
|
497
|
+
/**
|
|
498
|
+
* Grid size in pixels as `[width, height]`.
|
|
499
|
+
*
|
|
500
|
+
* Typically calculated as:
|
|
501
|
+
* `[t.grid.cols * t.grid.cellWidth, t.grid.rows * t.grid.cellHeight]`
|
|
502
|
+
*
|
|
503
|
+
* @default [640.0, 320.0]
|
|
504
|
+
*/
|
|
505
|
+
gridPixelDimensions: [number, number];
|
|
506
|
+
/**
|
|
507
|
+
* Grid offset in pixels as `[offsetX, offsetY]`.
|
|
508
|
+
*
|
|
509
|
+
* Use `[t.grid.offsetX, t.grid.offsetY]` to match your grid position.
|
|
510
|
+
*
|
|
511
|
+
* @default [0.0, 0.0]
|
|
512
|
+
*/
|
|
513
|
+
gridOffsetDimensions: [number, number];
|
|
514
|
+
/**
|
|
515
|
+
* Array of distortion values (0-1) for each column.
|
|
516
|
+
*
|
|
517
|
+
* Must contain at least as many elements as columns (max 128).
|
|
518
|
+
* Values control the relative width of each column:
|
|
519
|
+
* - `0.0` = minimum width
|
|
520
|
+
* - `0.5` = normal width
|
|
521
|
+
* - `1.0` = maximum width
|
|
522
|
+
*
|
|
523
|
+
* @default Array(128).fill(0.5)
|
|
524
|
+
*/
|
|
525
|
+
widthFactors: number[];
|
|
526
|
+
/**
|
|
527
|
+
* Array of distortion values (0-1) for each row.
|
|
528
|
+
*
|
|
529
|
+
* Must contain at least as many elements as rows (max 128).
|
|
530
|
+
* Values control the relative height of each row:
|
|
531
|
+
* - `0.0` = minimum height
|
|
532
|
+
* - `0.5` = normal height
|
|
533
|
+
* - `1.0` = maximum height
|
|
534
|
+
*
|
|
535
|
+
* @default Array(128).fill(0.5)
|
|
536
|
+
*/
|
|
537
|
+
heightFactors: number[];
|
|
538
|
+
/**
|
|
539
|
+
* Intensity multiplier for width distortion.
|
|
540
|
+
*
|
|
541
|
+
* Higher values create more dramatic width variations.
|
|
542
|
+
*
|
|
543
|
+
* @default 0.5
|
|
544
|
+
*/
|
|
545
|
+
widthVariationScale: number;
|
|
546
|
+
/**
|
|
547
|
+
* Intensity multiplier for height distortion.
|
|
548
|
+
*
|
|
549
|
+
* Higher values create more dramatic height variations.
|
|
550
|
+
*
|
|
551
|
+
* @default 0.5
|
|
552
|
+
*/
|
|
553
|
+
heightVariationScale: number;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Configuration options for the `'glitch'` filter.
|
|
557
|
+
*
|
|
558
|
+
* Digital glitch effect with RGB channel separation, scanlines, and noise.
|
|
559
|
+
* Creates a corrupted/broken digital signal aesthetic.
|
|
560
|
+
* @example
|
|
561
|
+
* ```javascript
|
|
562
|
+
* const t = textmode.create({
|
|
563
|
+
* width: window.innerWidth,
|
|
564
|
+
* height: window.innerHeight,
|
|
565
|
+
* plugins: [FiltersPlugin],
|
|
566
|
+
* });
|
|
567
|
+
*
|
|
568
|
+
* let video;
|
|
569
|
+
*
|
|
570
|
+
* t.setup(async () => {
|
|
571
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
572
|
+
* video.play();
|
|
573
|
+
* video.loop();
|
|
574
|
+
* video.characters(' .:-=+*#%@');
|
|
575
|
+
* });
|
|
576
|
+
*
|
|
577
|
+
* t.draw(() => {
|
|
578
|
+
* t.background(0);
|
|
579
|
+
* if (video) {
|
|
580
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
581
|
+
* }
|
|
582
|
+
*
|
|
583
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
584
|
+
* t.layers.base.filter('glitch', {
|
|
585
|
+
* amount: Math.max(0, 0.2 + wobble * 0.8),
|
|
586
|
+
* });
|
|
587
|
+
* });
|
|
588
|
+
*
|
|
589
|
+
* t.windowResized(() => {
|
|
590
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
591
|
+
* });
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @category Stylization filters
|
|
595
|
+
*/
|
|
596
|
+
export interface GlitchOptions {
|
|
597
|
+
/**
|
|
598
|
+
* Glitch intensity.
|
|
599
|
+
*
|
|
600
|
+
* - `0.0` = no glitch effect
|
|
601
|
+
* - `0.5` = subtle glitching
|
|
602
|
+
* - `1.0+` = intense, chaotic glitching
|
|
603
|
+
*
|
|
604
|
+
* @default 0.0
|
|
605
|
+
*/
|
|
606
|
+
amount: number;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Configuration options for the `'crtMattias'` filter.
|
|
610
|
+
*
|
|
611
|
+
* CRT monitor emulation effect with screen curvature, animated scanlines,
|
|
612
|
+
* blur, vignette, and film grain noise. Based on Mattias Gustavsson's
|
|
613
|
+
* classic CRT shader.
|
|
614
|
+
* @example
|
|
615
|
+
* ```javascript
|
|
616
|
+
* const t = textmode.create({
|
|
617
|
+
* width: window.innerWidth,
|
|
618
|
+
* height: window.innerHeight,
|
|
619
|
+
* plugins: [FiltersPlugin],
|
|
620
|
+
* });
|
|
621
|
+
*
|
|
622
|
+
* let video;
|
|
623
|
+
*
|
|
624
|
+
* t.setup(async () => {
|
|
625
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
626
|
+
* video.play();
|
|
627
|
+
* video.loop();
|
|
628
|
+
* video.characters(' .:-=+*#%@');
|
|
629
|
+
* });
|
|
630
|
+
*
|
|
631
|
+
* t.draw(() => {
|
|
632
|
+
* t.background(0);
|
|
633
|
+
* if (video) {
|
|
634
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
635
|
+
* }
|
|
636
|
+
*
|
|
637
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
638
|
+
* t.layers.base.filter('crtMattias', {
|
|
639
|
+
* curvature: 0.45 + wobble * 0.1,
|
|
640
|
+
* scanSpeed: 1 + wobble * 0.25,
|
|
641
|
+
* time: t.secs,
|
|
642
|
+
* });
|
|
643
|
+
* });
|
|
644
|
+
*
|
|
645
|
+
* t.windowResized(() => {
|
|
646
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
647
|
+
* });
|
|
648
|
+
* ```
|
|
649
|
+
*
|
|
650
|
+
* @see {@link https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-mattias.glsl | Original shader by Mattias Gustavsson}
|
|
651
|
+
*
|
|
652
|
+
* @category Stylization filters
|
|
653
|
+
*/
|
|
654
|
+
export interface CrtMattiasOptions {
|
|
655
|
+
/**
|
|
656
|
+
* Amount of screen curvature/barrel distortion.
|
|
657
|
+
*
|
|
658
|
+
* - `0.0` = flat screen
|
|
659
|
+
* - `0.5` = moderate curvature (default)
|
|
660
|
+
* - `1.0` = maximum curvature
|
|
661
|
+
*
|
|
662
|
+
* @default 0.5
|
|
663
|
+
*/
|
|
664
|
+
curvature: number;
|
|
665
|
+
/**
|
|
666
|
+
* Speed of the scrolling scanline effect.
|
|
667
|
+
*
|
|
668
|
+
* Higher values make the scanline crawl faster.
|
|
669
|
+
*
|
|
670
|
+
* @default 1.0
|
|
671
|
+
*/
|
|
672
|
+
scanSpeed: number;
|
|
673
|
+
/**
|
|
674
|
+
* Animation time parameter.
|
|
675
|
+
*
|
|
676
|
+
* Increment this value each frame to animate the effect.
|
|
677
|
+
* Typically use elapsed time in seconds or frame count.
|
|
678
|
+
*
|
|
679
|
+
* @default 0.0
|
|
680
|
+
*/
|
|
681
|
+
time: number;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Configuration options for the `'scanlines'` filter.
|
|
685
|
+
*
|
|
686
|
+
* A standalone scanline effect that adds horizontal lines to the image
|
|
687
|
+
* to simulate a CRT display or old monitor. More customizable than
|
|
688
|
+
* the scanlines in crtMattias.
|
|
689
|
+
* @example
|
|
690
|
+
* ```javascript
|
|
691
|
+
* const t = textmode.create({
|
|
692
|
+
* width: window.innerWidth,
|
|
693
|
+
* height: window.innerHeight,
|
|
694
|
+
* plugins: [FiltersPlugin],
|
|
695
|
+
* });
|
|
696
|
+
*
|
|
697
|
+
* let video;
|
|
698
|
+
*
|
|
699
|
+
* t.setup(async () => {
|
|
700
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
701
|
+
* video.play();
|
|
702
|
+
* video.loop();
|
|
703
|
+
* video.characters(' .:-=+*#%@');
|
|
704
|
+
* });
|
|
705
|
+
*
|
|
706
|
+
* t.draw(() => {
|
|
707
|
+
* t.background(0);
|
|
708
|
+
* if (video) {
|
|
709
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
710
|
+
* }
|
|
711
|
+
*
|
|
712
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
713
|
+
* t.layers.base.filter('scanlines', {
|
|
714
|
+
* count: 256,
|
|
715
|
+
* lineWidth: 0.5,
|
|
716
|
+
* intensity: 0.7 + wobble * 0.1,
|
|
717
|
+
* speed: 1 + wobble * 0.15,
|
|
718
|
+
* time: t.secs,
|
|
719
|
+
* });
|
|
720
|
+
* });
|
|
721
|
+
*
|
|
722
|
+
* t.windowResized(() => {
|
|
723
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
724
|
+
* });
|
|
725
|
+
* ```
|
|
726
|
+
*
|
|
727
|
+
* @category Stylization filters
|
|
728
|
+
*/
|
|
729
|
+
export interface ScanlinesOptions {
|
|
730
|
+
/**
|
|
731
|
+
* Number of scanlines across the image height.
|
|
732
|
+
*
|
|
733
|
+
* Higher values create finer, more dense lines.
|
|
734
|
+
*
|
|
735
|
+
* Minimum value: `10.0`
|
|
736
|
+
*
|
|
737
|
+
* @default 300.0
|
|
738
|
+
*/
|
|
739
|
+
count: number;
|
|
740
|
+
/**
|
|
741
|
+
* Width of the lines relative to the spacing.
|
|
742
|
+
*
|
|
743
|
+
* - `0.0` = very thin lines (mostly transparent)
|
|
744
|
+
* - `0.5` = equal line and gap width
|
|
745
|
+
* - `1.0` = solid (no gaps)
|
|
746
|
+
*
|
|
747
|
+
* @default 0.5
|
|
748
|
+
*/
|
|
749
|
+
lineWidth: number;
|
|
750
|
+
/**
|
|
751
|
+
* Opacity/darkness of the scanlines.
|
|
752
|
+
*
|
|
753
|
+
* - `0.0` = invisible lines
|
|
754
|
+
* - `0.75` = clearly visible (default)
|
|
755
|
+
* - `1.0` = maximum darkness (solid black lines)
|
|
756
|
+
*
|
|
757
|
+
* @default 0.75
|
|
758
|
+
*/
|
|
759
|
+
intensity: number;
|
|
760
|
+
/**
|
|
761
|
+
* Scrolling speed of the lines.
|
|
762
|
+
*
|
|
763
|
+
* - `0.0` = static lines
|
|
764
|
+
* - `1.0` = normal scrolling speed
|
|
765
|
+
* - Higher values = faster scrolling
|
|
766
|
+
*
|
|
767
|
+
* @default 1.0
|
|
768
|
+
*/
|
|
769
|
+
speed: number;
|
|
770
|
+
/**
|
|
771
|
+
* Animation time parameter.
|
|
772
|
+
*
|
|
773
|
+
* Increment this value each frame to animate the scrolling effect.
|
|
774
|
+
*
|
|
775
|
+
* @default 0.0
|
|
776
|
+
*/
|
|
777
|
+
time: number;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Configuration options for the `'vignette'` filter.
|
|
781
|
+
*
|
|
782
|
+
* Darkens the edges and corners of the image, drawing focus to the center.
|
|
783
|
+
* Useful for creating a cinematic look or highlighting central content.
|
|
784
|
+
* @example
|
|
785
|
+
* ```javascript
|
|
786
|
+
* const t = textmode.create({
|
|
787
|
+
* width: window.innerWidth,
|
|
788
|
+
* height: window.innerHeight,
|
|
789
|
+
* plugins: [FiltersPlugin],
|
|
790
|
+
* });
|
|
791
|
+
*
|
|
792
|
+
* let video;
|
|
793
|
+
*
|
|
794
|
+
* t.setup(async () => {
|
|
795
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
796
|
+
* video.play();
|
|
797
|
+
* video.loop();
|
|
798
|
+
* video.characters(' .:-=+*#%@');
|
|
799
|
+
* });
|
|
800
|
+
*
|
|
801
|
+
* t.draw(() => {
|
|
802
|
+
* t.background(0);
|
|
803
|
+
* if (video) {
|
|
804
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
805
|
+
* }
|
|
806
|
+
*
|
|
807
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
808
|
+
* t.layers.base.filter('vignette', {
|
|
809
|
+
* amount: 0.5 + wobble * 0.2,
|
|
810
|
+
* softness: 0.5,
|
|
811
|
+
* roundness: 0.5 + wobble * 0.15,
|
|
812
|
+
* });
|
|
813
|
+
* });
|
|
814
|
+
*
|
|
815
|
+
* t.windowResized(() => {
|
|
816
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
817
|
+
* });
|
|
818
|
+
* ```
|
|
819
|
+
*
|
|
820
|
+
* @category Stylization filters
|
|
821
|
+
*/
|
|
822
|
+
export interface VignetteOptions {
|
|
823
|
+
/**
|
|
824
|
+
* Intensity of the darkening effect.
|
|
825
|
+
*
|
|
826
|
+
* - `0.0` = no vignette
|
|
827
|
+
* - `0.5` = moderate vignette (default)
|
|
828
|
+
* - `1.0` = very dark edges
|
|
829
|
+
*
|
|
830
|
+
* @default 0.5
|
|
831
|
+
*/
|
|
832
|
+
amount: number;
|
|
833
|
+
/**
|
|
834
|
+
* Falloff gradient softness.
|
|
835
|
+
*
|
|
836
|
+
* - `0.0` = hard edge (sharp transition)
|
|
837
|
+
* - `0.5` = moderate gradient (default)
|
|
838
|
+
* - `1.0` = very soft, gradual falloff
|
|
839
|
+
*
|
|
840
|
+
* @default 0.5
|
|
841
|
+
*/
|
|
842
|
+
softness: number;
|
|
843
|
+
/**
|
|
844
|
+
* Shape of the vignette.
|
|
845
|
+
*
|
|
846
|
+
* - `0.0` = rectangular (follows screen edges)
|
|
847
|
+
* - `0.5` = rounded rectangle (default)
|
|
848
|
+
* - `1.0` = circular/elliptical
|
|
849
|
+
*
|
|
850
|
+
* @default 0.5
|
|
851
|
+
*/
|
|
852
|
+
roundness: number;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Configuration options for the `'bloom'` filter.
|
|
856
|
+
*
|
|
857
|
+
* Creates a glow effect around bright areas of the image. Pixels above
|
|
858
|
+
* the brightness threshold emit a soft glow that spreads outward.
|
|
859
|
+
* Perfect for creating neon, glowing text, or dreamy effects.
|
|
860
|
+
* @example
|
|
861
|
+
* ```javascript
|
|
862
|
+
* const t = textmode.create({
|
|
863
|
+
* width: window.innerWidth,
|
|
864
|
+
* height: window.innerHeight,
|
|
865
|
+
* plugins: [FiltersPlugin],
|
|
866
|
+
* });
|
|
867
|
+
*
|
|
868
|
+
* let video;
|
|
869
|
+
*
|
|
870
|
+
* t.setup(async () => {
|
|
871
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
872
|
+
* video.play();
|
|
873
|
+
* video.loop();
|
|
874
|
+
* video.characters(' .:-=+*#%@');
|
|
875
|
+
* });
|
|
876
|
+
*
|
|
877
|
+
* t.draw(() => {
|
|
878
|
+
* t.background(0);
|
|
879
|
+
* if (video) {
|
|
880
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
881
|
+
* }
|
|
882
|
+
*
|
|
883
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
884
|
+
* t.layers.base.filter('bloom', {
|
|
885
|
+
* threshold: 0.5,
|
|
886
|
+
* intensity: 1.2 + wobble * 0.5,
|
|
887
|
+
* radius: 6 + wobble * 2,
|
|
888
|
+
* });
|
|
889
|
+
* });
|
|
890
|
+
*
|
|
891
|
+
* t.windowResized(() => {
|
|
892
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
893
|
+
* });
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* @category Stylization filters
|
|
897
|
+
*/
|
|
898
|
+
export interface BloomOptions {
|
|
899
|
+
/**
|
|
900
|
+
* Brightness level above which pixels will glow.
|
|
901
|
+
*
|
|
902
|
+
* - `0.0` = everything glows
|
|
903
|
+
* - `0.5` = mid-brightness and above glows (default)
|
|
904
|
+
* - `1.0` = only the brightest pixels glow
|
|
905
|
+
*
|
|
906
|
+
* @default 0.5
|
|
907
|
+
*/
|
|
908
|
+
threshold: number;
|
|
909
|
+
/**
|
|
910
|
+
* Strength of the glow effect.
|
|
911
|
+
*
|
|
912
|
+
* - `0.0` = no visible glow
|
|
913
|
+
* - `1.0` = normal glow intensity (default)
|
|
914
|
+
* - `2.0+` = very bright, intense glow
|
|
915
|
+
*
|
|
916
|
+
* @default 1.0
|
|
917
|
+
*/
|
|
918
|
+
intensity: number;
|
|
919
|
+
/**
|
|
920
|
+
* Size of the glow spread in pixels.
|
|
921
|
+
*
|
|
922
|
+
* Larger values create a wider, softer glow.
|
|
923
|
+
*
|
|
924
|
+
* - `1.0` = tight glow
|
|
925
|
+
* - `4.0` = moderate spread (default)
|
|
926
|
+
* - `10.0+` = wide, diffuse glow
|
|
927
|
+
*
|
|
928
|
+
* @default 4.0
|
|
929
|
+
*/
|
|
930
|
+
radius: number;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Configuration options for the `'filmGrain'` filter.
|
|
934
|
+
*
|
|
935
|
+
* Adds an animated film grain/noise texture overlay to simulate vintage
|
|
936
|
+
* film stock or analog video. The multi-layered noise creates an organic,
|
|
937
|
+
* moving grain pattern that's less visible in darker areas, mimicking
|
|
938
|
+
* real film characteristics.
|
|
939
|
+
* @example
|
|
940
|
+
* ```javascript
|
|
941
|
+
* const t = textmode.create({
|
|
942
|
+
* width: window.innerWidth,
|
|
943
|
+
* height: window.innerHeight,
|
|
944
|
+
* plugins: [FiltersPlugin],
|
|
945
|
+
* });
|
|
946
|
+
*
|
|
947
|
+
* let video;
|
|
948
|
+
*
|
|
949
|
+
* t.setup(async () => {
|
|
950
|
+
* video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
|
951
|
+
* video.play();
|
|
952
|
+
* video.loop();
|
|
953
|
+
* video.characters(' .:-=+*#%@');
|
|
954
|
+
* });
|
|
955
|
+
*
|
|
956
|
+
* t.draw(() => {
|
|
957
|
+
* t.background(0);
|
|
958
|
+
* if (video) {
|
|
959
|
+
* t.image(video, t.grid.cols, t.grid.rows);
|
|
960
|
+
* }
|
|
961
|
+
*
|
|
962
|
+
* const wobble = Math.sin(t.secs * 2);
|
|
963
|
+
* t.layers.base.filter('filmGrain', {
|
|
964
|
+
* intensity: 0.2 + wobble * 0.1,
|
|
965
|
+
* size: 2 + wobble * 0.5,
|
|
966
|
+
* speed: 1 + wobble * 0.2,
|
|
967
|
+
* time: t.secs,
|
|
968
|
+
* });
|
|
969
|
+
* });
|
|
970
|
+
*
|
|
971
|
+
* t.windowResized(() => {
|
|
972
|
+
* t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
973
|
+
* });
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* @category Stylization filters
|
|
977
|
+
*/
|
|
978
|
+
export interface FilmGrainOptions {
|
|
979
|
+
/**
|
|
980
|
+
* Strength of the grain effect.
|
|
981
|
+
*
|
|
982
|
+
* - `0.0` = no grain
|
|
983
|
+
* - `0.2` = subtle grain (default)
|
|
984
|
+
* - `0.5+` = heavy, noticeable grain
|
|
985
|
+
*
|
|
986
|
+
* @default 0.2
|
|
987
|
+
*/
|
|
988
|
+
intensity: number;
|
|
989
|
+
/**
|
|
990
|
+
* Size of grain particles.
|
|
991
|
+
*
|
|
992
|
+
* - `1.0` = fine grain
|
|
993
|
+
* - `2.0` = medium grain (default)
|
|
994
|
+
* - `5.0+` = coarse, chunky grain
|
|
995
|
+
*
|
|
996
|
+
* @default 2.0
|
|
997
|
+
*/
|
|
998
|
+
size: number;
|
|
999
|
+
/**
|
|
1000
|
+
* Animation speed of the grain.
|
|
1001
|
+
*
|
|
1002
|
+
* - `0.0` = static grain (not recommended)
|
|
1003
|
+
* - `1.0` = normal animation speed (default)
|
|
1004
|
+
* - `2.0+` = fast, flickering grain
|
|
1005
|
+
*
|
|
1006
|
+
* @default 1.0
|
|
1007
|
+
*/
|
|
1008
|
+
speed: number;
|
|
1009
|
+
/**
|
|
1010
|
+
* Animation time parameter.
|
|
1011
|
+
*
|
|
1012
|
+
* Increment this value each frame to animate the grain effect.
|
|
1013
|
+
*
|
|
1014
|
+
* @default 0.0
|
|
1015
|
+
*/
|
|
1016
|
+
time: number;
|
|
1017
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.filters.js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Image filters plugin for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/textmode.filters.umd.js",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
"build": "vite build && tsc -p tsconfig.json",
|
|
21
21
|
"dev": "vite --port 5179 --host",
|
|
22
22
|
"format": "prettier --write \"src/**/*.{ts,js}\"",
|
|
23
|
-
"format:check": "prettier --check \"src/**/*.{ts,js}\""
|
|
23
|
+
"format:check": "prettier --check \"src/**/*.{ts,js}\"",
|
|
24
|
+
"build:docs": "typedoc",
|
|
25
|
+
"dev:docs": "typedoc --watch"
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
|
-
"textmode.js": "
|
|
28
|
+
"textmode.js": ">=0.9.1"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
31
|
"@mapwhit/glsl-minify": "^1.0.0",
|
|
@@ -32,7 +34,11 @@
|
|
|
32
34
|
"prettier": "^3.8.1",
|
|
33
35
|
"tslib": "^2.8.1",
|
|
34
36
|
"typescript": "^5.9.2",
|
|
35
|
-
"vite": "^6.3.4"
|
|
37
|
+
"vite": "^6.3.4",
|
|
38
|
+
"typedoc": "^0.28.13",
|
|
39
|
+
"typedoc-plugin-frontmatter": "^1.3.1",
|
|
40
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
41
|
+
"typedoc-vitepress-theme": "^1.1.2"
|
|
36
42
|
},
|
|
37
43
|
"license": "MIT",
|
|
38
44
|
"author": "humanbydefinition",
|