textmode.filters.js 1.2.4-beta.1 → 1.2.4-beta.2
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 +0 -3
- package/dist/textmode.filters.esm.js +1 -1
- package/dist/textmode.filters.umd.js +1 -1
- package/dist/types/builtins/catalog.d.ts +4 -0
- package/dist/types/builtins/color-adjustment/grayscale.d.ts +2 -0
- package/dist/types/builtins/color-adjustment/sepia.d.ts +2 -0
- package/dist/types/builtins/color-adjustment/threshold.d.ts +2 -0
- package/dist/types/index.d.ts +29 -1
- package/dist/types/plugin/FiltersPlugin.d.ts +2 -0
- package/dist/types/public/augmentations.d.ts +4 -5
- package/dist/types/public/filter-types.d.ts +6 -0
- package/dist/types/runtime/TextmodeFilterManager.d.ts +2 -0
- package/package.json +6 -4
- package/dist/types/global.d.ts +0 -6
package/README.md
CHANGED
|
@@ -40,9 +40,6 @@ Use it to apply and tune GPU filters interactively while your sketch runs.
|
|
|
40
40
|
Follow the [official installation guide](https://code.textmode.art/docs/installation) to install
|
|
41
41
|
`textmode.filters.js` alongside `textmode.js` with npm or browser-ready UMD bundles.
|
|
42
42
|
|
|
43
|
-
Version 2 requires `textmode.js` 0.18.x. Install `FiltersPlugin` before using `t.filter()`,
|
|
44
|
-
`layer.filter()`, `t.filters`, `t.layers.filters`, or `t.finalDraw()`:
|
|
45
|
-
|
|
46
43
|
```js
|
|
47
44
|
import { textmode } from 'textmode.js';
|
|
48
45
|
import { FiltersPlugin } from 'textmode.filters.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"textmode.js";function e(e){const t=Object.entries(e.uniforms).map(([e,[t,r]])=>[e,t,r]),r=e.primary??t[0]?.[1];if(t.length>0&&void 0===r)throw new TypeError(`Builtin filter "${e.id}" requires an explicit primary parameter.`);const o={id:e.id,source:e.shader,uniforms:t,...void 0!==r?{primary:r}:{}};return Object.freeze(o)}var t=e({id:"brightness",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=A.rgb*U0;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),r=e({id:"contrast",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=(A.rgb-0.5)*U0+0.5;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),o=e({id:"grayscale",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));fragColor=vec4(mix(A.rgb,vec3(B),U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),i=e({id:"hueRotate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U1;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+U1/360.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"angle",uniforms:{U1:["angle",0]}}),a=e({id:"invert",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}",uniforms:{}}),s=e({id:"posterize",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ub;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*Ub)/Ub;fragColor=vec4(B,A.a);}",primary:"levels",uniforms:{Ub:["levels",4]}}),n=e({id:"saturation",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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*U0,0.,1.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),u=e({id:"sepia",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=vec3(dot(A.rgb,vec3(0.393,0.769,0.189)),dot(A.rgb,vec3(0.349,0.686,0.168)),dot(A.rgb,vec3(0.272,0.534,0.131)));fragColor=vec4(mix(A.rgb,B,U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),f=e({id:"threshold",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uj;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=step(Uj,dot(A.rgb,vec3(0.299,0.587,0.114)));fragColor=vec4(vec3(B),A.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5]}}),v=e({id:"chromaticAberration",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform vec2 U4;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=U4*U0*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);}",primary:"amount",uniforms:{U0:["amount",5],U4:["direction",[1,0]]}});function l(){return new Array(128).fill(.5)}var c=e({id:"gridDistortion",shader:"#version 300 es\nprecision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 U5;uniform vec2 U7;uniform vec2 U6;uniform float Ul[128];uniform float U8[128];uniform float Um;uniform float U9;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-U6)/U7;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(U5.x);int F=int(U5.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=Ul[H];G+=0.1+I*Um;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=U8[K];J+=0.1+L*U9;}}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=Ul[H];float R=0.1+I*Um;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=U8[K];float W=0.1+L*U9;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);}",primary:"gridCellDimensions",uniforms:{U5:["gridCellDimensions",[80,40]],U7:["gridPixelDimensions",[640,320]],U6:["gridOffsetDimensions",[0,0]],Ul:["widthFactors",l()],U8:["heightFactors",l()],Um:["widthVariationScale",.5],U9:["heightVariationScale",.5]}}),h=e({id:"pixelate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uc;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(Uc)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}",primary:"pixelSize",uniforms:{Uc:["pixelSize",4]}}),m=e({id:"bloom",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uj;uniform float Ua;uniform float Ud;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)*Ud*H.x,0.);vec2 O=vec2(0.,float(L)*Ud*H.y);vec3 P=texture(u_texture,v_uv+N).rgb;I+=C(P,Uj)*M;if(L!=0){vec3 Q=texture(u_texture,v_uv+O).rgb;I+=C(Q,Uj)*M;J+=M;}J+=M;}float R=0.1;for(int L=1;L<=4;L++){float S=float(L)*Ud;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,Uj)*Z;I+=C(W,Uj)*Z;I+=C(X,Uj)*Z;I+=C(Y,Uj)*Z;J+=Z*4.;}I/=J;vec3 a=G.rgb+I*Ua;fragColor=vec4(a,G.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5],Ua:["intensity",1],Ud:["radius",4]}}),x=e({id:"crtMattias",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uk;uniform float U3;uniform float Uf;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),U3);vec3 T;float U=sin(0.1*Uk+Q.y*21.)*sin(0.23*Uk+Q.y*29.)*sin(0.3+0.11*Uk+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*(Uk*Uf)+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.*Uk);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*Uk),I(Q+0.0001*Uk+0.3),I(Q+0.0001*Uk+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.);}",primary:"curvature",uniforms:{U3:["curvature",.5],Uf:["scanSpeed",1],Uk:["time",0]}}),p=e({id:"filmGrain",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ua;uniform float Ug;uniform float Ui;uniform float Uk;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/Ug;M+=vec2(Uk*Ui*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)*Ua;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);}",primary:"intensity",uniforms:{Ua:["intensity",.2],Ug:["size",2],Ui:["speed",1],Uk:["time",0]}}),d=e({id:"glitch",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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=U0*0.1;float E=floor(C.y*20.);float F=A(vec2(E,floor(U0*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*U0;O-=P;float Q=A(C+fract(U0))*0.1*U0;O+=Q;fragColor=vec4(O,N);}",primary:"amount",uniforms:{U0:["amount",0]}}),_=e({id:"scanlines",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uk;uniform float U2;uniform float Ua;uniform float Ui;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*U2-Uk*Ui)*3.141592*2.);B=B*0.5+0.5;float C=1.-(Ua*(1.-B));fragColor=vec4(A.rgb*C,A.a);}",primary:"count",uniforms:{U2:["count",300],Ua:["intensity",.75],Ui:["speed",1],Uk:["time",0]}}),g=e({id:"vignette",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform float Uh;uniform float Ue;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,Ue);float G=mix(max(C,1.),length(vec2(C,1.)),Ue);F/=G;float H=1.-U0;float I=H+Uh*0.5+0.01;float J=1.-smoothstep(H,I,F);vec3 K=A.rgb*J;fragColor=vec4(K,A.a);}",primary:"amount",uniforms:{U0:["amount",.5],Uh:["softness",.5],Ue:["roundness",.5]}}),U=Object.freeze({invert:a,grayscale:o,sepia:u,threshold:f,brightness:t,contrast:r,saturation:n,hueRotate:i,posterize:s,chromaticAberration:v,pixelate:h,gridDistortion:c,glitch:d,crtMattias:x,scanlines:_,vignette:g,bloom:m,filmGrain:p}),y=class{t;o;i=/* @__PURE__ */new Map;u=!1;constructor(e,t,r){this.t=e,this.o=t;for(const o of r)this.i.set(o.id,{id:o.id,source:o.source,uniforms:o.uniforms,...o.primary?{primary:o.primary}:{}})}has(e){return this.i.has(e)}get(e){return this.i.get(e)}async register(e,t,r){const o="string"==typeof t?await this.t.createShader(this.o,t):t;this.u&&("string"==typeof t&&o.dispose(),this.v());const i=(a=r,Object.entries(a).map(([e,[t,r]])=>[e,t,r]));var a;this.l(e,{id:e,shader:o,uniforms:i,...i[0]?{primary:i[0][1]}:{}})}unregister(e){const t=this.i.get(e);return!!t&&(t.shader?.dispose(),this.i.delete(e),!0)}async initializeBuiltins(){const e=[];try{for(const[t,r]of this.i){if(!r.source||r.shader)continue;const o=await this.t.createShader(this.o,r.source);this.u&&(o.dispose(),this.v()),this.i.get(t)===r?(r.shader=o,e.push({descriptor:r,shader:o})):o.dispose()}}catch(t){for(const r of e.reverse())r.descriptor.shader===r.shader&&(r.descriptor.shader=void 0,this.u||r.shader.dispose());throw t}}dispose(){for(const e of this.i.values())e.shader?.dispose();this.i.clear(),this.u=!0}l(e,t){this.i.get(e)?.shader?.dispose(),this.i.set(e,t)}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},C=class{t;o;h=/* @__PURE__ */new WeakMap;m=/* @__PURE__ */new Set;p;constructor(e){this.t=e,this.o="#version 300 es\nlayout(location=0)in vec2 a_position;layout(location=1)in vec2 a_texCoord;out vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position*2.,0.,1.);}"}get vertexSource(){return this.o}applyLayer(e,t,r){let o=this.h.get(e);return o||(o=this._(t.width,t.height),this.h.set(e,o)),this.U(t,r,o)}applyComposite(e,t){return this.p??=this._(e.width,e.height),this.U(e,t,this.p)}disposeLayer(e){const t=this.h.get(e);t&&this.C(t),this.h.delete(e)}dispose(){for(const e of[...this.m])this.C(e);this.h=/* @__PURE__ */new WeakMap,this.p=void 0}U(e,t,r){if(0===t.length)return e;this.F(r,e.width,e.height);let o=e;for(const i of t){const e=r[0]===o?r[1]:(r[1],r[0]);this.A(o,e,i.shader,this.B(i)),o=e}return o}A(e,t,r,o){this.t.push();let i=!1;try{t.begin(),i=!0,this.t.shader(r),this.t.setUniforms({u_texture:e.textures[0],u_resolution:[t.width,t.height],...o}),this.t.rect(t.width,t.height)}finally{try{i&&t.end()}finally{this.t.pop()}}}B(e){const t={};for(const[r,o,i]of e.uniforms){let a=i;if("number"==typeof e.params&&o===e.primary)a=e.params;else if(e.params&&"object"==typeof e.params&&o in e.params){const t=e.params[o];F(t)&&(a=t)}t[r]=a}return t}_(e,t){const r=[this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1}),this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1})];return this.m.add(r),r}F(e,t,r){e[0].width===t&&e[0].height===r||(e[0].resize(t,r),e[1].resize(t,r))}C(e){e[0].dispose(),e[1].dispose(),this.m.delete(e),this.p===e&&(this.p=void 0)}};function F(e){return"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||e instanceof Float32Array||e instanceof Int32Array||"object"==typeof e&&null!==e}var A=class{D=0;H=!1;G=!1;J=[];T=[];L=/* @__PURE__ */new WeakMap;I=/* @__PURE__ */new Set;beginFrame(){this.D+=1;for(const e of this.I){const t=this.L.get(e);t&&(t.phase="draw")}this.H=!0}endFrame(){this.H=!1}queueLayer(e,t,r){const o=this.M(e);("postDraw"===o.phase?o.postQueue:o.drawQueue).push({name:t,params:r,frameToken:this.K()})}queueComposite(e,t){(this.G?this.T:this.J).push({name:e,params:t,frameToken:this.K()})}drainLayerDraw(e){return this.k(this.M(e).drawQueue)}drainLayerPostDraw(e){return this.k(this.M(e).postQueue)}setLayerPhase(e,t){this.M(e).phase=t}drainGlobal(){return this.k(this.J)}beginFinalDraw(){this.G=!0}endFinalDraw(){this.G=!1}drainFinal(){return this.k(this.T)}resetComposite(){this.J=[],this.T=[],this.G=!1}disposeLayer(e){this.L.delete(e),this.I.delete(e)}dispose(){this.J=[],this.T=[],this.L=/* @__PURE__ */new WeakMap,this.I.clear(),this.H=!1,this.G=!1}k(e){const t=this.D,r=[],o=[];for(const i of e)i.frameToken===t?r.push(i):i.frameToken>t&&o.push(i);return e.length=0,e.push(...o),r}M(e){let t=this.L.get(e);return t||(t={phase:"draw",drawQueue:[],postQueue:[]},this.L.set(e,t),this.I.add(e)),t}K(){return this.H?this.D:this.D+1}},B=class{t;P;O;S;N=()=>{};u=!1;constructor(e){this.t=e,this.S=new C(e),this.P=new y(e,this.S.vertexSource,Object.values(U)),this.O=new A}async register(e,t,r={}){if(this.v(),!e.trim())throw new TypeError("Filter id cannot be empty.");await this.P.register(e,t,r)}unregister(e){return this.P.unregister(e)}has(e){return this.P.has(e)}initializeBuiltins(){return this.v(),this.P.initializeBuiltins()}queueLayer(e,t,r){this.v(),this.O.queueLayer(e,t,r)}queueComposite(e,t){this.v(),this.O.queueComposite(e,t)}beginFrame(){this.O.beginFrame()}endFrame(){this.O.endFrame()}setFinalDrawCallback(e){this.N=e}transformLayer(e,t,r){if("resolved"===t){const t=this.j(r,this.O.drainLayerDraw(e),e,!1);return this.O.setLayerPhase(e,"postDraw"),t}try{return this.j(r,this.O.drainLayerPostDraw(e),e,!1)}finally{this.O.setLayerPhase(e,"draw")}}transformComposite(e){let t=e;try{t=this.j(t,this.O.drainGlobal(),void 0,!0),this.O.beginFinalDraw();try{this.N.call(this.t)}finally{this.O.endFinalDraw()}return this.j(t,this.O.drainFinal(),void 0,!0)}finally{this.O.resetComposite()}}disposeLayer(e){this.S.disposeLayer(e),this.O.disposeLayer(e)}dispose(){this.u||(this.P.dispose(),this.S.dispose(),this.O.dispose(),this.u=!0)}j(e,t,r,o){if(0===t.length)return e;const i=[];for(const a of t){const e=this.P.get(a.name);e?i.push(this.R(a.name,e,a.params)):console.warn(`[textmode.filters.js] Unknown filter: "${a.name}". Skipping.`)}return 0===i.length?e:o?this.S.applyComposite(e,i):this.S.applyLayer(r,e,i)}R(e,t,r){return{name:e,shader:this.W(t),uniforms:t.uniforms,params:r,...t.primary?{primary:t.primary}:{}}}W(e){if(e.shader)return e.shader;throw new Error("Filter shaders are not initialized. Wait for textmode setup to finish before drawing.")}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},D=/* @__PURE__ */new WeakMap,b={name:"textmode.filters",version:"1.2.4-beta.1",install(e,t){const r=D.get(e);r&&r.dispose();const o=new B(e);D.set(e,o),function(e,t){e.on("preSetup",()=>t.initializeBuiltins()),e.defineExtension("textmodifier","filter",{value:(e,r)=>t.queueComposite(e,r)}),e.defineExtension("textmodifier","filters",{get:()=>t}),e.defineExtension("textmodifier","finalDraw",{value:e=>{t.setFinalDrawCallback(e)}}),e.defineExtension("layerManager","filters",{get:()=>t});const r=t.queueLayer.bind(t);e.defineExtension("layer","filter",{value(e,t){r(this,e,t)}}),e.on("layerDisposed",e=>t.disposeLayer(e)),e.on("layerOutput",({layer:e,phase:r,output:o})=>t.transformLayer(e,r,o)),e.on("compositeOutput",e=>t.transformComposite(e)),e.on("preDraw",()=>t.beginFrame()),e.on("postDraw",()=>t.endFrame())}(t,o)},uninstall(e){D.get(e)?.dispose(),D.delete(e)}};"undefined"!=typeof window&&(window.FiltersPlugin=b);export{b as FiltersPlugin,B as TextmodeFilterManager};
|
|
1
|
+
import"textmode.js";function e(e){const t=Object.entries(e.uniforms).map(([e,[t,r]])=>[e,t,r]),r=e.primary??t[0]?.[1];if(t.length>0&&void 0===r)throw new TypeError(`Builtin filter "${e.id}" requires an explicit primary parameter.`);const o={id:e.id,source:e.shader,uniforms:t,...void 0!==r?{primary:r}:{}};return Object.freeze(o)}var t=e({id:"brightness",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=A.rgb*U0;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),r=e({id:"contrast",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=(A.rgb-0.5)*U0+0.5;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),o=e({id:"grayscale",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));fragColor=vec4(mix(A.rgb,vec3(B),U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),i=e({id:"hueRotate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U1;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+U1/360.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"angle",uniforms:{U1:["angle",0]}}),a=e({id:"invert",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}",uniforms:{}}),s=e({id:"posterize",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ub;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*Ub)/Ub;fragColor=vec4(B,A.a);}",primary:"levels",uniforms:{Ub:["levels",4]}}),n=e({id:"saturation",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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*U0,0.,1.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),u=e({id:"sepia",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=vec3(dot(A.rgb,vec3(0.393,0.769,0.189)),dot(A.rgb,vec3(0.349,0.686,0.168)),dot(A.rgb,vec3(0.272,0.534,0.131)));fragColor=vec4(mix(A.rgb,B,U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),f=e({id:"threshold",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uj;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=step(Uj,dot(A.rgb,vec3(0.299,0.587,0.114)));fragColor=vec4(vec3(B),A.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5]}}),v=e({id:"chromaticAberration",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform vec2 U4;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=U4*U0*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);}",primary:"amount",uniforms:{U0:["amount",5],U4:["direction",[1,0]]}});function l(){return new Array(128).fill(.5)}var c=e({id:"gridDistortion",shader:"#version 300 es\nprecision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 U5;uniform vec2 U7;uniform vec2 U6;uniform float Ul[128];uniform float U8[128];uniform float Um;uniform float U9;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-U6)/U7;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(U5.x);int F=int(U5.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=Ul[H];G+=0.1+I*Um;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=U8[K];J+=0.1+L*U9;}}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=Ul[H];float R=0.1+I*Um;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=U8[K];float W=0.1+L*U9;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);}",primary:"gridCellDimensions",uniforms:{U5:["gridCellDimensions",[80,40]],U7:["gridPixelDimensions",[640,320]],U6:["gridOffsetDimensions",[0,0]],Ul:["widthFactors",l()],U8:["heightFactors",l()],Um:["widthVariationScale",.5],U9:["heightVariationScale",.5]}}),h=e({id:"pixelate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uc;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(Uc)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}",primary:"pixelSize",uniforms:{Uc:["pixelSize",4]}}),m=e({id:"bloom",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uj;uniform float Ua;uniform float Ud;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)*Ud*H.x,0.);vec2 O=vec2(0.,float(L)*Ud*H.y);vec3 P=texture(u_texture,v_uv+N).rgb;I+=C(P,Uj)*M;if(L!=0){vec3 Q=texture(u_texture,v_uv+O).rgb;I+=C(Q,Uj)*M;J+=M;}J+=M;}float R=0.1;for(int L=1;L<=4;L++){float S=float(L)*Ud;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,Uj)*Z;I+=C(W,Uj)*Z;I+=C(X,Uj)*Z;I+=C(Y,Uj)*Z;J+=Z*4.;}I/=J;vec3 a=G.rgb+I*Ua;fragColor=vec4(a,G.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5],Ua:["intensity",1],Ud:["radius",4]}}),x=e({id:"crtMattias",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uk;uniform float U3;uniform float Uf;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),U3);vec3 T;float U=sin(0.1*Uk+Q.y*21.)*sin(0.23*Uk+Q.y*29.)*sin(0.3+0.11*Uk+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*(Uk*Uf)+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.*Uk);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*Uk),I(Q+0.0001*Uk+0.3),I(Q+0.0001*Uk+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.);}",primary:"curvature",uniforms:{U3:["curvature",.5],Uf:["scanSpeed",1],Uk:["time",0]}}),p=e({id:"filmGrain",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ua;uniform float Ug;uniform float Ui;uniform float Uk;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/Ug;M+=vec2(Uk*Ui*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)*Ua;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);}",primary:"intensity",uniforms:{Ua:["intensity",.2],Ug:["size",2],Ui:["speed",1],Uk:["time",0]}}),d=e({id:"glitch",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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=U0*0.1;float E=floor(C.y*20.);float F=A(vec2(E,floor(U0*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*U0;O-=P;float Q=A(C+fract(U0))*0.1*U0;O+=Q;fragColor=vec4(O,N);}",primary:"amount",uniforms:{U0:["amount",0]}}),_=e({id:"scanlines",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uk;uniform float U2;uniform float Ua;uniform float Ui;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*U2-Uk*Ui)*3.141592*2.);B=B*0.5+0.5;float C=1.-(Ua*(1.-B));fragColor=vec4(A.rgb*C,A.a);}",primary:"count",uniforms:{U2:["count",300],Ua:["intensity",.75],Ui:["speed",1],Uk:["time",0]}}),U=e({id:"vignette",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform float Uh;uniform float Ue;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,Ue);float G=mix(max(C,1.),length(vec2(C,1.)),Ue);F/=G;float H=1.-U0;float I=H+Uh*0.5+0.01;float J=1.-smoothstep(H,I,F);vec3 K=A.rgb*J;fragColor=vec4(K,A.a);}",primary:"amount",uniforms:{U0:["amount",.5],Uh:["softness",.5],Ue:["roundness",.5]}}),g=Object.freeze({invert:a,grayscale:o,sepia:u,threshold:f,brightness:t,contrast:r,saturation:n,hueRotate:i,posterize:s,chromaticAberration:v,pixelate:h,gridDistortion:c,glitch:d,crtMattias:x,scanlines:_,vignette:U,bloom:m,filmGrain:p}),y=class{t;o;i=/* @__PURE__ */new Map;u=!1;constructor(e,t,r){this.t=e,this.o=t;for(const o of r)this.i.set(o.id,{id:o.id,source:o.source,uniforms:o.uniforms,...o.primary?{primary:o.primary}:{}})}has(e){return this.i.has(e)}get(e){return this.i.get(e)}async register(e,t,r){const o="string"==typeof t?await this.t.createShader(this.o,t):t;this.u&&("string"==typeof t&&o.dispose(),this.v());const i=(a=r,Object.entries(a).map(([e,[t,r]])=>[e,t,r]));var a;this.l(e,{id:e,shader:o,uniforms:i,...i[0]?{primary:i[0][1]}:{}})}unregister(e){const t=this.i.get(e);return!!t&&(t.shader?.dispose(),this.i.delete(e),!0)}async initializeBuiltins(){const e=[];try{for(const[t,r]of this.i){if(!r.source||r.shader)continue;const o=await this.t.createShader(this.o,r.source);this.u&&(o.dispose(),this.v()),this.i.get(t)===r?(r.shader=o,e.push({descriptor:r,shader:o})):o.dispose()}}catch(t){for(const r of e.reverse())r.descriptor.shader===r.shader&&(r.descriptor.shader=void 0,this.u||r.shader.dispose());throw t}}dispose(){for(const e of this.i.values())e.shader?.dispose();this.i.clear(),this.u=!0}l(e,t){this.i.get(e)?.shader?.dispose(),this.i.set(e,t)}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},C=class{t;o;h=/* @__PURE__ */new WeakMap;m=/* @__PURE__ */new Set;p;constructor(e){this.t=e,this.o="#version 300 es\nlayout(location=0)in vec2 a_position;layout(location=1)in vec2 a_texCoord;out vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position*2.,0.,1.);}"}get vertexSource(){return this.o}applyLayer(e,t,r){let o=this.h.get(e);return o||(o=this._(t.width,t.height),this.h.set(e,o)),this.U(t,r,o)}applyComposite(e,t){return this.p??=this._(e.width,e.height),this.U(e,t,this.p)}disposeLayer(e){const t=this.h.get(e);t&&this.C(t),this.h.delete(e)}dispose(){for(const e of[...this.m])this.C(e);this.h=/* @__PURE__ */new WeakMap,this.p=void 0}U(e,t,r){if(0===t.length)return e;this.F(r,e.width,e.height);let o=e;for(const i of t){const e=r[0]===o?r[1]:(r[1],r[0]);this.A(o,e,i.shader,this.B(i)),o=e}return o}A(e,t,r,o){this.t.push();let i=!1;try{t.begin(),i=!0,this.t.shader(r),this.t.setUniforms({u_texture:e.textures[0],u_resolution:[t.width,t.height],...o}),this.t.rect(t.width,t.height)}finally{try{i&&t.end()}finally{this.t.pop()}}}B(e){const t={};for(const[r,o,i]of e.uniforms){let a=i;if("number"==typeof e.params&&o===e.primary)a=e.params;else if(e.params&&"object"==typeof e.params&&o in e.params){const t=e.params[o];F(t)&&(a=t)}t[r]=a}return t}_(e,t){const r=[this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1}),this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1})];return this.m.add(r),r}F(e,t,r){e[0].width===t&&e[0].height===r||(e[0].resize(t,r),e[1].resize(t,r))}C(e){e[0].dispose(),e[1].dispose(),this.m.delete(e),this.p===e&&(this.p=void 0)}};function F(e){return"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||e instanceof Float32Array||e instanceof Int32Array||"object"==typeof e&&null!==e}var A=class{D=0;H=!1;G=!1;J=[];T=[];L=/* @__PURE__ */new WeakMap;I=/* @__PURE__ */new Set;beginFrame(){this.D+=1;for(const e of this.I){const t=this.L.get(e);t&&(t.phase="draw")}this.H=!0}endFrame(){this.H=!1}queueLayer(e,t,r){const o=this.M(e);("postDraw"===o.phase?o.postQueue:o.drawQueue).push({name:t,params:r,frameToken:this.K()})}queueComposite(e,t){(this.G?this.T:this.J).push({name:e,params:t,frameToken:this.K()})}drainLayerDraw(e){return this.k(this.M(e).drawQueue)}drainLayerPostDraw(e){return this.k(this.M(e).postQueue)}setLayerPhase(e,t){this.M(e).phase=t}drainGlobal(){return this.k(this.J)}beginFinalDraw(){this.G=!0}endFinalDraw(){this.G=!1}drainFinal(){return this.k(this.T)}resetComposite(){this.J=[],this.T=[],this.G=!1}disposeLayer(e){this.L.delete(e),this.I.delete(e)}dispose(){this.J=[],this.T=[],this.L=/* @__PURE__ */new WeakMap,this.I.clear(),this.H=!1,this.G=!1}k(e){const t=this.D,r=[],o=[];for(const i of e)i.frameToken===t?r.push(i):i.frameToken>t&&o.push(i);return e.length=0,e.push(...o),r}M(e){let t=this.L.get(e);return t||(t={phase:"draw",drawQueue:[],postQueue:[]},this.L.set(e,t),this.I.add(e)),t}K(){return this.H?this.D:this.D+1}},B=class{t;P;O;S;N=()=>{};u=!1;constructor(e){this.t=e,this.S=new C(e),this.P=new y(e,this.S.vertexSource,Object.values(g)),this.O=new A}async register(e,t,r={}){if(this.v(),!e.trim())throw new TypeError("Filter id cannot be empty.");await this.P.register(e,t,r)}unregister(e){return this.P.unregister(e)}has(e){return this.P.has(e)}initializeBuiltins(){return this.v(),this.P.initializeBuiltins()}queueLayer(e,t,r){this.v(),this.O.queueLayer(e,t,r)}queueComposite(e,t){this.v(),this.O.queueComposite(e,t)}beginFrame(){this.O.beginFrame()}endFrame(){this.O.endFrame()}setFinalDrawCallback(e){this.N=e}transformLayer(e,t,r){if("resolved"===t){const t=this.j(r,this.O.drainLayerDraw(e),e,!1);return this.O.setLayerPhase(e,"postDraw"),t}try{return this.j(r,this.O.drainLayerPostDraw(e),e,!1)}finally{this.O.setLayerPhase(e,"draw")}}transformComposite(e){let t=e;try{t=this.j(t,this.O.drainGlobal(),void 0,!0),this.O.beginFinalDraw();try{this.N.call(this.t)}finally{this.O.endFinalDraw()}return this.j(t,this.O.drainFinal(),void 0,!0)}finally{this.O.resetComposite()}}disposeLayer(e){this.S.disposeLayer(e),this.O.disposeLayer(e)}dispose(){this.u||(this.P.dispose(),this.S.dispose(),this.O.dispose(),this.u=!0)}j(e,t,r,o){if(0===t.length)return e;const i=[];for(const a of t){const e=this.P.get(a.name);e?i.push(this.R(a.name,e,a.params)):console.warn(`[textmode.filters.js] Unknown filter: "${a.name}". Skipping.`)}return 0===i.length?e:o?this.S.applyComposite(e,i):this.S.applyLayer(r,e,i)}R(e,t,r){return{name:e,shader:this.W(t),uniforms:t.uniforms,params:r,...t.primary?{primary:t.primary}:{}}}W(e){if(e.shader)return e.shader;throw new Error("Filter shaders are not initialized. Wait for textmode setup to finish before drawing.")}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},D={name:"textmode.filters.js",install(e,t){const r=new B(e);try{!function(e,t){e.on("preSetup",()=>t.initializeBuiltins()),e.defineExtension("textmodifier","filter",{value:(e,r)=>t.queueComposite(e,r)}),e.defineExtension("textmodifier","filters",{get:()=>t}),e.defineExtension("textmodifier","finalDraw",{value:e=>{t.setFinalDrawCallback(e)}});const r=t.queueLayer.bind(t);e.defineExtension("layer","filter",{value(e,t){r(this,e,t)}}),e.on("layerDisposed",e=>t.disposeLayer(e)),e.on("layerOutput",({layer:e,phase:r,output:o})=>t.transformLayer(e,r,o)),e.on("compositeOutput",e=>t.transformComposite(e)),e.on("preDraw",()=>t.beginFrame()),e.on("postDraw",()=>t.endFrame())}(t,r)}catch(o){throw r.dispose(),o}return()=>r.dispose()}};"undefined"!=typeof window&&(window.FiltersPlugin=D);export{D as FiltersPlugin,B as TextmodeFilterManager};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).textmodeFilters={},e.textmode)}(this,function(e,t){function r(e){const t=Object.entries(e.uniforms).map(([e,[t,r]])=>[e,t,r]),r=e.primary??t[0]?.[1];if(t.length>0&&void 0===r)throw new TypeError(`Builtin filter "${e.id}" requires an explicit primary parameter.`);const o={id:e.id,source:e.shader,uniforms:t,...void 0!==r?{primary:r}:{}};return Object.freeze(o)}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var o=r({id:"brightness",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=A.rgb*U0;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),i=r({id:"contrast",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=(A.rgb-0.5)*U0+0.5;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),a=r({id:"grayscale",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));fragColor=vec4(mix(A.rgb,vec3(B),U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),s=r({id:"hueRotate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U1;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+U1/360.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"angle",uniforms:{U1:["angle",0]}}),n=r({id:"invert",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}",uniforms:{}}),u=r({id:"posterize",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ub;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*Ub)/Ub;fragColor=vec4(B,A.a);}",primary:"levels",uniforms:{Ub:["levels",4]}}),f=r({id:"saturation",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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*U0,0.,1.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),v=r({id:"sepia",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=vec3(dot(A.rgb,vec3(0.393,0.769,0.189)),dot(A.rgb,vec3(0.349,0.686,0.168)),dot(A.rgb,vec3(0.272,0.534,0.131)));fragColor=vec4(mix(A.rgb,B,U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),l=r({id:"threshold",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uj;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=step(Uj,dot(A.rgb,vec3(0.299,0.587,0.114)));fragColor=vec4(vec3(B),A.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5]}}),c=r({id:"chromaticAberration",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform vec2 U4;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=U4*U0*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);}",primary:"amount",uniforms:{U0:["amount",5],U4:["direction",[1,0]]}});function h(){return new Array(128).fill(.5)}var m=r({id:"gridDistortion",shader:"#version 300 es\nprecision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 U5;uniform vec2 U7;uniform vec2 U6;uniform float Ul[128];uniform float U8[128];uniform float Um;uniform float U9;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-U6)/U7;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(U5.x);int F=int(U5.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=Ul[H];G+=0.1+I*Um;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=U8[K];J+=0.1+L*U9;}}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=Ul[H];float R=0.1+I*Um;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=U8[K];float W=0.1+L*U9;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);}",primary:"gridCellDimensions",uniforms:{U5:["gridCellDimensions",[80,40]],U7:["gridPixelDimensions",[640,320]],U6:["gridOffsetDimensions",[0,0]],Ul:["widthFactors",h()],U8:["heightFactors",h()],Um:["widthVariationScale",.5],U9:["heightVariationScale",.5]}}),d=r({id:"pixelate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uc;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(Uc)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}",primary:"pixelSize",uniforms:{Uc:["pixelSize",4]}}),p=r({id:"bloom",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uj;uniform float Ua;uniform float Ud;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)*Ud*H.x,0.);vec2 O=vec2(0.,float(L)*Ud*H.y);vec3 P=texture(u_texture,v_uv+N).rgb;I+=C(P,Uj)*M;if(L!=0){vec3 Q=texture(u_texture,v_uv+O).rgb;I+=C(Q,Uj)*M;J+=M;}J+=M;}float R=0.1;for(int L=1;L<=4;L++){float S=float(L)*Ud;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,Uj)*Z;I+=C(W,Uj)*Z;I+=C(X,Uj)*Z;I+=C(Y,Uj)*Z;J+=Z*4.;}I/=J;vec3 a=G.rgb+I*Ua;fragColor=vec4(a,G.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5],Ua:["intensity",1],Ud:["radius",4]}}),x=r({id:"crtMattias",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uk;uniform float U3;uniform float Uf;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),U3);vec3 T;float U=sin(0.1*Uk+Q.y*21.)*sin(0.23*Uk+Q.y*29.)*sin(0.3+0.11*Uk+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*(Uk*Uf)+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.*Uk);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*Uk),I(Q+0.0001*Uk+0.3),I(Q+0.0001*Uk+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.);}",primary:"curvature",uniforms:{U3:["curvature",.5],Uf:["scanSpeed",1],Uk:["time",0]}}),_=r({id:"filmGrain",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ua;uniform float Ug;uniform float Ui;uniform float Uk;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/Ug;M+=vec2(Uk*Ui*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)*Ua;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);}",primary:"intensity",uniforms:{Ua:["intensity",.2],Ug:["size",2],Ui:["speed",1],Uk:["time",0]}}),g=r({id:"glitch",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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=U0*0.1;float E=floor(C.y*20.);float F=A(vec2(E,floor(U0*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*U0;O-=P;float Q=A(C+fract(U0))*0.1*U0;O+=Q;fragColor=vec4(O,N);}",primary:"amount",uniforms:{U0:["amount",0]}}),y=r({id:"scanlines",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uk;uniform float U2;uniform float Ua;uniform float Ui;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*U2-Uk*Ui)*3.141592*2.);B=B*0.5+0.5;float C=1.-(Ua*(1.-B));fragColor=vec4(A.rgb*C,A.a);}",primary:"count",uniforms:{U2:["count",300],Ua:["intensity",.75],Ui:["speed",1],Uk:["time",0]}}),U=r({id:"vignette",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform float Uh;uniform float Ue;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,Ue);float G=mix(max(C,1.),length(vec2(C,1.)),Ue);F/=G;float H=1.-U0;float I=H+Uh*0.5+0.01;float J=1.-smoothstep(H,I,F);vec3 K=A.rgb*J;fragColor=vec4(K,A.a);}",primary:"amount",uniforms:{U0:["amount",.5],Uh:["softness",.5],Ue:["roundness",.5]}}),C=Object.freeze({invert:n,grayscale:a,sepia:v,threshold:l,brightness:o,contrast:i,saturation:f,hueRotate:s,posterize:u,chromaticAberration:c,pixelate:d,gridDistortion:m,glitch:g,crtMattias:x,scanlines:y,vignette:U,bloom:p,filmGrain:_}),F=class{t;o;i=new Map;u=!1;constructor(e,t,r){this.t=e,this.o=t;for(const o of r)this.i.set(o.id,{id:o.id,source:o.source,uniforms:o.uniforms,...o.primary?{primary:o.primary}:{}})}has(e){return this.i.has(e)}get(e){return this.i.get(e)}async register(e,t,r){const o="string"==typeof t?await this.t.createShader(this.o,t):t;this.u&&("string"==typeof t&&o.dispose(),this.v());const i=(a=r,Object.entries(a).map(([e,[t,r]])=>[e,t,r]));var a;this.l(e,{id:e,shader:o,uniforms:i,...i[0]?{primary:i[0][1]}:{}})}unregister(e){const t=this.i.get(e);return!!t&&(t.shader?.dispose(),this.i.delete(e),!0)}async initializeBuiltins(){const e=[];try{for(const[t,r]of this.i){if(!r.source||r.shader)continue;const o=await this.t.createShader(this.o,r.source);this.u&&(o.dispose(),this.v()),this.i.get(t)===r?(r.shader=o,e.push({descriptor:r,shader:o})):o.dispose()}}catch(t){for(const r of e.reverse())r.descriptor.shader===r.shader&&(r.descriptor.shader=void 0,this.u||r.shader.dispose());throw t}}dispose(){for(const e of this.i.values())e.shader?.dispose();this.i.clear(),this.u=!0}l(e,t){this.i.get(e)?.shader?.dispose(),this.i.set(e,t)}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},A=class{t;o;h=new WeakMap;m=new Set;p;constructor(e){this.t=e,this.o="#version 300 es\nlayout(location=0)in vec2 a_position;layout(location=1)in vec2 a_texCoord;out vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position*2.,0.,1.);}"}get vertexSource(){return this.o}applyLayer(e,t,r){let o=this.h.get(e);return o||(o=this._(t.width,t.height),this.h.set(e,o)),this.U(t,r,o)}applyComposite(e,t){return this.p??=this._(e.width,e.height),this.U(e,t,this.p)}disposeLayer(e){const t=this.h.get(e);t&&this.C(t),this.h.delete(e)}dispose(){for(const e of[...this.m])this.C(e);this.h=new WeakMap,this.p=void 0}U(e,t,r){if(0===t.length)return e;this.F(r,e.width,e.height);let o=e;for(const i of t){const e=r[0]===o?r[1]:(r[1],r[0]);this.A(o,e,i.shader,this.B(i)),o=e}return o}A(e,t,r,o){this.t.push();let i=!1;try{t.begin(),i=!0,this.t.shader(r),this.t.setUniforms({u_texture:e.textures[0],u_resolution:[t.width,t.height],...o}),this.t.rect(t.width,t.height)}finally{try{i&&t.end()}finally{this.t.pop()}}}B(e){const t={};for(const[r,o,i]of e.uniforms){let a=i;if("number"==typeof e.params&&o===e.primary)a=e.params;else if(e.params&&"object"==typeof e.params&&o in e.params){const t=e.params[o];B(t)&&(a=t)}t[r]=a}return t}_(e,t){const r=[this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1}),this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1})];return this.m.add(r),r}F(e,t,r){e[0].width===t&&e[0].height===r||(e[0].resize(t,r),e[1].resize(t,r))}C(e){e[0].dispose(),e[1].dispose(),this.m.delete(e),this.p===e&&(this.p=void 0)}};function B(e){return"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||e instanceof Float32Array||e instanceof Int32Array||"object"==typeof e&&null!==e}var D=class{D=0;H=!1;G=!1;J=[];T=[];L=new WeakMap;I=new Set;beginFrame(){this.D+=1;for(const e of this.I){const t=this.L.get(e);t&&(t.phase="draw")}this.H=!0}endFrame(){this.H=!1}queueLayer(e,t,r){const o=this.M(e);("postDraw"===o.phase?o.postQueue:o.drawQueue).push({name:t,params:r,frameToken:this.K()})}queueComposite(e,t){(this.G?this.T:this.J).push({name:e,params:t,frameToken:this.K()})}drainLayerDraw(e){return this.k(this.M(e).drawQueue)}drainLayerPostDraw(e){return this.k(this.M(e).postQueue)}setLayerPhase(e,t){this.M(e).phase=t}drainGlobal(){return this.k(this.J)}beginFinalDraw(){this.G=!0}endFinalDraw(){this.G=!1}drainFinal(){return this.k(this.T)}resetComposite(){this.J=[],this.T=[],this.G=!1}disposeLayer(e){this.L.delete(e),this.I.delete(e)}dispose(){this.J=[],this.T=[],this.L=new WeakMap,this.I.clear(),this.H=!1,this.G=!1}k(e){const t=this.D,r=[],o=[];for(const i of e)i.frameToken===t?r.push(i):i.frameToken>t&&o.push(i);return e.length=0,e.push(...o),r}M(e){let t=this.L.get(e);return t||(t={phase:"draw",drawQueue:[],postQueue:[]},this.L.set(e,t),this.I.add(e)),t}K(){return this.H?this.D:this.D+1}},b=class{t;O;P;S;N=()=>{};u=!1;constructor(e){this.t=e,this.S=new A(e),this.O=new F(e,this.S.vertexSource,Object.values(C)),this.P=new D}async register(e,t,r={}){if(this.v(),!e.trim())throw new TypeError("Filter id cannot be empty.");await this.O.register(e,t,r)}unregister(e){return this.O.unregister(e)}has(e){return this.O.has(e)}initializeBuiltins(){return this.v(),this.O.initializeBuiltins()}queueLayer(e,t,r){this.v(),this.P.queueLayer(e,t,r)}queueComposite(e,t){this.v(),this.P.queueComposite(e,t)}beginFrame(){this.P.beginFrame()}endFrame(){this.P.endFrame()}setFinalDrawCallback(e){this.N=e}transformLayer(e,t,r){if("resolved"===t){const t=this.j(r,this.P.drainLayerDraw(e),e,!1);return this.P.setLayerPhase(e,"postDraw"),t}try{return this.j(r,this.P.drainLayerPostDraw(e),e,!1)}finally{this.P.setLayerPhase(e,"draw")}}transformComposite(e){let t=e;try{t=this.j(t,this.P.drainGlobal(),void 0,!0),this.P.beginFinalDraw();try{this.N.call(this.t)}finally{this.P.endFinalDraw()}return this.j(t,this.P.drainFinal(),void 0,!0)}finally{this.P.resetComposite()}}disposeLayer(e){this.S.disposeLayer(e),this.P.disposeLayer(e)}dispose(){this.u||(this.O.dispose(),this.S.dispose(),this.P.dispose(),this.u=!0)}j(e,t,r,o){if(0===t.length)return e;const i=[];for(const a of t){const e=this.O.get(a.name);e?i.push(this.R(a.name,e,a.params)):console.warn(`[textmode.filters.js] Unknown filter: "${a.name}". Skipping.`)}return 0===i.length?e:o?this.S.applyComposite(e,i):this.S.applyLayer(r,e,i)}R(e,t,r){return{name:e,shader:this.W(t),uniforms:t.uniforms,params:r,...t.primary?{primary:t.primary}:{}}}W(e){if(e.shader)return e.shader;throw new Error("Filter shaders are not initialized. Wait for textmode setup to finish before drawing.")}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},w=new WeakMap,Q={name:"textmode.filters",version:"1.2.4-beta.1",install(e,t){const r=w.get(e);r&&r.dispose();const o=new b(e);w.set(e,o),function(e,t){e.on("preSetup",()=>t.initializeBuiltins()),e.defineExtension("textmodifier","filter",{value:(e,r)=>t.queueComposite(e,r)}),e.defineExtension("textmodifier","filters",{get:()=>t}),e.defineExtension("textmodifier","finalDraw",{value:e=>{t.setFinalDrawCallback(e)}}),e.defineExtension("layerManager","filters",{get:()=>t});const r=t.queueLayer.bind(t);e.defineExtension("layer","filter",{value(e,t){r(this,e,t)}}),e.on("layerDisposed",e=>t.disposeLayer(e)),e.on("layerOutput",({layer:e,phase:r,output:o})=>t.transformLayer(e,r,o)),e.on("compositeOutput",e=>t.transformComposite(e)),e.on("preDraw",()=>t.beginFrame()),e.on("postDraw",()=>t.endFrame())}(t,o)},uninstall(e){w.get(e)?.dispose(),w.delete(e)}};"undefined"!=typeof window&&(window.FiltersPlugin=Q),e.FiltersPlugin=Q,e.TextmodeFilterManager=b});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).textmodeFilters={},e.textmode)}(this,function(e,t){function r(e){const t=Object.entries(e.uniforms).map(([e,[t,r]])=>[e,t,r]),r=e.primary??t[0]?.[1];if(t.length>0&&void 0===r)throw new TypeError(`Builtin filter "${e.id}" requires an explicit primary parameter.`);const o={id:e.id,source:e.shader,uniforms:t,...void 0!==r?{primary:r}:{}};return Object.freeze(o)}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var o=r({id:"brightness",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=A.rgb*U0;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),i=r({id:"contrast",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=(A.rgb-0.5)*U0+0.5;fragColor=vec4(B,A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),a=r({id:"grayscale",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));fragColor=vec4(mix(A.rgb,vec3(B),U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),s=r({id:"hueRotate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U1;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+U1/360.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"angle",uniforms:{U1:["angle",0]}}),n=r({id:"invert",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}",uniforms:{}}),u=r({id:"posterize",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ub;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=floor(A.rgb*Ub)/Ub;fragColor=vec4(B,A.a);}",primary:"levels",uniforms:{Ub:["levels",4]}}),f=r({id:"saturation",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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*U0,0.,1.);vec3 R=K(J);fragColor=vec4(R,F.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),v=r({id:"sepia",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float U0;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B=vec3(dot(A.rgb,vec3(0.393,0.769,0.189)),dot(A.rgb,vec3(0.349,0.686,0.168)),dot(A.rgb,vec3(0.272,0.534,0.131)));fragColor=vec4(mix(A.rgb,B,U0),A.a);}",primary:"amount",uniforms:{U0:["amount",1]}}),l=r({id:"threshold",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uj;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=step(Uj,dot(A.rgb,vec3(0.299,0.587,0.114)));fragColor=vec4(vec3(B),A.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5]}}),c=r({id:"chromaticAberration",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform vec2 U4;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=U4*U0*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);}",primary:"amount",uniforms:{U0:["amount",5],U4:["direction",[1,0]]}});function h(){return new Array(128).fill(.5)}var m=r({id:"gridDistortion",shader:"#version 300 es\nprecision mediump float;in vec2 v_uv;out vec4 fragColor;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform vec2 U5;uniform vec2 U7;uniform vec2 U6;uniform float Ul[128];uniform float U8[128];uniform float Um;uniform float U9;const int A=128;const int B=128;void main(){vec2 C=v_uv*u_resolution;vec2 D=(C-U6)/U7;if(D.x<0.||D.x>1.||D.y<0.||D.y>1.){fragColor=vec4(0.);return;}int E=int(U5.x);int F=int(U5.y);float G=0.;for(int H=0;H<A;H++){if(H<E){float I=Ul[H];G+=0.1+I*Um;}}float J=0.;for(int K=0;K<B;K++){if(K<F){float L=U8[K];J+=0.1+L*U9;}}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=Ul[H];float R=0.1+I*Um;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=U8[K];float W=0.1+L*U9;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);}",primary:"gridCellDimensions",uniforms:{U5:["gridCellDimensions",[80,40]],U7:["gridPixelDimensions",[640,320]],U6:["gridOffsetDimensions",[0,0]],Ul:["widthFactors",h()],U8:["heightFactors",h()],Um:["widthVariationScale",.5],U9:["heightVariationScale",.5]}}),d=r({id:"pixelate",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uc;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(Uc)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}",primary:"pixelSize",uniforms:{Uc:["pixelSize",4]}}),x=r({id:"bloom",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uj;uniform float Ua;uniform float Ud;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)*Ud*H.x,0.);vec2 O=vec2(0.,float(L)*Ud*H.y);vec3 P=texture(u_texture,v_uv+N).rgb;I+=C(P,Uj)*M;if(L!=0){vec3 Q=texture(u_texture,v_uv+O).rgb;I+=C(Q,Uj)*M;J+=M;}J+=M;}float R=0.1;for(int L=1;L<=4;L++){float S=float(L)*Ud;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,Uj)*Z;I+=C(W,Uj)*Z;I+=C(X,Uj)*Z;I+=C(Y,Uj)*Z;J+=Z*4.;}I/=J;vec3 a=G.rgb+I*Ua;fragColor=vec4(a,G.a);}",primary:"threshold",uniforms:{Uj:["threshold",.5],Ua:["intensity",1],Ud:["radius",4]}}),p=r({id:"crtMattias",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Uk;uniform float U3;uniform float Uf;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),U3);vec3 T;float U=sin(0.1*Uk+Q.y*21.)*sin(0.23*Uk+Q.y*29.)*sin(0.3+0.11*Uk+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*(Uk*Uf)+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.*Uk);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*Uk),I(Q+0.0001*Uk+0.3),I(Q+0.0001*Uk+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.);}",primary:"curvature",uniforms:{U3:["curvature",.5],Uf:["scanSpeed",1],Uk:["time",0]}}),_=r({id:"filmGrain",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ua;uniform float Ug;uniform float Ui;uniform float Uk;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/Ug;M+=vec2(Uk*Ui*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)*Ua;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);}",primary:"intensity",uniforms:{Ua:["intensity",.2],Ug:["size",2],Ui:["speed",1],Uk:["time",0]}}),y=r({id:"glitch",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;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=U0*0.1;float E=floor(C.y*20.);float F=A(vec2(E,floor(U0*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*U0;O-=P;float Q=A(C+fract(U0))*0.1*U0;O+=Q;fragColor=vec4(O,N);}",primary:"amount",uniforms:{U0:["amount",0]}}),g=r({id:"scanlines",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform float Uk;uniform float U2;uniform float Ua;uniform float Ui;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=sin((v_uv.y*U2-Uk*Ui)*3.141592*2.);B=B*0.5+0.5;float C=1.-(Ua*(1.-B));fragColor=vec4(A.rgb*C,A.a);}",primary:"count",uniforms:{U2:["count",300],Ua:["intensity",.75],Ui:["speed",1],Uk:["time",0]}}),U=r({id:"vignette",shader:"#version 300 es\nprecision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float U0;uniform float Uh;uniform float Ue;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,Ue);float G=mix(max(C,1.),length(vec2(C,1.)),Ue);F/=G;float H=1.-U0;float I=H+Uh*0.5+0.01;float J=1.-smoothstep(H,I,F);vec3 K=A.rgb*J;fragColor=vec4(K,A.a);}",primary:"amount",uniforms:{U0:["amount",.5],Uh:["softness",.5],Ue:["roundness",.5]}}),C=Object.freeze({invert:n,grayscale:a,sepia:v,threshold:l,brightness:o,contrast:i,saturation:f,hueRotate:s,posterize:u,chromaticAberration:c,pixelate:d,gridDistortion:m,glitch:y,crtMattias:p,scanlines:g,vignette:U,bloom:x,filmGrain:_}),F=class{t;o;i=new Map;u=!1;constructor(e,t,r){this.t=e,this.o=t;for(const o of r)this.i.set(o.id,{id:o.id,source:o.source,uniforms:o.uniforms,...o.primary?{primary:o.primary}:{}})}has(e){return this.i.has(e)}get(e){return this.i.get(e)}async register(e,t,r){const o="string"==typeof t?await this.t.createShader(this.o,t):t;this.u&&("string"==typeof t&&o.dispose(),this.v());const i=(a=r,Object.entries(a).map(([e,[t,r]])=>[e,t,r]));var a;this.l(e,{id:e,shader:o,uniforms:i,...i[0]?{primary:i[0][1]}:{}})}unregister(e){const t=this.i.get(e);return!!t&&(t.shader?.dispose(),this.i.delete(e),!0)}async initializeBuiltins(){const e=[];try{for(const[t,r]of this.i){if(!r.source||r.shader)continue;const o=await this.t.createShader(this.o,r.source);this.u&&(o.dispose(),this.v()),this.i.get(t)===r?(r.shader=o,e.push({descriptor:r,shader:o})):o.dispose()}}catch(t){for(const r of e.reverse())r.descriptor.shader===r.shader&&(r.descriptor.shader=void 0,this.u||r.shader.dispose());throw t}}dispose(){for(const e of this.i.values())e.shader?.dispose();this.i.clear(),this.u=!0}l(e,t){this.i.get(e)?.shader?.dispose(),this.i.set(e,t)}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},A=class{t;o;h=new WeakMap;m=new Set;p;constructor(e){this.t=e,this.o="#version 300 es\nlayout(location=0)in vec2 a_position;layout(location=1)in vec2 a_texCoord;out vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position*2.,0.,1.);}"}get vertexSource(){return this.o}applyLayer(e,t,r){let o=this.h.get(e);return o||(o=this._(t.width,t.height),this.h.set(e,o)),this.U(t,r,o)}applyComposite(e,t){return this.p??=this._(e.width,e.height),this.U(e,t,this.p)}disposeLayer(e){const t=this.h.get(e);t&&this.C(t),this.h.delete(e)}dispose(){for(const e of[...this.m])this.C(e);this.h=new WeakMap,this.p=void 0}U(e,t,r){if(0===t.length)return e;this.F(r,e.width,e.height);let o=e;for(const i of t){const e=r[0]===o?r[1]:(r[1],r[0]);this.A(o,e,i.shader,this.B(i)),o=e}return o}A(e,t,r,o){this.t.push();let i=!1;try{t.begin(),i=!0,this.t.shader(r),this.t.setUniforms({u_texture:e.textures[0],u_resolution:[t.width,t.height],...o}),this.t.rect(t.width,t.height)}finally{try{i&&t.end()}finally{this.t.pop()}}}B(e){const t={};for(const[r,o,i]of e.uniforms){let a=i;if("number"==typeof e.params&&o===e.primary)a=e.params;else if(e.params&&"object"==typeof e.params&&o in e.params){const t=e.params[o];B(t)&&(a=t)}t[r]=a}return t}_(e,t){const r=[this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1}),this.t.createFramebuffer({width:e,height:t,attachments:1,depth:!1})];return this.m.add(r),r}F(e,t,r){e[0].width===t&&e[0].height===r||(e[0].resize(t,r),e[1].resize(t,r))}C(e){e[0].dispose(),e[1].dispose(),this.m.delete(e),this.p===e&&(this.p=void 0)}};function B(e){return"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||e instanceof Float32Array||e instanceof Int32Array||"object"==typeof e&&null!==e}var D=class{D=0;H=!1;G=!1;J=[];T=[];L=new WeakMap;I=new Set;beginFrame(){this.D+=1;for(const e of this.I){const t=this.L.get(e);t&&(t.phase="draw")}this.H=!0}endFrame(){this.H=!1}queueLayer(e,t,r){const o=this.M(e);("postDraw"===o.phase?o.postQueue:o.drawQueue).push({name:t,params:r,frameToken:this.K()})}queueComposite(e,t){(this.G?this.T:this.J).push({name:e,params:t,frameToken:this.K()})}drainLayerDraw(e){return this.k(this.M(e).drawQueue)}drainLayerPostDraw(e){return this.k(this.M(e).postQueue)}setLayerPhase(e,t){this.M(e).phase=t}drainGlobal(){return this.k(this.J)}beginFinalDraw(){this.G=!0}endFinalDraw(){this.G=!1}drainFinal(){return this.k(this.T)}resetComposite(){this.J=[],this.T=[],this.G=!1}disposeLayer(e){this.L.delete(e),this.I.delete(e)}dispose(){this.J=[],this.T=[],this.L=new WeakMap,this.I.clear(),this.H=!1,this.G=!1}k(e){const t=this.D,r=[],o=[];for(const i of e)i.frameToken===t?r.push(i):i.frameToken>t&&o.push(i);return e.length=0,e.push(...o),r}M(e){let t=this.L.get(e);return t||(t={phase:"draw",drawQueue:[],postQueue:[]},this.L.set(e,t),this.I.add(e)),t}K(){return this.H?this.D:this.D+1}},b=class{t;O;P;S;j=()=>{};u=!1;constructor(e){this.t=e,this.S=new A(e),this.O=new F(e,this.S.vertexSource,Object.values(C)),this.P=new D}async register(e,t,r={}){if(this.v(),!e.trim())throw new TypeError("Filter id cannot be empty.");await this.O.register(e,t,r)}unregister(e){return this.O.unregister(e)}has(e){return this.O.has(e)}initializeBuiltins(){return this.v(),this.O.initializeBuiltins()}queueLayer(e,t,r){this.v(),this.P.queueLayer(e,t,r)}queueComposite(e,t){this.v(),this.P.queueComposite(e,t)}beginFrame(){this.P.beginFrame()}endFrame(){this.P.endFrame()}setFinalDrawCallback(e){this.j=e}transformLayer(e,t,r){if("resolved"===t){const t=this.N(r,this.P.drainLayerDraw(e),e,!1);return this.P.setLayerPhase(e,"postDraw"),t}try{return this.N(r,this.P.drainLayerPostDraw(e),e,!1)}finally{this.P.setLayerPhase(e,"draw")}}transformComposite(e){let t=e;try{t=this.N(t,this.P.drainGlobal(),void 0,!0),this.P.beginFinalDraw();try{this.j.call(this.t)}finally{this.P.endFinalDraw()}return this.N(t,this.P.drainFinal(),void 0,!0)}finally{this.P.resetComposite()}}disposeLayer(e){this.S.disposeLayer(e),this.P.disposeLayer(e)}dispose(){this.u||(this.O.dispose(),this.S.dispose(),this.P.dispose(),this.u=!0)}N(e,t,r,o){if(0===t.length)return e;const i=[];for(const a of t){const e=this.O.get(a.name);e?i.push(this.R(a.name,e,a.params)):console.warn(`[textmode.filters.js] Unknown filter: "${a.name}". Skipping.`)}return 0===i.length?e:o?this.S.applyComposite(e,i):this.S.applyLayer(r,e,i)}R(e,t,r){return{name:e,shader:this.W(t),uniforms:t.uniforms,params:r,...t.primary?{primary:t.primary}:{}}}W(e){if(e.shader)return e.shader;throw new Error("Filter shaders are not initialized. Wait for textmode setup to finish before drawing.")}v(){if(this.u)throw new Error("TextmodeFilterManager has been disposed.")}},w={name:"textmode.filters.js",install(e,t){const r=new b(e);try{!function(e,t){e.on("preSetup",()=>t.initializeBuiltins()),e.defineExtension("textmodifier","filter",{value:(e,r)=>t.queueComposite(e,r)}),e.defineExtension("textmodifier","filters",{get:()=>t}),e.defineExtension("textmodifier","finalDraw",{value:e=>{t.setFinalDrawCallback(e)}});const r=t.queueLayer.bind(t);e.defineExtension("layer","filter",{value(e,t){r(this,e,t)}}),e.on("layerDisposed",e=>t.disposeLayer(e)),e.on("layerOutput",({layer:e,phase:r,output:o})=>t.transformLayer(e,r,o)),e.on("compositeOutput",e=>t.transformComposite(e)),e.on("preDraw",()=>t.beginFrame()),e.on("postDraw",()=>t.endFrame())}(t,r)}catch(o){throw r.dispose(),o}return()=>r.dispose()}};"undefined"!=typeof window&&(window.FiltersPlugin=w),e.FiltersPlugin=w,e.TextmodeFilterManager=b});
|
|
@@ -19,6 +19,8 @@ import { type VignetteOptions } from './stylization/vignette';
|
|
|
19
19
|
/**
|
|
20
20
|
* Parameter types for every built-in filter.
|
|
21
21
|
*
|
|
22
|
+
* @category Built-in filters
|
|
23
|
+
*
|
|
22
24
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/interfaces/BuiltInFilterParameterMap | BuiltInFilterParameterMap API reference}
|
|
23
25
|
*/
|
|
24
26
|
export interface BuiltInFilterParameterMap {
|
|
@@ -134,6 +136,8 @@ export interface BuiltInFilterParameterMap {
|
|
|
134
136
|
/**
|
|
135
137
|
* Names installed synchronously by {@link FiltersPlugin}.
|
|
136
138
|
*
|
|
139
|
+
* @category Built-in filters
|
|
140
|
+
*
|
|
137
141
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/type-aliases/BuiltInFilterName | BuiltInFilterName API reference}
|
|
138
142
|
*/
|
|
139
143
|
export type BuiltInFilterName = keyof BuiltInFilterParameterMap;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options for the built-in grayscale effect.
|
|
3
3
|
*
|
|
4
|
+
* @category Color adjustment filters
|
|
5
|
+
*
|
|
4
6
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/interfaces/GrayscaleOptions | GrayscaleOptions API reference}
|
|
5
7
|
*/
|
|
6
8
|
export interface GrayscaleOptions {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options for the built-in threshold effect.
|
|
3
3
|
*
|
|
4
|
+
* @category Color adjustment filters
|
|
5
|
+
*
|
|
4
6
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/interfaces/ThresholdOptions | ThresholdOptions API reference}
|
|
5
7
|
*/
|
|
6
8
|
export interface ThresholdOptions {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,9 +2,31 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Complete optional filter system for textmode.js, including 18 setup-compiled GPU effects,
|
|
4
4
|
* custom registration, layer/global/final queues, and automatic resource cleanup.
|
|
5
|
+
*
|
|
6
|
+
* @categoryDescription Workflow
|
|
7
|
+
* The plugin that installs the filter system on a textmode.js sketch.
|
|
8
|
+
*
|
|
9
|
+
* @categoryDescription Filter management
|
|
10
|
+
* The runtime that owns filter registration, queues, GPU resources, and cleanup.
|
|
11
|
+
*
|
|
12
|
+
* @categoryDescription Built-in filters
|
|
13
|
+
* The shipped filter names and their parameter types.
|
|
14
|
+
*
|
|
15
|
+
* @categoryDescription Custom filters
|
|
16
|
+
* Types used when registering bespoke GPU filters on the manager.
|
|
17
|
+
*
|
|
18
|
+
* @categoryDescription Color adjustment filters
|
|
19
|
+
* Configuration options for the bundled color-adjustment effects.
|
|
20
|
+
*
|
|
21
|
+
* @categoryDescription Distortion filters
|
|
22
|
+
* Configuration options for the bundled distortion effects.
|
|
23
|
+
*
|
|
24
|
+
* @categoryDescription Stylization filters
|
|
25
|
+
* Configuration options for the bundled stylization effects.
|
|
26
|
+
*
|
|
27
|
+
* @showCategories
|
|
5
28
|
*/
|
|
6
29
|
import './public/augmentations';
|
|
7
|
-
import './global';
|
|
8
30
|
export { FiltersPlugin } from './plugin/FiltersPlugin';
|
|
9
31
|
export { TextmodeFilterManager } from './runtime/TextmodeFilterManager';
|
|
10
32
|
export type { TextmodeFilterShader, TextmodeFilterUniformDefinitions } from './public/filter-types';
|
|
@@ -27,3 +49,9 @@ export type { ScanlinesOptions } from './builtins/stylization/scanlines';
|
|
|
27
49
|
export type { SepiaOptions } from './builtins/color-adjustment/sepia';
|
|
28
50
|
export type { ThresholdOptions } from './builtins/color-adjustment/threshold';
|
|
29
51
|
export type { VignetteOptions } from './builtins/stylization/vignette';
|
|
52
|
+
import type { TextmodePlugin } from 'textmode.js';
|
|
53
|
+
declare global {
|
|
54
|
+
interface Window {
|
|
55
|
+
FiltersPlugin?: TextmodePlugin;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { TextmodePlugin } from 'textmode.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* GPU-accelerated filters plugin. Installing it adds the complete 18-filter workflow to one Textmodifier.
|
|
4
4
|
*
|
|
5
|
+
* @category Workflow
|
|
6
|
+
*
|
|
5
7
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/variables/FiltersPlugin | FiltersPlugin API reference}
|
|
6
8
|
*/
|
|
7
9
|
export declare const FiltersPlugin: TextmodePlugin;
|
|
@@ -2,17 +2,16 @@ import 'textmode.js';
|
|
|
2
2
|
import type { BuiltInFilterName, BuiltInFilterParameterMap } from '../builtins/catalog';
|
|
3
3
|
import type { TextmodeFilterManager } from '../runtime/TextmodeFilterManager';
|
|
4
4
|
type FilterArguments<TName extends string> = TName extends BuiltInFilterName ? [params?: BuiltInFilterParameterMap[TName]] : [params?: unknown];
|
|
5
|
-
declare module 'textmode.js' {
|
|
6
|
-
interface
|
|
5
|
+
declare module 'textmode.js/addon' {
|
|
6
|
+
interface TextmodifierExtensions {
|
|
7
7
|
filter<TName extends string>(name: TName, ...args: FilterArguments<TName>): void;
|
|
8
8
|
readonly filters: TextmodeFilterManager;
|
|
9
9
|
finalDraw(callback: () => void): void;
|
|
10
10
|
}
|
|
11
|
+
}
|
|
12
|
+
declare module 'textmode.js' {
|
|
11
13
|
interface TextmodeLayer {
|
|
12
14
|
filter<TName extends string>(name: TName, ...args: FilterArguments<TName>): void;
|
|
13
15
|
}
|
|
14
|
-
interface TextmodeLayerManager {
|
|
15
|
-
readonly filters: TextmodeFilterManager;
|
|
16
|
-
}
|
|
17
16
|
}
|
|
18
17
|
export {};
|
|
@@ -3,18 +3,24 @@ import type { BuiltInFilterName } from '../builtins/catalog';
|
|
|
3
3
|
/**
|
|
4
4
|
* Uniform declarations for a custom filter, mapping GLSL names to public parameter names and defaults.
|
|
5
5
|
*
|
|
6
|
+
* @category Custom filters
|
|
7
|
+
*
|
|
6
8
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/type-aliases/TextmodeFilterUniformDefinitions | TextmodeFilterUniformDefinitions API reference}
|
|
7
9
|
*/
|
|
8
10
|
export type TextmodeFilterUniformDefinitions = Record<string, readonly [paramName: string, defaultValue: TextmodeUniformValue]>;
|
|
9
11
|
/**
|
|
10
12
|
* A precompiled textmode shader, inline fragment source, or shader URL accepted by custom registration.
|
|
11
13
|
*
|
|
14
|
+
* @category Custom filters
|
|
15
|
+
*
|
|
12
16
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/type-aliases/TextmodeFilterShader | TextmodeFilterShader API reference}
|
|
13
17
|
*/
|
|
14
18
|
export type TextmodeFilterShader = TextmodeShader | string;
|
|
15
19
|
/**
|
|
16
20
|
* Built-in names retain completion while arbitrary custom names remain valid.
|
|
17
21
|
*
|
|
22
|
+
* @category Custom filters
|
|
23
|
+
*
|
|
18
24
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/type-aliases/FilterName | FilterName API reference}
|
|
19
25
|
*/
|
|
20
26
|
export type FilterName = BuiltInFilterName | (string & {});
|
|
@@ -2,6 +2,8 @@ import type { FilterName, TextmodeFilterShader, TextmodeFilterUniformDefinitions
|
|
|
2
2
|
/**
|
|
3
3
|
* Owns filter registration, queues, GPU resources, pass execution, and cleanup.
|
|
4
4
|
*
|
|
5
|
+
* @category Filter management
|
|
6
|
+
*
|
|
5
7
|
* @see {@link https://code.textmode.art/api/textmode.filters.js/classes/TextmodeFilterManager | TextmodeFilterManager API reference}
|
|
6
8
|
*/
|
|
7
9
|
export declare class TextmodeFilterManager {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.filters.js",
|
|
3
|
-
"version": "1.2.4-beta.
|
|
3
|
+
"version": "1.2.4-beta.2",
|
|
4
4
|
"description": "Image filters plugin for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"devEngines": {
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
+
"prebuild": "npm run clean",
|
|
36
|
+
"clean": "rm -rf dist",
|
|
35
37
|
"dev": "textmode-build dev --port 5179 --host",
|
|
36
38
|
"build:bundle": "textmode-build build",
|
|
37
39
|
"build:types": "textmode-types build",
|
|
@@ -57,16 +59,16 @@
|
|
|
57
59
|
"test:watch": "textmode-build test:watch"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
|
-
"textmode.js": "
|
|
62
|
+
"textmode.js": "^0.18.0-beta.2"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
65
|
"@textmode/build": "^0.1.0",
|
|
64
66
|
"@textmode/docs": "^0.3.0",
|
|
65
67
|
"@textmode/lint": "^0.1.0",
|
|
66
68
|
"@textmode/release": "^0.2.0",
|
|
67
|
-
"@textmode/tsconfig": "^0.2.
|
|
69
|
+
"@textmode/tsconfig": "^0.2.1",
|
|
68
70
|
"@types/node": "^24.0.0",
|
|
69
|
-
"textmode.js": "^0.
|
|
71
|
+
"textmode.js": "^0.18.0-beta.2",
|
|
70
72
|
"typescript": "^6.0.3",
|
|
71
73
|
"vitest": "^4.1.10"
|
|
72
74
|
},
|