bluedither 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4867 @@
1
+ var j=Object.defineProperty;var q=(e,o,t)=>o in e?j(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var a=(e,o,t)=>q(e,typeof o!="symbol"?o+"":o,t);var Z=`#version 300 es
2
+ precision mediump float;
3
+
4
+ layout(location = 0) in vec4 a_position;
5
+
6
+ uniform vec2 u_resolution;
7
+ uniform float u_pixelRatio;
8
+ uniform float u_imageAspectRatio;
9
+ uniform float u_originX;
10
+ uniform float u_originY;
11
+ uniform float u_worldWidth;
12
+ uniform float u_worldHeight;
13
+ uniform float u_fit;
14
+ uniform float u_scale;
15
+ uniform float u_rotation;
16
+ uniform float u_offsetX;
17
+ uniform float u_offsetY;
18
+
19
+ out vec2 v_objectUV;
20
+ out vec2 v_objectBoxSize;
21
+ out vec2 v_responsiveUV;
22
+ out vec2 v_responsiveBoxGivenSize;
23
+ out vec2 v_patternUV;
24
+ out vec2 v_patternBoxSize;
25
+ out vec2 v_imageUV;
26
+
27
+ vec3 getBoxSize(float boxRatio, vec2 givenBoxSize) {
28
+ vec2 box = vec2(0.);
29
+ // fit = none
30
+ box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y);
31
+ float noFitBoxWidth = box.x;
32
+ if (u_fit == 1.) { // fit = contain
33
+ box.x = boxRatio * min(u_resolution.x / boxRatio, u_resolution.y);
34
+ } else if (u_fit == 2.) { // fit = cover
35
+ box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y);
36
+ }
37
+ box.y = box.x / boxRatio;
38
+ return vec3(box, noFitBoxWidth);
39
+ }
40
+
41
+ void main() {
42
+ gl_Position = a_position;
43
+
44
+ vec2 uv = gl_Position.xy * .5;
45
+ vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
46
+ vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
47
+ givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
48
+ float r = u_rotation * 3.14159265358979323846 / 180.;
49
+ mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
50
+ vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
51
+
52
+
53
+ // ===================================================
54
+
55
+ float fixedRatio = 1.;
56
+ vec2 fixedRatioBoxGivenSize = vec2(
57
+ (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
58
+ (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
59
+ );
60
+
61
+ v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize).xy;
62
+ vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;
63
+
64
+ v_objectUV = uv;
65
+ v_objectUV *= objectWorldScale;
66
+ v_objectUV += boxOrigin * (objectWorldScale - 1.);
67
+ v_objectUV += graphicOffset;
68
+ v_objectUV /= u_scale;
69
+ v_objectUV = graphicRotation * v_objectUV;
70
+
71
+ // ===================================================
72
+
73
+ v_responsiveBoxGivenSize = vec2(
74
+ (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
75
+ (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
76
+ );
77
+ float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
78
+ vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy;
79
+ vec2 responsiveBoxScale = u_resolution.xy / responsiveBoxSize;
80
+
81
+ #ifdef ADD_HELPERS
82
+ v_responsiveHelperBox = uv;
83
+ v_responsiveHelperBox *= responsiveBoxScale;
84
+ v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.);
85
+ #endif
86
+
87
+ v_responsiveUV = uv;
88
+ v_responsiveUV *= responsiveBoxScale;
89
+ v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.);
90
+ v_responsiveUV += graphicOffset;
91
+ v_responsiveUV /= u_scale;
92
+ v_responsiveUV.x *= responsiveRatio;
93
+ v_responsiveUV = graphicRotation * v_responsiveUV;
94
+ v_responsiveUV.x /= responsiveRatio;
95
+
96
+ // ===================================================
97
+
98
+ float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
99
+ vec2 patternBoxGivenSize = vec2(
100
+ (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
101
+ (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
102
+ );
103
+ patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;
104
+
105
+ vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize);
106
+ v_patternBoxSize = boxSizeData.xy;
107
+ float patternBoxNoFitBoxWidth = boxSizeData.z;
108
+ vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;
109
+
110
+ v_patternUV = uv;
111
+ v_patternUV += graphicOffset / patternBoxScale;
112
+ v_patternUV += boxOrigin;
113
+ v_patternUV -= boxOrigin / patternBoxScale;
114
+ v_patternUV *= u_resolution.xy;
115
+ v_patternUV /= u_pixelRatio;
116
+ if (u_fit > 0.) {
117
+ v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);
118
+ }
119
+ v_patternUV /= u_scale;
120
+ v_patternUV = graphicRotation * v_patternUV;
121
+ v_patternUV += boxOrigin / patternBoxScale;
122
+ v_patternUV -= boxOrigin;
123
+ // x100 is a default multiplier between vertex and fragmant shaders
124
+ // we use it to avoid UV presision issues
125
+ v_patternUV *= .01;
126
+
127
+ // ===================================================
128
+
129
+ vec2 imageBoxSize;
130
+ if (u_fit == 1.) { // contain
131
+ imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
132
+ } else if (u_fit == 2.) { // cover
133
+ imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
134
+ } else {
135
+ imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);
136
+ }
137
+ imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;
138
+ vec2 imageBoxScale = u_resolution.xy / imageBoxSize;
139
+
140
+ v_imageUV = uv;
141
+ v_imageUV *= imageBoxScale;
142
+ v_imageUV += boxOrigin * (imageBoxScale - 1.);
143
+ v_imageUV += graphicOffset;
144
+ v_imageUV /= u_scale;
145
+ v_imageUV.x *= u_imageAspectRatio;
146
+ v_imageUV = graphicRotation * v_imageUV;
147
+ v_imageUV.x /= u_imageAspectRatio;
148
+
149
+ v_imageUV += .5;
150
+ v_imageUV.y = 1. - v_imageUV.y;
151
+ }`,z=8294400,X=class{constructor(e,o,t,i,n=0,s=0,r=2,l=z,m=[]){a(this,"parentElement");a(this,"canvasElement");a(this,"gl");a(this,"program",null);a(this,"uniformLocations",{});a(this,"fragmentShader");a(this,"rafId",null);a(this,"lastRenderTime",0);a(this,"currentFrame",0);a(this,"speed",0);a(this,"currentSpeed",0);a(this,"providedUniforms");a(this,"mipmaps",[]);a(this,"hasBeenDisposed",!1);a(this,"resolutionChanged",!0);a(this,"textures",new Map);a(this,"minPixelRatio");a(this,"maxPixelCount");a(this,"isSafari",oe());a(this,"uniformCache",{});a(this,"textureUnitMap",new Map);a(this,"initProgram",()=>{let e=$(this.gl,Z,this.fragmentShader);e&&(this.program=e)});a(this,"setupPositionAttribute",()=>{let e=this.gl.getAttribLocation(this.program,"a_position"),o=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,o);let t=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1];this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t),this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(e),this.gl.vertexAttribPointer(e,2,this.gl.FLOAT,!1,0,0)});a(this,"setupUniforms",()=>{let e={u_time:this.gl.getUniformLocation(this.program,"u_time"),u_pixelRatio:this.gl.getUniformLocation(this.program,"u_pixelRatio"),u_resolution:this.gl.getUniformLocation(this.program,"u_resolution")};Object.entries(this.providedUniforms).forEach(([o,t])=>{if(e[o]=this.gl.getUniformLocation(this.program,o),t instanceof HTMLImageElement){let i=`${o}AspectRatio`;e[i]=this.gl.getUniformLocation(this.program,i)}}),this.uniformLocations=e});a(this,"renderScale",1);a(this,"parentWidth",0);a(this,"parentHeight",0);a(this,"parentDevicePixelWidth",0);a(this,"parentDevicePixelHeight",0);a(this,"devicePixelsSupported",!1);a(this,"resizeObserver",null);a(this,"setupResizeObserver",()=>{this.resizeObserver=new ResizeObserver(([e])=>{if(e?.borderBoxSize[0]){let o=e.devicePixelContentBoxSize?.[0];o!==void 0&&(this.devicePixelsSupported=!0,this.parentDevicePixelWidth=o.inlineSize,this.parentDevicePixelHeight=o.blockSize),this.parentWidth=e.borderBoxSize[0].inlineSize,this.parentHeight=e.borderBoxSize[0].blockSize}this.handleResize()}),this.resizeObserver.observe(this.parentElement)});a(this,"handleVisualViewportChange",()=>{this.resizeObserver?.disconnect(),this.setupResizeObserver()});a(this,"handleResize",()=>{let e=0,o=0,t=Math.max(1,window.devicePixelRatio),i=visualViewport?.scale??1;if(this.devicePixelsSupported){let u=Math.max(1,this.minPixelRatio/t);e=this.parentDevicePixelWidth*u*i,o=this.parentDevicePixelHeight*u*i}else{let u=Math.max(t,this.minPixelRatio)*i;if(this.isSafari){let d=te();u*=Math.max(1,d)}e=Math.round(this.parentWidth)*u,o=Math.round(this.parentHeight)*u}let n=Math.sqrt(this.maxPixelCount)/Math.sqrt(e*o),s=Math.min(1,n),r=Math.round(e*s),l=Math.round(o*s),m=r/Math.round(this.parentWidth);(this.canvasElement.width!==r||this.canvasElement.height!==l||this.renderScale!==m)&&(this.renderScale=m,this.canvasElement.width=r,this.canvasElement.height=l,this.resolutionChanged=!0,this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.render(performance.now()))});a(this,"render",e=>{if(this.hasBeenDisposed)return;if(this.program===null){console.warn("Tried to render before program or gl was initialized");return}let o=e-this.lastRenderTime;this.lastRenderTime=e,this.currentSpeed!==0&&(this.currentFrame+=o*this.currentSpeed),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.uniform1f(this.uniformLocations.u_time,this.currentFrame*.001),this.resolutionChanged&&(this.gl.uniform2f(this.uniformLocations.u_resolution,this.gl.canvas.width,this.gl.canvas.height),this.gl.uniform1f(this.uniformLocations.u_pixelRatio,this.renderScale),this.resolutionChanged=!1),this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.currentSpeed!==0?this.requestRender():this.rafId=null});a(this,"requestRender",()=>{this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(this.render)});a(this,"setTextureUniform",(e,o)=>{if(!o.complete||o.naturalWidth===0)throw new Error(`Paper Shaders: image for uniform ${e} must be fully loaded`);let t=this.textures.get(e);t&&this.gl.deleteTexture(t),this.textureUnitMap.has(e)||this.textureUnitMap.set(e,this.textureUnitMap.size);let i=this.textureUnitMap.get(e);this.gl.activeTexture(this.gl.TEXTURE0+i);let n=this.gl.createTexture();this.gl.bindTexture(this.gl.TEXTURE_2D,n),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,o),this.mipmaps.includes(e)&&(this.gl.generateMipmap(this.gl.TEXTURE_2D),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_LINEAR));let s=this.gl.getError();if(s!==this.gl.NO_ERROR||n===null){console.error("Paper Shaders: WebGL error when uploading texture:",s);return}this.textures.set(e,n);let r=this.uniformLocations[e];if(r){this.gl.uniform1i(r,i);let l=`${e}AspectRatio`,m=this.uniformLocations[l];if(m){let u=o.naturalWidth/o.naturalHeight;this.gl.uniform1f(m,u)}}});a(this,"areUniformValuesEqual",(e,o)=>e===o?!0:Array.isArray(e)&&Array.isArray(o)&&e.length===o.length?e.every((t,i)=>this.areUniformValuesEqual(t,o[i])):!1);a(this,"setUniformValues",e=>{this.gl.useProgram(this.program),Object.entries(e).forEach(([o,t])=>{let i=t;if(t instanceof HTMLImageElement&&(i=`${t.src.slice(0,200)}|${t.naturalWidth}x${t.naturalHeight}`),this.areUniformValuesEqual(this.uniformCache[o],i))return;this.uniformCache[o]=i;let n=this.uniformLocations[o];if(!n){console.warn(`Uniform location for ${o} not found`);return}if(t instanceof HTMLImageElement)this.setTextureUniform(o,t);else if(Array.isArray(t)){let s=null,r=null;if(t[0]!==void 0&&Array.isArray(t[0])){let l=t[0].length;if(t.every(m=>m.length===l))s=t.flat(),r=l;else{console.warn(`All child arrays must be the same length for ${o}`);return}}else s=t,r=s.length;switch(r){case 2:this.gl.uniform2fv(n,s);break;case 3:this.gl.uniform3fv(n,s);break;case 4:this.gl.uniform4fv(n,s);break;case 9:this.gl.uniformMatrix3fv(n,!1,s);break;case 16:this.gl.uniformMatrix4fv(n,!1,s);break;default:console.warn(`Unsupported uniform array length: ${r}`)}}else typeof t=="number"?this.gl.uniform1f(n,t):typeof t=="boolean"?this.gl.uniform1i(n,t?1:0):console.warn(`Unsupported uniform type for ${o}: ${typeof t}`)})});a(this,"getCurrentFrame",()=>this.currentFrame);a(this,"setFrame",e=>{this.currentFrame=e,this.lastRenderTime=performance.now(),this.render(performance.now())});a(this,"setSpeed",(e=1)=>{this.speed=e,this.setCurrentSpeed(document.hidden?0:e)});a(this,"setCurrentSpeed",e=>{this.currentSpeed=e,this.rafId===null&&e!==0&&(this.lastRenderTime=performance.now(),this.rafId=requestAnimationFrame(this.render)),this.rafId!==null&&e===0&&(cancelAnimationFrame(this.rafId),this.rafId=null)});a(this,"setMaxPixelCount",(e=z)=>{this.maxPixelCount=e,this.handleResize()});a(this,"setMinPixelRatio",(e=2)=>{this.minPixelRatio=e,this.handleResize()});a(this,"setUniforms",e=>{this.setUniformValues(e),this.providedUniforms={...this.providedUniforms,...e},this.render(performance.now())});a(this,"handleDocumentVisibilityChange",()=>{this.setCurrentSpeed(document.hidden?0:this.speed)});a(this,"dispose",()=>{this.hasBeenDisposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.gl&&this.program&&(this.textures.forEach(e=>{this.gl.deleteTexture(e)}),this.textures.clear(),this.gl.deleteProgram(this.program),this.program=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.getError()),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),visualViewport?.removeEventListener("resize",this.handleVisualViewportChange),document.removeEventListener("visibilitychange",this.handleDocumentVisibilityChange),this.uniformLocations={},this.canvasElement.remove(),delete this.parentElement.paperShaderMount});if(e instanceof HTMLElement)this.parentElement=e;else throw new Error("Paper Shaders: parent element must be an HTMLElement");if(!document.querySelector("style[data-paper-shader]")){let x=document.createElement("style");x.innerHTML=ee,x.setAttribute("data-paper-shader",""),document.head.prepend(x)}let u=document.createElement("canvas");this.canvasElement=u,this.parentElement.prepend(u),this.fragmentShader=o,this.providedUniforms=t,this.mipmaps=m,this.currentFrame=s,this.minPixelRatio=r,this.maxPixelCount=l;let d=u.getContext("webgl2",i);if(!d)throw new Error("Paper Shaders: WebGL is not supported in this browser");this.gl=d,this.initProgram(),this.setupPositionAttribute(),this.setupUniforms(),this.setUniformValues(this.providedUniforms),this.setupResizeObserver(),visualViewport?.addEventListener("resize",this.handleVisualViewportChange),this.setSpeed(n),this.parentElement.setAttribute("data-paper-shader",""),this.parentElement.paperShaderMount=this,document.addEventListener("visibilitychange",this.handleDocumentVisibilityChange)}};function O(e,o,t){let i=e.createShader(o);return i?(e.shaderSource(i,t),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)?i:(console.error("An error occurred compiling the shaders: "+e.getShaderInfoLog(i)),e.deleteShader(i),null)):null}function $(e,o,t){let i=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT),n=i?i.precision:null;n&&n<23&&(o=o.replace(/precision\s+(lowp|mediump)\s+float;/g,"precision highp float;"),t=t.replace(/precision\s+(lowp|mediump)\s+float/g,"precision highp float").replace(/\b(uniform|varying|attribute)\s+(lowp|mediump)\s+(\w+)/g,"$1 highp $3"));let s=O(e,e.VERTEX_SHADER,o),r=O(e,e.FRAGMENT_SHADER,t);if(!s||!r)return null;let l=e.createProgram();return l?(e.attachShader(l,s),e.attachShader(l,r),e.linkProgram(l),e.getProgramParameter(l,e.LINK_STATUS)?(e.detachShader(l,s),e.detachShader(l,r),e.deleteShader(s),e.deleteShader(r),l):(console.error("Unable to initialize the shader program: "+e.getProgramInfoLog(l)),e.deleteProgram(l),e.deleteShader(s),e.deleteShader(r),null)):null}var ee=`@layer paper-shaders {
152
+ :where([data-paper-shader]) {
153
+ isolation: isolate;
154
+ position: relative;
155
+
156
+ & canvas {
157
+ contain: strict;
158
+ display: block;
159
+ position: absolute;
160
+ inset: 0;
161
+ z-index: -1;
162
+ width: 100%;
163
+ height: 100%;
164
+ border-radius: inherit;
165
+ corner-shape: inherit;
166
+ }
167
+ }
168
+ }`;function oe(){let e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")&&!e.includes("android")}function te(){let e=visualViewport?.scale??1,o=visualViewport?.width??window.innerWidth,t=window.innerWidth-document.documentElement.clientWidth,i=e*o+t,n=outerWidth/i,s=Math.round(100*n);return s%5===0?s/100:s===33?1/3:s===67?2/3:s===133?4/3:n}var c=`
169
+ #define TWO_PI 6.28318530718
170
+ #define PI 3.14159265358979323846
171
+ `,f=`
172
+ vec2 rotate(vec2 uv, float th) {
173
+ return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;
174
+ }
175
+ `,w=`
176
+ float hash11(float p) {
177
+ p = fract(p * 0.3183099) + 0.1;
178
+ p *= p + 19.19;
179
+ return fract(p * p);
180
+ }
181
+ `,g=`
182
+ float hash21(vec2 p) {
183
+ p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1;
184
+ p += dot(p, p + 19.19);
185
+ return fract(p.x * p.y);
186
+ }
187
+ `,_=`
188
+ float randomR(vec2 p) {
189
+ vec2 uv = floor(p) / 100. + .5;
190
+ return texture(u_noiseTexture, fract(uv)).r;
191
+ }
192
+ `,E=`
193
+ vec2 randomGB(vec2 p) {
194
+ vec2 uv = floor(p) / 100. + .5;
195
+ return texture(u_noiseTexture, fract(uv)).gb;
196
+ }
197
+ `,p=`
198
+ color += 1. / 256. * (fract(sin(dot(.014 * gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123) - .5);
199
+ `,h=`
200
+ vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
201
+ float snoise(vec2 v) {
202
+ const vec4 C = vec4(0.211324865405187, 0.366025403784439,
203
+ -0.577350269189626, 0.024390243902439);
204
+ vec2 i = floor(v + dot(v, C.yy));
205
+ vec2 x0 = v - i + dot(i, C.xx);
206
+ vec2 i1;
207
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
208
+ vec4 x12 = x0.xyxy + C.xxzz;
209
+ x12.xy -= i1;
210
+ i = mod(i, 289.0);
211
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
212
+ + i.x + vec3(0.0, i1.x, 1.0));
213
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),
214
+ dot(x12.zw, x12.zw)), 0.0);
215
+ m = m * m;
216
+ m = m * m;
217
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
218
+ vec3 h = abs(x) - 0.5;
219
+ vec3 ox = floor(x + 0.5);
220
+ vec3 a0 = x - ox;
221
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
222
+ vec3 g;
223
+ g.x = a0.x * x0.x + h.x * x0.y;
224
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
225
+ return 130.0 * dot(m, g);
226
+ }
227
+ `,ae=`
228
+ float fiberRandom(vec2 p) {
229
+ vec2 uv = floor(p) / 100.;
230
+ return texture(u_noiseTexture, fract(uv)).b;
231
+ }
232
+
233
+ float fiberValueNoise(vec2 st) {
234
+ vec2 i = floor(st);
235
+ vec2 f = fract(st);
236
+ float a = fiberRandom(i);
237
+ float b = fiberRandom(i + vec2(1.0, 0.0));
238
+ float c = fiberRandom(i + vec2(0.0, 1.0));
239
+ float d = fiberRandom(i + vec2(1.0, 1.0));
240
+ vec2 u = f * f * (3.0 - 2.0 * f);
241
+ float x1 = mix(a, b, u.x);
242
+ float x2 = mix(c, d, u.x);
243
+ return mix(x1, x2, u.y);
244
+ }
245
+
246
+ float fiberNoiseFbm(in vec2 n, vec2 seedOffset) {
247
+ float total = 0.0, amplitude = 1.;
248
+ for (int i = 0; i < 4; i++) {
249
+ n = rotate(n, .7);
250
+ total += fiberValueNoise(n + seedOffset) * amplitude;
251
+ n *= 2.;
252
+ amplitude *= 0.6;
253
+ }
254
+ return total;
255
+ }
256
+
257
+ float fiberNoise(vec2 uv, vec2 seedOffset) {
258
+ float epsilon = 0.001;
259
+ float n1 = fiberNoiseFbm(uv + vec2(epsilon, 0.0), seedOffset);
260
+ float n2 = fiberNoiseFbm(uv - vec2(epsilon, 0.0), seedOffset);
261
+ float n3 = fiberNoiseFbm(uv + vec2(0.0, epsilon), seedOffset);
262
+ float n4 = fiberNoiseFbm(uv - vec2(0.0, epsilon), seedOffset);
263
+ return length(vec2(n1 - n2, n3 - n4)) / (2.0 * epsilon);
264
+ }
265
+ `,D={maxColorCount:10},ce=`#version 300 es
266
+ precision mediump float;
267
+
268
+ uniform float u_time;
269
+
270
+ uniform vec4 u_colors[${D.maxColorCount}];
271
+ uniform float u_colorsCount;
272
+
273
+ uniform float u_distortion;
274
+ uniform float u_swirl;
275
+ uniform float u_grainMixer;
276
+ uniform float u_grainOverlay;
277
+
278
+ in vec2 v_objectUV;
279
+ out vec4 fragColor;
280
+
281
+ ${c}
282
+ ${f}
283
+ ${g}
284
+
285
+ float valueNoise(vec2 st) {
286
+ vec2 i = floor(st);
287
+ vec2 f = fract(st);
288
+ float a = hash21(i);
289
+ float b = hash21(i + vec2(1.0, 0.0));
290
+ float c = hash21(i + vec2(0.0, 1.0));
291
+ float d = hash21(i + vec2(1.0, 1.0));
292
+ vec2 u = f * f * (3.0 - 2.0 * f);
293
+ float x1 = mix(a, b, u.x);
294
+ float x2 = mix(c, d, u.x);
295
+ return mix(x1, x2, u.y);
296
+ }
297
+
298
+ float noise(vec2 n, vec2 seedOffset) {
299
+ return valueNoise(n + seedOffset);
300
+ }
301
+
302
+ vec2 getPosition(int i, float t) {
303
+ float a = float(i) * .37;
304
+ float b = .6 + fract(float(i) / 3.) * .9;
305
+ float c = .8 + fract(float(i + 1) / 4.);
306
+
307
+ float x = sin(t * b + a);
308
+ float y = cos(t * c + a * 1.5);
309
+
310
+ return .5 + .5 * vec2(x, y);
311
+ }
312
+
313
+ void main() {
314
+ vec2 uv = v_objectUV;
315
+ uv += .5;
316
+ vec2 grainUV = uv * 1000.;
317
+
318
+ float grain = noise(grainUV, vec2(0.));
319
+ float mixerGrain = .4 * u_grainMixer * (grain - .5);
320
+
321
+ const float firstFrameOffset = 41.5;
322
+ float t = .5 * (u_time + firstFrameOffset);
323
+
324
+ float radius = smoothstep(0., 1., length(uv - .5));
325
+ float center = 1. - radius;
326
+ for (float i = 1.; i <= 2.; i++) {
327
+ uv.x += u_distortion * center / i * sin(t + i * .4 * smoothstep(.0, 1., uv.y)) * cos(.2 * t + i * 2.4 * smoothstep(.0, 1., uv.y));
328
+ uv.y += u_distortion * center / i * cos(t + i * 2. * smoothstep(.0, 1., uv.x));
329
+ }
330
+
331
+ vec2 uvRotated = uv;
332
+ uvRotated -= vec2(.5);
333
+ float angle = 3. * u_swirl * radius;
334
+ uvRotated = rotate(uvRotated, -angle);
335
+ uvRotated += vec2(.5);
336
+
337
+ vec3 color = vec3(0.);
338
+ float opacity = 0.;
339
+ float totalWeight = 0.;
340
+
341
+ for (int i = 0; i < ${D.maxColorCount}; i++) {
342
+ if (i >= int(u_colorsCount)) break;
343
+
344
+ vec2 pos = getPosition(i, t) + mixerGrain;
345
+ vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
346
+ float opacityFraction = u_colors[i].a;
347
+
348
+ float dist = length(uvRotated - pos);
349
+
350
+ dist = pow(dist, 3.5);
351
+ float weight = 1. / (dist + 1e-3);
352
+ color += colorFraction * weight;
353
+ opacity += opacityFraction * weight;
354
+ totalWeight += weight;
355
+ }
356
+
357
+ color /= max(1e-4, totalWeight);
358
+ opacity /= max(1e-4, totalWeight);
359
+
360
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
361
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
362
+ grainOverlay = pow(grainOverlay, 1.3);
363
+
364
+ float grainOverlayV = grainOverlay * 2. - 1.;
365
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
366
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
367
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
368
+ color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
369
+
370
+ opacity += .5 * grainOverlayStrength;
371
+ opacity = clamp(opacity, 0., 1.);
372
+
373
+ fragColor = vec4(color, opacity);
374
+ }
375
+ `,k={maxColorCount:10,maxNoiseIterations:8},ue=`#version 300 es
376
+ precision mediump float;
377
+
378
+ uniform float u_time;
379
+
380
+ uniform sampler2D u_noiseTexture;
381
+
382
+ uniform vec4 u_colorBack;
383
+ uniform vec4 u_colors[${k.maxColorCount}];
384
+ uniform float u_colorsCount;
385
+
386
+ uniform float u_thickness;
387
+ uniform float u_radius;
388
+ uniform float u_innerShape;
389
+ uniform float u_noiseScale;
390
+ uniform float u_noiseIterations;
391
+
392
+ in vec2 v_objectUV;
393
+
394
+ out vec4 fragColor;
395
+
396
+ ${c}
397
+ ${_}
398
+ float valueNoise(vec2 st) {
399
+ vec2 i = floor(st);
400
+ vec2 f = fract(st);
401
+ float a = randomR(i);
402
+ float b = randomR(i + vec2(1.0, 0.0));
403
+ float c = randomR(i + vec2(0.0, 1.0));
404
+ float d = randomR(i + vec2(1.0, 1.0));
405
+ vec2 u = f * f * (3.0 - 2.0 * f);
406
+ float x1 = mix(a, b, u.x);
407
+ float x2 = mix(c, d, u.x);
408
+ return mix(x1, x2, u.y);
409
+ }
410
+ vec2 fbm(vec2 n0, vec2 n1) {
411
+ vec2 total = vec2(0.0);
412
+ float amplitude = .4;
413
+ for (int i = 0; i < ${k.maxNoiseIterations}; i++) {
414
+ if (i >= int(u_noiseIterations)) break;
415
+ total.x += valueNoise(n0) * amplitude;
416
+ total.y += valueNoise(n1) * amplitude;
417
+ n0 *= 1.99;
418
+ n1 *= 1.99;
419
+ amplitude *= 0.65;
420
+ }
421
+ return total;
422
+ }
423
+
424
+ float getNoise(vec2 uv, vec2 pUv, float t) {
425
+ vec2 pUvLeft = pUv + .03 * t;
426
+ float period = max(abs(u_noiseScale * TWO_PI), 1e-6);
427
+ vec2 pUvRight = vec2(fract(pUv.x / period) * period, pUv.y) + .03 * t;
428
+ vec2 noise = fbm(pUvLeft, pUvRight);
429
+ return mix(noise.y, noise.x, smoothstep(-.25, .25, uv.x));
430
+ }
431
+
432
+ float getRingShape(vec2 uv) {
433
+ float radius = u_radius;
434
+ float thickness = u_thickness;
435
+
436
+ float distance = length(uv);
437
+ float ringValue = 1. - smoothstep(radius, radius + thickness, distance);
438
+ ringValue *= smoothstep(radius - pow(u_innerShape, 3.) * thickness, radius, distance);
439
+
440
+ return ringValue;
441
+ }
442
+
443
+ void main() {
444
+ vec2 shape_uv = v_objectUV;
445
+
446
+ float t = u_time;
447
+
448
+ float cycleDuration = 3.;
449
+ float period2 = 2.0 * cycleDuration;
450
+ float localTime1 = fract((0.1 * t + cycleDuration) / period2) * period2;
451
+ float localTime2 = fract((0.1 * t) / period2) * period2;
452
+ float timeBlend = .5 + .5 * sin(.1 * t * PI / cycleDuration - .5 * PI);
453
+
454
+ float atg = atan(shape_uv.y, shape_uv.x) + .001;
455
+ float l = length(shape_uv);
456
+ float radialOffset = .5 * l - inversesqrt(max(1e-4, l));
457
+ vec2 polar_uv1 = vec2(atg, localTime1 - radialOffset) * u_noiseScale;
458
+ vec2 polar_uv2 = vec2(atg, localTime2 - radialOffset) * u_noiseScale;
459
+
460
+ float noise1 = getNoise(shape_uv, polar_uv1, t);
461
+ float noise2 = getNoise(shape_uv, polar_uv2, t);
462
+
463
+ float noise = mix(noise1, noise2, timeBlend);
464
+
465
+ shape_uv *= (.8 + 1.2 * noise);
466
+
467
+ float ringShape = getRingShape(shape_uv);
468
+
469
+ float mixer = ringShape * ringShape * (u_colorsCount - 1.);
470
+ int idxLast = int(u_colorsCount) - 1;
471
+ vec4 gradient = u_colors[idxLast];
472
+ gradient.rgb *= gradient.a;
473
+ for (int i = ${k.maxColorCount} - 2; i >= 0; i--) {
474
+ float localT = clamp(mixer - float(idxLast - i - 1), 0., 1.);
475
+ vec4 c = u_colors[i];
476
+ c.rgb *= c.a;
477
+ gradient = mix(gradient, c, localT);
478
+ }
479
+
480
+ vec3 color = gradient.rgb * ringShape;
481
+ float opacity = gradient.a * ringShape;
482
+
483
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
484
+ color = color + bgColor * (1. - opacity);
485
+ opacity = opacity + u_colorBack.a * (1. - opacity);
486
+
487
+ ${p}
488
+
489
+ fragColor = vec4(color, opacity);
490
+ }
491
+ `,fe=`#version 300 es
492
+ precision mediump float;
493
+
494
+ uniform float u_time;
495
+ uniform vec2 u_resolution;
496
+ uniform float u_pixelRatio;
497
+
498
+ uniform vec4 u_colorFront;
499
+ uniform vec4 u_colorMid;
500
+ uniform vec4 u_colorBack;
501
+ uniform float u_brightness;
502
+ uniform float u_contrast;
503
+
504
+ in vec2 v_patternUV;
505
+
506
+ out vec4 fragColor;
507
+
508
+ ${f}
509
+
510
+ float neuroShape(vec2 uv, float t) {
511
+ vec2 sine_acc = vec2(0.);
512
+ vec2 res = vec2(0.);
513
+ float scale = 8.;
514
+
515
+ for (int j = 0; j < 15; j++) {
516
+ uv = rotate(uv, 1.);
517
+ sine_acc = rotate(sine_acc, 1.);
518
+ vec2 layer = uv * scale + float(j) + sine_acc - t;
519
+ sine_acc += sin(layer);
520
+ res += (.5 + .5 * cos(layer)) / scale;
521
+ scale *= (1.2);
522
+ }
523
+ return res.x + res.y;
524
+ }
525
+
526
+ void main() {
527
+ vec2 shape_uv = v_patternUV;
528
+ shape_uv *= .13;
529
+
530
+ float t = .5 * u_time;
531
+
532
+ float noise = neuroShape(shape_uv, t);
533
+
534
+ noise = (1. + u_brightness) * noise * noise;
535
+ noise = pow(noise, .7 + 6. * u_contrast);
536
+ noise = min(1.4, noise);
537
+
538
+ float blend = smoothstep(0.7, 1.4, noise);
539
+
540
+ vec4 frontC = u_colorFront;
541
+ frontC.rgb *= frontC.a;
542
+ vec4 midC = u_colorMid;
543
+ midC.rgb *= midC.a;
544
+ vec4 blendFront = mix(midC, frontC, blend);
545
+
546
+ float safeNoise = max(noise, 0.0);
547
+ vec3 color = blendFront.rgb * safeNoise;
548
+ float opacity = clamp(blendFront.a * safeNoise, 0., 1.);
549
+
550
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
551
+ color = color + bgColor * (1. - opacity);
552
+ opacity = opacity + u_colorBack.a * (1. - opacity);
553
+
554
+ ${p}
555
+
556
+ fragColor = vec4(color, opacity);
557
+ }
558
+ `,T={maxColorCount:10},me=`#version 300 es
559
+ precision mediump float;
560
+
561
+ uniform float u_time;
562
+
563
+ uniform sampler2D u_noiseTexture;
564
+
565
+ uniform vec4 u_colorBack;
566
+ uniform vec4 u_colors[${T.maxColorCount}];
567
+ uniform float u_colorsCount;
568
+ uniform float u_stepsPerColor;
569
+ uniform float u_size;
570
+ uniform float u_sizeRange;
571
+ uniform float u_spreading;
572
+
573
+ in vec2 v_patternUV;
574
+
575
+ out vec4 fragColor;
576
+
577
+ ${c}
578
+ ${f}
579
+ ${_}
580
+ ${E}
581
+
582
+
583
+ vec3 voronoiShape(vec2 uv, float time) {
584
+ vec2 i_uv = floor(uv);
585
+ vec2 f_uv = fract(uv);
586
+
587
+ float spreading = .25 * clamp(u_spreading, 0., 1.);
588
+
589
+ float minDist = 1.;
590
+ vec2 randomizer = vec2(0.);
591
+ for (int y = -1; y <= 1; y++) {
592
+ for (int x = -1; x <= 1; x++) {
593
+ vec2 tileOffset = vec2(float(x), float(y));
594
+ vec2 rand = randomGB(i_uv + tileOffset);
595
+ vec2 cellCenter = vec2(.5 + 1e-4);
596
+ cellCenter += spreading * cos(time + TWO_PI * rand);
597
+ cellCenter -= .5;
598
+ cellCenter = rotate(cellCenter, randomR(vec2(rand.x, rand.y)) + .1 * time);
599
+ cellCenter += .5;
600
+ float dist = length(tileOffset + cellCenter - f_uv);
601
+ if (dist < minDist) {
602
+ minDist = dist;
603
+ randomizer = rand;
604
+ }
605
+ }
606
+ }
607
+
608
+ return vec3(minDist, randomizer);
609
+ }
610
+
611
+ void main() {
612
+
613
+ vec2 shape_uv = v_patternUV;
614
+ shape_uv *= 1.5;
615
+
616
+ const float firstFrameOffset = -10.;
617
+ float t = u_time + firstFrameOffset;
618
+
619
+ vec3 voronoi = voronoiShape(shape_uv, t) + 1e-4;
620
+
621
+ float radius = .25 * clamp(u_size, 0., 1.) - .5 * clamp(u_sizeRange, 0., 1.) * voronoi[2];
622
+ float dist = voronoi[0];
623
+ float edgeWidth = fwidth(dist);
624
+ float dots = 1. - smoothstep(radius - edgeWidth, radius + edgeWidth, dist);
625
+
626
+ float shape = voronoi[1];
627
+
628
+ float mixer = shape * (u_colorsCount - 1.);
629
+ mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
630
+ float steps = max(1., u_stepsPerColor);
631
+
632
+ vec4 gradient = u_colors[0];
633
+ gradient.rgb *= gradient.a;
634
+ for (int i = 1; i < ${T.maxColorCount}; i++) {
635
+ if (i >= int(u_colorsCount)) break;
636
+ float localT = clamp(mixer - float(i - 1), 0.0, 1.0);
637
+ localT = round(localT * steps) / steps;
638
+ vec4 c = u_colors[i];
639
+ c.rgb *= c.a;
640
+ gradient = mix(gradient, c, localT);
641
+ }
642
+
643
+ if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {
644
+ float localT = mixer + 1.;
645
+ if (mixer > (u_colorsCount - 1.)) {
646
+ localT = mixer - (u_colorsCount - 1.);
647
+ }
648
+ localT = round(localT * steps) / steps;
649
+ vec4 cFst = u_colors[0];
650
+ cFst.rgb *= cFst.a;
651
+ vec4 cLast = u_colors[int(u_colorsCount - 1.)];
652
+ cLast.rgb *= cLast.a;
653
+ gradient = mix(cLast, cFst, localT);
654
+ }
655
+
656
+ vec3 color = gradient.rgb * dots;
657
+ float opacity = gradient.a * dots;
658
+
659
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
660
+ color = color + bgColor * (1. - opacity);
661
+ opacity = opacity + u_colorBack.a * (1. - opacity);
662
+
663
+ fragColor = vec4(color, opacity);
664
+ }
665
+ `,pe=`#version 300 es
666
+ precision mediump float;
667
+
668
+ uniform vec4 u_colorBack;
669
+ uniform vec4 u_colorFill;
670
+ uniform vec4 u_colorStroke;
671
+ uniform float u_dotSize;
672
+ uniform float u_gapX;
673
+ uniform float u_gapY;
674
+ uniform float u_strokeWidth;
675
+ uniform float u_sizeRange;
676
+ uniform float u_opacityRange;
677
+ uniform float u_shape;
678
+
679
+ in vec2 v_patternUV;
680
+
681
+ out vec4 fragColor;
682
+
683
+ ${c}
684
+ ${h}
685
+
686
+ float polygon(vec2 p, float N, float rot) {
687
+ float a = atan(p.x, p.y) + rot;
688
+ float r = TWO_PI / float(N);
689
+
690
+ return cos(floor(.5 + a / r) * r - a) * length(p);
691
+ }
692
+
693
+ void main() {
694
+
695
+ // x100 is a default multiplier between vertex and fragmant shaders
696
+ // we use it to avoid UV presision issues
697
+ vec2 shape_uv = 100. * v_patternUV;
698
+
699
+ vec2 gap = max(abs(vec2(u_gapX, u_gapY)), vec2(1e-6));
700
+ vec2 grid = fract(shape_uv / gap) + 1e-4;
701
+ vec2 grid_idx = floor(shape_uv / gap);
702
+ float sizeRandomizer = .5 + .8 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));
703
+ float opacity_randomizer = .5 + .7 * snoise(2. * vec2(grid_idx.y, grid_idx.x));
704
+
705
+ vec2 center = vec2(0.5) - 1e-3;
706
+ vec2 p = (grid - center) * vec2(u_gapX, u_gapY);
707
+
708
+ float baseSize = u_dotSize * (1. - sizeRandomizer * u_sizeRange);
709
+ float strokeWidth = u_strokeWidth * (1. - sizeRandomizer * u_sizeRange);
710
+
711
+ float dist;
712
+ if (u_shape < 0.5) {
713
+ // Circle
714
+ dist = length(p);
715
+ } else if (u_shape < 1.5) {
716
+ // Diamond
717
+ strokeWidth *= 1.5;
718
+ dist = polygon(1.5 * p, 4., .25 * PI);
719
+ } else if (u_shape < 2.5) {
720
+ // Square
721
+ dist = polygon(1.03 * p, 4., 1e-3);
722
+ } else {
723
+ // Triangle
724
+ strokeWidth *= 1.5;
725
+ p = p * 2. - 1.;
726
+ p *= .9;
727
+ p.y = 1. - p.y;
728
+ p.y -= .75 * baseSize;
729
+ dist = polygon(p, 3., 1e-3);
730
+ }
731
+
732
+ float edgeWidth = fwidth(dist);
733
+ float shapeOuter = 1. - smoothstep(baseSize - edgeWidth, baseSize + edgeWidth, dist - strokeWidth);
734
+ float shapeInner = 1. - smoothstep(baseSize - edgeWidth, baseSize + edgeWidth, dist);
735
+ float stroke = shapeOuter - shapeInner;
736
+
737
+ float dotOpacity = max(0., 1. - opacity_randomizer * u_opacityRange);
738
+ stroke *= dotOpacity;
739
+ shapeInner *= dotOpacity;
740
+
741
+ stroke *= u_colorStroke.a;
742
+ shapeInner *= u_colorFill.a;
743
+
744
+ vec3 color = vec3(0.);
745
+ color += stroke * u_colorStroke.rgb;
746
+ color += shapeInner * u_colorFill.rgb;
747
+ color += (1. - shapeInner - stroke) * u_colorBack.rgb * u_colorBack.a;
748
+
749
+ float opacity = 0.;
750
+ opacity += stroke;
751
+ opacity += shapeInner;
752
+ opacity += (1. - opacity) * u_colorBack.a;
753
+
754
+ fragColor = vec4(color, opacity);
755
+ }
756
+ `;var G={maxColorCount:10},ve=`#version 300 es
757
+ precision mediump float;
758
+
759
+ uniform float u_time;
760
+ uniform float u_scale;
761
+
762
+ uniform vec4 u_colors[${G.maxColorCount}];
763
+ uniform float u_colorsCount;
764
+ uniform float u_stepsPerColor;
765
+ uniform float u_softness;
766
+
767
+ in vec2 v_patternUV;
768
+
769
+ out vec4 fragColor;
770
+
771
+ ${h}
772
+
773
+ float getNoise(vec2 uv, float t) {
774
+ float noise = .5 * snoise(uv - vec2(0., .3 * t));
775
+ noise += .5 * snoise(2. * uv + vec2(0., .32 * t));
776
+
777
+ return noise;
778
+ }
779
+
780
+ float steppedSmooth(float m, float steps, float softness) {
781
+ float stepT = floor(m * steps) / steps;
782
+ float f = m * steps - floor(m * steps);
783
+ float fw = steps * fwidth(m);
784
+ float smoothed = smoothstep(.5 - softness, min(1., .5 + softness + fw), f);
785
+ return stepT + smoothed / steps;
786
+ }
787
+
788
+ void main() {
789
+ vec2 shape_uv = v_patternUV;
790
+ shape_uv *= .1;
791
+
792
+ float t = .2 * u_time;
793
+
794
+ float shape = .5 + .5 * getNoise(shape_uv, t);
795
+
796
+ bool u_extraSides = true;
797
+
798
+ float mixer = shape * (u_colorsCount - 1.);
799
+ if (u_extraSides == true) {
800
+ mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
801
+ }
802
+
803
+ float steps = max(1., u_stepsPerColor);
804
+
805
+ vec4 gradient = u_colors[0];
806
+ gradient.rgb *= gradient.a;
807
+ for (int i = 1; i < ${G.maxColorCount}; i++) {
808
+ if (i >= int(u_colorsCount)) break;
809
+
810
+ float localM = clamp(mixer - float(i - 1), 0., 1.);
811
+ localM = steppedSmooth(localM, steps, .5 * u_softness);
812
+
813
+ vec4 c = u_colors[i];
814
+ c.rgb *= c.a;
815
+ gradient = mix(gradient, c, localM);
816
+ }
817
+
818
+ if (u_extraSides == true) {
819
+ if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {
820
+ float localM = mixer + 1.;
821
+ if (mixer > (u_colorsCount - 1.)) {
822
+ localM = mixer - (u_colorsCount - 1.);
823
+ }
824
+ localM = steppedSmooth(localM, steps, .5 * u_softness);
825
+ vec4 cFst = u_colors[0];
826
+ cFst.rgb *= cFst.a;
827
+ vec4 cLast = u_colors[int(u_colorsCount - 1.)];
828
+ cLast.rgb *= cLast.a;
829
+ gradient = mix(cLast, cFst, localM);
830
+ }
831
+ }
832
+
833
+ vec3 color = gradient.rgb;
834
+ float opacity = gradient.a;
835
+
836
+ ${p}
837
+
838
+ fragColor = vec4(color, opacity);
839
+ }
840
+ `,R={maxColorCount:8,maxBallsCount:20},de=`#version 300 es
841
+ precision mediump float;
842
+
843
+ uniform float u_time;
844
+
845
+ uniform sampler2D u_noiseTexture;
846
+
847
+ uniform vec4 u_colorBack;
848
+ uniform vec4 u_colors[${R.maxColorCount}];
849
+ uniform float u_colorsCount;
850
+ uniform float u_size;
851
+ uniform float u_sizeRange;
852
+ uniform float u_count;
853
+
854
+ in vec2 v_objectUV;
855
+
856
+ out vec4 fragColor;
857
+
858
+ ${c}
859
+ ${_}
860
+ float noise(float x) {
861
+ float i = floor(x);
862
+ float f = fract(x);
863
+ float u = f * f * (3.0 - 2.0 * f);
864
+ vec2 p0 = vec2(i, 0.0);
865
+ vec2 p1 = vec2(i + 1.0, 0.0);
866
+ return mix(randomR(p0), randomR(p1), u);
867
+ }
868
+
869
+ float getBallShape(vec2 uv, vec2 c, float p) {
870
+ float s = .5 * length(uv - c);
871
+ s = 1. - clamp(s, 0., 1.);
872
+ s = pow(s, p);
873
+ return s;
874
+ }
875
+
876
+ void main() {
877
+ vec2 shape_uv = v_objectUV;
878
+
879
+ shape_uv += .5;
880
+
881
+ const float firstFrameOffset = 2503.4;
882
+ float t = .2 * (u_time + firstFrameOffset);
883
+
884
+ vec3 totalColor = vec3(0.);
885
+ float totalShape = 0.;
886
+ float totalOpacity = 0.;
887
+
888
+ for (int i = 0; i < ${R.maxBallsCount}; i++) {
889
+ if (i >= int(ceil(u_count))) break;
890
+
891
+ float idxFract = float(i) / float(${R.maxBallsCount});
892
+ float angle = TWO_PI * idxFract;
893
+
894
+ float speed = 1. - .2 * idxFract;
895
+ float noiseX = noise(angle * 10. + float(i) + t * speed);
896
+ float noiseY = noise(angle * 20. + float(i) - t * speed);
897
+
898
+ vec2 pos = vec2(.5) + 1e-4 + .9 * (vec2(noiseX, noiseY) - .5);
899
+
900
+ int safeIndex = i % int(u_colorsCount + 0.5);
901
+ vec4 ballColor = u_colors[safeIndex];
902
+ ballColor.rgb *= ballColor.a;
903
+
904
+ float sizeFrac = 1.;
905
+ if (float(i) > floor(u_count - 1.)) {
906
+ sizeFrac *= fract(u_count);
907
+ }
908
+
909
+ float shape = getBallShape(shape_uv, pos, 45. - 30. * u_size * sizeFrac);
910
+ shape *= pow(u_size, .2);
911
+ shape = smoothstep(0., 1., shape);
912
+
913
+ totalColor += ballColor.rgb * shape;
914
+ totalShape += shape;
915
+ totalOpacity += ballColor.a * shape;
916
+ }
917
+
918
+ totalColor /= max(totalShape, 1e-4);
919
+ totalOpacity /= max(totalShape, 1e-4);
920
+
921
+ float edge_width = fwidth(totalShape);
922
+ float finalShape = smoothstep(.4, .4 + edge_width, totalShape);
923
+
924
+ vec3 color = totalColor * finalShape;
925
+ float opacity = totalOpacity * finalShape;
926
+
927
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
928
+ color = color + bgColor * (1. - opacity);
929
+ opacity = opacity + u_colorBack.a * (1. - opacity);
930
+
931
+ ${p}
932
+
933
+ fragColor = vec4(color, opacity);
934
+ }
935
+ `,ge=`#version 300 es
936
+ precision mediump float;
937
+
938
+ uniform float u_time;
939
+
940
+ uniform vec4 u_colorFront;
941
+ uniform vec4 u_colorBack;
942
+ uniform float u_proportion;
943
+ uniform float u_softness;
944
+ uniform float u_octaveCount;
945
+ uniform float u_persistence;
946
+ uniform float u_lacunarity;
947
+
948
+ in vec2 v_patternUV;
949
+
950
+ out vec4 fragColor;
951
+
952
+ ${c}
953
+ ${w}
954
+ ${g}
955
+
956
+ float hash31(vec3 p) {
957
+ p = fract(p * 0.3183099) + 0.1;
958
+ p += dot(p, p.yzx + 19.19);
959
+ return fract(p.x * (p.y + p.z));
960
+ }
961
+
962
+ vec3 gradientPredefined(float hash) {
963
+ int idx = int(hash * 12.0) % 12;
964
+
965
+ if (idx == 0) return vec3(1, 1, 0);
966
+ if (idx == 1) return vec3(-1, 1, 0);
967
+ if (idx == 2) return vec3(1, -1, 0);
968
+ if (idx == 3) return vec3(-1, -1, 0);
969
+ if (idx == 4) return vec3(1, 0, 1);
970
+ if (idx == 5) return vec3(-1, 0, 1);
971
+ if (idx == 6) return vec3(1, 0, -1);
972
+ if (idx == 7) return vec3(-1, 0, -1);
973
+ if (idx == 8) return vec3(0, 1, 1);
974
+ if (idx == 9) return vec3(0, -1, 1);
975
+ if (idx == 10) return vec3(0, 1, -1);
976
+ return vec3(0, -1, -1);// idx == 11
977
+ }
978
+
979
+ float interpolateSafe(float v000, float v001, float v010, float v011,
980
+ float v100, float v101, float v110, float v111, vec3 t) {
981
+ t = clamp(t, 0.0, 1.0);
982
+
983
+ float v00 = mix(v000, v100, t.x);
984
+ float v01 = mix(v001, v101, t.x);
985
+ float v10 = mix(v010, v110, t.x);
986
+ float v11 = mix(v011, v111, t.x);
987
+
988
+ float v0 = mix(v00, v10, t.y);
989
+ float v1 = mix(v01, v11, t.y);
990
+
991
+ return mix(v0, v1, t.z);
992
+ }
993
+
994
+ vec3 fade(vec3 t) {
995
+ return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
996
+ }
997
+
998
+ float perlinNoise(vec3 position, float seed) {
999
+ position += vec3(seed * 127.1, seed * 311.7, seed * 74.7);
1000
+
1001
+ vec3 i = floor(position);
1002
+ vec3 f = fract(position);
1003
+ float h000 = hash31(i);
1004
+ float h001 = hash31(i + vec3(0, 0, 1));
1005
+ float h010 = hash31(i + vec3(0, 1, 0));
1006
+ float h011 = hash31(i + vec3(0, 1, 1));
1007
+ float h100 = hash31(i + vec3(1, 0, 0));
1008
+ float h101 = hash31(i + vec3(1, 0, 1));
1009
+ float h110 = hash31(i + vec3(1, 1, 0));
1010
+ float h111 = hash31(i + vec3(1, 1, 1));
1011
+ vec3 g000 = gradientPredefined(h000);
1012
+ vec3 g001 = gradientPredefined(h001);
1013
+ vec3 g010 = gradientPredefined(h010);
1014
+ vec3 g011 = gradientPredefined(h011);
1015
+ vec3 g100 = gradientPredefined(h100);
1016
+ vec3 g101 = gradientPredefined(h101);
1017
+ vec3 g110 = gradientPredefined(h110);
1018
+ vec3 g111 = gradientPredefined(h111);
1019
+ float v000 = dot(g000, f - vec3(0, 0, 0));
1020
+ float v001 = dot(g001, f - vec3(0, 0, 1));
1021
+ float v010 = dot(g010, f - vec3(0, 1, 0));
1022
+ float v011 = dot(g011, f - vec3(0, 1, 1));
1023
+ float v100 = dot(g100, f - vec3(1, 0, 0));
1024
+ float v101 = dot(g101, f - vec3(1, 0, 1));
1025
+ float v110 = dot(g110, f - vec3(1, 1, 0));
1026
+ float v111 = dot(g111, f - vec3(1, 1, 1));
1027
+
1028
+ vec3 u = fade(f);
1029
+ return interpolateSafe(v000, v001, v010, v011, v100, v101, v110, v111, u);
1030
+ }
1031
+
1032
+ float p_noise(vec3 position, int octaveCount, float persistence, float lacunarity) {
1033
+ float value = 0.0;
1034
+ float amplitude = 1.0;
1035
+ float frequency = 10.0;
1036
+ float maxValue = 0.0;
1037
+ octaveCount = clamp(octaveCount, 1, 8);
1038
+
1039
+ for (int i = 0; i < octaveCount; i++) {
1040
+ float seed = float(i) * 0.7319;
1041
+ value += perlinNoise(position * frequency, seed) * amplitude;
1042
+ maxValue += amplitude;
1043
+ amplitude *= persistence;
1044
+ frequency *= lacunarity;
1045
+ }
1046
+ return value;
1047
+ }
1048
+
1049
+ float get_max_amp(float persistence, float octaveCount) {
1050
+ persistence = clamp(persistence * 0.999, 0.0, 0.999);
1051
+ octaveCount = clamp(octaveCount, 1.0, 8.0);
1052
+
1053
+ if (abs(persistence - 1.0) < 0.001) {
1054
+ return octaveCount;
1055
+ }
1056
+
1057
+ return (1.0 - pow(persistence, octaveCount)) / max(1e-4, (1.0 - persistence));
1058
+ }
1059
+
1060
+ void main() {
1061
+ vec2 uv = v_patternUV;
1062
+ uv *= .5;
1063
+
1064
+ float t = .2 * u_time;
1065
+
1066
+ vec3 p = vec3(uv, t);
1067
+
1068
+ float octCount = floor(u_octaveCount);
1069
+ float noise = p_noise(p, int(octCount), u_persistence, u_lacunarity);
1070
+
1071
+ float max_amp = get_max_amp(u_persistence, octCount);
1072
+ float noise_normalized = clamp((noise + max_amp) / max(1e-4, (2. * max_amp)) + (u_proportion - .5), 0.0, 1.0);
1073
+ float sharpness = clamp(u_softness, 0., 1.);
1074
+ float smooth_w = 0.5 * max(fwidth(noise_normalized), 0.001);
1075
+ float res = smoothstep(
1076
+ .5 - .5 * sharpness - smooth_w,
1077
+ .5 + .5 * sharpness + smooth_w,
1078
+ noise_normalized
1079
+ );
1080
+
1081
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
1082
+ float fgOpacity = u_colorFront.a;
1083
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1084
+ float bgOpacity = u_colorBack.a;
1085
+
1086
+ vec3 color = fgColor * res;
1087
+ float opacity = fgOpacity * res;
1088
+
1089
+ color += bgColor * (1. - opacity);
1090
+ opacity += bgOpacity * (1. - opacity);
1091
+
1092
+ ${p}
1093
+
1094
+ fragColor = vec4(color, opacity);
1095
+ }
1096
+ `,Q={maxColorCount:5},he=`#version 300 es
1097
+ precision mediump float;
1098
+
1099
+ uniform float u_time;
1100
+
1101
+ uniform float u_scale;
1102
+
1103
+ uniform sampler2D u_noiseTexture;
1104
+
1105
+ uniform vec4 u_colors[${Q.maxColorCount}];
1106
+ uniform float u_colorsCount;
1107
+
1108
+ uniform float u_stepsPerColor;
1109
+ uniform vec4 u_colorGlow;
1110
+ uniform vec4 u_colorGap;
1111
+ uniform float u_distortion;
1112
+ uniform float u_gap;
1113
+ uniform float u_glow;
1114
+
1115
+ in vec2 v_patternUV;
1116
+
1117
+ out vec4 fragColor;
1118
+
1119
+ ${c}
1120
+ ${E}
1121
+
1122
+ vec4 voronoi(vec2 x, float t) {
1123
+ vec2 ip = floor(x);
1124
+ vec2 fp = fract(x);
1125
+
1126
+ vec2 mg, mr;
1127
+ float md = 8.;
1128
+ float rand = 0.;
1129
+
1130
+ for (int j = -1; j <= 1; j++) {
1131
+ for (int i = -1; i <= 1; i++) {
1132
+ vec2 g = vec2(float(i), float(j));
1133
+ vec2 o = randomGB(ip + g);
1134
+ float raw_hash = o.x;
1135
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
1136
+ vec2 r = g + o - fp;
1137
+ float d = dot(r, r);
1138
+
1139
+ if (d < md) {
1140
+ md = d;
1141
+ mr = r;
1142
+ mg = g;
1143
+ rand = raw_hash;
1144
+ }
1145
+ }
1146
+ }
1147
+
1148
+ md = 8.;
1149
+ for (int j = -2; j <= 2; j++) {
1150
+ for (int i = -2; i <= 2; i++) {
1151
+ vec2 g = mg + vec2(float(i), float(j));
1152
+ vec2 o = randomGB(ip + g);
1153
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
1154
+ vec2 r = g + o - fp;
1155
+ if (dot(mr - r, mr - r) > .00001) {
1156
+ md = min(md, dot(.5 * (mr + r), normalize(r - mr)));
1157
+ }
1158
+ }
1159
+ }
1160
+
1161
+ return vec4(md, mr, rand);
1162
+ }
1163
+
1164
+ void main() {
1165
+ vec2 shape_uv = v_patternUV;
1166
+ shape_uv *= 1.25;
1167
+
1168
+ float t = u_time;
1169
+
1170
+ vec4 voronoiRes = voronoi(shape_uv, t);
1171
+
1172
+ float shape = clamp(voronoiRes.w, 0., 1.);
1173
+ float mixer = shape * (u_colorsCount - 1.);
1174
+ mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
1175
+ float steps = max(1., u_stepsPerColor);
1176
+
1177
+ vec4 gradient = u_colors[0];
1178
+ gradient.rgb *= gradient.a;
1179
+ for (int i = 1; i < ${Q.maxColorCount}; i++) {
1180
+ if (i >= int(u_colorsCount)) break;
1181
+ float localT = clamp(mixer - float(i - 1), 0.0, 1.0);
1182
+ localT = round(localT * steps) / steps;
1183
+ vec4 c = u_colors[i];
1184
+ c.rgb *= c.a;
1185
+ gradient = mix(gradient, c, localT);
1186
+ }
1187
+
1188
+ if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {
1189
+ float localT = mixer + 1.;
1190
+ if (mixer > (u_colorsCount - 1.)) {
1191
+ localT = mixer - (u_colorsCount - 1.);
1192
+ }
1193
+ localT = round(localT * steps) / steps;
1194
+ vec4 cFst = u_colors[0];
1195
+ cFst.rgb *= cFst.a;
1196
+ vec4 cLast = u_colors[int(u_colorsCount - 1.)];
1197
+ cLast.rgb *= cLast.a;
1198
+ gradient = mix(cLast, cFst, localT);
1199
+ }
1200
+
1201
+ vec3 cellColor = gradient.rgb;
1202
+ float cellOpacity = gradient.a;
1203
+
1204
+ float glows = length(voronoiRes.yz * u_glow);
1205
+ glows = pow(glows, 1.5);
1206
+
1207
+ vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);
1208
+ float opacity = cellOpacity + u_colorGlow.a * glows;
1209
+
1210
+ float edge = voronoiRes.x;
1211
+ float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);
1212
+ edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);
1213
+
1214
+ color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);
1215
+ opacity = mix(u_colorGap.a, opacity, edge);
1216
+
1217
+ fragColor = vec4(color, opacity);
1218
+ }
1219
+ `,xe=`#version 300 es
1220
+ precision mediump float;
1221
+
1222
+ uniform vec4 u_colorFront;
1223
+ uniform vec4 u_colorBack;
1224
+ uniform float u_shape;
1225
+ uniform float u_frequency;
1226
+ uniform float u_amplitude;
1227
+ uniform float u_spacing;
1228
+ uniform float u_proportion;
1229
+ uniform float u_softness;
1230
+
1231
+ in vec2 v_patternUV;
1232
+
1233
+ out vec4 fragColor;
1234
+
1235
+ ${c}
1236
+
1237
+ void main() {
1238
+ vec2 shape_uv = v_patternUV;
1239
+ shape_uv *= 4.;
1240
+
1241
+ float wave = .5 * cos(shape_uv.x * u_frequency * TWO_PI);
1242
+ float zigzag = 2. * abs(fract(shape_uv.x * u_frequency) - .5);
1243
+ float irregular = sin(shape_uv.x * .25 * u_frequency * TWO_PI) * cos(shape_uv.x * u_frequency * TWO_PI);
1244
+ float irregular2 = .75 * (sin(shape_uv.x * u_frequency * TWO_PI) + .5 * cos(shape_uv.x * .5 * u_frequency * TWO_PI));
1245
+
1246
+ float offset = mix(zigzag, wave, smoothstep(0., 1., u_shape));
1247
+ offset = mix(offset, irregular, smoothstep(1., 2., u_shape));
1248
+ offset = mix(offset, irregular2, smoothstep(2., 3., u_shape));
1249
+ offset *= 2. * u_amplitude;
1250
+
1251
+ float spacing = (.001 + u_spacing);
1252
+ float shape = .5 + .5 * sin((shape_uv.y + offset) * PI / spacing);
1253
+
1254
+ float aa = .0001 + fwidth(shape);
1255
+ float dc = 1. - clamp(u_proportion, 0., 1.);
1256
+ float e0 = dc - u_softness - aa;
1257
+ float e1 = dc + u_softness + aa;
1258
+ float res = smoothstep(min(e0, e1), max(e0, e1), shape);
1259
+
1260
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
1261
+ float fgOpacity = u_colorFront.a;
1262
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1263
+ float bgOpacity = u_colorBack.a;
1264
+
1265
+ vec3 color = fgColor * res;
1266
+ float opacity = fgOpacity * res;
1267
+
1268
+ color += bgColor * (1. - opacity);
1269
+ opacity += bgOpacity * (1. - opacity);
1270
+
1271
+ fragColor = vec4(color, opacity);
1272
+ }
1273
+ `,N={maxColorCount:10},_e=`#version 300 es
1274
+ precision mediump float;
1275
+
1276
+ uniform float u_time;
1277
+ uniform float u_scale;
1278
+
1279
+ uniform sampler2D u_noiseTexture;
1280
+
1281
+ uniform vec4 u_colors[${N.maxColorCount}];
1282
+ uniform float u_colorsCount;
1283
+ uniform float u_proportion;
1284
+ uniform float u_softness;
1285
+ uniform float u_shape;
1286
+ uniform float u_shapeScale;
1287
+ uniform float u_distortion;
1288
+ uniform float u_swirl;
1289
+ uniform float u_swirlIterations;
1290
+
1291
+ in vec2 v_patternUV;
1292
+
1293
+ out vec4 fragColor;
1294
+
1295
+ ${c}
1296
+ ${f}
1297
+ float randomG(vec2 p) {
1298
+ vec2 uv = floor(p) / 100. + .5;
1299
+ return texture(u_noiseTexture, fract(uv)).g;
1300
+ }
1301
+ float valueNoise(vec2 st) {
1302
+ vec2 i = floor(st);
1303
+ vec2 f = fract(st);
1304
+ float a = randomG(i);
1305
+ float b = randomG(i + vec2(1.0, 0.0));
1306
+ float c = randomG(i + vec2(0.0, 1.0));
1307
+ float d = randomG(i + vec2(1.0, 1.0));
1308
+ vec2 u = f * f * (3.0 - 2.0 * f);
1309
+ float x1 = mix(a, b, u.x);
1310
+ float x2 = mix(c, d, u.x);
1311
+ return mix(x1, x2, u.y);
1312
+ }
1313
+
1314
+
1315
+ void main() {
1316
+ vec2 uv = v_patternUV;
1317
+ uv *= .5;
1318
+
1319
+ const float firstFrameOffset = 118.;
1320
+ float t = 0.0625 * (u_time + firstFrameOffset);
1321
+
1322
+ float n1 = valueNoise(uv * 1. + t);
1323
+ float n2 = valueNoise(uv * 2. - t);
1324
+ float angle = n1 * TWO_PI;
1325
+ uv.x += 4. * u_distortion * n2 * cos(angle);
1326
+ uv.y += 4. * u_distortion * n2 * sin(angle);
1327
+
1328
+ float swirl = u_swirl;
1329
+ for (int i = 1; i <= 20; i++) {
1330
+ if (i >= int(u_swirlIterations)) break;
1331
+ float iFloat = float(i);
1332
+ // swirl *= (1. - smoothstep(.0, .25, length(fwidth(uv))));
1333
+ uv.x += swirl / iFloat * cos(t + iFloat * 1.5 * uv.y);
1334
+ uv.y += swirl / iFloat * cos(t + iFloat * 1. * uv.x);
1335
+ }
1336
+
1337
+ float proportion = clamp(u_proportion, 0., 1.);
1338
+
1339
+ float shape = 0.;
1340
+ if (u_shape < .5) {
1341
+ vec2 checksShape_uv = uv * (.5 + 3.5 * u_shapeScale);
1342
+ shape = .5 + .5 * sin(checksShape_uv.x) * cos(checksShape_uv.y);
1343
+ shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
1344
+ } else if (u_shape < 1.5) {
1345
+ vec2 stripesShape_uv = uv * (2. * u_shapeScale);
1346
+ float f = fract(stripesShape_uv.y);
1347
+ shape = smoothstep(.0, .55, f) * (1.0 - smoothstep(.45, 1., f));
1348
+ shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
1349
+ } else {
1350
+ float shapeScaling = 5. * (1. - u_shapeScale);
1351
+ float e0 = 0.45 - shapeScaling;
1352
+ float e1 = 0.55 + shapeScaling;
1353
+ shape = smoothstep(min(e0, e1), max(e0, e1), 1.0 - uv.y + 0.3 * (proportion - 0.5));
1354
+ }
1355
+
1356
+ float mixer = shape * (u_colorsCount - 1.);
1357
+ vec4 gradient = u_colors[0];
1358
+ gradient.rgb *= gradient.a;
1359
+ float aa = fwidth(shape);
1360
+ for (int i = 1; i < ${N.maxColorCount}; i++) {
1361
+ if (i >= int(u_colorsCount)) break;
1362
+ float m = clamp(mixer - float(i - 1), 0.0, 1.0);
1363
+
1364
+ float localMixerStart = floor(m);
1365
+ float softness = .5 * u_softness + fwidth(m);
1366
+ float smoothed = smoothstep(max(0., .5 - softness - aa), min(1., .5 + softness + aa), m - localMixerStart);
1367
+ float stepped = localMixerStart + smoothed;
1368
+
1369
+ m = mix(stepped, m, u_softness);
1370
+
1371
+ vec4 c = u_colors[i];
1372
+ c.rgb *= c.a;
1373
+ gradient = mix(gradient, c, m);
1374
+ }
1375
+
1376
+ vec3 color = gradient.rgb;
1377
+ float opacity = gradient.a;
1378
+
1379
+ ${p}
1380
+
1381
+ fragColor = vec4(color, opacity);
1382
+ }
1383
+ `;var P={maxColorCount:5},ye=`#version 300 es
1384
+ precision mediump float;
1385
+
1386
+ uniform float u_time;
1387
+
1388
+ uniform sampler2D u_noiseTexture;
1389
+
1390
+ uniform vec4 u_colorBack;
1391
+ uniform vec4 u_colorBloom;
1392
+ uniform vec4 u_colors[${P.maxColorCount}];
1393
+ uniform float u_colorsCount;
1394
+
1395
+ uniform float u_density;
1396
+ uniform float u_spotty;
1397
+ uniform float u_midSize;
1398
+ uniform float u_midIntensity;
1399
+ uniform float u_intensity;
1400
+ uniform float u_bloom;
1401
+
1402
+ in vec2 v_objectUV;
1403
+
1404
+ out vec4 fragColor;
1405
+
1406
+ ${c}
1407
+ ${f}
1408
+ ${_}
1409
+ float valueNoise(vec2 st) {
1410
+ vec2 i = floor(st);
1411
+ vec2 f = fract(st);
1412
+ float a = randomR(i);
1413
+ float b = randomR(i + vec2(1.0, 0.0));
1414
+ float c = randomR(i + vec2(0.0, 1.0));
1415
+ float d = randomR(i + vec2(1.0, 1.0));
1416
+ vec2 u = f * f * (3.0 - 2.0 * f);
1417
+ float x1 = mix(a, b, u.x);
1418
+ float x2 = mix(c, d, u.x);
1419
+ return mix(x1, x2, u.y);
1420
+ }
1421
+
1422
+ ${w}
1423
+
1424
+ float raysShape(vec2 uv, float r, float freq, float intensity, float radius) {
1425
+ float a = atan(uv.y, uv.x);
1426
+ vec2 left = vec2(a * freq, r);
1427
+ vec2 right = vec2(fract(a / TWO_PI) * TWO_PI * freq, r);
1428
+ float n_left = pow(valueNoise(left), intensity);
1429
+ float n_right = pow(valueNoise(right), intensity);
1430
+ float shape = mix(n_right, n_left, smoothstep(-.15, .15, uv.x));
1431
+ return shape;
1432
+ }
1433
+
1434
+ void main() {
1435
+ vec2 shape_uv = v_objectUV;
1436
+
1437
+ float t = .2 * u_time;
1438
+
1439
+ float radius = length(shape_uv);
1440
+ float spots = 6.5 * abs(u_spotty);
1441
+
1442
+ float intensity = 4. - 3. * clamp(u_intensity, 0., 1.);
1443
+
1444
+ float delta = 1. - smoothstep(0., 1., radius);
1445
+
1446
+ float midSize = 10. * abs(u_midSize);
1447
+ float ms_lo = 0.02 * midSize;
1448
+ float ms_hi = max(midSize, 1e-6);
1449
+ float middleShape = pow(u_midIntensity, 0.3) * (1. - smoothstep(ms_lo, ms_hi, 3.0 * radius));
1450
+ middleShape = pow(middleShape, 5.0);
1451
+
1452
+ vec3 accumColor = vec3(0.0);
1453
+ float accumAlpha = 0.0;
1454
+
1455
+ for (int i = 0; i < ${P.maxColorCount}; i++) {
1456
+ if (i >= int(u_colorsCount)) break;
1457
+
1458
+ vec2 rotatedUV = rotate(shape_uv, float(i) + 1.0);
1459
+
1460
+ float r1 = radius * (1.0 + 0.4 * float(i)) - 3.0 * t;
1461
+ float r2 = 0.5 * radius * (1.0 + spots) - 2.0 * t;
1462
+ float density = 6. * u_density + step(.5, u_density) * pow(4.5 * (u_density - .5), 4.);
1463
+ float f = mix(1.0, 3.0 + 0.5 * float(i), hash11(float(i) * 15.)) * density;
1464
+
1465
+ float ray = raysShape(rotatedUV, r1, 5.0 * f, intensity, radius);
1466
+ ray *= raysShape(rotatedUV, r2, 4.0 * f, intensity, radius);
1467
+ ray += (1. + 4. * ray) * middleShape;
1468
+ ray = clamp(ray, 0.0, 1.0);
1469
+
1470
+ float srcAlpha = u_colors[i].a * ray;
1471
+ vec3 srcColor = u_colors[i].rgb * srcAlpha;
1472
+
1473
+ vec3 alphaBlendColor = accumColor + (1.0 - accumAlpha) * srcColor;
1474
+ float alphaBlendAlpha = accumAlpha + (1.0 - accumAlpha) * srcAlpha;
1475
+
1476
+ vec3 addBlendColor = accumColor + srcColor;
1477
+ float addBlendAlpha = accumAlpha + srcAlpha;
1478
+
1479
+ accumColor = mix(alphaBlendColor, addBlendColor, u_bloom);
1480
+ accumAlpha = mix(alphaBlendAlpha, addBlendAlpha, u_bloom);
1481
+ }
1482
+
1483
+ float overlayAlpha = u_colorBloom.a;
1484
+ vec3 overlayColor = u_colorBloom.rgb * overlayAlpha;
1485
+
1486
+ vec3 colorWithOverlay = accumColor + accumAlpha * overlayColor;
1487
+ accumColor = mix(accumColor, colorWithOverlay, u_bloom);
1488
+
1489
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1490
+
1491
+ vec3 color = accumColor + (1. - accumAlpha) * bgColor;
1492
+ float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;
1493
+ color = clamp(color, 0., 1.);
1494
+ opacity = clamp(opacity, 0., 1.);
1495
+
1496
+ ${p}
1497
+
1498
+ fragColor = vec4(color, opacity);
1499
+ }
1500
+ `,Ae=`#version 300 es
1501
+ precision mediump float;
1502
+
1503
+ uniform float u_time;
1504
+
1505
+ uniform vec4 u_colorBack;
1506
+ uniform vec4 u_colorFront;
1507
+ uniform float u_density;
1508
+ uniform float u_distortion;
1509
+ uniform float u_strokeWidth;
1510
+ uniform float u_strokeCap;
1511
+ uniform float u_strokeTaper;
1512
+ uniform float u_noise;
1513
+ uniform float u_noiseFrequency;
1514
+ uniform float u_softness;
1515
+
1516
+ in vec2 v_patternUV;
1517
+
1518
+ out vec4 fragColor;
1519
+
1520
+ ${c}
1521
+ ${h}
1522
+
1523
+ void main() {
1524
+ vec2 uv = 2. * v_patternUV;
1525
+
1526
+ float t = u_time;
1527
+ float l = length(uv);
1528
+ float density = clamp(u_density, 0., 1.);
1529
+ l = pow(max(l, 1e-6), density);
1530
+ float angle = atan(uv.y, uv.x) - t;
1531
+ float angleNormalised = angle / TWO_PI;
1532
+
1533
+ angleNormalised += .125 * u_noise * snoise(16. * pow(u_noiseFrequency, 3.) * uv);
1534
+
1535
+ float offset = l + angleNormalised;
1536
+ offset -= u_distortion * (sin(4. * l - .5 * t) * cos(PI + l + .5 * t));
1537
+ float stripe = fract(offset);
1538
+
1539
+ float shape = 2. * abs(stripe - .5);
1540
+ float width = 1. - clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);
1541
+
1542
+
1543
+ float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));
1544
+ width = mix(width, wCap, u_strokeCap);
1545
+ width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);
1546
+
1547
+ float fw = fwidth(offset);
1548
+ float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));
1549
+ float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));
1550
+ pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));
1551
+
1552
+ float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);
1553
+
1554
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
1555
+ float fgOpacity = u_colorFront.a;
1556
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1557
+ float bgOpacity = u_colorBack.a;
1558
+
1559
+ vec3 color = fgColor * res;
1560
+ float opacity = fgOpacity * res;
1561
+
1562
+ color += bgColor * (1. - opacity);
1563
+ opacity += bgOpacity * (1. - opacity);
1564
+
1565
+ ${p}
1566
+
1567
+ fragColor = vec4(color, opacity);
1568
+ }
1569
+ `,W={maxColorCount:10},be=`#version 300 es
1570
+ precision mediump float;
1571
+
1572
+ uniform float u_time;
1573
+
1574
+ uniform vec4 u_colorBack;
1575
+ uniform vec4 u_colors[${W.maxColorCount}];
1576
+ uniform float u_colorsCount;
1577
+ uniform float u_bandCount;
1578
+ uniform float u_twist;
1579
+ uniform float u_center;
1580
+ uniform float u_proportion;
1581
+ uniform float u_softness;
1582
+ uniform float u_noise;
1583
+ uniform float u_noiseFrequency;
1584
+
1585
+ in vec2 v_objectUV;
1586
+
1587
+ out vec4 fragColor;
1588
+
1589
+ ${c}
1590
+ ${h}
1591
+ ${f}
1592
+
1593
+ void main() {
1594
+ vec2 shape_uv = v_objectUV;
1595
+
1596
+ float l = length(shape_uv);
1597
+ l = max(1e-4, l);
1598
+
1599
+ float t = u_time;
1600
+
1601
+ float angle = ceil(u_bandCount) * atan(shape_uv.y, shape_uv.x) + t;
1602
+ float angle_norm = angle / TWO_PI;
1603
+
1604
+ float twist = 3. * clamp(u_twist, 0., 1.);
1605
+ float offset = pow(l, -twist) + angle_norm;
1606
+
1607
+ float shape = fract(offset);
1608
+ shape = 1. - abs(2. * shape - 1.);
1609
+ shape += u_noise * snoise(15. * pow(u_noiseFrequency, 2.) * shape_uv);
1610
+
1611
+ float mid = smoothstep(.2, .2 + .8 * u_center, pow(l, twist));
1612
+ shape = mix(0., shape, mid);
1613
+
1614
+ float proportion = clamp(u_proportion, 0., 1.);
1615
+ float exponent = mix(.25, 1., proportion * 2.);
1616
+ exponent = mix(exponent, 10., max(0., proportion * 2. - 1.));
1617
+ shape = pow(shape, exponent);
1618
+
1619
+ float mixer = shape * u_colorsCount;
1620
+ vec4 gradient = u_colors[0];
1621
+ gradient.rgb *= gradient.a;
1622
+
1623
+ float outerShape = 0.;
1624
+ for (int i = 1; i < ${W.maxColorCount+1}; i++) {
1625
+ if (i > int(u_colorsCount)) break;
1626
+
1627
+ float m = clamp(mixer - float(i - 1), 0., 1.);
1628
+ float aa = fwidth(m);
1629
+ m = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, m);
1630
+
1631
+ if (i == 1) {
1632
+ outerShape = m;
1633
+ }
1634
+
1635
+ vec4 c = u_colors[i - 1];
1636
+ c.rgb *= c.a;
1637
+ gradient = mix(gradient, c, m);
1638
+ }
1639
+
1640
+ float midAA = .1 * fwidth(pow(l, -twist));
1641
+ float outerMid = smoothstep(.2, .2 + midAA, pow(l, twist));
1642
+ outerShape = mix(0., outerShape, outerMid);
1643
+
1644
+ vec3 color = gradient.rgb * outerShape;
1645
+ float opacity = gradient.a * outerShape;
1646
+
1647
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1648
+ color = color + bgColor * (1.0 - opacity);
1649
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
1650
+
1651
+ ${p}
1652
+
1653
+ fragColor = vec4(color, opacity);
1654
+ }
1655
+ `,J=`#version 300 es
1656
+ precision mediump float;
1657
+
1658
+ uniform float u_time;
1659
+
1660
+ uniform vec2 u_resolution;
1661
+ uniform float u_pixelRatio;
1662
+ uniform float u_originX;
1663
+ uniform float u_originY;
1664
+ uniform float u_worldWidth;
1665
+ uniform float u_worldHeight;
1666
+ uniform float u_fit;
1667
+ uniform float u_scale;
1668
+ uniform float u_rotation;
1669
+ uniform float u_offsetX;
1670
+ uniform float u_offsetY;
1671
+
1672
+ uniform float u_pxSize;
1673
+ uniform vec4 u_colorBack;
1674
+ uniform vec4 u_colorFront;
1675
+ uniform float u_shape;
1676
+ uniform float u_type;
1677
+
1678
+ out vec4 fragColor;
1679
+
1680
+ ${h}
1681
+ ${c}
1682
+ ${w}
1683
+ ${g}
1684
+
1685
+ float getSimplexNoise(vec2 uv, float t) {
1686
+ float noise = .5 * snoise(uv - vec2(0., .3 * t));
1687
+ noise += .5 * snoise(2. * uv + vec2(0., .32 * t));
1688
+
1689
+ return noise;
1690
+ }
1691
+
1692
+ const int bayer2x2[4] = int[4](0, 2, 3, 1);
1693
+ const int bayer4x4[16] = int[16](
1694
+ 0, 8, 2, 10,
1695
+ 12, 4, 14, 6,
1696
+ 3, 11, 1, 9,
1697
+ 15, 7, 13, 5
1698
+ );
1699
+
1700
+ const int bayer8x8[64] = int[64](
1701
+ 0, 32, 8, 40, 2, 34, 10, 42,
1702
+ 48, 16, 56, 24, 50, 18, 58, 26,
1703
+ 12, 44, 4, 36, 14, 46, 6, 38,
1704
+ 60, 28, 52, 20, 62, 30, 54, 22,
1705
+ 3, 35, 11, 43, 1, 33, 9, 41,
1706
+ 51, 19, 59, 27, 49, 17, 57, 25,
1707
+ 15, 47, 7, 39, 13, 45, 5, 37,
1708
+ 63, 31, 55, 23, 61, 29, 53, 21
1709
+ );
1710
+
1711
+ float getBayerValue(vec2 uv, int size) {
1712
+ ivec2 pos = ivec2(fract(uv / float(size)) * float(size));
1713
+ int index = pos.y * size + pos.x;
1714
+
1715
+ if (size == 2) {
1716
+ return float(bayer2x2[index]) / 4.0;
1717
+ } else if (size == 4) {
1718
+ return float(bayer4x4[index]) / 16.0;
1719
+ } else if (size == 8) {
1720
+ return float(bayer8x8[index]) / 64.0;
1721
+ }
1722
+ return 0.0;
1723
+ }
1724
+
1725
+
1726
+ void main() {
1727
+ float t = .5 * u_time;
1728
+
1729
+ float pxSize = u_pxSize * u_pixelRatio;
1730
+ vec2 pxSizeUV = gl_FragCoord.xy - .5 * u_resolution;
1731
+ pxSizeUV /= pxSize;
1732
+ vec2 canvasPixelizedUV = (floor(pxSizeUV) + .5) * pxSize;
1733
+ vec2 normalizedUV = canvasPixelizedUV / u_resolution;
1734
+
1735
+ vec2 ditheringNoiseUV = canvasPixelizedUV;
1736
+ vec2 shapeUV = normalizedUV;
1737
+
1738
+ vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
1739
+ vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
1740
+ givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
1741
+ float r = u_rotation * PI / 180.;
1742
+ mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
1743
+ vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
1744
+
1745
+ float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
1746
+ vec2 boxSize = vec2(
1747
+ (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
1748
+ (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
1749
+ );
1750
+
1751
+ if (u_shape > 3.5) {
1752
+ vec2 objectBoxSize = vec2(0.);
1753
+ // fit = none
1754
+ objectBoxSize.x = min(boxSize.x, boxSize.y);
1755
+ if (u_fit == 1.) { // fit = contain
1756
+ objectBoxSize.x = min(u_resolution.x, u_resolution.y);
1757
+ } else if (u_fit == 2.) { // fit = cover
1758
+ objectBoxSize.x = max(u_resolution.x, u_resolution.y);
1759
+ }
1760
+ objectBoxSize.y = objectBoxSize.x;
1761
+ vec2 objectWorldScale = u_resolution.xy / objectBoxSize;
1762
+
1763
+ shapeUV *= objectWorldScale;
1764
+ shapeUV += boxOrigin * (objectWorldScale - 1.);
1765
+ shapeUV += vec2(-u_offsetX, u_offsetY);
1766
+ shapeUV /= u_scale;
1767
+ shapeUV = graphicRotation * shapeUV;
1768
+ } else {
1769
+ vec2 patternBoxSize = vec2(0.);
1770
+ // fit = none
1771
+ patternBoxSize.x = patternBoxRatio * min(boxSize.x / patternBoxRatio, boxSize.y);
1772
+ float patternWorldNoFitBoxWidth = patternBoxSize.x;
1773
+ if (u_fit == 1.) { // fit = contain
1774
+ patternBoxSize.x = patternBoxRatio * min(u_resolution.x / patternBoxRatio, u_resolution.y);
1775
+ } else if (u_fit == 2.) { // fit = cover
1776
+ patternBoxSize.x = patternBoxRatio * max(u_resolution.x / patternBoxRatio, u_resolution.y);
1777
+ }
1778
+ patternBoxSize.y = patternBoxSize.x / patternBoxRatio;
1779
+ vec2 patternWorldScale = u_resolution.xy / patternBoxSize;
1780
+
1781
+ shapeUV += vec2(-u_offsetX, u_offsetY) / patternWorldScale;
1782
+ shapeUV += boxOrigin;
1783
+ shapeUV -= boxOrigin / patternWorldScale;
1784
+ shapeUV *= u_resolution.xy;
1785
+ shapeUV /= u_pixelRatio;
1786
+ if (u_fit > 0.) {
1787
+ shapeUV *= (patternWorldNoFitBoxWidth / patternBoxSize.x);
1788
+ }
1789
+ shapeUV /= u_scale;
1790
+ shapeUV = graphicRotation * shapeUV;
1791
+ shapeUV += boxOrigin / patternWorldScale;
1792
+ shapeUV -= boxOrigin;
1793
+ shapeUV += .5;
1794
+ }
1795
+
1796
+ float shape = 0.;
1797
+ if (u_shape < 1.5) {
1798
+ // Simplex noise
1799
+ shapeUV *= .001;
1800
+
1801
+ shape = 0.5 + 0.5 * getSimplexNoise(shapeUV, t);
1802
+ shape = smoothstep(0.3, 0.9, shape);
1803
+
1804
+ } else if (u_shape < 2.5) {
1805
+ // Warp
1806
+ shapeUV *= .003;
1807
+
1808
+ for (float i = 1.0; i < 6.0; i++) {
1809
+ shapeUV.x += 0.6 / i * cos(i * 2.5 * shapeUV.y + t);
1810
+ shapeUV.y += 0.6 / i * cos(i * 1.5 * shapeUV.x + t);
1811
+ }
1812
+
1813
+ shape = .15 / max(0.001, abs(sin(t - shapeUV.y - shapeUV.x)));
1814
+ shape = smoothstep(0.02, 1., shape);
1815
+
1816
+ } else if (u_shape < 3.5) {
1817
+ // Dots
1818
+ shapeUV *= .05;
1819
+
1820
+ float stripeIdx = floor(2. * shapeUV.x / TWO_PI);
1821
+ float rand = hash11(stripeIdx * 10.);
1822
+ rand = sign(rand - .5) * pow(.1 + abs(rand), .4);
1823
+ shape = sin(shapeUV.x) * cos(shapeUV.y - 5. * rand * t);
1824
+ shape = pow(abs(shape), 6.);
1825
+
1826
+ } else if (u_shape < 4.5) {
1827
+ // Sine wave
1828
+ shapeUV *= 4.;
1829
+
1830
+ float wave = cos(.5 * shapeUV.x - 2. * t) * sin(1.5 * shapeUV.x + t) * (.75 + .25 * cos(3. * t));
1831
+ shape = 1. - smoothstep(-1., 1., shapeUV.y + wave);
1832
+
1833
+ } else if (u_shape < 5.5) {
1834
+ // Ripple
1835
+
1836
+ float dist = length(shapeUV);
1837
+ float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;
1838
+ shape = waves;
1839
+
1840
+ } else if (u_shape < 6.5) {
1841
+ // Swirl
1842
+
1843
+ float l = length(shapeUV);
1844
+ float angle = 6. * atan(shapeUV.y, shapeUV.x) + 4. * t;
1845
+ float twist = 1.2;
1846
+ float offset = 1. / pow(max(l, 1e-6), twist) + angle / TWO_PI;
1847
+ float mid = smoothstep(0., 1., pow(l, twist));
1848
+ shape = mix(0., fract(offset), mid);
1849
+
1850
+ } else {
1851
+ // Sphere
1852
+ shapeUV *= 2.;
1853
+
1854
+ float d = 1. - pow(length(shapeUV), 2.);
1855
+ vec3 pos = vec3(shapeUV, sqrt(max(0., d)));
1856
+ vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
1857
+ shape = .5 + .5 * dot(lightPos, pos);
1858
+ shape *= step(0., d);
1859
+ }
1860
+
1861
+
1862
+ int type = int(floor(u_type));
1863
+ float dithering = 0.0;
1864
+
1865
+ switch (type) {
1866
+ case 1: {
1867
+ dithering = step(hash21(ditheringNoiseUV), shape);
1868
+ } break;
1869
+ case 2:
1870
+ dithering = getBayerValue(pxSizeUV, 2);
1871
+ break;
1872
+ case 3:
1873
+ dithering = getBayerValue(pxSizeUV, 4);
1874
+ break;
1875
+ default :
1876
+ dithering = getBayerValue(pxSizeUV, 8);
1877
+ break;
1878
+ }
1879
+
1880
+ dithering -= .5;
1881
+ float res = step(.5, shape + dithering);
1882
+
1883
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
1884
+ float fgOpacity = u_colorFront.a;
1885
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
1886
+ float bgOpacity = u_colorBack.a;
1887
+
1888
+ vec3 color = fgColor * res;
1889
+ float opacity = fgOpacity * res;
1890
+
1891
+ color += bgColor * (1. - opacity);
1892
+ opacity += bgOpacity * (1. - opacity);
1893
+
1894
+ fragColor = vec4(color, opacity);
1895
+ }
1896
+ `,B={simplex:1,warp:2,dots:3,wave:4,ripple:5,swirl:6,sphere:7},S={random:1,"2x2":2,"4x4":3,"8x8":4},Y={maxColorCount:7},Ce=`#version 300 es
1897
+ precision lowp float;
1898
+
1899
+ uniform mediump float u_time;
1900
+ uniform mediump vec2 u_resolution;
1901
+ uniform mediump float u_pixelRatio;
1902
+
1903
+ uniform sampler2D u_noiseTexture;
1904
+
1905
+ uniform vec4 u_colorBack;
1906
+ uniform vec4 u_colors[${Y.maxColorCount}];
1907
+ uniform float u_colorsCount;
1908
+ uniform float u_softness;
1909
+ uniform float u_intensity;
1910
+ uniform float u_noise;
1911
+ uniform float u_shape;
1912
+
1913
+ uniform mediump float u_originX;
1914
+ uniform mediump float u_originY;
1915
+ uniform mediump float u_worldWidth;
1916
+ uniform mediump float u_worldHeight;
1917
+ uniform mediump float u_fit;
1918
+
1919
+ uniform mediump float u_scale;
1920
+ uniform mediump float u_rotation;
1921
+ uniform mediump float u_offsetX;
1922
+ uniform mediump float u_offsetY;
1923
+
1924
+ in vec2 v_objectUV;
1925
+ in vec2 v_patternUV;
1926
+ in vec2 v_objectBoxSize;
1927
+ in vec2 v_patternBoxSize;
1928
+
1929
+ out vec4 fragColor;
1930
+
1931
+ ${c}
1932
+ ${h}
1933
+ ${f}
1934
+ ${_}
1935
+
1936
+ float valueNoiseR(vec2 st) {
1937
+ vec2 i = floor(st);
1938
+ vec2 f = fract(st);
1939
+ float a = randomR(i);
1940
+ float b = randomR(i + vec2(1.0, 0.0));
1941
+ float c = randomR(i + vec2(0.0, 1.0));
1942
+ float d = randomR(i + vec2(1.0, 1.0));
1943
+ vec2 u = f * f * (3.0 - 2.0 * f);
1944
+ float x1 = mix(a, b, u.x);
1945
+ float x2 = mix(c, d, u.x);
1946
+ return mix(x1, x2, u.y);
1947
+ }
1948
+ vec4 fbmR(vec2 n0, vec2 n1, vec2 n2, vec2 n3) {
1949
+ float amplitude = 0.2;
1950
+ vec4 total = vec4(0.);
1951
+ for (int i = 0; i < 3; i++) {
1952
+ n0 = rotate(n0, 0.3);
1953
+ n1 = rotate(n1, 0.3);
1954
+ n2 = rotate(n2, 0.3);
1955
+ n3 = rotate(n3, 0.3);
1956
+ total.x += valueNoiseR(n0) * amplitude;
1957
+ total.y += valueNoiseR(n1) * amplitude;
1958
+ total.z += valueNoiseR(n2) * amplitude;
1959
+ total.z += valueNoiseR(n3) * amplitude;
1960
+ n0 *= 1.99;
1961
+ n1 *= 1.99;
1962
+ n2 *= 1.99;
1963
+ n3 *= 1.99;
1964
+ amplitude *= 0.6;
1965
+ }
1966
+ return total;
1967
+ }
1968
+
1969
+ ${w}
1970
+
1971
+ vec2 truchet(vec2 uv, float idx){
1972
+ idx = fract(((idx - .5) * 2.));
1973
+ if (idx > 0.75) {
1974
+ uv = vec2(1.0) - uv;
1975
+ } else if (idx > 0.5) {
1976
+ uv = vec2(1.0 - uv.x, uv.y);
1977
+ } else if (idx > 0.25) {
1978
+ uv = 1.0 - vec2(1.0 - uv.x, uv.y);
1979
+ }
1980
+ return uv;
1981
+ }
1982
+
1983
+ void main() {
1984
+
1985
+ const float firstFrameOffset = 7.;
1986
+ float t = .1 * (u_time + firstFrameOffset);
1987
+
1988
+ vec2 shape_uv = vec2(0.);
1989
+ vec2 grain_uv = vec2(0.);
1990
+
1991
+ float r = u_rotation * PI / 180.;
1992
+ float cr = cos(r);
1993
+ float sr = sin(r);
1994
+ mat2 graphicRotation = mat2(cr, sr, -sr, cr);
1995
+ vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
1996
+
1997
+ if (u_shape > 3.5) {
1998
+ shape_uv = v_objectUV;
1999
+ grain_uv = shape_uv;
2000
+
2001
+ // apply inverse transform to grain_uv so it respects the originXY
2002
+ grain_uv = transpose(graphicRotation) * grain_uv;
2003
+ grain_uv *= u_scale;
2004
+ grain_uv -= graphicOffset;
2005
+ grain_uv *= v_objectBoxSize;
2006
+ grain_uv *= .7;
2007
+ } else {
2008
+ shape_uv = .5 * v_patternUV;
2009
+ grain_uv = 100. * v_patternUV;
2010
+
2011
+ // apply inverse transform to grain_uv so it respects the originXY
2012
+ grain_uv = transpose(graphicRotation) * grain_uv;
2013
+ grain_uv *= u_scale;
2014
+ if (u_fit > 0.) {
2015
+ vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
2016
+ givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
2017
+ float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
2018
+ vec2 patternBoxGivenSize = vec2(
2019
+ (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
2020
+ (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
2021
+ );
2022
+ patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;
2023
+ float patternBoxNoFitBoxWidth = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);
2024
+ grain_uv /= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);
2025
+ }
2026
+ vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;
2027
+ grain_uv -= graphicOffset / patternBoxScale;
2028
+ grain_uv *= 1.6;
2029
+ }
2030
+
2031
+
2032
+ float shape = 0.;
2033
+
2034
+ if (u_shape < 1.5) {
2035
+ // Sine wave
2036
+
2037
+ float wave = cos(.5 * shape_uv.x - 4. * t) * sin(1.5 * shape_uv.x + 2. * t) * (.75 + .25 * cos(6. * t));
2038
+ shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
2039
+
2040
+ } else if (u_shape < 2.5) {
2041
+ // Grid (dots)
2042
+
2043
+ float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
2044
+ float rand = hash11(stripeIdx * 100.);
2045
+ rand = sign(rand - .5) * pow(4. * abs(rand), .3);
2046
+ shape = sin(shape_uv.x) * cos(shape_uv.y - 5. * rand * t);
2047
+ shape = pow(abs(shape), 4.);
2048
+
2049
+ } else if (u_shape < 3.5) {
2050
+ // Truchet pattern
2051
+
2052
+ float n2 = valueNoiseR(shape_uv * .4 - 3.75 * t);
2053
+ shape_uv.x += 10.;
2054
+ shape_uv *= .6;
2055
+
2056
+ vec2 tile = truchet(fract(shape_uv), randomR(floor(shape_uv)));
2057
+
2058
+ float distance1 = length(tile);
2059
+ float distance2 = length(tile - vec2(1.));
2060
+
2061
+ n2 -= .5;
2062
+ n2 *= .1;
2063
+ shape = smoothstep(.2, .55, distance1 + n2) * (1. - smoothstep(.45, .8, distance1 - n2));
2064
+ shape += smoothstep(.2, .55, distance2 + n2) * (1. - smoothstep(.45, .8, distance2 - n2));
2065
+
2066
+ shape = pow(shape, 1.5);
2067
+
2068
+ } else if (u_shape < 4.5) {
2069
+ // Corners
2070
+
2071
+ shape_uv *= .6;
2072
+ vec2 outer = vec2(.5);
2073
+
2074
+ vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * sin(5.25 * t)));
2075
+ vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
2076
+ shape = 1. - bl.x * bl.y * tr.x * tr.y;
2077
+
2078
+ shape_uv = -shape_uv;
2079
+ bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * cos(5.25 * t)));
2080
+ tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
2081
+ shape -= bl.x * bl.y * tr.x * tr.y;
2082
+
2083
+ shape = 1. - smoothstep(0., 1., shape);
2084
+
2085
+ } else if (u_shape < 5.5) {
2086
+ // Ripple
2087
+
2088
+ shape_uv *= 2.;
2089
+ float dist = length(.4 * shape_uv);
2090
+ float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;
2091
+ shape = waves;
2092
+
2093
+ } else if (u_shape < 6.5) {
2094
+ // Blob
2095
+
2096
+ t *= 2.;
2097
+
2098
+ vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));
2099
+ vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));
2100
+ vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));
2101
+ vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));
2102
+
2103
+ shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);
2104
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);
2105
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);
2106
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);
2107
+
2108
+ shape = smoothstep(.0, .9, shape);
2109
+ float edge = smoothstep(.25, .3, shape);
2110
+ shape = mix(.0, shape, edge);
2111
+
2112
+ } else {
2113
+ // Sphere
2114
+
2115
+ shape_uv *= 2.;
2116
+ float d = 1. - pow(length(shape_uv), 2.);
2117
+ vec3 pos = vec3(shape_uv, sqrt(max(d, 0.)));
2118
+ vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
2119
+ shape = .5 + .5 * dot(lightPos, pos);
2120
+ shape *= step(0., d);
2121
+ }
2122
+
2123
+ float baseNoise = snoise(grain_uv * .5);
2124
+ vec4 fbmVals = fbmR(
2125
+ .002 * grain_uv + 10.,
2126
+ .003 * grain_uv,
2127
+ .001 * grain_uv,
2128
+ rotate(.4 * grain_uv, 2.)
2129
+ );
2130
+ float grainDist = baseNoise * snoise(grain_uv * .2) - fbmVals.x - fbmVals.y;
2131
+ float rawNoise = .75 * baseNoise - fbmVals.w - fbmVals.z;
2132
+ float noise = clamp(rawNoise, 0., 1.);
2133
+
2134
+ shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);
2135
+ shape += u_noise * 10. / u_colorsCount * noise;
2136
+
2137
+ float aa = fwidth(shape);
2138
+
2139
+ shape = clamp(shape - .5 / u_colorsCount, 0., 1.);
2140
+ float totalShape = smoothstep(0., u_softness + 2. * aa, clamp(shape * u_colorsCount, 0., 1.));
2141
+ float mixer = shape * (u_colorsCount - 1.);
2142
+
2143
+ int cntStop = int(u_colorsCount) - 1;
2144
+ vec4 gradient = u_colors[0];
2145
+ gradient.rgb *= gradient.a;
2146
+ for (int i = 1; i < ${Y.maxColorCount}; i++) {
2147
+ if (i > cntStop) break;
2148
+
2149
+ float localT = clamp(mixer - float(i - 1), 0., 1.);
2150
+ localT = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, localT);
2151
+
2152
+ vec4 c = u_colors[i];
2153
+ c.rgb *= c.a;
2154
+ gradient = mix(gradient, c, localT);
2155
+ }
2156
+
2157
+ vec3 color = gradient.rgb * totalShape;
2158
+ float opacity = gradient.a * totalShape;
2159
+
2160
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
2161
+ color = color + bgColor * (1.0 - opacity);
2162
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
2163
+
2164
+ fragColor = vec4(color, opacity);
2165
+ }
2166
+ `;var I={maxColorCount:5,maxSpots:4},we=`#version 300 es
2167
+ precision lowp float;
2168
+
2169
+ uniform float u_time;
2170
+
2171
+ uniform vec4 u_colorBack;
2172
+ uniform vec4 u_colors[${I.maxColorCount}];
2173
+ uniform float u_colorsCount;
2174
+ uniform float u_roundness;
2175
+ uniform float u_thickness;
2176
+ uniform float u_marginLeft;
2177
+ uniform float u_marginRight;
2178
+ uniform float u_marginTop;
2179
+ uniform float u_marginBottom;
2180
+ uniform float u_aspectRatio;
2181
+ uniform float u_softness;
2182
+ uniform float u_intensity;
2183
+ uniform float u_bloom;
2184
+ uniform float u_spotSize;
2185
+ uniform float u_spots;
2186
+ uniform float u_pulse;
2187
+ uniform float u_smoke;
2188
+ uniform float u_smokeSize;
2189
+
2190
+ uniform sampler2D u_noiseTexture;
2191
+
2192
+ in vec2 v_responsiveUV;
2193
+ in vec2 v_responsiveBoxGivenSize;
2194
+ in vec2 v_patternUV;
2195
+
2196
+ out vec4 fragColor;
2197
+
2198
+ ${c}
2199
+
2200
+ float beat(float time) {
2201
+ float first = pow(abs(sin(time * TWO_PI)), 10.);
2202
+ float second = pow(abs(sin((time - .15) * TWO_PI)), 10.);
2203
+
2204
+ return clamp(first + 0.6 * second, 0.0, 1.0);
2205
+ }
2206
+
2207
+ float sst(float edge0, float edge1, float x) {
2208
+ return smoothstep(edge0, edge1, x);
2209
+ }
2210
+
2211
+ float roundedBox(vec2 uv, vec2 halfSize, float distance, float cornerDistance, float thickness, float softness) {
2212
+ float borderDistance = abs(distance);
2213
+ float aa = 2. * fwidth(distance);
2214
+ float border = 1. - sst(min(mix(thickness, -thickness, softness), thickness + aa), max(mix(thickness, -thickness, softness), thickness + aa), borderDistance);
2215
+ float cornerFadeCircles = 0.;
2216
+ cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv + halfSize) / thickness)));
2217
+ cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(-halfSize.x, halfSize.y)) / thickness)));
2218
+ cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(halfSize.x, -halfSize.y)) / thickness)));
2219
+ cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - halfSize) / thickness)));
2220
+ aa = fwidth(cornerDistance);
2221
+ float cornerFade = sst(0., mix(aa, thickness, softness), cornerDistance);
2222
+ cornerFade *= cornerFadeCircles;
2223
+ border += cornerFade;
2224
+ return border;
2225
+ }
2226
+
2227
+ ${E}
2228
+
2229
+ float randomG(vec2 p) {
2230
+ vec2 uv = floor(p) / 100. + .5;
2231
+ return texture(u_noiseTexture, fract(uv)).g;
2232
+ }
2233
+ float valueNoise(vec2 st) {
2234
+ vec2 i = floor(st);
2235
+ vec2 f = fract(st);
2236
+ float a = randomG(i);
2237
+ float b = randomG(i + vec2(1.0, 0.0));
2238
+ float c = randomG(i + vec2(0.0, 1.0));
2239
+ float d = randomG(i + vec2(1.0, 1.0));
2240
+ vec2 u = f * f * (3.0 - 2.0 * f);
2241
+ float x1 = mix(a, b, u.x);
2242
+ float x2 = mix(c, d, u.x);
2243
+ return mix(x1, x2, u.y);
2244
+ }
2245
+
2246
+ void main() {
2247
+ const float firstFrameOffset = 109.;
2248
+ float t = 1.2 * (u_time + firstFrameOffset);
2249
+
2250
+ vec2 borderUV = v_responsiveUV;
2251
+ float pulse = u_pulse * beat(.18 * u_time);
2252
+
2253
+ float canvasRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
2254
+ vec2 halfSize = vec2(.5);
2255
+ borderUV.x *= max(canvasRatio, 1.);
2256
+ borderUV.y /= min(canvasRatio, 1.);
2257
+ halfSize.x *= max(canvasRatio, 1.);
2258
+ halfSize.y /= min(canvasRatio, 1.);
2259
+
2260
+ float mL = u_marginLeft;
2261
+ float mR = u_marginRight;
2262
+ float mT = u_marginTop;
2263
+ float mB = u_marginBottom;
2264
+ float mX = mL + mR;
2265
+ float mY = mT + mB;
2266
+
2267
+ if (u_aspectRatio > 0.) {
2268
+ float shapeRatio = canvasRatio * (1. - mX) / max(1. - mY, 1e-6);
2269
+ float freeX = shapeRatio > 1. ? (1. - mX) * (1. - 1. / max(abs(shapeRatio), 1e-6)) : 0.;
2270
+ float freeY = shapeRatio < 1. ? (1. - mY) * (1. - shapeRatio) : 0.;
2271
+ mL += freeX * 0.5;
2272
+ mR += freeX * 0.5;
2273
+ mT += freeY * 0.5;
2274
+ mB += freeY * 0.5;
2275
+ mX = mL + mR;
2276
+ mY = mT + mB;
2277
+ }
2278
+
2279
+ float thickness = .5 * u_thickness * min(halfSize.x, halfSize.y);
2280
+
2281
+ halfSize.x *= (1. - mX);
2282
+ halfSize.y *= (1. - mY);
2283
+
2284
+ vec2 centerShift = vec2(
2285
+ (mL - mR) * max(canvasRatio, 1.) * 0.5,
2286
+ (mB - mT) / min(canvasRatio, 1.) * 0.5
2287
+ );
2288
+
2289
+ borderUV -= centerShift;
2290
+ halfSize -= mix(thickness, 0., u_softness);
2291
+
2292
+ float radius = mix(0., min(halfSize.x, halfSize.y), u_roundness);
2293
+ vec2 d = abs(borderUV) - halfSize + radius;
2294
+ float outsideDistance = length(max(d, .0001)) - radius;
2295
+ float insideDistance = min(max(d.x, d.y), .0001);
2296
+ float cornerDistance = abs(min(max(d.x, d.y) - .45 * radius, .0));
2297
+ float distance = outsideDistance + insideDistance;
2298
+
2299
+ float borderThickness = mix(thickness, 3. * thickness, u_softness);
2300
+ float border = roundedBox(borderUV, halfSize, distance, cornerDistance, borderThickness, u_softness);
2301
+ border = pow(border, 1. + u_softness);
2302
+
2303
+ vec2 smokeUV = .3 * u_smokeSize * v_patternUV;
2304
+ float smoke = clamp(3. * valueNoise(2.7 * smokeUV + .5 * t), 0., 1.);
2305
+ smoke -= valueNoise(3.4 * smokeUV - .5 * t);
2306
+ float smokeThickness = thickness + .2;
2307
+ smokeThickness = min(.4, max(smokeThickness, .1));
2308
+ smoke *= roundedBox(borderUV, halfSize, distance, cornerDistance, smokeThickness, 1.);
2309
+ smoke = 30. * smoke * smoke;
2310
+ smoke *= mix(0., .5, pow(u_smoke, 2.));
2311
+ smoke *= mix(1., pulse, u_pulse);
2312
+ smoke = clamp(smoke, 0., 1.);
2313
+ border += smoke;
2314
+
2315
+ border = clamp(border, 0., 1.);
2316
+
2317
+ vec3 blendColor = vec3(0.);
2318
+ float blendAlpha = 0.;
2319
+ vec3 addColor = vec3(0.);
2320
+ float addAlpha = 0.;
2321
+
2322
+ float bloom = 4. * u_bloom;
2323
+ float intensity = 1. + (1. + 4. * u_softness) * u_intensity;
2324
+
2325
+ float angle = atan(borderUV.y, borderUV.x) / TWO_PI;
2326
+
2327
+ for (int colorIdx = 0; colorIdx < ${I.maxColorCount}; colorIdx++) {
2328
+ if (colorIdx >= int(u_colorsCount)) break;
2329
+ float colorIdxF = float(colorIdx);
2330
+
2331
+ vec3 c = u_colors[colorIdx].rgb * u_colors[colorIdx].a;
2332
+ float a = u_colors[colorIdx].a;
2333
+
2334
+ for (int spotIdx = 0; spotIdx < ${I.maxSpots}; spotIdx++) {
2335
+ if (spotIdx >= int(u_spots)) break;
2336
+ float spotIdxF = float(spotIdx);
2337
+
2338
+ vec2 randVal = randomGB(vec2(spotIdxF * 10. + 2., 40. + colorIdxF));
2339
+
2340
+ float time = (.1 + .15 * abs(sin(spotIdxF * (2. + colorIdxF)) * cos(spotIdxF * (2. + 2.5 * colorIdxF)))) * t + randVal.x * 3.;
2341
+ time *= mix(1., -1., step(.5, randVal.y));
2342
+
2343
+ float mask = .5 + .5 * mix(
2344
+ sin(t + spotIdxF * (5. - 1.5 * colorIdxF)),
2345
+ cos(t + spotIdxF * (3. + 1.3 * colorIdxF)),
2346
+ step(mod(colorIdxF, 2.), .5)
2347
+ );
2348
+
2349
+ float p = clamp(2. * u_pulse - randVal.x, 0., 1.);
2350
+ mask = mix(mask, pulse, p);
2351
+
2352
+ float atg1 = fract(angle + time);
2353
+ float spotSize = .05 + .6 * pow(u_spotSize, 2.) + .05 * randVal.x;
2354
+ spotSize = mix(spotSize, .1, p);
2355
+ float sector = sst(.5 - spotSize, .5, atg1) * (1. - sst(.5, .5 + spotSize, atg1));
2356
+
2357
+ sector *= mask;
2358
+ sector *= border;
2359
+ sector *= intensity;
2360
+ sector = clamp(sector, 0., 1.);
2361
+
2362
+ vec3 srcColor = c * sector;
2363
+ float srcAlpha = a * sector;
2364
+
2365
+ blendColor += ((1. - blendAlpha) * srcColor);
2366
+ blendAlpha = blendAlpha + (1. - blendAlpha) * srcAlpha;
2367
+ addColor += srcColor;
2368
+ addAlpha += srcAlpha;
2369
+ }
2370
+ }
2371
+
2372
+ vec3 accumColor = mix(blendColor, addColor, bloom);
2373
+ float accumAlpha = mix(blendAlpha, addAlpha, bloom);
2374
+ accumAlpha = clamp(accumAlpha, 0., 1.);
2375
+
2376
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
2377
+ vec3 color = accumColor + (1. - accumAlpha) * bgColor;
2378
+ float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;
2379
+
2380
+ ${p}
2381
+
2382
+ fragColor = vec4(color, opacity);
2383
+ }`;var F={maxColorCount:7},Be=`#version 300 es
2384
+ precision lowp float;
2385
+
2386
+ uniform float u_time;
2387
+ uniform mediump float u_scale;
2388
+
2389
+ uniform vec4 u_colors[${F.maxColorCount}];
2390
+ uniform float u_colorsCount;
2391
+ uniform vec4 u_colorBack;
2392
+ uniform float u_density;
2393
+ uniform float u_angle1;
2394
+ uniform float u_angle2;
2395
+ uniform float u_length;
2396
+ uniform bool u_edges;
2397
+ uniform float u_blur;
2398
+ uniform float u_fadeIn;
2399
+ uniform float u_fadeOut;
2400
+ uniform float u_gradient;
2401
+
2402
+ in vec2 v_objectUV;
2403
+
2404
+ out vec4 fragColor;
2405
+
2406
+ ${c}
2407
+
2408
+ const float zLimit = .5;
2409
+
2410
+ vec2 getPanel(float angle, vec2 uv, float invLength, float aa) {
2411
+ float sinA = sin(angle);
2412
+ float cosA = cos(angle);
2413
+
2414
+ float denom = sinA - uv.y * cosA;
2415
+ if (abs(denom) < .01) return vec2(0.);
2416
+
2417
+ float z = uv.y / denom;
2418
+
2419
+ if (z <= 0. || z > zLimit) return vec2(0.);
2420
+
2421
+ float zRatio = z / zLimit;
2422
+ float panelMap = 1. - zRatio;
2423
+ float x = uv.x * (cosA * z + 1.) * invLength;
2424
+
2425
+ float zOffset = zRatio - .5;
2426
+ float left = -.5 + zOffset * u_angle1;
2427
+ float right = .5 - zOffset * u_angle2;
2428
+ float blurX = aa + 2. * panelMap * u_blur;
2429
+
2430
+ float leftEdge1 = left - blurX;
2431
+ float leftEdge2 = left + .25 * blurX;
2432
+ float rightEdge1 = right - .25 * blurX;
2433
+ float rightEdge2 = right + blurX;
2434
+
2435
+ float panel = smoothstep(leftEdge1, leftEdge2, x) * (1.0 - smoothstep(rightEdge1, rightEdge2, x));
2436
+ panel *= mix(0., panel, smoothstep(0., .01 / max(u_scale, 1e-6), panelMap));
2437
+
2438
+ float midScreen = abs(sinA);
2439
+ if (u_edges == true) {
2440
+ panelMap = mix(.99, panelMap, panel * clamp(panelMap / (.15 * (1. - pow(midScreen, .1))), 0.0, 1.0));
2441
+ } else if (midScreen < .07) {
2442
+ panel *= (midScreen * 15.);
2443
+ }
2444
+
2445
+ return vec2(panel, panelMap);
2446
+ }
2447
+
2448
+ vec4 blendColor(vec4 colorA, float panelMask, float panelMap) {
2449
+ float fade = 1. - smoothstep(.97 - .97 * u_fadeIn, 1., panelMap);
2450
+
2451
+ fade *= smoothstep(-.2 * (1. - u_fadeOut), u_fadeOut, panelMap);
2452
+
2453
+ vec3 blendedRGB = mix(vec3(0.), colorA.rgb, fade);
2454
+ float blendedAlpha = mix(0., colorA.a, fade);
2455
+
2456
+ return vec4(blendedRGB, blendedAlpha) * panelMask;
2457
+ }
2458
+
2459
+ void main() {
2460
+ vec2 uv = v_objectUV;
2461
+ uv *= 1.25;
2462
+
2463
+ float t = .02 * u_time;
2464
+ t = fract(t);
2465
+ bool reverseTime = (t < 0.5);
2466
+
2467
+ vec3 color = vec3(0.);
2468
+ float opacity = 0.;
2469
+
2470
+ float aa = .005 / u_scale;
2471
+ int colorsCount = int(u_colorsCount);
2472
+
2473
+ vec4 premultipliedColors[${F.maxColorCount}];
2474
+ for (int i = 0; i < ${F.maxColorCount}; i++) {
2475
+ if (i >= colorsCount) break;
2476
+ vec4 c = u_colors[i];
2477
+ c.rgb *= c.a;
2478
+ premultipliedColors[i] = c;
2479
+ }
2480
+
2481
+ float invLength = 1.5 / max(u_length, .001);
2482
+
2483
+ float totalColorWeight = 0.;
2484
+ int panelsNumber = 12;
2485
+
2486
+ float densityNormalizer = 1.;
2487
+ if (colorsCount == 4) {
2488
+ panelsNumber = 16;
2489
+ densityNormalizer = 1.34;
2490
+ } else if (colorsCount == 5) {
2491
+ panelsNumber = 20;
2492
+ densityNormalizer = 1.67;
2493
+ } else if (colorsCount == 7) {
2494
+ panelsNumber = 14;
2495
+ densityNormalizer = 1.17;
2496
+ }
2497
+
2498
+ float fPanelsNumber = float(panelsNumber);
2499
+
2500
+ float totalPanelsShape = 0.;
2501
+ float panelGrad = 1. - clamp(u_gradient, 0., 1.);
2502
+
2503
+ for (int set = 0; set < 2; set++) {
2504
+ bool isForward = (set == 0 && !reverseTime) || (set == 1 && reverseTime);
2505
+ if (!isForward) continue;
2506
+
2507
+ for (int i = 0; i <= 20; i++) {
2508
+ if (i >= panelsNumber) break;
2509
+
2510
+ int idx = panelsNumber - 1 - i;
2511
+
2512
+ float offset = float(idx) / fPanelsNumber;
2513
+ if (set == 1) {
2514
+ offset += .5;
2515
+ }
2516
+
2517
+ float densityFract = densityNormalizer * fract(t + offset);
2518
+ float angleNorm = densityFract / u_density;
2519
+ if (densityFract >= .5 || angleNorm >= .3) continue;
2520
+
2521
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
2522
+ float smoothAngle = clamp((.3 - angleNorm) / .05, 0., 1.);
2523
+ if (smoothDensity * smoothAngle < .001) continue;
2524
+
2525
+ if (angleNorm > .5) {
2526
+ angleNorm = 0.5;
2527
+ }
2528
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength, aa);
2529
+ if (panel[0] <= .001) continue;
2530
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
2531
+ float panelMap = panel[1];
2532
+
2533
+ int colorIdx = idx % colorsCount;
2534
+ int nextColorIdx = (idx + 1) % colorsCount;
2535
+
2536
+ vec4 colorA = premultipliedColors[colorIdx];
2537
+ vec4 colorB = premultipliedColors[nextColorIdx];
2538
+
2539
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
2540
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
2541
+ color = blended.rgb + color * (1. - blended.a);
2542
+ opacity = blended.a + opacity * (1. - blended.a);
2543
+ }
2544
+
2545
+
2546
+ for (int i = 0; i <= 20; i++) {
2547
+ if (i >= panelsNumber) break;
2548
+
2549
+ int idx = panelsNumber - 1 - i;
2550
+
2551
+ float offset = float(idx) / fPanelsNumber;
2552
+ if (set == 0) {
2553
+ offset += .5;
2554
+ }
2555
+
2556
+ float densityFract = densityNormalizer * fract(-t + offset);
2557
+ float angleNorm = -densityFract / u_density;
2558
+ if (densityFract >= .5 || angleNorm < -.3) continue;
2559
+
2560
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
2561
+ float smoothAngle = clamp((angleNorm + .3) / .05, 0., 1.);
2562
+ if (smoothDensity * smoothAngle < .001) continue;
2563
+
2564
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength, aa);
2565
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
2566
+ if (panelMask <= .001) continue;
2567
+ float panelMap = panel[1];
2568
+
2569
+ int colorIdx = (colorsCount - (idx % colorsCount)) % colorsCount;
2570
+ if (colorIdx < 0) colorIdx += colorsCount;
2571
+ int nextColorIdx = (colorIdx + 1) % colorsCount;
2572
+
2573
+ vec4 colorA = premultipliedColors[colorIdx];
2574
+ vec4 colorB = premultipliedColors[nextColorIdx];
2575
+
2576
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
2577
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
2578
+ color = blended.rgb + color * (1. - blended.a);
2579
+ opacity = blended.a + opacity * (1. - blended.a);
2580
+ }
2581
+ }
2582
+
2583
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
2584
+ color = color + bgColor * (1.0 - opacity);
2585
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
2586
+
2587
+ ${p}
2588
+
2589
+ fragColor = vec4(color, opacity);
2590
+ }
2591
+ `,L={maxColorCount:10},Se=`#version 300 es
2592
+ precision mediump float;
2593
+
2594
+ uniform vec4 u_colors[${L.maxColorCount}];
2595
+ uniform float u_colorsCount;
2596
+
2597
+ uniform float u_positions;
2598
+ uniform float u_waveX;
2599
+ uniform float u_waveXShift;
2600
+ uniform float u_waveY;
2601
+ uniform float u_waveYShift;
2602
+ uniform float u_mixing;
2603
+ uniform float u_grainMixer;
2604
+ uniform float u_grainOverlay;
2605
+
2606
+ in vec2 v_objectUV;
2607
+ out vec4 fragColor;
2608
+
2609
+ ${c}
2610
+ ${f}
2611
+ ${g}
2612
+
2613
+ float valueNoise(vec2 st) {
2614
+ vec2 i = floor(st);
2615
+ vec2 f = fract(st);
2616
+ float a = hash21(i);
2617
+ float b = hash21(i + vec2(1.0, 0.0));
2618
+ float c = hash21(i + vec2(0.0, 1.0));
2619
+ float d = hash21(i + vec2(1.0, 1.0));
2620
+ vec2 u = f * f * (3.0 - 2.0 * f);
2621
+ float x1 = mix(a, b, u.x);
2622
+ float x2 = mix(c, d, u.x);
2623
+ return mix(x1, x2, u.y);
2624
+ }
2625
+
2626
+ float noise(vec2 n, vec2 seedOffset) {
2627
+ return valueNoise(n + seedOffset);
2628
+ }
2629
+
2630
+ vec2 getPosition(int i, float t) {
2631
+ float a = float(i) * .37;
2632
+ float b = .6 + mod(float(i), 3.) * .3;
2633
+ float c = .8 + mod(float(i + 1), 4.) * 0.25;
2634
+
2635
+ float x = sin(t * b + a);
2636
+ float y = cos(t * c + a * 1.5);
2637
+
2638
+ return .5 + .5 * vec2(x, y);
2639
+ }
2640
+
2641
+ void main() {
2642
+ vec2 uv = v_objectUV;
2643
+ uv += .5;
2644
+ vec2 grainUV = uv * 1000.;
2645
+
2646
+ float grain = noise(grainUV, vec2(0.));
2647
+ float mixerGrain = .4 * u_grainMixer * (grain - .5);
2648
+
2649
+ float radius = smoothstep(0., 1., length(uv - .5));
2650
+ float center = 1. - radius;
2651
+ for (float i = 1.; i <= 2.; i++) {
2652
+ uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));
2653
+ uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));
2654
+ }
2655
+
2656
+ vec3 color = vec3(0.);
2657
+ float opacity = 0.;
2658
+ float totalWeight = 0.;
2659
+ float positionSeed = 25. + .33 * u_positions;
2660
+
2661
+ for (int i = 0; i < ${L.maxColorCount}; i++) {
2662
+ if (i >= int(u_colorsCount)) break;
2663
+
2664
+ vec2 pos = getPosition(i, positionSeed) + mixerGrain;
2665
+ float dist = length(uv - pos);
2666
+ dist = length(uv - pos);
2667
+
2668
+ vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
2669
+ float opacityFraction = u_colors[i].a;
2670
+
2671
+ float mixing = pow(u_mixing, .7);
2672
+ float power = mix(2., 1., mixing);
2673
+ dist = pow(dist, power);
2674
+
2675
+ float w = 1. / (dist + 1e-3);
2676
+ float baseSharpness = mix(.0, 8., clamp(w, 0., 1.));
2677
+ float sharpness = mix(baseSharpness, 1., mixing);
2678
+ w = pow(w, sharpness);
2679
+ color += colorFraction * w;
2680
+ opacity += opacityFraction * w;
2681
+ totalWeight += w;
2682
+ }
2683
+
2684
+ color /= max(1e-4, totalWeight);
2685
+ opacity /= max(1e-4, totalWeight);
2686
+
2687
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
2688
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
2689
+ grainOverlay = pow(grainOverlay, 1.3);
2690
+
2691
+ float grainOverlayV = grainOverlay * 2. - 1.;
2692
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
2693
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
2694
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
2695
+ color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
2696
+
2697
+ opacity += .5 * grainOverlayStrength;
2698
+ opacity = clamp(opacity, 0., 1.);
2699
+
2700
+ fragColor = vec4(color, opacity);
2701
+ }
2702
+ `,H={maxColorCount:10},Ue=`#version 300 es
2703
+ precision mediump float;
2704
+
2705
+ uniform vec4 u_colorBack;
2706
+ uniform vec4 u_colors[${H.maxColorCount}];
2707
+ uniform float u_colorsCount;
2708
+
2709
+ uniform float u_radius;
2710
+ uniform float u_focalDistance;
2711
+ uniform float u_focalAngle;
2712
+ uniform float u_falloff;
2713
+ uniform float u_mixing;
2714
+ uniform float u_distortion;
2715
+ uniform float u_distortionShift;
2716
+ uniform float u_distortionFreq;
2717
+ uniform float u_grainMixer;
2718
+ uniform float u_grainOverlay;
2719
+
2720
+ in vec2 v_objectUV;
2721
+ out vec4 fragColor;
2722
+
2723
+ ${c}
2724
+ ${f}
2725
+ ${g}
2726
+
2727
+ float valueNoise(vec2 st) {
2728
+ vec2 i = floor(st);
2729
+ vec2 f = fract(st);
2730
+ float a = hash21(i);
2731
+ float b = hash21(i + vec2(1.0, 0.0));
2732
+ float c = hash21(i + vec2(0.0, 1.0));
2733
+ float d = hash21(i + vec2(1.0, 1.0));
2734
+ vec2 u = f * f * (3.0 - 2.0 * f);
2735
+ float x1 = mix(a, b, u.x);
2736
+ float x2 = mix(c, d, u.x);
2737
+ return mix(x1, x2, u.y);
2738
+ }
2739
+
2740
+ float noise(vec2 n, vec2 seedOffset) {
2741
+ return valueNoise(n + seedOffset);
2742
+ }
2743
+
2744
+ vec2 getPosition(int i, float t) {
2745
+ float a = float(i) * .37;
2746
+ float b = .6 + mod(float(i), 3.) * .3;
2747
+ float c = .8 + mod(float(i + 1), 4.) * 0.25;
2748
+
2749
+ float x = sin(t * b + a);
2750
+ float y = cos(t * c + a * 1.5);
2751
+
2752
+ return .5 + .5 * vec2(x, y);
2753
+ }
2754
+
2755
+ void main() {
2756
+ vec2 uv = 2. * v_objectUV;
2757
+ vec2 grainUV = uv * 1000.;
2758
+
2759
+ vec2 center = vec2(0.);
2760
+ float angleRad = -radians(u_focalAngle + 90.);
2761
+ vec2 focalPoint = vec2(cos(angleRad), sin(angleRad)) * u_focalDistance;
2762
+ float radius = u_radius;
2763
+
2764
+ vec2 c_to_uv = uv - center;
2765
+ vec2 f_to_uv = uv - focalPoint;
2766
+ vec2 f_to_c = center - focalPoint;
2767
+ float r = length(c_to_uv);
2768
+
2769
+ float fragAngle = atan(c_to_uv.y, c_to_uv.x);
2770
+ float angleDiff = fract((fragAngle - angleRad + PI) / TWO_PI) * TWO_PI - PI;
2771
+
2772
+ float halfAngle = acos(clamp(radius / max(u_focalDistance, 1e-4), 0.0, 1.0));
2773
+ float e0 = 0.6 * PI, e1 = halfAngle;
2774
+ float lo = min(e0, e1), hi = max(e0, e1);
2775
+ float s = smoothstep(lo, hi, abs(angleDiff));
2776
+ float isInSector = (e1 >= e0) ? (1.0 - s) : s;
2777
+
2778
+ float a = dot(f_to_uv, f_to_uv);
2779
+ float b = -2.0 * dot(f_to_uv, f_to_c);
2780
+ float c = dot(f_to_c, f_to_c) - radius * radius;
2781
+
2782
+ float discriminant = b * b - 4.0 * a * c;
2783
+ float t = 1.0;
2784
+
2785
+ if (discriminant >= 0.0) {
2786
+ float sqrtD = sqrt(discriminant);
2787
+ float div = max(1e-4, 2.0 * a);
2788
+ float t0 = (-b - sqrtD) / div;
2789
+ float t1 = (-b + sqrtD) / div;
2790
+ t = max(t0, t1);
2791
+ if (t < 0.0) t = 0.0;
2792
+ }
2793
+
2794
+ float dist = length(f_to_uv);
2795
+ float normalized = dist / max(1e-4, length(f_to_uv * t));
2796
+ float shape = clamp(normalized, 0.0, 1.0);
2797
+
2798
+ float falloffMapped = mix(.2 + .8 * max(0., u_falloff + 1.), mix(1., 15., u_falloff * u_falloff), step(.0, u_falloff));
2799
+
2800
+ float falloffExp = mix(falloffMapped, 1., shape);
2801
+ shape = pow(shape, falloffExp);
2802
+ shape = 1. - clamp(shape, 0., 1.);
2803
+
2804
+
2805
+ float outerMask = .002;
2806
+ float outer = 1.0 - smoothstep(radius - outerMask, radius + outerMask, r);
2807
+ outer = mix(outer, 1., isInSector);
2808
+
2809
+ shape = mix(0., shape, outer);
2810
+ shape *= 1. - smoothstep(radius - .01, radius, r);
2811
+
2812
+ float angle = atan(f_to_uv.y, f_to_uv.x);
2813
+ shape -= pow(u_distortion, 2.) * shape * pow(abs(sin(PI * clamp(length(f_to_uv) - 0.2 + u_distortionShift, 0.0, 1.0))), 4.0) * (sin(u_distortionFreq * angle) + cos(floor(0.65 * u_distortionFreq) * angle));
2814
+
2815
+ float grain = noise(grainUV, vec2(0.));
2816
+ float mixerGrain = .4 * u_grainMixer * (grain - .5);
2817
+
2818
+ float mixer = shape * u_colorsCount + mixerGrain;
2819
+ vec4 gradient = u_colors[0];
2820
+ gradient.rgb *= gradient.a;
2821
+
2822
+ float outerShape = 0.;
2823
+ for (int i = 1; i < ${H.maxColorCount+1}; i++) {
2824
+ if (i > int(u_colorsCount)) break;
2825
+ float mLinear = clamp(mixer - float(i - 1), 0.0, 1.0);
2826
+
2827
+ float aa = fwidth(mLinear);
2828
+ float width = min(u_mixing, 0.5);
2829
+ float t = clamp((mLinear - (0.5 - width - aa)) / (2. * width + 2. * aa), 0., 1.);
2830
+ float p = mix(2., 1., clamp((u_mixing - 0.5) * 2., 0., 1.));
2831
+ float m = t < 0.5
2832
+ ? 0.5 * pow(2. * t, p)
2833
+ : 1. - 0.5 * pow(2. * (1. - t), p);
2834
+
2835
+ float quadBlend = clamp((u_mixing - 0.5) * 2., 0., 1.);
2836
+ m = mix(m, m * m, 0.5 * quadBlend);
2837
+
2838
+ if (i == 1) {
2839
+ outerShape = m;
2840
+ }
2841
+
2842
+ vec4 c = u_colors[i - 1];
2843
+ c.rgb *= c.a;
2844
+ gradient = mix(gradient, c, m);
2845
+ }
2846
+
2847
+ vec3 color = gradient.rgb * outerShape;
2848
+ float opacity = gradient.a * outerShape;
2849
+
2850
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
2851
+ color = color + bgColor * (1.0 - opacity);
2852
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
2853
+
2854
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
2855
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
2856
+ grainOverlay = pow(grainOverlay, 1.3);
2857
+
2858
+ float grainOverlayV = grainOverlay * 2. - 1.;
2859
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
2860
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
2861
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
2862
+ color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
2863
+
2864
+ opacity += .5 * grainOverlayStrength;
2865
+ opacity = clamp(opacity, 0., 1.);
2866
+
2867
+ fragColor = vec4(color, opacity);
2868
+ }
2869
+ `,Ve=`#version 300 es
2870
+ precision mediump float;
2871
+
2872
+ uniform vec2 u_resolution;
2873
+ uniform float u_pixelRatio;
2874
+
2875
+ uniform vec4 u_colorFront;
2876
+ uniform vec4 u_colorBack;
2877
+
2878
+ uniform sampler2D u_image;
2879
+ uniform float u_imageAspectRatio;
2880
+
2881
+ uniform float u_contrast;
2882
+ uniform float u_roughness;
2883
+ uniform float u_fiber;
2884
+ uniform float u_fiberSize;
2885
+ uniform float u_crumples;
2886
+ uniform float u_crumpleSize;
2887
+ uniform float u_folds;
2888
+ uniform float u_foldCount;
2889
+ uniform float u_drops;
2890
+ uniform float u_seed;
2891
+ uniform float u_fade;
2892
+
2893
+ uniform sampler2D u_noiseTexture;
2894
+
2895
+ in vec2 v_imageUV;
2896
+
2897
+ out vec4 fragColor;
2898
+
2899
+ float getUvFrame(vec2 uv) {
2900
+ float aax = 2. * fwidth(uv.x);
2901
+ float aay = 2. * fwidth(uv.y);
2902
+
2903
+ float left = smoothstep(0., aax, uv.x);
2904
+ float right = 1. - smoothstep(1. - aax, 1., uv.x);
2905
+ float bottom = smoothstep(0., aay, uv.y);
2906
+ float top = 1. - smoothstep(1. - aay, 1., uv.y);
2907
+
2908
+ return left * right * bottom * top;
2909
+ }
2910
+
2911
+ ${c}
2912
+ ${f}
2913
+ ${_}
2914
+ float valueNoise(vec2 st) {
2915
+ vec2 i = floor(st);
2916
+ vec2 f = fract(st);
2917
+ float a = randomR(i);
2918
+ float b = randomR(i + vec2(1.0, 0.0));
2919
+ float c = randomR(i + vec2(0.0, 1.0));
2920
+ float d = randomR(i + vec2(1.0, 1.0));
2921
+ vec2 u = f * f * (3.0 - 2.0 * f);
2922
+ float x1 = mix(a, b, u.x);
2923
+ float x2 = mix(c, d, u.x);
2924
+ return mix(x1, x2, u.y);
2925
+ }
2926
+ float fbm(vec2 n) {
2927
+ float total = 0.0, amplitude = .4;
2928
+ for (int i = 0; i < 3; i++) {
2929
+ total += valueNoise(n) * amplitude;
2930
+ n *= 1.99;
2931
+ amplitude *= 0.65;
2932
+ }
2933
+ return total;
2934
+ }
2935
+
2936
+
2937
+ float randomG(vec2 p) {
2938
+ vec2 uv = floor(p) / 50. + .5;
2939
+ return texture(u_noiseTexture, fract(uv)).g;
2940
+ }
2941
+ float roughness(vec2 p) {
2942
+ p *= .1;
2943
+ float o = 0.;
2944
+ for (float i = 0.; ++i < 4.; p *= 2.1) {
2945
+ vec4 w = vec4(floor(p), ceil(p));
2946
+ vec2 f = fract(p);
2947
+ o += mix(
2948
+ mix(randomG(w.xy), randomG(w.xw), f.y),
2949
+ mix(randomG(w.zy), randomG(w.zw), f.y),
2950
+ f.x);
2951
+ o += .2 / exp(2. * abs(sin(.2 * p.x + .5 * p.y)));
2952
+ }
2953
+ return o / 3.;
2954
+ }
2955
+
2956
+ ${ae}
2957
+
2958
+ vec2 randomGB(vec2 p) {
2959
+ vec2 uv = floor(p) / 50. + .5;
2960
+ return texture(u_noiseTexture, fract(uv)).gb;
2961
+ }
2962
+ float crumpledNoise(vec2 t, float pw) {
2963
+ vec2 p = floor(t);
2964
+ float wsum = 0.;
2965
+ float cl = 0.;
2966
+ for (int y = -1; y < 2; y += 1) {
2967
+ for (int x = -1; x < 2; x += 1) {
2968
+ vec2 b = vec2(float(x), float(y));
2969
+ vec2 q = b + p;
2970
+ vec2 q2 = q - floor(q / 8.) * 8.;
2971
+ vec2 c = q + randomGB(q2);
2972
+ vec2 r = c - t;
2973
+ float w = pow(smoothstep(0., 1., 1. - abs(r.x)), pw) * pow(smoothstep(0., 1., 1. - abs(r.y)), pw);
2974
+ cl += (.5 + .5 * sin((q2.x + q2.y * 5.) * 8.)) * w;
2975
+ wsum += w;
2976
+ }
2977
+ }
2978
+ return pow(wsum != 0.0 ? cl / wsum : 0.0, .5) * 2.;
2979
+ }
2980
+ float crumplesShape(vec2 uv) {
2981
+ return crumpledNoise(uv * .25, 16.) * crumpledNoise(uv * .5, 2.);
2982
+ }
2983
+
2984
+
2985
+ vec2 folds(vec2 uv) {
2986
+ vec3 pp = vec3(0.);
2987
+ float l = 9.;
2988
+ for (float i = 0.; i < 15.; i++) {
2989
+ if (i >= u_foldCount) break;
2990
+ vec2 rand = randomGB(vec2(i, i * u_seed));
2991
+ float an = rand.x * TWO_PI;
2992
+ vec2 p = vec2(cos(an), sin(an)) * rand.y;
2993
+ float dist = distance(uv, p);
2994
+ l = min(l, dist);
2995
+
2996
+ if (l == dist) {
2997
+ pp.xy = (uv - p.xy);
2998
+ pp.z = dist;
2999
+ }
3000
+ }
3001
+ return mix(pp.xy, vec2(0.), pow(pp.z, .25));
3002
+ }
3003
+
3004
+ float drops(vec2 uv) {
3005
+ vec2 iDropsUV = floor(uv);
3006
+ vec2 fDropsUV = fract(uv);
3007
+ float dropsMinDist = 1.;
3008
+ for (int j = -1; j <= 1; j++) {
3009
+ for (int i = -1; i <= 1; i++) {
3010
+ vec2 neighbor = vec2(float(i), float(j));
3011
+ vec2 offset = randomGB(iDropsUV + neighbor);
3012
+ offset = .5 + .5 * sin(10. * u_seed + TWO_PI * offset);
3013
+ vec2 pos = neighbor + offset - fDropsUV;
3014
+ float dist = length(pos);
3015
+ dropsMinDist = min(dropsMinDist, dropsMinDist*dist);
3016
+ }
3017
+ }
3018
+ return 1. - smoothstep(.05, .09, pow(dropsMinDist, .5));
3019
+ }
3020
+
3021
+ float lst(float edge0, float edge1, float x) {
3022
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
3023
+ }
3024
+
3025
+ void main() {
3026
+
3027
+ vec2 imageUV = v_imageUV;
3028
+ vec2 patternUV = v_imageUV - .5;
3029
+ patternUV = 5. * (patternUV * vec2(u_imageAspectRatio, 1.));
3030
+
3031
+ vec2 roughnessUv = 1.5 * (gl_FragCoord.xy - .5 * u_resolution) / u_pixelRatio;
3032
+ float roughness = roughness(roughnessUv + vec2(1., 0.)) - roughness(roughnessUv - vec2(1., 0.));
3033
+
3034
+ vec2 crumplesUV = fract(patternUV * .02 / u_crumpleSize - u_seed) * 32.;
3035
+ float crumples = u_crumples * (crumplesShape(crumplesUV + vec2(.05, 0.)) - crumplesShape(crumplesUV));
3036
+
3037
+ vec2 fiberUV = 2. / u_fiberSize * patternUV;
3038
+ float fiber = fiberNoise(fiberUV, vec2(0.));
3039
+ fiber = .5 * u_fiber * (fiber - 1.);
3040
+
3041
+ vec2 normal = vec2(0.);
3042
+ vec2 normalImage = vec2(0.);
3043
+
3044
+ vec2 foldsUV = patternUV * .12;
3045
+ foldsUV = rotate(foldsUV, 4. * u_seed);
3046
+ vec2 w = folds(foldsUV);
3047
+ foldsUV = rotate(foldsUV + .007 * cos(u_seed), .01 * sin(u_seed));
3048
+ vec2 w2 = folds(foldsUV);
3049
+
3050
+ float drops = u_drops * drops(patternUV * 2.);
3051
+
3052
+ float fade = u_fade * fbm(.17 * patternUV + 10. * u_seed);
3053
+ fade = clamp(8. * fade * fade * fade, 0., 1.);
3054
+
3055
+ w = mix(w, vec2(0.), fade);
3056
+ w2 = mix(w2, vec2(0.), fade);
3057
+ crumples = mix(crumples, 0., fade);
3058
+ drops = mix(drops, 0., fade);
3059
+ fiber *= mix(1., .5, fade);
3060
+ roughness *= mix(1., .5, fade);
3061
+
3062
+ normal.xy += u_folds * min(5. * u_contrast, 1.) * 4. * max(vec2(0.), w + w2);
3063
+ normalImage.xy += u_folds * 2. * w;
3064
+
3065
+ normal.xy += crumples;
3066
+ normalImage.xy += 1.5 * crumples;
3067
+
3068
+ normal.xy += 3. * drops;
3069
+ normalImage.xy += .2 * drops;
3070
+
3071
+ normal.xy += u_roughness * 1.5 * roughness;
3072
+ normal.xy += fiber;
3073
+
3074
+ normalImage += u_roughness * .75 * roughness;
3075
+ normalImage += .2 * fiber;
3076
+
3077
+ vec3 lightPos = vec3(1., 2., 1.);
3078
+ float res = dot(normalize(vec3(normal, 9.5 - 9. * pow(u_contrast, .1))), normalize(lightPos));
3079
+
3080
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
3081
+ float fgOpacity = u_colorFront.a;
3082
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
3083
+ float bgOpacity = u_colorBack.a;
3084
+
3085
+ imageUV += .02 * normalImage;
3086
+ float frame = getUvFrame(imageUV);
3087
+ vec4 image = texture(u_image, imageUV);
3088
+ image.rgb += .6 * pow(u_contrast, .4) * (res - .7);
3089
+
3090
+ frame *= image.a;
3091
+
3092
+ vec3 color = fgColor * res;
3093
+ float opacity = fgOpacity * res;
3094
+
3095
+ color += bgColor * (1. - opacity);
3096
+ opacity += bgOpacity * (1. - opacity);
3097
+ opacity = mix(opacity, 1., frame);
3098
+
3099
+ color -= .007 * drops;
3100
+
3101
+ color.rgb = mix(color, image.rgb, frame);
3102
+
3103
+ fragColor = vec4(color, opacity);
3104
+ }
3105
+ `,ke=`#version 300 es
3106
+ precision mediump float;
3107
+
3108
+ uniform float u_time;
3109
+
3110
+ uniform vec4 u_colorBack;
3111
+ uniform vec4 u_colorHighlight;
3112
+
3113
+ uniform sampler2D u_image;
3114
+ uniform float u_imageAspectRatio;
3115
+
3116
+ uniform float u_size;
3117
+ uniform float u_highlights;
3118
+ uniform float u_layering;
3119
+ uniform float u_edges;
3120
+ uniform float u_caustic;
3121
+ uniform float u_waves;
3122
+
3123
+ in vec2 v_imageUV;
3124
+
3125
+ out vec4 fragColor;
3126
+
3127
+ ${c}
3128
+ ${f}
3129
+ ${h}
3130
+
3131
+ float getUvFrame(vec2 uv) {
3132
+ float aax = 2. * fwidth(uv.x);
3133
+ float aay = 2. * fwidth(uv.y);
3134
+
3135
+ float left = smoothstep(0., aax, uv.x);
3136
+ float right = 1.0 - smoothstep(1. - aax, 1., uv.x);
3137
+ float bottom = smoothstep(0., aay, uv.y);
3138
+ float top = 1.0 - smoothstep(1. - aay, 1., uv.y);
3139
+
3140
+ return left * right * bottom * top;
3141
+ }
3142
+
3143
+ mat2 rotate2D(float r) {
3144
+ return mat2(cos(r), sin(r), -sin(r), cos(r));
3145
+ }
3146
+
3147
+ float getCausticNoise(vec2 uv, float t, float scale) {
3148
+ vec2 n = vec2(.1);
3149
+ vec2 N = vec2(.1);
3150
+ mat2 m = rotate2D(.5);
3151
+ for (int j = 0; j < 6; j++) {
3152
+ uv *= m;
3153
+ n *= m;
3154
+ vec2 q = uv * scale + float(j) + n + (.5 + .5 * float(j)) * (mod(float(j), 2.) - 1.) * t;
3155
+ n += sin(q);
3156
+ N += cos(q) / scale;
3157
+ scale *= 1.1;
3158
+ }
3159
+ return (N.x + N.y + 1.);
3160
+ }
3161
+
3162
+ void main() {
3163
+ vec2 imageUV = v_imageUV;
3164
+ vec2 patternUV = v_imageUV - .5;
3165
+ patternUV = (patternUV * vec2(u_imageAspectRatio, 1.));
3166
+ patternUV /= (.01 + .09 * u_size);
3167
+
3168
+ float t = u_time;
3169
+
3170
+ float wavesNoise = snoise((.3 + .1 * sin(t)) * .1 * patternUV + vec2(0., .4 * t));
3171
+
3172
+ float causticNoise = getCausticNoise(patternUV + u_waves * vec2(1., -1.) * wavesNoise, 2. * t, 1.5);
3173
+
3174
+ causticNoise += u_layering * getCausticNoise(patternUV + 2. * u_waves * vec2(1., -1.) * wavesNoise, 1.5 * t, 2.);
3175
+ causticNoise = causticNoise * causticNoise;
3176
+
3177
+ float edgesDistortion = smoothstep(0., .1, imageUV.x);
3178
+ edgesDistortion *= smoothstep(0., .1, imageUV.y);
3179
+ edgesDistortion *= (smoothstep(1., 1.1, imageUV.x) + (1.0 - smoothstep(.8, .95, imageUV.x)));
3180
+ edgesDistortion *= (1.0 - smoothstep(.9, 1., imageUV.y));
3181
+ edgesDistortion = mix(edgesDistortion, 1., u_edges);
3182
+
3183
+ float causticNoiseDistortion = .02 * causticNoise * edgesDistortion;
3184
+
3185
+ float wavesDistortion = .1 * u_waves * wavesNoise;
3186
+
3187
+ imageUV += vec2(wavesDistortion, -wavesDistortion);
3188
+ imageUV += (u_caustic * causticNoiseDistortion);
3189
+
3190
+ float frame = getUvFrame(imageUV);
3191
+
3192
+ vec4 image = texture(u_image, imageUV);
3193
+ vec4 backColor = u_colorBack;
3194
+ backColor.rgb *= backColor.a;
3195
+
3196
+ vec3 color = mix(backColor.rgb, image.rgb, image.a * frame);
3197
+ float opacity = backColor.a + image.a * frame;
3198
+
3199
+ causticNoise = max(-.2, causticNoise);
3200
+
3201
+ float hightlight = .025 * u_highlights * causticNoise;
3202
+ hightlight *= u_colorHighlight.a;
3203
+ color = mix(color, u_colorHighlight.rgb, .05 * u_highlights * causticNoise);
3204
+ opacity += hightlight;
3205
+
3206
+ color += hightlight * (.5 + .5 * wavesNoise);
3207
+ opacity += hightlight * (.5 + .5 * wavesNoise);
3208
+
3209
+ opacity = clamp(opacity, 0., 1.);
3210
+
3211
+ fragColor = vec4(color, opacity);
3212
+ }
3213
+ `,Re=`#version 300 es
3214
+ precision mediump float;
3215
+
3216
+ uniform vec2 u_resolution;
3217
+ uniform float u_pixelRatio;
3218
+ uniform float u_rotation;
3219
+
3220
+ uniform vec4 u_colorBack;
3221
+ uniform vec4 u_colorShadow;
3222
+ uniform vec4 u_colorHighlight;
3223
+
3224
+ uniform sampler2D u_image;
3225
+ uniform float u_imageAspectRatio;
3226
+
3227
+ uniform float u_size;
3228
+ uniform float u_shadows;
3229
+ uniform float u_angle;
3230
+ uniform float u_stretch;
3231
+ uniform float u_shape;
3232
+ uniform float u_distortion;
3233
+ uniform float u_highlights;
3234
+ uniform float u_distortionShape;
3235
+ uniform float u_shift;
3236
+ uniform float u_blur;
3237
+ uniform float u_edges;
3238
+ uniform float u_marginLeft;
3239
+ uniform float u_marginRight;
3240
+ uniform float u_marginTop;
3241
+ uniform float u_marginBottom;
3242
+ uniform float u_grainMixer;
3243
+ uniform float u_grainOverlay;
3244
+
3245
+ in vec2 v_imageUV;
3246
+
3247
+ out vec4 fragColor;
3248
+
3249
+ ${c}
3250
+ ${f}
3251
+ ${g}
3252
+
3253
+ float valueNoise(vec2 st) {
3254
+ vec2 i = floor(st);
3255
+ vec2 f = fract(st);
3256
+ float a = hash21(i);
3257
+ float b = hash21(i + vec2(1.0, 0.0));
3258
+ float c = hash21(i + vec2(0.0, 1.0));
3259
+ float d = hash21(i + vec2(1.0, 1.0));
3260
+ vec2 u = f * f * (3.0 - 2.0 * f);
3261
+ float x1 = mix(a, b, u.x);
3262
+ float x2 = mix(c, d, u.x);
3263
+ return mix(x1, x2, u.y);
3264
+ }
3265
+
3266
+ float getUvFrame(vec2 uv, float softness) {
3267
+ float aax = 2. * fwidth(uv.x);
3268
+ float aay = 2. * fwidth(uv.y);
3269
+ float left = smoothstep(0., aax + softness, uv.x);
3270
+ float right = 1. - smoothstep(1. - softness - aax, 1., uv.x);
3271
+ float bottom = smoothstep(0., aay + softness, uv.y);
3272
+ float top = 1. - smoothstep(1. - softness - aay, 1., uv.y);
3273
+ return left * right * bottom * top;
3274
+ }
3275
+
3276
+ const int MAX_RADIUS = 50;
3277
+ vec4 samplePremultiplied(sampler2D tex, vec2 uv) {
3278
+ vec4 c = texture(tex, uv);
3279
+ c.rgb *= c.a;
3280
+ return c;
3281
+ }
3282
+ vec4 getBlur(sampler2D tex, vec2 uv, vec2 texelSize, vec2 dir, float sigma) {
3283
+ if (sigma <= .5) return texture(tex, uv);
3284
+ int radius = int(min(float(MAX_RADIUS), ceil(3.0 * sigma)));
3285
+
3286
+ float twoSigma2 = 2.0 * sigma * sigma;
3287
+ float gaussianNorm = 1.0 / sqrt(TWO_PI * sigma * sigma);
3288
+
3289
+ vec4 sum = samplePremultiplied(tex, uv) * gaussianNorm;
3290
+ float weightSum = gaussianNorm;
3291
+
3292
+ for (int i = 1; i <= MAX_RADIUS; i++) {
3293
+ if (i > radius) break;
3294
+
3295
+ float x = float(i);
3296
+ float w = exp(-(x * x) / twoSigma2) * gaussianNorm;
3297
+
3298
+ vec2 offset = dir * texelSize * x;
3299
+ vec4 s1 = samplePremultiplied(tex, uv + offset);
3300
+ vec4 s2 = samplePremultiplied(tex, uv - offset);
3301
+
3302
+ sum += (s1 + s2) * w;
3303
+ weightSum += 2.0 * w;
3304
+ }
3305
+
3306
+ vec4 result = sum / weightSum;
3307
+ if (result.a > 0.) {
3308
+ result.rgb /= result.a;
3309
+ }
3310
+
3311
+ return result;
3312
+ }
3313
+
3314
+ vec2 rotateAspect(vec2 p, float a, float aspect) {
3315
+ p.x *= aspect;
3316
+ p = rotate(p, a);
3317
+ p.x /= aspect;
3318
+ return p;
3319
+ }
3320
+
3321
+ float smoothFract(float x) {
3322
+ float f = fract(x);
3323
+ float w = fwidth(x);
3324
+
3325
+ float edge = abs(f - 0.5) - 0.5;
3326
+ float band = smoothstep(-w, w, edge);
3327
+
3328
+ return mix(f, 1.0 - f, band);
3329
+ }
3330
+
3331
+ void main() {
3332
+
3333
+ float patternRotation = -u_angle * PI / 180.;
3334
+ float patternSize = mix(200., 5., u_size);
3335
+
3336
+ vec2 uv = v_imageUV;
3337
+
3338
+ vec2 uvMask = gl_FragCoord.xy / u_resolution.xy;
3339
+ vec2 sw = vec2(.005);
3340
+ vec4 margins = vec4(u_marginLeft, u_marginTop, u_marginRight, u_marginBottom);
3341
+ float mask =
3342
+ smoothstep(margins[0], margins[0] + sw.x, uvMask.x + sw.x) *
3343
+ smoothstep(margins[2], margins[2] + sw.x, 1.0 - uvMask.x + sw.x) *
3344
+ smoothstep(margins[1], margins[1] + sw.y, uvMask.y + sw.y) *
3345
+ smoothstep(margins[3], margins[3] + sw.y, 1.0 - uvMask.y + sw.y);
3346
+ float maskOuter =
3347
+ smoothstep(margins[0] - sw.x, margins[0], uvMask.x + sw.x) *
3348
+ smoothstep(margins[2] - sw.x, margins[2], 1.0 - uvMask.x + sw.x) *
3349
+ smoothstep(margins[1] - sw.y, margins[1], uvMask.y + sw.y) *
3350
+ smoothstep(margins[3] - sw.y, margins[3], 1.0 - uvMask.y + sw.y);
3351
+ float maskStroke = maskOuter - mask;
3352
+ float maskInner =
3353
+ smoothstep(margins[0] - 2. * sw.x, margins[0], uvMask.x) *
3354
+ smoothstep(margins[2] - 2. * sw.x, margins[2], 1.0 - uvMask.x) *
3355
+ smoothstep(margins[1] - 2. * sw.y, margins[1], uvMask.y) *
3356
+ smoothstep(margins[3] - 2. * sw.y, margins[3], 1.0 - uvMask.y);
3357
+ float maskStrokeInner = maskInner - mask;
3358
+
3359
+ uv -= .5;
3360
+ uv *= patternSize;
3361
+ uv = rotateAspect(uv, patternRotation, u_imageAspectRatio);
3362
+
3363
+ float curve = 0.;
3364
+ float patternY = uv.y / u_imageAspectRatio;
3365
+ if (u_shape > 4.5) {
3366
+ // pattern
3367
+ curve = .5 + .5 * sin(.5 * PI * uv.x) * cos(.5 * PI * patternY);
3368
+ } else if (u_shape > 3.5) {
3369
+ // zigzag
3370
+ curve = 10. * abs(fract(.1 * patternY) - .5);
3371
+ } else if (u_shape > 2.5) {
3372
+ // wave
3373
+ curve = 4. * sin(.23 * patternY);
3374
+ } else if (u_shape > 1.5) {
3375
+ // lines irregular
3376
+ curve = .5 + .5 * sin(.5 * uv.x) * sin(1.7 * uv.x);
3377
+ } else {
3378
+ // lines
3379
+ }
3380
+
3381
+ vec2 UvToFract = uv + curve;
3382
+ vec2 fractOrigUV = fract(uv);
3383
+ vec2 floorOrigUV = floor(uv);
3384
+
3385
+ float x = smoothFract(UvToFract.x);
3386
+ float xNonSmooth = fract(UvToFract.x) + .0001;
3387
+
3388
+ float highlightsWidth = 2. * max(.001, fwidth(UvToFract.x));
3389
+ highlightsWidth += 2. * maskStrokeInner;
3390
+ float highlights = smoothstep(0., highlightsWidth, xNonSmooth);
3391
+ highlights *= smoothstep(1., 1. - highlightsWidth, xNonSmooth);
3392
+ highlights = 1. - highlights;
3393
+ highlights *= u_highlights;
3394
+ highlights = clamp(highlights, 0., 1.);
3395
+ highlights *= mask;
3396
+
3397
+ float shadows = pow(x, 1.3);
3398
+ float distortion = 0.;
3399
+ float fadeX = 1.;
3400
+ float frameFade = 0.;
3401
+
3402
+ float aa = fwidth(xNonSmooth);
3403
+ aa = max(aa, fwidth(uv.x));
3404
+ aa = max(aa, fwidth(UvToFract.x));
3405
+ aa = max(aa, .0001);
3406
+
3407
+ if (u_distortionShape == 1.) {
3408
+ distortion = -pow(1.5 * x, 3.);
3409
+ distortion += (.5 - u_shift);
3410
+
3411
+ frameFade = pow(1.5 * x, 3.);
3412
+ aa = max(.2, aa);
3413
+ aa += mix(.2, 0., u_size);
3414
+ fadeX = smoothstep(0., aa, xNonSmooth) * smoothstep(1., 1. - aa, xNonSmooth);
3415
+ distortion = mix(.5, distortion, fadeX);
3416
+ } else if (u_distortionShape == 2.) {
3417
+ distortion = 2. * pow(x, 2.);
3418
+ distortion -= (.5 + u_shift);
3419
+
3420
+ frameFade = pow(abs(x - .5), 4.);
3421
+ aa = max(.2, aa);
3422
+ aa += mix(.2, 0., u_size);
3423
+ fadeX = smoothstep(0., aa, xNonSmooth) * smoothstep(1., 1. - aa, xNonSmooth);
3424
+ distortion = mix(.5, distortion, fadeX);
3425
+ frameFade = mix(1., frameFade, .5 * fadeX);
3426
+ } else if (u_distortionShape == 3.) {
3427
+ distortion = pow(2. * (xNonSmooth - .5), 6.);
3428
+ distortion -= .25;
3429
+ distortion -= u_shift;
3430
+
3431
+ frameFade = 1. - 2. * pow(abs(x - .4), 2.);
3432
+ aa = .15;
3433
+ aa += mix(.1, 0., u_size);
3434
+ fadeX = smoothstep(0., aa, xNonSmooth) * smoothstep(1., 1. - aa, xNonSmooth);
3435
+ frameFade = mix(1., frameFade, fadeX);
3436
+
3437
+ } else if (u_distortionShape == 4.) {
3438
+ x = xNonSmooth;
3439
+ distortion = sin((x + .25) * TWO_PI);
3440
+ shadows = .5 + .5 * asin(distortion) / (.5 * PI);
3441
+ distortion *= .5;
3442
+ distortion -= u_shift;
3443
+ frameFade = .5 + .5 * sin(x * TWO_PI);
3444
+ } else if (u_distortionShape == 5.) {
3445
+ distortion -= pow(abs(x), .2) * x;
3446
+ distortion += .33;
3447
+ distortion -= 3. * u_shift;
3448
+ distortion *= .33;
3449
+
3450
+ frameFade = .3 * (smoothstep(.0, 1., x));
3451
+ shadows = pow(x, 2.5);
3452
+
3453
+ aa = max(.1, aa);
3454
+ aa += mix(.1, 0., u_size);
3455
+ fadeX = smoothstep(0., aa, xNonSmooth) * smoothstep(1., 1. - aa, xNonSmooth);
3456
+ distortion *= fadeX;
3457
+ }
3458
+
3459
+ vec2 dudx = dFdx(v_imageUV);
3460
+ vec2 dudy = dFdy(v_imageUV);
3461
+ vec2 grainUV = v_imageUV - .5;
3462
+ grainUV *= (.8 / vec2(length(dudx), length(dudy)));
3463
+ grainUV += .5;
3464
+ float grain = valueNoise(grainUV);
3465
+ grain = smoothstep(.4, .7, grain);
3466
+ grain *= u_grainMixer;
3467
+ distortion = mix(distortion, 0., grain);
3468
+
3469
+ shadows = min(shadows, 1.);
3470
+ shadows += maskStrokeInner;
3471
+ shadows *= mask;
3472
+ shadows = min(shadows, 1.);
3473
+ shadows *= pow(u_shadows, 2.);
3474
+ shadows = clamp(shadows, 0., 1.);
3475
+
3476
+ distortion *= 3. * u_distortion;
3477
+ frameFade *= u_distortion;
3478
+
3479
+ fractOrigUV.x += distortion;
3480
+ floorOrigUV = rotateAspect(floorOrigUV, -patternRotation, u_imageAspectRatio);
3481
+ fractOrigUV = rotateAspect(fractOrigUV, -patternRotation, u_imageAspectRatio);
3482
+
3483
+ uv = (floorOrigUV + fractOrigUV) / patternSize;
3484
+ uv += pow(maskStroke, 4.);
3485
+
3486
+ uv += vec2(.5);
3487
+
3488
+ uv = mix(v_imageUV, uv, smoothstep(0., .7, mask));
3489
+ float blur = mix(0., 50., u_blur);
3490
+ blur = mix(0., blur, smoothstep(.5, 1., mask));
3491
+
3492
+ float edgeDistortion = mix(.0, .04, u_edges);
3493
+ edgeDistortion += .06 * frameFade * u_edges;
3494
+ edgeDistortion *= mask;
3495
+ float frame = getUvFrame(uv, edgeDistortion);
3496
+
3497
+ float stretch = 1. - smoothstep(0., .5, xNonSmooth) * smoothstep(1., 1. - .5, xNonSmooth);
3498
+ stretch = pow(stretch, 2.);
3499
+ stretch *= mask;
3500
+ stretch *= getUvFrame(uv, .1 + .05 * mask * frameFade);
3501
+ uv.y = mix(uv.y, .5, u_stretch * stretch);
3502
+
3503
+ vec4 image = getBlur(u_image, uv, 1. / u_resolution / u_pixelRatio, vec2(0., 1.), blur);
3504
+ image.rgb *= image.a;
3505
+ vec4 backColor = u_colorBack;
3506
+ backColor.rgb *= backColor.a;
3507
+ vec4 highlightColor = u_colorHighlight;
3508
+ highlightColor.rgb *= highlightColor.a;
3509
+ vec4 shadowColor = u_colorShadow;
3510
+
3511
+ vec3 color = highlightColor.rgb * highlights;
3512
+ float opacity = highlightColor.a * highlights;
3513
+
3514
+ shadows = mix(shadows * shadowColor.a, 0., highlights);
3515
+ color = mix(color, shadowColor.rgb * shadowColor.a, .5 * shadows);
3516
+ color += .5 * pow(shadows, .5) * shadowColor.rgb;
3517
+ opacity += shadows;
3518
+ color = clamp(color, vec3(0.), vec3(1.));
3519
+ opacity = clamp(opacity, 0., 1.);
3520
+
3521
+ color += image.rgb * (1. - opacity) * frame;
3522
+ opacity += image.a * (1. - opacity) * frame;
3523
+
3524
+ color += backColor.rgb * (1. - opacity);
3525
+ opacity += backColor.a * (1. - opacity);
3526
+
3527
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
3528
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
3529
+ grainOverlay = pow(grainOverlay, 1.3);
3530
+
3531
+ float grainOverlayV = grainOverlay * 2. - 1.;
3532
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
3533
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
3534
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
3535
+ grainOverlayStrength *= mask;
3536
+ color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
3537
+
3538
+ opacity += .5 * grainOverlayStrength;
3539
+ opacity = clamp(opacity, 0., 1.);
3540
+
3541
+ fragColor = vec4(color, opacity);
3542
+ }
3543
+ `;var Ie=`#version 300 es
3544
+ precision mediump float;
3545
+
3546
+ uniform vec2 u_resolution;
3547
+ uniform float u_pixelRatio;
3548
+ uniform float u_originX;
3549
+ uniform float u_originY;
3550
+ uniform float u_worldWidth;
3551
+ uniform float u_worldHeight;
3552
+ uniform float u_fit;
3553
+
3554
+ uniform float u_scale;
3555
+ uniform float u_rotation;
3556
+ uniform float u_offsetX;
3557
+ uniform float u_offsetY;
3558
+
3559
+ uniform vec4 u_colorFront;
3560
+ uniform vec4 u_colorBack;
3561
+ uniform vec4 u_colorHighlight;
3562
+
3563
+ uniform sampler2D u_image;
3564
+ uniform float u_imageAspectRatio;
3565
+
3566
+ uniform float u_type;
3567
+ uniform float u_pxSize;
3568
+ uniform bool u_originalColors;
3569
+ uniform bool u_inverted;
3570
+ uniform float u_colorSteps;
3571
+
3572
+ out vec4 fragColor;
3573
+
3574
+
3575
+ ${g}
3576
+ ${c}
3577
+
3578
+ float getUvFrame(vec2 uv, vec2 pad) {
3579
+ float aa = 0.0001;
3580
+
3581
+ float left = smoothstep(-pad.x, -pad.x + aa, uv.x);
3582
+ float right = smoothstep(1.0 + pad.x, 1.0 + pad.x - aa, uv.x);
3583
+ float bottom = smoothstep(-pad.y, -pad.y + aa, uv.y);
3584
+ float top = smoothstep(1.0 + pad.y, 1.0 + pad.y - aa, uv.y);
3585
+
3586
+ return left * right * bottom * top;
3587
+ }
3588
+
3589
+ vec2 getImageUV(vec2 uv) {
3590
+ vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
3591
+ float r = u_rotation * PI / 180.;
3592
+ mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
3593
+ vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
3594
+
3595
+ vec2 imageBoxSize;
3596
+ if (u_fit == 1.) { // contain
3597
+ imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
3598
+ } else if (u_fit == 2.) { // cover
3599
+ imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
3600
+ } else {
3601
+ imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);
3602
+ }
3603
+ imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;
3604
+ vec2 imageBoxScale = u_resolution.xy / imageBoxSize;
3605
+
3606
+ vec2 imageUV = uv;
3607
+ imageUV *= imageBoxScale;
3608
+ imageUV += boxOrigin * (imageBoxScale - 1.);
3609
+ imageUV += graphicOffset;
3610
+ imageUV /= u_scale;
3611
+ imageUV.x *= u_imageAspectRatio;
3612
+ imageUV = graphicRotation * imageUV;
3613
+ imageUV.x /= u_imageAspectRatio;
3614
+
3615
+ imageUV += .5;
3616
+ imageUV.y = 1. - imageUV.y;
3617
+
3618
+ return imageUV;
3619
+ }
3620
+
3621
+ const int bayer2x2[4] = int[4](0, 2, 3, 1);
3622
+ const int bayer4x4[16] = int[16](
3623
+ 0, 8, 2, 10,
3624
+ 12, 4, 14, 6,
3625
+ 3, 11, 1, 9,
3626
+ 15, 7, 13, 5
3627
+ );
3628
+
3629
+ const int bayer8x8[64] = int[64](
3630
+ 0, 32, 8, 40, 2, 34, 10, 42,
3631
+ 48, 16, 56, 24, 50, 18, 58, 26,
3632
+ 12, 44, 4, 36, 14, 46, 6, 38,
3633
+ 60, 28, 52, 20, 62, 30, 54, 22,
3634
+ 3, 35, 11, 43, 1, 33, 9, 41,
3635
+ 51, 19, 59, 27, 49, 17, 57, 25,
3636
+ 15, 47, 7, 39, 13, 45, 5, 37,
3637
+ 63, 31, 55, 23, 61, 29, 53, 21
3638
+ );
3639
+
3640
+ float getBayerValue(vec2 uv, int size) {
3641
+ ivec2 pos = ivec2(fract(uv / float(size)) * float(size));
3642
+ int index = pos.y * size + pos.x;
3643
+
3644
+ if (size == 2) {
3645
+ return float(bayer2x2[index]) / 4.0;
3646
+ } else if (size == 4) {
3647
+ return float(bayer4x4[index]) / 16.0;
3648
+ } else if (size == 8) {
3649
+ return float(bayer8x8[index]) / 64.0;
3650
+ }
3651
+ return 0.0;
3652
+ }
3653
+
3654
+
3655
+ void main() {
3656
+
3657
+ float pxSize = u_pxSize * u_pixelRatio;
3658
+ vec2 pxSizeUV = gl_FragCoord.xy - .5 * u_resolution;
3659
+ pxSizeUV /= pxSize;
3660
+ vec2 canvasPixelizedUV = (floor(pxSizeUV) + .5) * pxSize;
3661
+ vec2 normalizedUV = canvasPixelizedUV / u_resolution;
3662
+
3663
+ vec2 imageUV = getImageUV(normalizedUV);
3664
+ vec2 ditheringNoiseUV = canvasPixelizedUV;
3665
+ vec4 image = texture(u_image, imageUV);
3666
+ float frame = getUvFrame(imageUV, pxSize / u_resolution);
3667
+
3668
+ int type = int(floor(u_type));
3669
+ float dithering = 0.0;
3670
+
3671
+ float lum = dot(vec3(.2126, .7152, .0722), image.rgb);
3672
+ lum = u_inverted ? (1. - lum) : lum;
3673
+
3674
+ switch (type) {
3675
+ case 1: {
3676
+ dithering = step(hash21(ditheringNoiseUV), lum);
3677
+ } break;
3678
+ case 2:
3679
+ dithering = getBayerValue(pxSizeUV, 2);
3680
+ break;
3681
+ case 3:
3682
+ dithering = getBayerValue(pxSizeUV, 4);
3683
+ break;
3684
+ default :
3685
+ dithering = getBayerValue(pxSizeUV, 8);
3686
+ break;
3687
+ }
3688
+
3689
+ float colorSteps = max(floor(u_colorSteps), 1.);
3690
+ vec3 color = vec3(0.0);
3691
+ float opacity = 1.;
3692
+
3693
+ dithering -= .5;
3694
+ float brightness = clamp(lum + dithering / colorSteps, 0.0, 1.0);
3695
+ brightness = mix(0.0, brightness, frame);
3696
+ brightness = mix(0.0, brightness, image.a);
3697
+ float quantLum = floor(brightness * colorSteps + 0.5) / colorSteps;
3698
+ quantLum = mix(0.0, quantLum, frame);
3699
+
3700
+ if (u_originalColors == true) {
3701
+ vec3 normColor = image.rgb / max(lum, 0.001);
3702
+ color = normColor * quantLum;
3703
+
3704
+ float quantAlpha = floor(image.a * colorSteps + 0.5) / colorSteps;
3705
+ opacity = mix(quantLum, 1., quantAlpha);
3706
+ } else {
3707
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
3708
+ float fgOpacity = u_colorFront.a;
3709
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
3710
+ float bgOpacity = u_colorBack.a;
3711
+ vec3 hlColor = u_colorHighlight.rgb * u_colorHighlight.a;
3712
+ float hlOpacity = u_colorHighlight.a;
3713
+
3714
+ fgColor = mix(fgColor, hlColor, step(1.02 - .02 * u_colorSteps, brightness));
3715
+ fgOpacity = mix(fgOpacity, hlOpacity, step(1.02 - .02 * u_colorSteps, brightness));
3716
+
3717
+ color = fgColor * quantLum;
3718
+ opacity = fgOpacity * quantLum;
3719
+ color += bgColor * (1.0 - opacity);
3720
+ opacity += bgOpacity * (1.0 - opacity);
3721
+ }
3722
+
3723
+ fragColor = vec4(color, opacity);
3724
+ }
3725
+ `,K={maxColorCount:10},Fe=`#version 300 es
3726
+ precision highp float;
3727
+
3728
+ in mediump vec2 v_imageUV;
3729
+ in mediump vec2 v_objectUV;
3730
+ out vec4 fragColor;
3731
+
3732
+ uniform sampler2D u_image;
3733
+ uniform float u_time;
3734
+ uniform mediump float u_imageAspectRatio;
3735
+
3736
+ uniform vec4 u_colorBack;
3737
+ uniform vec4 u_colors[${K.maxColorCount}];
3738
+ uniform float u_colorsCount;
3739
+
3740
+ uniform float u_angle;
3741
+ uniform float u_noise;
3742
+ uniform float u_innerGlow;
3743
+ uniform float u_outerGlow;
3744
+ uniform float u_contour;
3745
+
3746
+ #define TWO_PI 6.28318530718
3747
+ #define PI 3.14159265358979323846
3748
+
3749
+ float getImgFrame(vec2 uv, float th) {
3750
+ float frame = 1.;
3751
+ frame *= smoothstep(0., th, uv.y);
3752
+ frame *= 1. - smoothstep(1. - th, 1., uv.y);
3753
+ frame *= smoothstep(0., th, uv.x);
3754
+ frame *= 1. - smoothstep(1. - th, 1., uv.x);
3755
+ return frame;
3756
+ }
3757
+
3758
+ float circle(vec2 uv, vec2 c, vec2 r) {
3759
+ return 1. - smoothstep(r[0], r[1], length(uv - c));
3760
+ }
3761
+
3762
+ float lst(float edge0, float edge1, float x) {
3763
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
3764
+ }
3765
+
3766
+ float sst(float edge0, float edge1, float x) {
3767
+ return smoothstep(edge0, edge1, x);
3768
+ }
3769
+
3770
+ float shadowShape(vec2 uv, float t, float contour) {
3771
+ vec2 scaledUV = uv;
3772
+
3773
+ // base shape tranjectory
3774
+ float posY = mix(-1., 2., t);
3775
+
3776
+ // scaleX when it's moving down
3777
+ scaledUV.y -= .5;
3778
+ float mainCircleScale = sst(0., .8, posY) * lst(1.4, .9, posY);
3779
+ scaledUV *= vec2(1., 1. + 1.5 * mainCircleScale);
3780
+ scaledUV.y += .5;
3781
+
3782
+ // base shape
3783
+ float innerR = .4;
3784
+ float outerR = 1. - .3 * (sst(.1, .2, t) * (1. - sst(.2, .5, t)));
3785
+ float s = circle(scaledUV, vec2(.5, posY - .2), vec2(innerR, outerR));
3786
+ float shapeSizing = sst(.2, .3, t) * sst(.6, .3, t);
3787
+ s = pow(s, 1.4);
3788
+ s *= 1.2;
3789
+
3790
+ // flat gradient to take over the shadow shape
3791
+ float topFlattener = 0.;
3792
+ {
3793
+ float pos = posY - uv.y;
3794
+ float edge = 1.2;
3795
+ topFlattener = lst(-.4, 0., pos) * (1. - sst(.0, edge, pos));
3796
+ topFlattener = pow(topFlattener, 3.);
3797
+ float topFlattenerMixer = (1. - sst(.0, .3, pos));
3798
+ s = mix(topFlattener, s, topFlattenerMixer);
3799
+ }
3800
+
3801
+ // apple right circle
3802
+ {
3803
+ float visibility = sst(.6, .7, t) * (1. - sst(.8, .9, t));
3804
+ float angle = -2. -t * TWO_PI;
3805
+ float rightCircle = circle(uv, vec2(.95 - .2 * cos(angle), .4 - .1 * sin(angle)), vec2(.15, .3));
3806
+ rightCircle *= visibility;
3807
+ s = mix(s, 0., rightCircle);
3808
+ }
3809
+
3810
+ // apple top circle
3811
+ {
3812
+ float topCircle = circle(uv, vec2(.5, .19), vec2(.05, .25));
3813
+ topCircle += 2. * contour * circle(uv, vec2(.5, .19), vec2(.2, .5));
3814
+ float visibility = .55 * sst(.2, .3, t) * (1. - sst(.3, .45, t));
3815
+ topCircle *= visibility;
3816
+ s = mix(s, 0., topCircle);
3817
+ }
3818
+
3819
+ float leafMask = circle(uv, vec2(.53, .13), vec2(.08, .19));
3820
+ leafMask = mix(leafMask, 0., 1. - sst(.4, .54, uv.x));
3821
+ leafMask = mix(0., leafMask, sst(.0, .2, uv.y));
3822
+ leafMask *= (sst(.5, 1.1, posY) * sst(1.5, 1.3, posY));
3823
+ s += leafMask;
3824
+
3825
+ // apple bottom circle
3826
+ {
3827
+ float visibility = sst(.0, .4, t) * (1. - sst(.6, .8, t));
3828
+ s = mix(s, 0., visibility * circle(uv, vec2(.52, .92), vec2(.09, .25)));
3829
+ }
3830
+
3831
+ // random balls that are invisible if apple logo is selected
3832
+ {
3833
+ float pos = sst(.0, .6, t) * (1. - sst(.6, 1., t));
3834
+ s = mix(s, .5, circle(uv, vec2(.0, 1.2 - .5 * pos), vec2(.1, .3)));
3835
+ s = mix(s, .0, circle(uv, vec2(1., .5 + .5 * pos), vec2(.1, .3)));
3836
+
3837
+ s = mix(s, 1., circle(uv, vec2(.95, .2 + .2 * sst(.3, .4, t) * sst(.7, .5, t)), vec2(.07, .22)));
3838
+ s = mix(s, 1., circle(uv, vec2(.95, .2 + .2 * sst(.3, .4, t) * (1. - sst(.5, .7, t))), vec2(.07, .22)));
3839
+ s /= max(1e-4, sst(1., .85, uv.y));
3840
+ }
3841
+
3842
+ s = clamp(0., 1., s);
3843
+ return s;
3844
+ }
3845
+
3846
+ float blurEdge3x3(sampler2D tex, vec2 uv, vec2 dudx, vec2 dudy, float radius, float centerSample) {
3847
+ vec2 texel = 1.0 / vec2(textureSize(tex, 0));
3848
+ vec2 r = radius * texel;
3849
+
3850
+ float w1 = 1.0, w2 = 2.0, w4 = 4.0;
3851
+ float norm = 16.0;
3852
+ float sum = w4 * centerSample;
3853
+
3854
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, -r.y), dudx, dudy).g;
3855
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, r.y), dudx, dudy).g;
3856
+ sum += w2 * textureGrad(tex, uv + vec2(-r.x, 0.0), dudx, dudy).g;
3857
+ sum += w2 * textureGrad(tex, uv + vec2(r.x, 0.0), dudx, dudy).g;
3858
+
3859
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, -r.y), dudx, dudy).g;
3860
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, -r.y), dudx, dudy).g;
3861
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, r.y), dudx, dudy).g;
3862
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, r.y), dudx, dudy).g;
3863
+
3864
+ return sum / norm;
3865
+ }
3866
+
3867
+ void main() {
3868
+ vec2 uv = v_objectUV + .5;
3869
+ uv.y = 1. - uv.y;
3870
+
3871
+ vec2 imgUV = v_imageUV;
3872
+ imgUV -= .5;
3873
+ imgUV *= 0.5714285714285714;
3874
+ imgUV += .5;
3875
+ float imgSoftFrame = getImgFrame(imgUV, .03);
3876
+
3877
+ vec4 img = texture(u_image, imgUV);
3878
+ vec2 dudx = dFdx(imgUV);
3879
+ vec2 dudy = dFdy(imgUV);
3880
+
3881
+ if (img.a == 0.) {
3882
+ fragColor = u_colorBack;
3883
+ return;
3884
+ }
3885
+
3886
+ float t = .1 * u_time;
3887
+ t -= .3;
3888
+
3889
+ float tCopy = t + 1. / 3.;
3890
+ float tCopy2 = t + 2. / 3.;
3891
+
3892
+ t = mod(t, 1.);
3893
+ tCopy = mod(tCopy, 1.);
3894
+ tCopy2 = mod(tCopy2, 1.);
3895
+
3896
+ vec2 animationUV = imgUV - vec2(.5);
3897
+ float angle = -u_angle * PI / 180.;
3898
+ float cosA = cos(angle);
3899
+ float sinA = sin(angle);
3900
+ animationUV = vec2(
3901
+ animationUV.x * cosA - animationUV.y * sinA,
3902
+ animationUV.x * sinA + animationUV.y * cosA
3903
+ ) + vec2(.5);
3904
+
3905
+ float shape = img[0];
3906
+
3907
+ img[1] = blurEdge3x3(u_image, imgUV, dudx, dudy, 8., img[1]);
3908
+
3909
+ float outerBlur = 1. - mix(1., img[1], shape);
3910
+ float innerBlur = mix(img[1], 0., shape);
3911
+ float contour = mix(img[2], 0., shape);
3912
+
3913
+ outerBlur *= imgSoftFrame;
3914
+
3915
+ float shadow = shadowShape(animationUV, t, innerBlur);
3916
+ float shadowCopy = shadowShape(animationUV, tCopy, innerBlur);
3917
+ float shadowCopy2 = shadowShape(animationUV, tCopy2, innerBlur);
3918
+
3919
+ float inner = .8 + .8 * innerBlur;
3920
+ inner = mix(inner, 0., shadow);
3921
+ inner = mix(inner, 0., shadowCopy);
3922
+ inner = mix(inner, 0., shadowCopy2);
3923
+
3924
+ inner *= mix(0., 2., u_innerGlow);
3925
+
3926
+ inner += (u_contour * 2.) * contour;
3927
+ inner = min(1., inner);
3928
+ inner *= (1. - shape);
3929
+
3930
+ float outer = 0.;
3931
+ {
3932
+ t *= 3.;
3933
+ t = mod(t - .1, 1.);
3934
+
3935
+ outer = .9 * pow(outerBlur, .8);
3936
+ float y = mod(animationUV.y - t, 1.);
3937
+ float animatedMask = sst(.3, .65, y) * (1. - sst(.65, 1., y));
3938
+ animatedMask = .5 + animatedMask;
3939
+ outer *= animatedMask;
3940
+ outer *= mix(0., 5., pow(u_outerGlow, 2.));
3941
+ outer *= imgSoftFrame;
3942
+ }
3943
+
3944
+ inner = pow(inner, 1.2);
3945
+ float heat = clamp(inner + outer, 0., 1.);
3946
+
3947
+ heat += (.005 + .35 * u_noise) * (fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123) - .5);
3948
+
3949
+ float mixer = heat * u_colorsCount;
3950
+ vec4 gradient = u_colors[0];
3951
+ gradient.rgb *= gradient.a;
3952
+ float outerShape = 0.;
3953
+ for (int i = 1; i < ${K.maxColorCount+1}; i++) {
3954
+ if (i > int(u_colorsCount)) break;
3955
+ float m = clamp(mixer - float(i - 1), 0., 1.);
3956
+ if (i == 1) {
3957
+ outerShape = m;
3958
+ }
3959
+ vec4 c = u_colors[i - 1];
3960
+ c.rgb *= c.a;
3961
+ gradient = mix(gradient, c, m);
3962
+ }
3963
+
3964
+ vec3 color = gradient.rgb * outerShape;
3965
+ float opacity = gradient.a * outerShape;
3966
+
3967
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
3968
+ color = color + bgColor * (1.0 - opacity);
3969
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
3970
+
3971
+ color += .02 * (fract(sin(dot(uv + 1., vec2(12.9898, 78.233))) * 43758.5453123) - .5);
3972
+
3973
+ fragColor = vec4(color, opacity);
3974
+ }
3975
+ `;var Me=`#version 300 es
3976
+ precision mediump float;
3977
+
3978
+ uniform sampler2D u_image;
3979
+ uniform float u_imageAspectRatio;
3980
+
3981
+ uniform vec2 u_resolution;
3982
+ uniform float u_time;
3983
+
3984
+ uniform vec4 u_colorBack;
3985
+ uniform vec4 u_colorTint;
3986
+
3987
+ uniform float u_softness;
3988
+ uniform float u_repetition;
3989
+ uniform float u_shiftRed;
3990
+ uniform float u_shiftBlue;
3991
+ uniform float u_distortion;
3992
+ uniform float u_contour;
3993
+ uniform float u_angle;
3994
+
3995
+ uniform float u_shape;
3996
+ uniform bool u_isImage;
3997
+
3998
+ in vec2 v_objectUV;
3999
+ in vec2 v_responsiveUV;
4000
+ in vec2 v_responsiveBoxGivenSize;
4001
+ in vec2 v_imageUV;
4002
+
4003
+ out vec4 fragColor;
4004
+
4005
+ ${c}
4006
+ ${f}
4007
+ ${h}
4008
+
4009
+ float getColorChanges(float c1, float c2, float stripe_p, vec3 w, float blur, float bump, float tint) {
4010
+
4011
+ float ch = mix(c2, c1, smoothstep(.0, 2. * blur, stripe_p));
4012
+
4013
+ float border = w[0];
4014
+ ch = mix(ch, c2, smoothstep(border, border + 2. * blur, stripe_p));
4015
+
4016
+ if (u_isImage == true) {
4017
+ bump = smoothstep(.2, .8, bump);
4018
+ }
4019
+ border = w[0] + .4 * (1. - bump) * w[1];
4020
+ ch = mix(ch, c1, smoothstep(border, border + 2. * blur, stripe_p));
4021
+
4022
+ border = w[0] + .5 * (1. - bump) * w[1];
4023
+ ch = mix(ch, c2, smoothstep(border, border + 2. * blur, stripe_p));
4024
+
4025
+ border = w[0] + w[1];
4026
+ ch = mix(ch, c1, smoothstep(border, border + 2. * blur, stripe_p));
4027
+
4028
+ float gradient_t = (stripe_p - w[0] - w[1]) / w[2];
4029
+ float gradient = mix(c1, c2, smoothstep(0., 1., gradient_t));
4030
+ ch = mix(ch, gradient, smoothstep(border, border + .5 * blur, stripe_p));
4031
+
4032
+ // Tint color is applied with color burn blending
4033
+ ch = mix(ch, 1. - min(1., (1. - ch) / max(tint, 0.0001)), u_colorTint.a);
4034
+ return ch;
4035
+ }
4036
+
4037
+ float getImgFrame(vec2 uv, float th) {
4038
+ float frame = 1.;
4039
+ frame *= smoothstep(0., th, uv.y);
4040
+ frame *= 1.0 - smoothstep(1. - th, 1., uv.y);
4041
+ frame *= smoothstep(0., th, uv.x);
4042
+ frame *= 1.0 - smoothstep(1. - th, 1., uv.x);
4043
+ return frame;
4044
+ }
4045
+
4046
+ float blurEdge3x3(sampler2D tex, vec2 uv, vec2 dudx, vec2 dudy, float radius, float centerSample) {
4047
+ vec2 texel = 1.0 / vec2(textureSize(tex, 0));
4048
+ vec2 r = radius * texel;
4049
+
4050
+ float w1 = 1.0, w2 = 2.0, w4 = 4.0;
4051
+ float norm = 16.0;
4052
+ float sum = w4 * centerSample;
4053
+
4054
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, -r.y), dudx, dudy).r;
4055
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, r.y), dudx, dudy).r;
4056
+ sum += w2 * textureGrad(tex, uv + vec2(-r.x, 0.0), dudx, dudy).r;
4057
+ sum += w2 * textureGrad(tex, uv + vec2(r.x, 0.0), dudx, dudy).r;
4058
+
4059
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, -r.y), dudx, dudy).r;
4060
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, -r.y), dudx, dudy).r;
4061
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, r.y), dudx, dudy).r;
4062
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, r.y), dudx, dudy).r;
4063
+
4064
+ return sum / norm;
4065
+ }
4066
+
4067
+ float lst(float edge0, float edge1, float x) {
4068
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
4069
+ }
4070
+
4071
+ void main() {
4072
+
4073
+ const float firstFrameOffset = 2.8;
4074
+ float t = .3 * (u_time + firstFrameOffset);
4075
+
4076
+ vec2 uv = v_imageUV;
4077
+ vec2 dudx = dFdx(v_imageUV);
4078
+ vec2 dudy = dFdy(v_imageUV);
4079
+ vec4 img = textureGrad(u_image, uv, dudx, dudy);
4080
+
4081
+ if (u_isImage == false) {
4082
+ uv = v_objectUV + .5;
4083
+ uv.y = 1. - uv.y;
4084
+ }
4085
+
4086
+ float cycleWidth = u_repetition;
4087
+ float edge = 0.;
4088
+ float contOffset = 1.;
4089
+
4090
+ vec2 rotatedUV = uv - vec2(.5);
4091
+ float angle = (-u_angle + 70.) * PI / 180.;
4092
+ float cosA = cos(angle);
4093
+ float sinA = sin(angle);
4094
+ rotatedUV = vec2(
4095
+ rotatedUV.x * cosA - rotatedUV.y * sinA,
4096
+ rotatedUV.x * sinA + rotatedUV.y * cosA
4097
+ ) + vec2(.5);
4098
+
4099
+ if (u_isImage == true) {
4100
+ float edgeRaw = img.r;
4101
+ edge = blurEdge3x3(u_image, uv, dudx, dudy, 6., edgeRaw);
4102
+ edge = pow(edge, 1.6);
4103
+ edge *= mix(0.0, 1.0, smoothstep(0.0, 0.4, u_contour));
4104
+ } else {
4105
+ if (u_shape < 1.) {
4106
+ // full-fill on canvas
4107
+ vec2 borderUV = v_responsiveUV + .5;
4108
+ float ratio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
4109
+ vec2 mask = min(borderUV, 1. - borderUV);
4110
+ vec2 pixel_thickness = 250. / v_responsiveBoxGivenSize;
4111
+ float maskX = smoothstep(0.0, pixel_thickness.x, mask.x);
4112
+ float maskY = smoothstep(0.0, pixel_thickness.y, mask.y);
4113
+ maskX = pow(maskX, .25);
4114
+ maskY = pow(maskY, .25);
4115
+ edge = clamp(1. - maskX * maskY, 0., 1.);
4116
+
4117
+ uv = v_responsiveUV;
4118
+ if (ratio > 1.) {
4119
+ uv.y /= ratio;
4120
+ } else {
4121
+ uv.x *= ratio;
4122
+ }
4123
+ uv += .5;
4124
+ uv.y = 1. - uv.y;
4125
+
4126
+ cycleWidth *= 2.;
4127
+ contOffset = 1.5;
4128
+
4129
+ } else if (u_shape < 2.) {
4130
+ // circle
4131
+ vec2 shapeUV = uv - .5;
4132
+ shapeUV *= .67;
4133
+ edge = pow(clamp(3. * length(shapeUV), 0., 1.), 18.);
4134
+ } else if (u_shape < 3.) {
4135
+ // daisy
4136
+ vec2 shapeUV = uv - .5;
4137
+ shapeUV *= 1.68;
4138
+
4139
+ float r = length(shapeUV) * 2.;
4140
+ float a = atan(shapeUV.y, shapeUV.x) + .2;
4141
+ r *= (1. + .05 * sin(3. * a + 2. * t));
4142
+ float f = abs(cos(a * 3.));
4143
+ edge = smoothstep(f, f + .7, r);
4144
+ edge *= edge;
4145
+
4146
+ uv *= .8;
4147
+ cycleWidth *= 1.6;
4148
+
4149
+ } else if (u_shape < 4.) {
4150
+ // diamond
4151
+ vec2 shapeUV = uv - .5;
4152
+ shapeUV = rotate(shapeUV, .25 * PI);
4153
+ shapeUV *= 1.42;
4154
+ shapeUV += .5;
4155
+ vec2 mask = min(shapeUV, 1. - shapeUV);
4156
+ vec2 pixel_thickness = vec2(.15);
4157
+ float maskX = smoothstep(0.0, pixel_thickness.x, mask.x);
4158
+ float maskY = smoothstep(0.0, pixel_thickness.y, mask.y);
4159
+ maskX = pow(maskX, .25);
4160
+ maskY = pow(maskY, .25);
4161
+ edge = clamp(1. - maskX * maskY, 0., 1.);
4162
+ } else if (u_shape < 5.) {
4163
+ // metaballs
4164
+ vec2 shapeUV = uv - .5;
4165
+ shapeUV *= 1.3;
4166
+ edge = 0.;
4167
+ for (int i = 0; i < 5; i++) {
4168
+ float fi = float(i);
4169
+ float speed = 1.5 + 2./3. * sin(fi * 12.345);
4170
+ float angle = -fi * 1.5;
4171
+ vec2 dir1 = vec2(cos(angle), sin(angle));
4172
+ vec2 dir2 = vec2(cos(angle + 1.57), sin(angle + 1.));
4173
+ vec2 traj = .4 * (dir1 * sin(t * speed + fi * 1.23) + dir2 * cos(t * (speed * 0.7) + fi * 2.17));
4174
+ float d = length(shapeUV + traj);
4175
+ edge += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);
4176
+ }
4177
+ edge = 1. - smoothstep(.65, .9, edge);
4178
+ edge = pow(edge, 4.);
4179
+ }
4180
+
4181
+ edge = mix(smoothstep(.9 - 2. * fwidth(edge), .9, edge), edge, smoothstep(0.0, 0.4, u_contour));
4182
+
4183
+ }
4184
+
4185
+ float opacity = 0.;
4186
+ if (u_isImage == true) {
4187
+ opacity = img.g;
4188
+ float frame = getImgFrame(v_imageUV, 0.);
4189
+ opacity *= frame;
4190
+ } else {
4191
+ opacity = 1. - smoothstep(.9 - 2. * fwidth(edge), .9, edge);
4192
+ if (u_shape < 2.) {
4193
+ edge = 1.2 * edge;
4194
+ } else if (u_shape < 5.) {
4195
+ edge = 1.8 * pow(edge, 1.5);
4196
+ }
4197
+ }
4198
+
4199
+ float diagBLtoTR = rotatedUV.x - rotatedUV.y;
4200
+ float diagTLtoBR = rotatedUV.x + rotatedUV.y;
4201
+
4202
+ vec3 color = vec3(0.);
4203
+ vec3 color1 = vec3(.98, 0.98, 1.);
4204
+ vec3 color2 = vec3(.1, .1, .1 + .1 * smoothstep(.7, 1.3, diagTLtoBR));
4205
+
4206
+ vec2 grad_uv = uv - .5;
4207
+
4208
+ float dist = length(grad_uv + vec2(0., .2 * diagBLtoTR));
4209
+ grad_uv = rotate(grad_uv, (.25 - .2 * diagBLtoTR) * PI);
4210
+ float direction = grad_uv.x;
4211
+
4212
+ float bump = pow(1.8 * dist, 1.2);
4213
+ bump = 1. - bump;
4214
+ bump *= pow(uv.y, .3);
4215
+
4216
+
4217
+ float thin_strip_1_ratio = .12 / cycleWidth * (1. - .4 * bump);
4218
+ float thin_strip_2_ratio = .07 / cycleWidth * (1. + .4 * bump);
4219
+ float wide_strip_ratio = (1. - thin_strip_1_ratio - thin_strip_2_ratio);
4220
+
4221
+ float thin_strip_1_width = cycleWidth * thin_strip_1_ratio;
4222
+ float thin_strip_2_width = cycleWidth * thin_strip_2_ratio;
4223
+
4224
+ float noise = snoise(uv - t);
4225
+
4226
+ edge += (1. - edge) * u_distortion * noise;
4227
+
4228
+ direction += diagBLtoTR;
4229
+ float contour = 0.;
4230
+ direction -= 2. * noise * diagBLtoTR * (smoothstep(0., 1., edge) * (1.0 - smoothstep(0., 1., edge)));
4231
+ direction *= mix(1., 1. - edge, smoothstep(.5, 1., u_contour));
4232
+ direction -= 1.7 * edge * smoothstep(.5, 1., u_contour);
4233
+ direction += .2 * pow(u_contour, 4.) * (1.0 - smoothstep(0., 1., edge));
4234
+
4235
+ bump *= clamp(pow(uv.y, .1), .3, 1.);
4236
+ direction *= (.1 + (1.1 - edge) * bump);
4237
+
4238
+ direction *= (.4 + .6 * (1.0 - smoothstep(.5, 1., edge)));
4239
+ direction += .18 * (smoothstep(.1, .2, uv.y) * (1.0 - smoothstep(.2, .4, uv.y)));
4240
+ direction += .03 * (smoothstep(.1, .2, 1. - uv.y) * (1.0 - smoothstep(.2, .4, 1. - uv.y)));
4241
+
4242
+ direction *= (.5 + .5 * pow(uv.y, 2.));
4243
+ direction *= cycleWidth;
4244
+ direction -= t;
4245
+
4246
+
4247
+ float colorDispersion = (1. - bump);
4248
+ colorDispersion = clamp(colorDispersion, 0., 1.);
4249
+ float dispersionRed = colorDispersion;
4250
+ dispersionRed += .03 * bump * noise;
4251
+ dispersionRed += 5. * (smoothstep(-.1, .2, uv.y) * (1.0 - smoothstep(.1, .5, uv.y))) * (smoothstep(.4, .6, bump) * (1.0 - smoothstep(.4, 1., bump)));
4252
+ dispersionRed -= diagBLtoTR;
4253
+
4254
+ float dispersionBlue = colorDispersion;
4255
+ dispersionBlue *= 1.3;
4256
+ dispersionBlue += (smoothstep(0., .4, uv.y) * (1.0 - smoothstep(.1, .8, uv.y))) * (smoothstep(.4, .6, bump) * (1.0 - smoothstep(.4, .8, bump)));
4257
+ dispersionBlue -= .2 * edge;
4258
+
4259
+ dispersionRed *= (u_shiftRed / 20.);
4260
+ dispersionBlue *= (u_shiftBlue / 20.);
4261
+
4262
+ float blur = 0.;
4263
+ float rExtraBlur = 0.;
4264
+ float gExtraBlur = 0.;
4265
+ if (u_isImage == true) {
4266
+ float softness = 0.05 * u_softness;
4267
+ blur = softness + .5 * smoothstep(1., 10., u_repetition) * smoothstep(.0, 1., edge);
4268
+ float smallCanvasT = 1.0 - smoothstep(100., 500., min(u_resolution.x, u_resolution.y));
4269
+ blur += smallCanvasT * smoothstep(.0, 1., edge);
4270
+ rExtraBlur = softness * (0.05 + .1 * (u_shiftRed / 20.) * bump);
4271
+ gExtraBlur = softness * 0.05 / max(0.001, abs(1. - diagBLtoTR));
4272
+ } else {
4273
+ blur = u_softness / 15. + .3 * contour;
4274
+ }
4275
+
4276
+ vec3 w = vec3(thin_strip_1_width, thin_strip_2_width, wide_strip_ratio);
4277
+ w[1] -= .02 * smoothstep(.0, 1., edge + bump);
4278
+ float stripe_r = fract(direction + dispersionRed);
4279
+ float r = getColorChanges(color1.r, color2.r, stripe_r, w, blur + fwidth(stripe_r) + rExtraBlur, bump, u_colorTint.r);
4280
+ float stripe_g = fract(direction);
4281
+ float g = getColorChanges(color1.g, color2.g, stripe_g, w, blur + fwidth(stripe_g) + gExtraBlur, bump, u_colorTint.g);
4282
+ float stripe_b = fract(direction - dispersionBlue);
4283
+ float b = getColorChanges(color1.b, color2.b, stripe_b, w, blur + fwidth(stripe_b), bump, u_colorTint.b);
4284
+
4285
+ color = vec3(r, g, b);
4286
+ color *= opacity;
4287
+
4288
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
4289
+ color = color + bgColor * (1. - opacity);
4290
+ opacity = opacity + u_colorBack.a * (1. - opacity);
4291
+
4292
+ ${p}
4293
+
4294
+ fragColor = vec4(color, opacity);
4295
+ }
4296
+ `;var Ee=`#version 300 es
4297
+ precision mediump float;
4298
+
4299
+ uniform float u_rotation;
4300
+
4301
+ uniform float u_time;
4302
+
4303
+ uniform vec4 u_colorFront;
4304
+ uniform vec4 u_colorBack;
4305
+ uniform float u_radius;
4306
+ uniform float u_contrast;
4307
+
4308
+ uniform sampler2D u_image;
4309
+ uniform float u_imageAspectRatio;
4310
+
4311
+ uniform float u_size;
4312
+ uniform float u_grainMixer;
4313
+ uniform float u_grainOverlay;
4314
+ uniform float u_grainSize;
4315
+ uniform float u_grid;
4316
+ uniform bool u_originalColors;
4317
+ uniform bool u_inverted;
4318
+ uniform float u_type;
4319
+
4320
+ in vec2 v_imageUV;
4321
+
4322
+ out vec4 fragColor;
4323
+
4324
+ ${c}
4325
+ ${f}
4326
+ ${g}
4327
+
4328
+ float valueNoise(vec2 st) {
4329
+ vec2 i = floor(st);
4330
+ vec2 f = fract(st);
4331
+ float a = hash21(i);
4332
+ float b = hash21(i + vec2(1.0, 0.0));
4333
+ float c = hash21(i + vec2(0.0, 1.0));
4334
+ float d = hash21(i + vec2(1.0, 1.0));
4335
+ vec2 u = f * f * (3.0 - 2.0 * f);
4336
+ float x1 = mix(a, b, u.x);
4337
+ float x2 = mix(c, d, u.x);
4338
+ return mix(x1, x2, u.y);
4339
+ }
4340
+
4341
+ float lst(float edge0, float edge1, float x) {
4342
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
4343
+ }
4344
+
4345
+ float sst(float edge0, float edge1, float x) {
4346
+ return smoothstep(edge0, edge1, x);
4347
+ }
4348
+
4349
+ float getCircle(vec2 uv, float r, float baseR) {
4350
+ r = mix(.25 * baseR, 0., r);
4351
+ float d = length(uv - .5);
4352
+ float aa = fwidth(d);
4353
+ return 1. - smoothstep(r - aa, r + aa, d);
4354
+ }
4355
+
4356
+ float getCell(vec2 uv) {
4357
+ float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));
4358
+ float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));
4359
+ return insideX * insideY;
4360
+ }
4361
+
4362
+ float getCircleWithHole(vec2 uv, float r, float baseR) {
4363
+ float cell = getCell(uv);
4364
+
4365
+ r = mix(.75 * baseR, 0., r);
4366
+ float rMod = mod(r, .5);
4367
+
4368
+ float d = length(uv - .5);
4369
+ float aa = fwidth(d);
4370
+ float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);
4371
+ if (r < .5) {
4372
+ return circle;
4373
+ } else {
4374
+ return cell - circle;
4375
+ }
4376
+ }
4377
+
4378
+ float getGooeyBall(vec2 uv, float r, float baseR) {
4379
+ float d = length(uv - .5);
4380
+ float sizeRadius = .3;
4381
+ if (u_grid == 1.) {
4382
+ sizeRadius = .42;
4383
+ }
4384
+ sizeRadius = mix(sizeRadius * baseR, 0., r);
4385
+ d = 1. - sst(0., sizeRadius, d);
4386
+
4387
+ d = pow(d, 2. + baseR);
4388
+ return d;
4389
+ }
4390
+
4391
+ float getSoftBall(vec2 uv, float r, float baseR) {
4392
+ float d = length(uv - .5);
4393
+ float sizeRadius = clamp(baseR, 0., 1.);
4394
+ sizeRadius = mix(.5 * sizeRadius, 0., r);
4395
+ d = 1. - lst(0., sizeRadius, d);
4396
+ float powRadius = 1. - lst(0., 2., baseR);
4397
+ d = pow(d, 4. + 3. * powRadius);
4398
+ return d;
4399
+ }
4400
+
4401
+ float getUvFrame(vec2 uv, vec2 pad) {
4402
+ float aa = 0.0001;
4403
+
4404
+ float left = smoothstep(-pad.x, -pad.x + aa, uv.x);
4405
+ float right = smoothstep(1.0 + pad.x, 1.0 + pad.x - aa, uv.x);
4406
+ float bottom = smoothstep(-pad.y, -pad.y + aa, uv.y);
4407
+ float top = smoothstep(1.0 + pad.y, 1.0 + pad.y - aa, uv.y);
4408
+
4409
+ return left * right * bottom * top;
4410
+ }
4411
+
4412
+ float sigmoid(float x, float k) {
4413
+ return 1.0 / (1.0 + exp(-k * (x - 0.5)));
4414
+ }
4415
+
4416
+ float getLumAtPx(vec2 uv, float contrast) {
4417
+ vec4 tex = texture(u_image, uv);
4418
+ vec3 color = vec3(
4419
+ sigmoid(tex.r, contrast),
4420
+ sigmoid(tex.g, contrast),
4421
+ sigmoid(tex.b, contrast)
4422
+ );
4423
+ float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);
4424
+ lum = mix(1., lum, tex.a);
4425
+ lum = u_inverted ? (1. - lum) : lum;
4426
+ return lum;
4427
+ }
4428
+
4429
+ float getLumBall(vec2 p, vec2 pad, vec2 inCellOffset, float contrast, float baseR, float stepSize, out vec4 ballColor) {
4430
+ p += inCellOffset;
4431
+ vec2 uv_i = floor(p);
4432
+ vec2 uv_f = fract(p);
4433
+ vec2 samplingUV = (uv_i + .5 - inCellOffset) * pad + vec2(.5);
4434
+ float outOfFrame = getUvFrame(samplingUV, pad * stepSize);
4435
+
4436
+ float lum = getLumAtPx(samplingUV, contrast);
4437
+ ballColor = texture(u_image, samplingUV);
4438
+ ballColor.rgb *= ballColor.a;
4439
+ ballColor *= outOfFrame;
4440
+
4441
+ float ball = 0.;
4442
+ if (u_type == 0.) {
4443
+ // classic
4444
+ ball = getCircle(uv_f, lum, baseR);
4445
+ } else if (u_type == 1.) {
4446
+ // gooey
4447
+ ball = getGooeyBall(uv_f, lum, baseR);
4448
+ } else if (u_type == 2.) {
4449
+ // holes
4450
+ ball = getCircleWithHole(uv_f, lum, baseR);
4451
+ } else if (u_type == 3.) {
4452
+ // soft
4453
+ ball = getSoftBall(uv_f, lum, baseR);
4454
+ }
4455
+
4456
+ return ball * outOfFrame;
4457
+ }
4458
+
4459
+
4460
+ void main() {
4461
+
4462
+ float stepMultiplier = 1.;
4463
+ if (u_type == 0.) {
4464
+ // classic
4465
+ stepMultiplier = 2.;
4466
+ } else if (u_type == 1. || u_type == 3.) {
4467
+ // gooey & soft
4468
+ stepMultiplier = 6.;
4469
+ }
4470
+
4471
+ float cellsPerSide = mix(300., 7., pow(u_size, .7));
4472
+ cellsPerSide /= stepMultiplier;
4473
+ float cellSizeY = 1. / cellsPerSide;
4474
+ vec2 pad = cellSizeY * vec2(1. / u_imageAspectRatio, 1.);
4475
+ if (u_type == 1. && u_grid == 1.) {
4476
+ // gooey diagonal grid works differently
4477
+ pad *= .7;
4478
+ }
4479
+
4480
+ vec2 uv = v_imageUV;
4481
+ uv -= vec2(.5);
4482
+ uv /= pad;
4483
+
4484
+ float contrast = mix(0., 15., pow(u_contrast, 1.5));
4485
+ float baseRadius = u_radius;
4486
+ if (u_originalColors == true) {
4487
+ contrast = mix(.1, 4., pow(u_contrast, 2.));
4488
+ baseRadius = 2. * pow(.5 * u_radius, .3);
4489
+ }
4490
+
4491
+ float totalShape = 0.;
4492
+ vec3 totalColor = vec3(0.);
4493
+ float totalOpacity = 0.;
4494
+
4495
+ vec4 ballColor;
4496
+ float shape;
4497
+ float stepSize = 1. / stepMultiplier;
4498
+ for (float x = -0.5; x < 0.5; x += stepSize) {
4499
+ for (float y = -0.5; y < 0.5; y += stepSize) {
4500
+ vec2 offset = vec2(x, y);
4501
+
4502
+ if (u_grid == 1.) {
4503
+ float rowIndex = floor((y + .5) / stepSize);
4504
+ float colIndex = floor((x + .5) / stepSize);
4505
+ if (stepSize == 1.) {
4506
+ rowIndex = floor(uv.y + y + 1.);
4507
+ if (u_type == 1.) {
4508
+ colIndex = floor(uv.x + x + 1.);
4509
+ }
4510
+ }
4511
+ if (u_type == 1.) {
4512
+ if (mod(rowIndex + colIndex, 2.) == 1.) {
4513
+ continue;
4514
+ }
4515
+ } else {
4516
+ if (mod(rowIndex, 2.) == 1.) {
4517
+ offset.x += .5 * stepSize;
4518
+ }
4519
+ }
4520
+ }
4521
+
4522
+ shape = getLumBall(uv, pad, offset, contrast, baseRadius, stepSize, ballColor);
4523
+ totalColor += ballColor.rgb * shape;
4524
+ totalShape += shape;
4525
+ totalOpacity += shape;
4526
+ }
4527
+ }
4528
+
4529
+ const float eps = 1e-4;
4530
+
4531
+ totalColor /= max(totalShape, eps);
4532
+ totalOpacity /= max(totalShape, eps);
4533
+
4534
+ float finalShape = 0.;
4535
+ if (u_type == 0.) {
4536
+ finalShape = min(1., totalShape);
4537
+ } else if (u_type == 1.) {
4538
+ float aa = fwidth(totalShape);
4539
+ float th = .5;
4540
+ finalShape = smoothstep(th - aa, th + aa, totalShape);
4541
+ } else if (u_type == 2.) {
4542
+ finalShape = min(1., totalShape);
4543
+ } else if (u_type == 3.) {
4544
+ finalShape = totalShape;
4545
+ }
4546
+
4547
+ vec2 grainSize = mix(2000., 200., u_grainSize) * vec2(1., 1. / u_imageAspectRatio);
4548
+ vec2 grainUV = v_imageUV - .5;
4549
+ grainUV *= grainSize;
4550
+ grainUV += .5;
4551
+ float grain = valueNoise(grainUV);
4552
+ grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);
4553
+ grain *= u_grainMixer;
4554
+ finalShape = mix(finalShape, 0., grain);
4555
+
4556
+ vec3 color = vec3(0.);
4557
+ float opacity = 0.;
4558
+
4559
+ if (u_originalColors == true) {
4560
+ color = totalColor * finalShape;
4561
+ opacity = totalOpacity * finalShape;
4562
+
4563
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
4564
+ color = color + bgColor * (1. - opacity);
4565
+ opacity = opacity + u_colorBack.a * (1. - opacity);
4566
+ } else {
4567
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
4568
+ float fgOpacity = u_colorFront.a;
4569
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
4570
+ float bgOpacity = u_colorBack.a;
4571
+
4572
+ color = fgColor * finalShape;
4573
+ opacity = fgOpacity * finalShape;
4574
+ color += bgColor * (1. - opacity);
4575
+ opacity += bgOpacity * (1. - opacity);
4576
+ }
4577
+
4578
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
4579
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
4580
+ grainOverlay = pow(grainOverlay, 1.3);
4581
+
4582
+ float grainOverlayV = grainOverlay * 2. - 1.;
4583
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
4584
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
4585
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
4586
+ color = mix(color, grainOverlayColor, .5 * grainOverlayStrength);
4587
+
4588
+ opacity += .5 * grainOverlayStrength;
4589
+ opacity = clamp(opacity, 0., 1.);
4590
+
4591
+ fragColor = vec4(color, opacity);
4592
+ }
4593
+ `;var ze=`#version 300 es
4594
+ precision mediump float;
4595
+
4596
+ uniform sampler2D u_image;
4597
+ uniform float u_imageAspectRatio;
4598
+
4599
+ uniform vec4 u_colorBack;
4600
+ uniform vec4 u_colorC;
4601
+ uniform vec4 u_colorM;
4602
+ uniform vec4 u_colorY;
4603
+ uniform vec4 u_colorK;
4604
+ uniform float u_size;
4605
+ uniform float u_minDot;
4606
+ uniform float u_contrast;
4607
+ uniform float u_grainSize;
4608
+ uniform float u_grainMixer;
4609
+ uniform float u_grainOverlay;
4610
+ uniform float u_gridNoise;
4611
+ uniform float u_softness;
4612
+ uniform float u_floodC;
4613
+ uniform float u_floodM;
4614
+ uniform float u_floodY;
4615
+ uniform float u_floodK;
4616
+ uniform float u_gainC;
4617
+ uniform float u_gainM;
4618
+ uniform float u_gainY;
4619
+ uniform float u_gainK;
4620
+ uniform float u_type;
4621
+ uniform sampler2D u_noiseTexture;
4622
+
4623
+ in vec2 v_imageUV;
4624
+ out vec4 fragColor;
4625
+
4626
+ const float shiftC = -.5;
4627
+ const float shiftM = -.25;
4628
+ const float shiftY = .2;
4629
+ const float shiftK = 0.;
4630
+
4631
+ // Precomputed sin/cos for rotation angles (15\xB0, 75\xB0, 0\xB0, 45\xB0)
4632
+ const float cosC = 0.9659258; const float sinC = 0.2588190; // 15\xB0
4633
+ const float cosM = 0.2588190; const float sinM = 0.9659258; // 75\xB0
4634
+ const float cosY = 1.0; const float sinY = 0.0; // 0\xB0
4635
+ const float cosK = 0.7071068; const float sinK = 0.7071068; // 45\xB0
4636
+
4637
+ ${c}
4638
+
4639
+ vec2 randomRG(vec2 p) {
4640
+ vec2 uv = floor(p) / 100. + .5;
4641
+ return texture(u_noiseTexture, fract(uv)).rg;
4642
+ }
4643
+ vec3 hash23(vec2 p) {
4644
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.3183099, 0.3678794, 0.3141592)) + 0.1;
4645
+ p3 += dot(p3, p3.yzx + 19.19);
4646
+ return fract(vec3(p3.x * p3.y, p3.y * p3.z, p3.z * p3.x));
4647
+ }
4648
+
4649
+ float sst(float edge0, float edge1, float x) {
4650
+ return smoothstep(edge0, edge1, x);
4651
+ }
4652
+
4653
+ vec3 valueNoise3(vec2 st) {
4654
+ vec2 i = floor(st);
4655
+ vec2 f = fract(st);
4656
+ vec3 a = hash23(i);
4657
+ vec3 b = hash23(i + vec2(1.0, 0.0));
4658
+ vec3 c = hash23(i + vec2(0.0, 1.0));
4659
+ vec3 d = hash23(i + vec2(1.0, 1.0));
4660
+ vec2 u = f * f * (3.0 - 2.0 * f);
4661
+ vec3 x1 = mix(a, b, u.x);
4662
+ vec3 x2 = mix(c, d, u.x);
4663
+ return mix(x1, x2, u.y);
4664
+ }
4665
+
4666
+ float getUvFrame(vec2 uv, vec2 pad) {
4667
+ float left = smoothstep(-pad.x, 0., uv.x);
4668
+ float right = smoothstep(1. + pad.x, 1., uv.x);
4669
+ float bottom = smoothstep(-pad.y, 0., uv.y);
4670
+ float top = smoothstep(1. + pad.y, 1., uv.y);
4671
+
4672
+ return left * right * bottom * top;
4673
+ }
4674
+
4675
+ vec4 RGBAtoCMYK(vec4 rgba) {
4676
+ float k = 1. - max(max(rgba.r, rgba.g), rgba.b);
4677
+ float denom = 1. - k;
4678
+ vec3 cmy = vec3(0.);
4679
+ if (denom > 1e-5) {
4680
+ cmy = (1. - rgba.rgb - vec3(k)) / denom;
4681
+ }
4682
+ return vec4(cmy, k) * rgba.a;
4683
+ }
4684
+
4685
+ vec3 applyContrast(vec3 rgb) {
4686
+ return clamp((rgb - 0.5) * u_contrast + 0.5, 0.0, 1.0);
4687
+ }
4688
+
4689
+ // Single-component CMYK extractors with contrast built-in, alpha-aware
4690
+ float getCyan(vec4 rgba) {
4691
+ vec3 c = clamp((rgba.rgb - 0.5) * u_contrast + 0.5, 0.0, 1.0);
4692
+ float maxRGB = max(max(c.r, c.g), c.b);
4693
+ return (maxRGB > 1e-5 ? (maxRGB - c.r) / maxRGB : 0.) * rgba.a;
4694
+ }
4695
+ float getMagenta(vec4 rgba) {
4696
+ vec3 c = clamp((rgba.rgb - 0.5) * u_contrast + 0.5, 0.0, 1.0);
4697
+ float maxRGB = max(max(c.r, c.g), c.b);
4698
+ return (maxRGB > 1e-5 ? (maxRGB - c.g) / maxRGB : 0.) * rgba.a;
4699
+ }
4700
+ float getYellow(vec4 rgba) {
4701
+ vec3 c = clamp((rgba.rgb - 0.5) * u_contrast + 0.5, 0.0, 1.0);
4702
+ float maxRGB = max(max(c.r, c.g), c.b);
4703
+ return (maxRGB > 1e-5 ? (maxRGB - c.b) / maxRGB : 0.) * rgba.a;
4704
+ }
4705
+ float getBlack(vec4 rgba) {
4706
+ vec3 c = clamp((rgba.rgb - 0.5) * u_contrast + 0.5, 0.0, 1.0);
4707
+ return (1. - max(max(c.r, c.g), c.b)) * rgba.a;
4708
+ }
4709
+
4710
+ vec2 cellCenterPos(vec2 uv, vec2 cellOffset, float channelIdx) {
4711
+ vec2 cellCenter = floor(uv) + .5 + cellOffset;
4712
+ return cellCenter + (randomRG(cellCenter + channelIdx * 50.) - .5) * u_gridNoise;
4713
+ }
4714
+
4715
+ vec2 gridToImageUV(vec2 cellCenter, float cosA, float sinA, float shift, vec2 pad) {
4716
+ vec2 uvGrid = mat2(cosA, -sinA, sinA, cosA) * (cellCenter - shift);
4717
+ return uvGrid * pad + 0.5;
4718
+ }
4719
+
4720
+ void colorMask(vec2 pos, vec2 cellCenter, float rad, float transparency, float grain, float channelAddon, float channelgain, float generalComp, bool isJoined, inout float outMask) {
4721
+ float dist = length(pos - cellCenter);
4722
+
4723
+ float radius = rad;
4724
+ radius *= (1. + generalComp);
4725
+ radius += (.15 + channelgain * radius);
4726
+ radius = max(0., radius);
4727
+ radius = mix(0., radius, transparency);
4728
+ radius += channelAddon;
4729
+ radius *= (1. - grain);
4730
+
4731
+ float mask = 1. - sst(0., radius, dist);
4732
+ if (isJoined) {
4733
+ // ink or sharp (joined)
4734
+ mask = pow(mask, 1.2);
4735
+ } else {
4736
+ // dots (separate)
4737
+ mask = sst(.5 - .5 * u_softness, .51 + .49 * u_softness, mask);
4738
+ }
4739
+
4740
+ mask *= mix(1., mix(.5, 1., 1.5 * radius), u_softness);
4741
+ outMask += mask;
4742
+ }
4743
+
4744
+ vec3 applyInk(vec3 paper, vec3 inkColor, float cov) {
4745
+ vec3 inkEffect = mix(vec3(1.0), inkColor, clamp(cov, 0.0, 1.0));
4746
+ return paper * inkEffect;
4747
+ }
4748
+
4749
+ void main() {
4750
+ vec2 uv = v_imageUV;
4751
+
4752
+ float cellsPerSide = mix(400.0, 7.0, pow(u_size, 0.7));
4753
+ float cellSizeY = 1.0 / cellsPerSide;
4754
+ vec2 pad = cellSizeY * vec2(1.0 / u_imageAspectRatio, 1.0);
4755
+ vec2 uvGrid = (uv - .5) / pad;
4756
+ float insideImageBox = getUvFrame(uv, pad);
4757
+
4758
+ float generalComp = .1 * u_softness + .1 * u_gridNoise + .1 * (1. - step(0.5, u_type)) * (1.5 - u_softness);
4759
+
4760
+ vec2 uvC = mat2(cosC, sinC, -sinC, cosC) * uvGrid + shiftC;
4761
+ vec2 uvM = mat2(cosM, sinM, -sinM, cosM) * uvGrid + shiftM;
4762
+ vec2 uvY = mat2(cosY, sinY, -sinY, cosY) * uvGrid + shiftY;
4763
+ vec2 uvK = mat2(cosK, sinK, -sinK, cosK) * uvGrid + shiftK;
4764
+
4765
+ vec2 grainSize = mix(2000., 200., u_grainSize) * vec2(1., 1. / u_imageAspectRatio);
4766
+ vec2 grainUV = (v_imageUV - .5) * grainSize + .5;
4767
+ vec3 noiseValues = valueNoise3(grainUV);
4768
+ float grain = sst(.55, 1., noiseValues.r);
4769
+ grain *= u_grainMixer;
4770
+
4771
+ vec4 outMask = vec4(0.);
4772
+ bool isJoined = u_type > 0.5;
4773
+
4774
+ if (u_type < 1.5) {
4775
+ // dots or ink: per-cell color sampling
4776
+ for (int dy = -1; dy <= 1; dy++) {
4777
+ for (int dx = -1; dx <= 1; dx++) {
4778
+ vec2 cellOffset = vec2(float(dx), float(dy));
4779
+
4780
+ vec2 cellCenterC = cellCenterPos(uvC, cellOffset, 0.);
4781
+ vec4 texC = texture(u_image, gridToImageUV(cellCenterC, cosC, sinC, shiftC, pad));
4782
+ colorMask(uvC, cellCenterC, getCyan(texC), insideImageBox * texC.a, grain, u_floodC, u_gainC, generalComp, isJoined, outMask[0]);
4783
+
4784
+ vec2 cellCenterM = cellCenterPos(uvM, cellOffset, 1.);
4785
+ vec4 texM = texture(u_image, gridToImageUV(cellCenterM, cosM, sinM, shiftM, pad));
4786
+ colorMask(uvM, cellCenterM, getMagenta(texM), insideImageBox * texM.a, grain, u_floodM, u_gainM, generalComp, isJoined, outMask[1]);
4787
+
4788
+ vec2 cellCenterY = cellCenterPos(uvY, cellOffset, 2.);
4789
+ vec4 texY = texture(u_image, gridToImageUV(cellCenterY, cosY, sinY, shiftY, pad));
4790
+ colorMask(uvY, cellCenterY, getYellow(texY), insideImageBox * texY.a, grain, u_floodY, u_gainY, generalComp, isJoined, outMask[2]);
4791
+
4792
+ vec2 cellCenterK = cellCenterPos(uvK, cellOffset, 3.);
4793
+ vec4 texK = texture(u_image, gridToImageUV(cellCenterK, cosK, sinK, shiftK, pad));
4794
+ colorMask(uvK, cellCenterK, getBlack(texK), insideImageBox * texK.a, grain, u_floodK, u_gainK, generalComp, isJoined, outMask[3]);
4795
+ }
4796
+ }
4797
+ } else {
4798
+ // sharp: direct px color sampling
4799
+ vec4 tex = texture(u_image, uv);
4800
+ tex.rgb = applyContrast(tex.rgb);
4801
+ insideImageBox *= tex.a;
4802
+ vec4 cmykOriginal = RGBAtoCMYK(tex);
4803
+ for (int dy = -1; dy <= 1; dy++) {
4804
+ for (int dx = -1; dx <= 1; dx++) {
4805
+ vec2 cellOffset = vec2(float(dx), float(dy));
4806
+
4807
+ colorMask(uvC, cellCenterPos(uvC, cellOffset, 0.), cmykOriginal.x, insideImageBox, grain, u_floodC, u_gainC, generalComp, isJoined, outMask[0]);
4808
+ colorMask(uvM, cellCenterPos(uvM, cellOffset, 1.), cmykOriginal.y, insideImageBox, grain, u_floodM, u_gainM, generalComp, isJoined, outMask[1]);
4809
+ colorMask(uvY, cellCenterPos(uvY, cellOffset, 2.), cmykOriginal.z, insideImageBox, grain, u_floodY, u_gainY, generalComp, isJoined, outMask[2]);
4810
+ colorMask(uvK, cellCenterPos(uvK, cellOffset, 3.), cmykOriginal.w, insideImageBox, grain, u_floodK, u_gainK, generalComp, isJoined, outMask[3]);
4811
+ }
4812
+ }
4813
+ }
4814
+
4815
+ float shape;
4816
+
4817
+ float C = outMask[0];
4818
+ float M = outMask[1];
4819
+ float Y = outMask[2];
4820
+ float K = outMask[3];
4821
+
4822
+ if (isJoined) {
4823
+ // ink or sharp: apply threshold for joined dots
4824
+ float th = .5;
4825
+ float sLeft = th * u_softness;
4826
+ float sRight = (1. - th) * u_softness + .01;
4827
+ C = smoothstep(th - sLeft - fwidth(C), th + sRight, C);
4828
+ M = smoothstep(th - sLeft - fwidth(M), th + sRight, M);
4829
+ Y = smoothstep(th - sLeft - fwidth(Y), th + sRight, Y);
4830
+ K = smoothstep(th - sLeft - fwidth(K), th + sRight, K);
4831
+ }
4832
+
4833
+ C *= u_colorC.a;
4834
+ M *= u_colorM.a;
4835
+ Y *= u_colorY.a;
4836
+ K *= u_colorK.a;
4837
+
4838
+ vec3 ink = vec3(1.);
4839
+ ink = applyInk(ink, u_colorK.rgb, K);
4840
+ ink = applyInk(ink, u_colorC.rgb, C);
4841
+ ink = applyInk(ink, u_colorM.rgb, M);
4842
+ ink = applyInk(ink, u_colorY.rgb, Y);
4843
+
4844
+ shape = clamp(max(max(C, M), max(Y, K)), 0., 1.);
4845
+
4846
+ vec3 color = u_colorBack.rgb * u_colorBack.a;
4847
+
4848
+ float opacity = u_colorBack.a;
4849
+ color = mix(color, ink, shape);
4850
+ opacity += shape;
4851
+ opacity = clamp(opacity, 0., 1.);
4852
+
4853
+ float grainOverlay = mix(noiseValues.g, noiseValues.b, .5);
4854
+ grainOverlay = pow(grainOverlay, 1.3);
4855
+
4856
+ float grainOverlayV = grainOverlay * 2. - 1.;
4857
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
4858
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
4859
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
4860
+ color = mix(color, grainOverlayColor, .5 * grainOverlayStrength);
4861
+
4862
+ opacity += .5 * grainOverlayStrength;
4863
+ opacity = clamp(opacity, 0., 1.);
4864
+
4865
+ fragColor = vec4(color, opacity);
4866
+ }
4867
+ `;function A(e){if(Array.isArray(e))return e.length===4?e:e.length===3?[...e,1]:M;if(typeof e!="string")return M;let o,t,i,n=1;if(e.startsWith("#"))[o,t,i,n]=ie(e);else if(e.startsWith("rgb"))[o,t,i,n]=re(e);else if(e.startsWith("hsl"))[o,t,i,n]=le(se(e));else return console.error("Unsupported color format",e),M;return[C(o,0,1),C(t,0,1),C(i,0,1),C(n,0,1)]}function ie(e){e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(s=>s+s).join("")),e.length===6&&(e=e+"ff");let o=parseInt(e.slice(0,2),16)/255,t=parseInt(e.slice(2,4),16)/255,i=parseInt(e.slice(4,6),16)/255,n=parseInt(e.slice(6,8),16)/255;return[o,t,i,n]}function re(e){let o=e.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+))?\s*\)$/i);return o?[parseInt(o[1]??"0")/255,parseInt(o[2]??"0")/255,parseInt(o[3]??"0")/255,o[4]===void 0?1:parseFloat(o[4])]:[0,0,0,1]}function se(e){let o=e.match(/^hsla?\s*\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([0-9.]+))?\s*\)$/i);return o?[parseInt(o[1]??"0"),parseInt(o[2]??"0"),parseInt(o[3]??"0"),o[4]===void 0?1:parseFloat(o[4])]:[0,0,0,1]}function le(e){let[o,t,i,n]=e,s=o/360,r=t/100,l=i/100,m,u,d;if(t===0)m=u=d=l;else{let x=(y,V,v)=>(v<0&&(v+=1),v>1&&(v-=1),v<.16666666666666666?y+(V-y)*6*v:v<.5?V:v<.6666666666666666?y+(V-y)*(.6666666666666666-v)*6:y),b=l<.5?l*(1+r):l+r-l*r,U=2*l-b;m=x(U,b,s+1/3),u=x(U,b,s),d=x(U,b,s-1/3)}return[m,u,d,n]}var C=(e,o,t)=>Math.min(Math.max(e,o),t),M=[0,0,0,1];function Qe(e,o){let t=B[o.shape]??B.warp,i=S[o.type]??S["2x2"],n={u_colorFront:A(o.colorFront),u_colorBack:A(o.colorBack),u_shape:t,u_type:i,u_pxSize:o.size,u_scale:o.scale,u_rotation:parseFloat(o.rotation)||180,u_originX:.5,u_originY:.5,u_worldWidth:0,u_worldHeight:0,u_fit:0,u_offsetX:0,u_offsetY:0},s=new X(e,J,n,{alpha:!0,premultipliedAlpha:!1},o.speed,0,2);return{updateParams(r){let l={};r.colorFront!==void 0&&(l.u_colorFront=A(r.colorFront)),r.colorBack!==void 0&&(l.u_colorBack=A(r.colorBack)),r.shape!==void 0&&(l.u_shape=B[r.shape]??t),r.type!==void 0&&(l.u_type=S[r.type]??i),r.size!==void 0&&(l.u_pxSize=r.size),r.scale!==void 0&&(l.u_scale=r.scale),r.rotation!==void 0&&(l.u_rotation=parseFloat(r.rotation)||180),r.speed!==void 0&&s.setSpeed(r.speed),Object.keys(l).length>0&&s.setUniforms(l)},destroy(){s.dispose()}}}export{Qe as createDitheringRenderer};