@paper-design/shaders 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,128 +1,145 @@
1
1
  /***** Paper Shaders: https://github.com/paper-design/shaders *****/
2
- var g=class{canvas;gl;program=null;uniformLocations={};fragmentShader;rafId=null;lastFrameTime=0;totalAnimationTime=0;speed=1;providedUniforms;hasBeenDisposed=!1;resolutionChanged=!0;constructor(r,t,o={},i,n=1){this.canvas=r,this.fragmentShader=t,this.providedUniforms=o;let u=r.getContext("webgl",i);if(!u)throw new Error("WebGL not supported");this.gl=u,this.initWebGL(),this.setupResizeObserver(),this.setSpeed(n),this.canvas.setAttribute("data-paper-shaders","true")}initWebGL=()=>{let r=R(this.gl,y,this.fragmentShader);r&&(this.program=r,this.setupPositionAttribute(),this.setupUniforms())};setupPositionAttribute=()=>{let r=this.gl.getAttribLocation(this.program,"a_position"),t=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t);let o=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1];this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(o),this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,2,this.gl.FLOAT,!1,0,0)};setupUniforms=()=>{this.uniformLocations={u_time:this.gl.getUniformLocation(this.program,"u_time"),u_resolution:this.gl.getUniformLocation(this.program,"u_resolution"),...Object.fromEntries(Object.keys(this.providedUniforms).map(r=>[r,this.gl.getUniformLocation(this.program,r)]))}};resizeObserver=null;setupResizeObserver=()=>{this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver.observe(this.canvas),this.handleResize()};handleResize=()=>{let r=Math.min(2,window.devicePixelRatio),t=this.canvas.clientWidth*r,o=this.canvas.clientHeight*r;(this.canvas.width!==t||this.canvas.height!==o)&&(this.canvas.width=t,this.canvas.height=o,this.resolutionChanged=!0,this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.render(performance.now()))};render=r=>{if(this.hasBeenDisposed)return;let t=r-this.lastFrameTime;this.lastFrameTime=r,this.speed!==0&&(this.totalAnimationTime+=t*this.speed),this.gl.useProgram(this.program),this.gl.uniform1f(this.uniformLocations.u_time,this.totalAnimationTime*.001),this.resolutionChanged&&(this.gl.uniform2f(this.uniformLocations.u_resolution,this.gl.canvas.width,this.gl.canvas.height),this.resolutionChanged=!1),this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.speed!==0?this.requestRender():this.rafId=null};requestRender=()=>{this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(this.render)};updateProvidedUniforms=()=>{this.gl.useProgram(this.program),Object.entries(this.providedUniforms).forEach(([r,t])=>{let o=this.uniformLocations[r];if(o)if(Array.isArray(t))switch(t.length){case 2:this.gl.uniform2fv(o,t);break;case 3:this.gl.uniform3fv(o,t);break;case 4:this.gl.uniform4fv(o,t);break;default:t.length===9?this.gl.uniformMatrix3fv(o,!1,t):t.length===16?this.gl.uniformMatrix4fv(o,!1,t):console.warn(`Unsupported uniform array length: ${t.length}`)}else typeof t=="number"?this.gl.uniform1f(o,t):typeof t=="boolean"?this.gl.uniform1i(o,t?1:0):console.warn(`Unsupported uniform type for ${r}: ${typeof t}`)})};setSpeed=(r=1)=>{this.speed=r,this.rafId===null&&r!==0&&(this.lastFrameTime=performance.now(),this.rafId=requestAnimationFrame(this.render)),this.rafId!==null&&r===0&&(cancelAnimationFrame(this.rafId),this.rafId=null)};setUniforms=r=>{this.providedUniforms={...this.providedUniforms,...r},this.updateProvidedUniforms(),this.render(performance.now())};dispose=()=>{this.hasBeenDisposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.gl&&this.program&&(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),this.uniformLocations={}}},y=`
3
- attribute vec4 a_position;
4
- void main() {
5
- gl_Position = a_position;
6
- }
7
- `;function x(e,r,t){let o=e.createShader(r);return o?(e.shaderSource(o,t),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)?o:(console.error("An error occurred compiling the shaders: "+e.getShaderInfoLog(o)),e.deleteShader(o),null)):null}function R(e,r,t){let o=x(e,e.VERTEX_SHADER,r),i=x(e,e.FRAGMENT_SHADER,t);if(!o||!i)return null;let n=e.createProgram();return n?(e.attachShader(n,o),e.attachShader(n,i),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS)?(e.detachShader(n,o),e.detachShader(n,i),e.deleteShader(o),e.deleteShader(i),n):(console.error("Unable to initialize the shader program: "+e.getProgramInfoLog(n)),e.deleteProgram(n),e.deleteShader(o),e.deleteShader(i),null)):null}var F=`
8
- precision highp float;
9
- uniform vec2 u_resolution;
10
- uniform float u_time;
2
+ var g=class{canvas;gl;program=null;uniformLocations={};fragmentShader;rafId=null;lastFrameTime=0;totalAnimationTime=0;speed=1;providedUniforms;hasBeenDisposed=!1;resolutionChanged=!0;constructor(o,r,t={},a,i=1,s=0){this.canvas=o,this.fragmentShader=r,this.providedUniforms=t,this.totalAnimationTime=s;let n=o.getContext("webgl2",a);if(!n)throw new Error("WebGL not supported");this.gl=n,this.initWebGL(),this.setupResizeObserver(),this.setSpeed(i),this.canvas.setAttribute("data-paper-shaders","true")}initWebGL=()=>{let o=S(this.gl,y,this.fragmentShader);o&&(this.program=o,this.setupPositionAttribute(),this.setupUniforms())};setupPositionAttribute=()=>{let o=this.gl.getAttribLocation(this.program,"a_position"),r=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,r);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(o),this.gl.vertexAttribPointer(o,2,this.gl.FLOAT,!1,0,0)};setupUniforms=()=>{this.uniformLocations={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.fromEntries(Object.keys(this.providedUniforms).map(o=>[o,this.gl.getUniformLocation(this.program,o)]))}};resizeObserver=null;setupResizeObserver=()=>{this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver.observe(this.canvas),this.handleResize()};handleResize=()=>{let o=window.devicePixelRatio,r=this.canvas.clientWidth*o,t=this.canvas.clientHeight*o;(this.canvas.width!==r||this.canvas.height!==t)&&(this.canvas.width=r,this.canvas.height=t,this.resolutionChanged=!0,this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.render(performance.now()))};render=o=>{if(this.hasBeenDisposed)return;let r=o-this.lastFrameTime;this.lastFrameTime=o,this.speed!==0&&(this.totalAnimationTime+=r*this.speed),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.uniform1f(this.uniformLocations.u_time,this.totalAnimationTime*.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,window.devicePixelRatio),this.resolutionChanged=!1),this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.speed!==0?this.requestRender():this.rafId=null};requestRender=()=>{this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(this.render)};updateProvidedUniforms=()=>{this.gl.useProgram(this.program),Object.entries(this.providedUniforms).forEach(([o,r])=>{let t=this.uniformLocations[o];if(t)if(Array.isArray(r))switch(r.length){case 2:this.gl.uniform2fv(t,r);break;case 3:this.gl.uniform3fv(t,r);break;case 4:this.gl.uniform4fv(t,r);break;default:r.length===9?this.gl.uniformMatrix3fv(t,!1,r):r.length===16?this.gl.uniformMatrix4fv(t,!1,r):console.warn(`Unsupported uniform array length: ${r.length}`)}else typeof r=="number"?this.gl.uniform1f(t,r):typeof r=="boolean"?this.gl.uniform1i(t,r?1:0):console.warn(`Unsupported uniform type for ${o}: ${typeof r}`)})};setSeed=o=>{let r=8.333333333333334;this.totalAnimationTime=o*r,this.lastFrameTime=performance.now(),this.render(performance.now())};setSpeed=(o=1)=>{this.speed=o,this.rafId===null&&o!==0&&(this.lastFrameTime=performance.now(),this.rafId=requestAnimationFrame(this.render)),this.rafId!==null&&o===0&&(cancelAnimationFrame(this.rafId),this.rafId=null)};setUniforms=o=>{this.providedUniforms={...this.providedUniforms,...o},this.updateProvidedUniforms(),this.render(performance.now())};dispose=()=>{this.hasBeenDisposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.gl&&this.program&&(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),this.uniformLocations={}}},y=`#version 300 es
3
+ layout(location = 0) in vec4 a_position;
11
4
 
12
- uniform vec4 u_color1;
13
- uniform vec4 u_color2;
14
- uniform float u_scale;
15
- uniform float u_grainAmount;
5
+ void main() {
6
+ gl_Position = a_position;
7
+ }
8
+ `;function x(e,o,r){let t=e.createShader(o);return t?(e.shaderSource(t,r),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)?t:(console.error("An error occurred compiling the shaders: "+e.getShaderInfoLog(t)),e.deleteShader(t),null)):null}function S(e,o,r){let t=x(e,e.VERTEX_SHADER,o),a=x(e,e.FRAGMENT_SHADER,r);if(!t||!a)return null;let i=e.createProgram();return i?(e.attachShader(i,t),e.attachShader(i,a),e.linkProgram(i),e.getProgramParameter(i,e.LINK_STATUS)?(e.detachShader(i,t),e.detachShader(i,a),e.deleteShader(t),e.deleteShader(a),i):(console.error("Unable to initialize the shader program: "+e.getProgramInfoLog(i)),e.deleteProgram(i),e.deleteShader(t),e.deleteShader(a),null)):null}var z=`#version 300 es
9
+ precision highp float;
16
10
 
17
- // Simplex 2D noise
18
- vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
11
+ uniform vec2 u_resolution;
12
+ uniform float u_pixelRatio;
13
+ uniform float u_time;
19
14
 
20
- float snoise(vec2 v) {
21
- const vec4 C = vec4(0.211324865405187, 0.366025403784439,
22
- -0.577350269189626, 0.024390243902439);
23
- vec2 i = floor(v + dot(v, C.yy));
24
- vec2 x0 = v - i + dot(i, C.xx);
25
- vec2 i1;
26
- i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
27
- vec4 x12 = x0.xyxy + C.xxzz;
28
- x12.xy -= i1;
29
- i = mod(i, 289.0);
30
- vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))
31
- + i.x + vec3(0.0, i1.x, 1.0));
32
- vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),
33
- dot(x12.zw,x12.zw)), 0.0);
34
- m = m*m ;
35
- m = m*m ;
36
- vec3 x = 2.0 * fract(p * C.www) - 1.0;
37
- vec3 h = abs(x) - 0.5;
38
- vec3 ox = floor(x + 0.5);
39
- vec3 a0 = x - ox;
40
- m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
41
- vec3 g;
42
- g.x = a0.x * x0.x + h.x * x0.y;
43
- g.yz = a0.yz * x12.xz + h.yz * x12.yw;
44
- return 130.0 * dot(m, g);
45
- }
15
+ uniform float u_scale;
16
+ uniform vec4 u_color1;
17
+ uniform vec4 u_color2;
18
+ uniform float u_grainAmount;
46
19
 
47
- void main() {
48
- vec2 st = gl_FragCoord.xy / u_resolution.xy;
20
+ out vec4 fragColor;
49
21
 
50
- // Calculate the aspect ratio of the shader
51
- float shaderAspect = u_resolution.x / u_resolution.y;
22
+ // Simplex 2D noise
23
+ vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
52
24
 
53
- // Define the aspect ratio of your content (e.g., 1.0 for square)
54
- float contentAspect = 1.0;
25
+ float snoise(vec2 v) {
26
+ const vec4 C = vec4(0.211324865405187, 0.366025403784439,
27
+ -0.577350269189626, 0.024390243902439);
28
+ vec2 i = floor(v + dot(v, C.yy));
29
+ vec2 x0 = v - i + dot(i, C.xx);
30
+ vec2 i1;
31
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
32
+ vec4 x12 = x0.xyxy + C.xxzz;
33
+ x12.xy -= i1;
34
+ i = mod(i, 289.0);
35
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
36
+ + i.x + vec3(0.0, i1.x, 1.0));
37
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),
38
+ dot(x12.zw, x12.zw)), 0.0);
39
+ m = m * m;
40
+ m = m * m;
41
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
42
+ vec3 h = abs(x) - 0.5;
43
+ vec3 ox = floor(x + 0.5);
44
+ vec3 a0 = x - ox;
45
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
46
+ vec3 g;
47
+ g.x = a0.x * x0.x + h.x * x0.y;
48
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
49
+ return 130.0 * dot(m, g);
50
+ }
55
51
 
56
- // Adjust st to maintain content aspect ratio
57
- if (shaderAspect > contentAspect) {
58
- float scale = shaderAspect / contentAspect;
59
- st.x = (st.x - 0.5) * scale + 0.5;
60
- } else {
61
- float scale = contentAspect / shaderAspect;
62
- st.y = (st.y - 0.5) * scale + 0.5;
63
- }
52
+ float rand(vec2 n) {
53
+ return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
54
+ }
55
+ float noise(vec2 n) {
56
+ const vec2 d = vec2(0.0, 1.0);
57
+ vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
58
+ return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
59
+ }
60
+ float fbm(vec2 n) {
61
+ float total = 0.0, amplitude = .2;
62
+ for (int i = 0; i < 6; i++) {
63
+ total += noise(n) * amplitude;
64
+ n += n;
65
+ amplitude *= 0.6;
66
+ }
67
+ return total;
68
+ }
64
69
 
65
- // Create blobby texture
66
- float n = snoise(st * u_scale + u_time);
67
- n += 0.5 * snoise(st * u_scale * 2.0 - u_time * 0.5);
68
- n += 0.25 * snoise(st * u_scale * 4.0 + u_time * 0.25);
69
- n = n * 0.5 + 0.5;
70
+ void main() {
71
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
70
72
 
71
- // Color interpolation
72
- vec4 color = mix(u_color1, u_color2, n);
73
+ uv -= .5;
74
+ float scale = .5 * u_scale + 1e-4;
75
+ uv *= (.0004 * (1. - step(1. - scale, 1.) / scale));
76
+ uv *= u_resolution;
77
+ uv /= u_pixelRatio;
78
+ uv += .5;
73
79
 
74
- // Add grain
75
- float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);
76
- color += (grain - 0.5) * u_grainAmount;
80
+ // Create blobby texture
81
+ float n = snoise(uv + u_time);
82
+ n += 0.5 * snoise(uv * 2.0 - u_time * 0.5);
83
+ n += 0.25 * snoise(uv * 4.0 + u_time * 0.25);
84
+ n = n * 0.5 + 0.5;
77
85
 
78
- gl_FragColor = color;
79
- }
80
- `;var A=`
81
- // Mesh Gradient: https://www.shadertoy.com/view/wdyczG
82
- #define S(a,b,t) smoothstep(a,b,t)
86
+ // Color interpolation
87
+ vec3 color = mix(u_color1.rgb, u_color2.rgb, n);
88
+ float opacity = mix(u_color1.a, u_color2.a, n);
89
+
90
+ // Add grain
91
+ float grain = fbm(uv * 1000.);
92
+ color.rgb += (grain - 0.5) * u_grainAmount;
83
93
 
94
+ fragColor = vec4(color * opacity, opacity);
95
+ }
96
+ `;var C=`#version 300 es
84
97
  precision highp float;
85
98
 
99
+ uniform float u_pixelRatio;
100
+ uniform vec2 u_resolution;
101
+ uniform float u_time;
102
+
86
103
  uniform vec4 u_color1;
87
104
  uniform vec4 u_color2;
88
105
  uniform vec4 u_color3;
89
106
  uniform vec4 u_color4;
90
- uniform vec2 u_resolution;
91
- uniform float u_time;
92
107
 
93
- mat2 Rot(float a)
94
- {
108
+ out vec4 fragColor;
109
+
110
+ #define S(a,b,t) smoothstep(a,b,t)
111
+
112
+ mat2 Rot(float a) {
95
113
  float s = sin(a);
96
114
  float c = cos(a);
97
115
  return mat2(c, -s, s, c);
98
116
  }
99
117
 
100
-
101
118
  vec2 hash(vec2 p) {
102
119
  vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
103
120
  p3 += dot(p3, p3.yzx + 33.33);
104
121
  return fract((p3.xx+p3.yz)*p3.zy);
105
122
  }
106
123
 
107
- float noise( in vec2 p )
108
- {
124
+ float noise( in vec2 p ) {
109
125
  vec2 i = floor( p );
110
126
  vec2 f = fract( p );
111
-
112
- vec2 u = f*f*(3.0-2.0*f);
127
+ vec2 u = f*f*(3.0-2.0*f);
113
128
 
114
129
  float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
115
130
  dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
116
131
  mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
117
132
  dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
118
- return 0.5 + 0.5*n;
133
+ return 0.5 + 0.5*n;
119
134
  }
120
135
 
121
136
 
122
137
  void main() {
123
138
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
124
139
  float ratio = u_resolution.x / u_resolution.y;
125
-
140
+
141
+ uv /= u_pixelRatio;
142
+
126
143
  vec2 tuv = uv;
127
144
  tuv -= .5;
128
145
 
@@ -131,7 +148,7 @@ void main() {
131
148
 
132
149
  tuv.y *= 1./ratio;
133
150
  tuv *= Rot(radians((degree-.5)*720.+180.));
134
- tuv.y *= ratio;
151
+ tuv.y *= ratio;
135
152
 
136
153
 
137
154
  // Wave warp with sin
@@ -139,121 +156,138 @@ void main() {
139
156
  float amplitude = 30.;
140
157
  float speed = u_time * 2.;
141
158
  tuv.x += sin(tuv.y*frequency+speed)/amplitude;
142
- tuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);
159
+ tuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);
160
+
161
+
162
+ float proportion_1 = S(-.3, .2, (tuv*Rot(radians(-5.))).x);
163
+ vec3 layer1_color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, proportion_1);
164
+ float layer1_opacity = mix(u_color1.a, u_color2.a, proportion_1);
165
+ vec3 layer2_color = mix(u_color3.rgb * u_color3.a, u_color4.rgb * u_color4.a, proportion_1);
166
+ float layer2_opacity = mix(u_color3.a, u_color4.a, proportion_1);
143
167
 
168
+ float proportion_2 = S(.5, -.3, tuv.y);
169
+ vec3 color = mix(layer1_color, layer2_color, proportion_2);
170
+ float opacity = mix(layer1_opacity, layer2_opacity, proportion_2);
171
+
172
+ fragColor = vec4(color, opacity);
173
+ }
174
+ `;var R=`#version 300 es
175
+ precision highp float;
176
+
177
+ uniform float u_pixelRatio;
178
+ uniform vec2 u_resolution;
179
+ uniform float u_time;
180
+
181
+ uniform float u_scale;
182
+
183
+ uniform vec4 u_colorBack;
184
+ uniform vec4 u_colorInner;
185
+ uniform vec4 u_colorOuter;
186
+ uniform float u_noiseScale;
187
+ uniform float u_thickness;
144
188
 
145
- // draw the image
146
- vec4 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));
147
- vec4 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));
189
+ out vec4 fragColor;
190
+
191
+ #define TWO_PI 6.28318530718
192
+ #define PI 3.14159265358979323846
148
193
 
149
- vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));
150
- gl_FragColor = finalComp;
194
+ float random(in vec2 st) {
195
+ return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
196
+ }
197
+ float noise(in vec2 st) {
198
+ vec2 i = floor(st);
199
+ vec2 f = fract(st);
200
+ float a = random(i);
201
+ float b = random(i + vec2(1.0, 0.0));
202
+ float c = random(i + vec2(0.0, 1.0));
203
+ float d = random(i + vec2(1.0, 1.0));
204
+ vec2 u = f * f * (3.0 - 2.0 * f);
205
+ return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
206
+ }
207
+ float fbm(in vec2 n) {
208
+ float total = 0.0, amplitude = .4;
209
+ for (int i = 0; i < 12; i++) {
210
+ total += noise(n) * amplitude;
211
+ n += n;
212
+ amplitude *= 0.6;
213
+ }
214
+ return total;
151
215
  }
152
- `;var S=`
153
216
 
154
- precision highp float;
217
+ float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {
218
+ float distance = length(uv);
219
+ float line_width = outerRadius - innerRadius;
220
+ float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);
221
+ ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);
222
+ return clamp(ringValue, 0., 1.);
223
+ }
155
224
 
156
- uniform vec4 u_colorBack;
157
- uniform vec4 u_color1;
158
- uniform vec4 u_color2;
159
- uniform float u_scale;
160
- uniform float u_thickness;
161
- uniform vec2 u_resolution;
162
- uniform float u_time;
225
+ void main() {
226
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
227
+ float ratio = u_resolution.x / u_resolution.y;
163
228
 
164
- #define TWO_PI 6.28318530718
165
- #define PI 3.14159265358979323846
229
+ uv -= .5;
230
+ uv /= u_pixelRatio;
231
+ float scale = .5 * u_scale + 1e-4;
232
+ uv *= (1. - step(1. - scale, 1.) / scale);
233
+ uv *= 3.;
234
+ uv.x *= ratio;
166
235
 
167
- float rand(vec2 n) {
168
- return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
169
- }
170
- float noise(vec2 n) {
171
- const vec2 d = vec2(0.0, 1.0);
172
- vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
173
- return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
174
- }
175
- float fbm(vec2 n) {
176
- float total = 0.0, amplitude = .4;
177
- for (int i = 0; i < 12; i++) {
178
- total += noise(n) * amplitude;
179
- n += n;
180
- amplitude *= 0.6;
181
- }
182
- return total;
183
- }
236
+ float t = u_time;
184
237
 
185
- float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {
186
- float distance = length(uv);
187
- float line_width = outerRadius - innerRadius;
188
- float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);
189
- ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);
190
- return clamp(ringValue, 0., 1.);
191
- }
238
+ float atg = atan(uv.y, uv.x);
239
+ float angle = (atg + PI) / TWO_PI;
192
240
 
193
- void main() {
241
+ vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));
242
+ polar_uv *= u_noiseScale;
194
243
 
195
- vec2 uv = gl_FragCoord.xy / u_resolution.xy;
196
- float ratio = u_resolution.x / u_resolution.y;
244
+ float noise_left = fbm(polar_uv + .05 * t);
245
+ polar_uv.x = mod(polar_uv.x, u_noiseScale * TWO_PI);
246
+ float noise_right = fbm(polar_uv + .05 * t);
247
+ float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));
197
248
 
198
- uv -= .5;
199
- uv *= 2.;
200
- uv.x *= ratio;
249
+ float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);
201
250
 
202
- float t = u_time;
251
+ float radius = .4 - .25 * u_thickness;
252
+ float thickness = u_thickness;
253
+ thickness = pow(thickness, 2.);
203
254
 
204
- float atg = atan(uv.y, uv.x);
205
- float angle = (atg + PI) / TWO_PI;
255
+ float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);
206
256
 
207
- vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));
208
- polar_uv *= u_scale;
257
+ float ring_shape_outer = 1. - pow(ring_shape, 7.);
258
+ ring_shape_outer *= ring_shape;
209
259
 
210
- float noise_left = fbm(polar_uv + .05 * t);
211
- polar_uv.x = mod(polar_uv.x, u_scale * TWO_PI);
212
- float noise_right = fbm(polar_uv + .05 * t);
213
- float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));
260
+ float ring_shape_inner = ring_shape - ring_shape_outer;
261
+ ring_shape_inner *= ring_shape;
214
262
 
215
- float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);
263
+ float background = u_colorBack.a;
216
264
 
217
- float radius = .4 - .25 * u_thickness;
218
- float thickness = u_thickness;
219
- thickness = pow(thickness, 2.);
265
+ float opacity = ring_shape_outer * u_colorOuter.a;
266
+ opacity += ring_shape_inner * u_colorInner.a;
267
+ opacity += background * (1. - ring_shape_inner * u_colorInner.a - ring_shape_outer * u_colorOuter.a);
220
268
 
221
- float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);
222
- ring_shape = clamp(ring_shape, 0., 1.);
223
-
224
- float ring_shape_outer = 1. - pow(ring_shape, 7.);
225
- ring_shape_outer *= ring_shape;
226
-
227
- float ring_shape_inner = ring_shape - ring_shape_outer;
228
- ring_shape_inner *= ring_shape;
269
+ vec3 color = u_colorBack.rgb * (1. - ring_shape) * background;
270
+ color += u_colorOuter.rgb * ring_shape_outer * u_colorOuter.a;
271
+ color += u_colorInner.rgb * ring_shape_inner * u_colorInner.a;
229
272
 
230
- ring_shape_outer *= u_color2.a;
231
- ring_shape_inner *= u_color1.a;
273
+ color += u_colorBack.rgb * ring_shape_inner * (1. - u_colorInner.a) * background;
274
+ color += u_colorBack.rgb * ring_shape_outer * (1. - u_colorOuter.a) * background;
232
275
 
233
- float background = 1. - ring_shape;
234
- background *= u_colorBack.a;
235
-
236
- vec3 color = u_color2.rgb * ring_shape_outer;
237
- color += u_color1.rgb * ring_shape_inner;
238
- color += u_colorBack.rgb * background;
239
-
240
- float opacity = ring_shape_outer;
241
- opacity += ring_shape_inner;
242
- opacity += background;
243
-
244
- gl_FragColor = vec4(color, opacity);
245
- }
246
- `;var z=`
247
- precision mediump float;
276
+ fragColor = vec4(color, opacity);
277
+ }
278
+ `;var w=`#version 300 es
279
+ precision highp float;
280
+
281
+ uniform float u_time;
282
+ uniform float u_pixelRatio;
283
+ uniform vec2 u_resolution;
248
284
 
285
+ uniform float u_scale;
249
286
  uniform vec4 u_colorFront;
250
287
  uniform vec4 u_colorBack;
251
- uniform float u_scale;
252
288
  uniform float u_brightness;
253
289
 
254
- uniform float u_time;
255
- uniform float u_ratio;
256
- uniform vec2 u_resolution;
290
+ out vec4 fragColor;
257
291
 
258
292
  vec2 rotate(vec2 uv, float th) {
259
293
  return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;
@@ -279,11 +313,13 @@ void main() {
279
313
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
280
314
 
281
315
  uv -= .5;
282
- uv *= (.001 * u_scale * u_resolution);
316
+ float scale = .5 * u_scale + 1e-4;
317
+ uv *= (.001 * (1. - step(1. - scale, 1.) / scale));
318
+ uv *= u_resolution;
319
+ uv /= u_pixelRatio;
283
320
  uv += .5;
284
321
 
285
322
  float t = u_time;
286
- vec3 color = vec3(0.);
287
323
 
288
324
  float noise = neuro_shape(uv, t);
289
325
 
@@ -291,28 +327,36 @@ void main() {
291
327
  noise += pow(noise, 12.);
292
328
  noise = max(.0, noise - .5);
293
329
 
294
- gl_FragColor = mix(u_colorBack, u_colorFront, noise);
330
+ vec3 color = mix(u_colorBack.rgb * u_colorBack.a, u_colorFront.rgb * u_colorFront.a, noise);
331
+ float opacity = mix(u_colorBack.a, u_colorFront.a, noise);
332
+
333
+ fragColor = vec4(color, opacity);
295
334
  }
296
- `;var w=`
297
- precision mediump float;
335
+ `;var F=`#version 300 es
336
+ precision highp float;
298
337
 
338
+ uniform float u_time;
339
+ uniform float u_pixelRatio;
340
+ uniform vec2 u_resolution;
341
+
342
+ uniform float u_scale;
299
343
  uniform vec4 u_color1;
300
344
  uniform vec4 u_color2;
301
345
  uniform vec4 u_color3;
302
346
  uniform vec4 u_color4;
303
347
  uniform float u_dotSize;
304
348
  uniform float u_dotSizeRange;
305
- uniform float u_scale;
306
349
  uniform float u_spreading;
307
- uniform float u_time;
308
- uniform float u_ratio;
309
- uniform vec2 u_resolution;
350
+
351
+ out vec4 fragColor;
310
352
 
311
353
  #define TWO_PI 6.28318530718
312
- #define PI 3.14159265358979323846
313
354
 
355
+ float random(in vec2 st) {
356
+ return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
357
+ }
314
358
  vec2 random2(vec2 p) {
315
- return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
359
+ return vec2(random(p), random(200. * p));
316
360
  }
317
361
 
318
362
  vec3 get_voronoi_shape(vec2 _uv, float time) {
@@ -325,7 +369,7 @@ vec3 get_voronoi_shape(vec2 _uv, float time) {
325
369
  for (int x = -1; x <= 1; x++) {
326
370
  vec2 tile_offset = vec2(float(x), float(y));
327
371
  vec2 rand = random2(i_uv + tile_offset);
328
- vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);
372
+ vec2 cell_center = .5 + 1e-4 + .25 * clamp(u_spreading, 0., 1.) * sin(time + TWO_PI * rand);
329
373
  float dist = length(tile_offset + cell_center - f_uv);
330
374
  if (dist < min_dist) {
331
375
  min_dist = dist;
@@ -342,40 +386,169 @@ void main() {
342
386
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
343
387
 
344
388
  uv -= .5;
345
- uv *= (.001 * u_scale * u_resolution);
389
+ float scale = .5 * u_scale + 1e-4;
390
+ uv *= (.02 * (1. - step(1. - scale, 1.) / scale));
391
+ uv *= u_resolution;
392
+ uv /= u_pixelRatio;
346
393
  uv += .5;
347
394
 
348
395
  float t = u_time;
349
396
 
350
- vec3 voronoi = get_voronoi_shape(uv, t);
351
- float radius = u_dotSize - u_dotSizeRange * voronoi[2];
397
+ vec3 voronoi = get_voronoi_shape(uv, t) + 1e-4;
352
398
 
353
- float radius_smoother = .001 + .001 * (u_scale - 1.);
354
- float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);
399
+ float radius = .25 * clamp(u_dotSize, 0., 1.) - .5 * clamp(u_dotSizeRange, 0., 1.) * voronoi[2];
400
+ float dist = voronoi[0];
401
+ float edge_width = fwidth(dist);
402
+ float shape = smoothstep(radius + edge_width, radius - edge_width, dist);
355
403
 
356
404
  float color_randomizer = voronoi[1];
357
- vec4 color =
358
- u_color1 * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +
359
- u_color2 * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +
360
- u_color3 * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +
361
- u_color4 * step(0.75, color_randomizer) * step(color_randomizer, 1.0);
362
405
 
363
- gl_FragColor = color * shape;
406
+ float opacity =
407
+ u_color1.a * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +
408
+ u_color2.a * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +
409
+ u_color3.a * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +
410
+ u_color4.a * step(0.75, color_randomizer) * step(color_randomizer, 1.0);
411
+
412
+ opacity *= shape;
413
+
414
+ vec3 color =
415
+ u_color1.rgb * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +
416
+ u_color2.rgb * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +
417
+ u_color3.rgb * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +
418
+ u_color4.rgb * step(0.75, color_randomizer) * step(color_randomizer, 1.0);
419
+
420
+ fragColor = vec4(color * opacity, opacity);
421
+ }
422
+ `;var k={Circle:0,Diamond:1,Square:2,Triangle:3},I=`#version 300 es
423
+ precision highp float;
424
+
425
+ uniform vec2 u_resolution;
426
+ uniform float u_pixelRatio;
427
+
428
+ uniform vec4 u_colorBack;
429
+ uniform vec4 u_colorFill;
430
+ uniform vec4 u_colorStroke;
431
+ uniform float u_dotSize;
432
+ uniform float u_gridSpacingX;
433
+ uniform float u_gridSpacingY;
434
+ uniform float u_strokeWidth;
435
+ uniform float u_sizeRange;
436
+ uniform float u_opacityRange;
437
+ uniform float u_shape;
438
+
439
+ out vec4 fragColor;
440
+
441
+ #define TWO_PI 6.28318530718
442
+ #define PI 3.14159265358979323846
443
+
444
+ float hash(vec2 st) {
445
+ return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
446
+ }
447
+
448
+ vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
449
+
450
+ float snoise(vec2 v) {
451
+ const vec4 C = vec4(0.211324865405187, 0.366025403784439,
452
+ -0.577350269189626, 0.024390243902439);
453
+ vec2 i = floor(v + dot(v, C.yy));
454
+ vec2 x0 = v - i + dot(i, C.xx);
455
+ vec2 i1;
456
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
457
+ vec4 x12 = x0.xyxy + C.xxzz;
458
+ x12.xy -= i1;
459
+ i = mod(i, 289.0);
460
+ vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))
461
+ + i.x + vec3(0.0, i1.x, 1.0));
462
+ vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),
463
+ dot(x12.zw,x12.zw)), 0.0);
464
+ m = m*m ;
465
+ m = m*m ;
466
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
467
+ vec3 h = abs(x) - 0.5;
468
+ vec3 ox = floor(x + 0.5);
469
+ vec3 a0 = x - ox;
470
+ m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
471
+ vec3 g;
472
+ g.x = a0.x * x0.x + h.x * x0.y;
473
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
474
+ return 130.0 * dot(m, g);
475
+ }
476
+ float polygon(vec2 p, float N, float rot) {
477
+ float a = atan(p.x, p.y) + rot;
478
+ float r = TWO_PI / float(N);
479
+
480
+ return cos(floor(.5 + a/r) * r - a) * length(p);
364
481
  }
365
- `;var C=`
482
+
483
+ void main() {
484
+ vec2 uv = gl_FragCoord.xy;
485
+ uv.y = u_resolution.y - uv.y;
486
+
487
+ uv /= u_pixelRatio;
488
+
489
+ vec2 grid = fract(uv / vec2(u_gridSpacingX, u_gridSpacingY)) + 1e-4;
490
+ vec2 grid_idx = floor(uv / vec2(u_gridSpacingX, u_gridSpacingY));
491
+ float size_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));
492
+ float opacity_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.y, grid_idx.x));
493
+
494
+ vec2 center = vec2(0.5) - 1e-3;
495
+ vec2 p = (grid - center) * vec2(u_gridSpacingX, u_gridSpacingY);
496
+
497
+ float base_size = u_dotSize * (1. - size_randomizer * clamp(u_sizeRange, 0., 1.));
498
+ float stroke_width = u_strokeWidth;
499
+
500
+ float dist;
501
+ if (u_shape < 0.5) {
502
+ // Circle
503
+ dist = length(p);
504
+ } else if (u_shape < 1.5) {
505
+ // Diamond
506
+ dist = polygon(1.5 * p, 4., .25 * PI);
507
+ } else if (u_shape < 2.5) {
508
+ // Square
509
+ dist = polygon(1.5 * p, 4., 1e-3);
510
+ } else {
511
+ // Triangle
512
+ p = p * 2. - 1.;
513
+ p.y -= .75 * base_size;
514
+ stroke_width *= 2.;
515
+ dist = polygon(p, 3., 1e-3);
516
+ }
517
+
518
+ float edge_width = fwidth(dist);
519
+ float shape_outer = smoothstep(base_size + edge_width, base_size - edge_width, dist);
520
+ float shape_inner = smoothstep(base_size - u_strokeWidth + edge_width, base_size - u_strokeWidth - edge_width, dist);
521
+ float stroke = clamp(shape_outer - shape_inner, 0., 1.);
522
+
523
+ float dot_opacity = max(0., 1. - opacity_randomizer * clamp(u_opacityRange, 0., 1.));
524
+
525
+ vec3 color = u_colorBack.rgb * u_colorBack.a;
526
+ color = mix(color, u_colorFill.rgb, u_colorFill.a * dot_opacity * shape_inner);
527
+ color = mix(color, u_colorStroke.rgb, u_colorStroke.a * dot_opacity * stroke);
528
+
529
+ float opacity = u_colorBack.a;
530
+ opacity += u_colorFill.a * shape_inner * dot_opacity;
531
+ opacity += u_colorStroke.a * stroke * dot_opacity;
532
+
533
+ fragColor = vec4(color, opacity);
534
+ }
535
+ `;var P=`#version 300 es
366
536
  precision highp float;
367
537
 
538
+ uniform float u_time;
539
+ uniform float u_pixelRatio;
540
+ uniform vec2 u_resolution;
541
+
542
+ uniform float u_scale;
543
+
368
544
  uniform vec4 u_color1;
369
545
  uniform vec4 u_color2;
370
546
  uniform vec4 u_color3;
371
547
  uniform vec4 u_color4;
372
548
  uniform vec4 u_color5;
373
- uniform float u_scale;
374
549
  uniform float u_steps_number;
375
550
 
376
- uniform float u_time;
377
- uniform vec2 u_resolution;
378
-
551
+ out vec4 fragColor;
379
552
 
380
553
  vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
381
554
  float snoise(vec2 v) {
@@ -425,20 +598,480 @@ void main() {
425
598
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
426
599
 
427
600
  uv -= .5;
428
- uv *= (.001 * u_scale * u_resolution);
601
+ float scale = .5 * u_scale + 1e-4;
602
+ uv *= (.0008 * (1. - step(1. - scale, 1.) / scale));
603
+ uv *= u_resolution;
604
+ uv /= u_pixelRatio;
429
605
  uv += .5;
430
606
 
431
- float t = u_time;
607
+ float t = u_time;
432
608
 
433
609
  float noise = .5 + .5 * get_noise(uv, t);
434
610
  noise = floor(noise * u_steps_number) / u_steps_number;
435
611
 
436
- vec4 col = u_color1;
612
+ vec3 color = u_color1.rgb * u_color1.a;
613
+ float opacity = u_color1.a;
437
614
  for (int i = 0; i < 5; i++) {
438
- vec4 next_col = getColor(i + 1);
439
- col = mix(col, next_col, smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise));
615
+ vec4 next_c = getColor(i + 1);
616
+ float proportion = smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise);
617
+ color = mix(color, next_c.rgb * next_c.a, proportion);
618
+ opacity = mix(opacity, next_c.a, proportion);
619
+ }
620
+ fragColor = vec4(color, opacity);
621
+ }
622
+ `;var U=`#version 300 es
623
+ precision highp float;
624
+
625
+ uniform float u_time;
626
+ uniform float u_pixelRatio;
627
+ uniform vec2 u_resolution;
628
+
629
+ uniform float u_scale;
630
+ uniform vec4 u_color1;
631
+ uniform vec4 u_color2;
632
+ uniform vec4 u_color3;
633
+ uniform float u_ballSize;
634
+ uniform float u_visibilityRange;
635
+
636
+ #define TWO_PI 6.28318530718
637
+
638
+ out vec4 fragColor;
639
+
640
+ float hash(float x) {
641
+ return fract(sin(x) * 43758.5453123);
642
+ }
643
+ float lerp(float a, float b, float t) {
644
+ return a + t * (b - a);
645
+ }
646
+ float noise(float x) {
647
+ float i = floor(x);
648
+ float f = fract(x);
649
+ float u = f * f * (3.0 - 2.0 * f); // Smoothstep function for interpolation
650
+ return lerp(hash(i), hash(i + 1.0), u);
651
+ }
652
+
653
+ float get_ball_shape(vec2 uv, vec2 c, float p) {
654
+ float s = .5 * length(uv - c);
655
+ s = 1. - clamp(s, 0., 1.);
656
+ s = pow(s, p);
657
+ return s;
658
+ }
659
+
660
+ void main() {
661
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
662
+ float ratio = u_resolution.x / u_resolution.y;
663
+
664
+ uv -= .5;
665
+ uv /= u_pixelRatio;
666
+ float scale = .5 * u_scale + 1e-4;
667
+ uv *= (18. * (1. - step(1. - scale, 1.) / scale));
668
+ uv += .5;
669
+ uv.x *= ratio;
670
+
671
+ float t = u_time;
672
+
673
+ vec3 total_color = vec3(0.);
674
+ float total_shape = 0.;
675
+
676
+ const int max_balls_number = 15;
677
+ for (int i = 0; i < max_balls_number; i++) {
678
+ vec2 pos = vec2(.5) + 1e-4;
679
+ float idx_fract = float(i) / float(max_balls_number);
680
+ float angle = TWO_PI * idx_fract;
681
+
682
+ float speed = 1. - .2 * idx_fract;
683
+ float noiseX = noise(angle * 10. + float(i) + t * speed);
684
+ float noiseY = noise(angle * 20. + float(i) - t * speed);
685
+
686
+ pos += 7. * (vec2(noiseX, noiseY) - .5);
687
+
688
+ vec4 ball_color;
689
+ if (i % 3 == 0) {
690
+ ball_color = u_color1;
691
+ } else if (i % 3 == 1) {
692
+ ball_color = u_color2;
693
+ } else {
694
+ ball_color = u_color3;
695
+ }
696
+
697
+ float shape = get_ball_shape(uv, pos, 6. - 4. * u_ballSize) * ball_color.a;
698
+
699
+ shape *= smoothstep((float(i) - 1.) / float(max_balls_number), idx_fract, u_visibilityRange);
700
+
701
+ total_color += ball_color.rgb * shape;
702
+ total_shape += shape;
703
+ }
704
+
705
+ total_color /= max(total_shape, 1e-4);
706
+
707
+ float edge_width = fwidth(total_shape);
708
+ float final_shape = smoothstep(.4, .4 + edge_width, total_shape);
709
+
710
+ vec3 color = total_color * final_shape;
711
+ float opacity = final_shape;
712
+
713
+ if (opacity < .01) {
714
+ discard;
715
+ }
716
+
717
+ fragColor = vec4(color, opacity);
718
+ }
719
+ `;var A=`#version 300 es
720
+ precision highp float;
721
+
722
+ uniform float u_time;
723
+ uniform float u_pixelRatio;
724
+ uniform vec2 u_resolution;
725
+
726
+ uniform float u_scale;
727
+ uniform vec4 u_color1;
728
+ uniform vec4 u_color2;
729
+ uniform float u_proportion;
730
+ uniform float u_contour;
731
+ uniform float u_octaveCount;
732
+ uniform float u_persistence;
733
+ uniform float u_lacunarity;
734
+
735
+ out vec4 fragColor;
736
+
737
+ #define TWO_PI 6.28318530718
738
+
739
+ uint hash(uint x, uint seed) {
740
+ const uint m = 0x5bd1e995U;
741
+ uint hash = seed;
742
+ // process input
743
+ uint k = x;
744
+ k *= m;
745
+ k ^= k >> 24;
746
+ k *= m;
747
+ hash *= m;
748
+ hash ^= k;
749
+ // some final mixing
750
+ hash ^= hash >> 13;
751
+ hash *= m;
752
+ hash ^= hash >> 15;
753
+ return hash;
754
+ }
755
+
756
+ uint hash(uvec3 x, uint seed){
757
+ const uint m = 0x5bd1e995U;
758
+ uint hash = seed;
759
+ // process first vector element
760
+ uint k = x.x;
761
+ k *= m;
762
+ k ^= k >> 24;
763
+ k *= m;
764
+ hash *= m;
765
+ hash ^= k;
766
+ // process second vector element
767
+ k = x.y;
768
+ k *= m;
769
+ k ^= k >> 24;
770
+ k *= m;
771
+ hash *= m;
772
+ hash ^= k;
773
+ // process third vector element
774
+ k = x.z;
775
+ k *= m;
776
+ k ^= k >> 24;
777
+ k *= m;
778
+ hash *= m;
779
+ hash ^= k;
780
+ // some final mixing
781
+ hash ^= hash >> 13;
782
+ hash *= m;
783
+ hash ^= hash >> 15;
784
+ return hash;
785
+ }
786
+
787
+
788
+ vec3 gradientdy(uint hash) {
789
+ switch (int(hash) & 15) { // look at the last four bits to pick a gradient dy
790
+ case 0:
791
+ return vec3(1, 1, 0);
792
+ case 1:
793
+ return vec3(-1, 1, 0);
794
+ case 2:
795
+ return vec3(1, -1, 0);
796
+ case 3:
797
+ return vec3(-1, -1, 0);
798
+ case 4:
799
+ return vec3(1, 0, 1);
800
+ case 5:
801
+ return vec3(-1, 0, 1);
802
+ case 6:
803
+ return vec3(1, 0, -1);
804
+ case 7:
805
+ return vec3(-1, 0, -1);
806
+ case 8:
807
+ return vec3(0, 1, 1);
808
+ case 9:
809
+ return vec3(0, -1, 1);
810
+ case 10:
811
+ return vec3(0, 1, -1);
812
+ case 11:
813
+ return vec3(0, -1, -1);
814
+ case 12:
815
+ return vec3(1, 1, 0);
816
+ case 13:
817
+ return vec3(-1, 1, 0);
818
+ case 14:
819
+ return vec3(0, -1, 1);
820
+ case 15:
821
+ return vec3(0, -1, -1);
822
+ }
823
+ }
824
+
825
+ float interpolate(float value1, float value2, float value3, float value4, float value5, float value6, float value7, float value8, vec3 t) {
826
+ return mix(
827
+ mix(mix(value1, value2, t.x), mix(value3, value4, t.x), t.y),
828
+ mix(mix(value5, value6, t.x), mix(value7, value8, t.x), t.y),
829
+ t.z
830
+ );
831
+ }
832
+
833
+ vec3 fade(vec3 t) {
834
+ return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
835
+ }
836
+
837
+ float perlinNoise(vec3 position, uint seed) {
838
+ position += 1e+4;
839
+ vec3 floorPosition = floor(position);
840
+ vec3 fractPosition = fract(position);
841
+ uvec3 cellCoordinates = uvec3(floorPosition);
842
+ float value1 = dot(gradientdy(hash(cellCoordinates, seed)), fractPosition);
843
+ float value2 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 0)), seed)), fractPosition - vec3(1, 0, 0));
844
+ float value3 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 0)), seed)), fractPosition - vec3(0, 1, 0));
845
+ float value4 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 0)), seed)), fractPosition - vec3(1, 1, 0));
846
+ float value5 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 0, 1)), seed)), fractPosition - vec3(0, 0, 1));
847
+ float value6 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 1)), seed)), fractPosition - vec3(1, 0, 1));
848
+ float value7 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 1)), seed)), fractPosition - vec3(0, 1, 1));
849
+ float value8 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 1)), seed)), fractPosition - vec3(1, 1, 1));
850
+ return interpolate(value1, value2, value3, value4, value5, value6, value7, value8, fade(fractPosition));
851
+ }
852
+
853
+ float p_noise(vec3 position, int octaveCount, float persistence, float lacunarity) {
854
+ float value = 0.0;
855
+ float amplitude = 1.0;
856
+ float currentFrequency = 10.;
857
+ uint currentSeed = uint(0);
858
+ for (int i = 0; i < octaveCount; i++) {
859
+ currentSeed = hash(currentSeed, 0x0U);
860
+ value += perlinNoise(position * currentFrequency, currentSeed) * amplitude;
861
+ amplitude *= persistence;
862
+ currentFrequency *= lacunarity;
863
+ }
864
+ return value;
865
+ }
866
+
867
+ float get_max_amp(float persistence, float octaveCount) {
868
+ persistence *= .999;
869
+ return (1. - pow(persistence, octaveCount)) / (1. - persistence);
870
+ }
871
+
872
+ void main() {
873
+
874
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
875
+ float t = .2 * u_time;
876
+
877
+ uv -= .5;
878
+ uv *= (.004 * u_scale * u_resolution);
879
+ uv /= u_pixelRatio;
880
+ uv += .5;
881
+
882
+ vec3 p = vec3(uv, t);
883
+
884
+ float oct_count = max(0., floor(u_octaveCount));
885
+ float persistence = clamp(u_persistence, 0., 1.);
886
+ float noise = p_noise(p, int(oct_count), persistence, u_lacunarity);
887
+
888
+ float max_amp = get_max_amp(persistence, oct_count);
889
+ float noise_normalized = (noise + max_amp) / (2. * max_amp) + (u_proportion - .5);
890
+ float sharpness = clamp(1. - u_contour, 0., 1.);
891
+ float smooth_w = 0.5 * fwidth(noise_normalized);
892
+ float sharp_noise = smoothstep(
893
+ .5 - .5 * sharpness - smooth_w,
894
+ .5 + .5 * sharpness + smooth_w,
895
+ noise_normalized
896
+ );
897
+
898
+ vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, sharp_noise);
899
+ float opacity = mix(u_color1.a, u_color2.a, sharp_noise);
900
+
901
+ fragColor = vec4(color, opacity);
902
+ }
903
+ `;var O=`#version 300 es
904
+ precision highp float;
905
+
906
+ uniform float u_time;
907
+ uniform float u_pixelRatio;
908
+ uniform vec2 u_resolution;
909
+
910
+ uniform float u_scale;
911
+
912
+ uniform vec4 u_colorCell1;
913
+ uniform vec4 u_colorCell2;
914
+ uniform vec4 u_colorCell3;
915
+ uniform vec4 u_colorEdges;
916
+ uniform vec4 u_colorMid;
917
+
918
+ uniform float u_colorGradient;
919
+ uniform float u_distance;
920
+ uniform float u_edgesSize;
921
+ uniform float u_edgesSharpness;
922
+ uniform float u_middleSize;
923
+ uniform float u_middleSharpness;
924
+
925
+ #define TWO_PI 6.28318530718
926
+
927
+ out vec4 fragColor;
928
+
929
+ vec2 hash(vec2 p) {
930
+ p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
931
+ return fract(sin(p) * 18.5453);
932
+ }
933
+
934
+ float smin(float angle, float b, float k) {
935
+ float h = clamp(.5 + .5 * (b - angle) / k, 0., 1.);
936
+ return mix(b, angle, h) - k * h * (1. - h);
937
+ }
938
+
939
+ vec4 blend_colors(vec4 c1, vec4 c2, vec4 c3, vec2 randomizer) {
940
+ vec3 color1 = c1.rgb * c1.a;
941
+ vec3 color2 = c2.rgb * c2.a;
942
+ vec3 color3 = c3.rgb * c3.a;
943
+
944
+ float mixer = clamp(u_colorGradient, 0., 1.);
945
+ float r1 = smoothstep(.5 - .5 * mixer, .5 + .5 * mixer, randomizer[0]);
946
+ float r2 = smoothstep(.6 - .6 * mixer, .6 + .4 * mixer, randomizer[1]);
947
+ vec3 blended_color_2 = mix(color1, color2, r1);
948
+ float blended_opacity_2 = mix(c1.a, c2.a, r1);
949
+ vec3 c = mix(blended_color_2, color3, r2);
950
+ float o = mix(blended_opacity_2, c3.a, r2);
951
+
952
+ return vec4(c, o);
953
+ }
954
+
955
+ void main() {
956
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
957
+ float t = u_time;
958
+ uv -= .5;
959
+ uv *= (.01 * u_scale * u_resolution);
960
+ uv /= u_pixelRatio;
961
+ uv += .5;
962
+
963
+ vec2 i_uv = floor(uv);
964
+ vec2 f_uv = fract(uv);
965
+
966
+ vec2 randomizer = vec2(0.);
967
+ vec3 distance = vec3(1.);
968
+
969
+ for (int y = -1; y <= 1; y++) {
970
+ for (int x = -1; x <= 1; x++) {
971
+ vec2 tile_offset = vec2(float(x), float(y));
972
+ vec2 o = hash(i_uv + tile_offset);
973
+ tile_offset += (.5 + clamp(u_distance, 0., .5) * sin(t + TWO_PI * o)) - f_uv;
974
+
975
+ float dist = dot(tile_offset, tile_offset);
976
+ float old_min_dist = distance.x;
977
+
978
+ distance.z = max(distance.x, max(distance.y, min(distance.z, dist)));
979
+ distance.y = max(distance.x, min(distance.y, dist));
980
+ distance.x = min(distance.x, dist);
981
+
982
+ if (old_min_dist > distance.x) {
983
+ randomizer = o;
984
+ }
985
+ }
440
986
  }
441
- gl_FragColor = col;
987
+
988
+ distance = sqrt(distance);
989
+
990
+ distance = sqrt(distance);
991
+ float cell_shape = min(smin(distance.z, distance.y, .1) - distance.x, 1.);
992
+
993
+ float dot_shape = pow(distance.x, 2.) / (2. * clamp(u_middleSize, 0., 1.) + 1e-4);
994
+ float dot_edge_width = fwidth(dot_shape);
995
+ float dotSharp = clamp(u_middleSharpness, 0., 1.);
996
+ dot_shape = 1. - smoothstep(.5 * dotSharp - dot_edge_width, 1. - .5 * dotSharp, dot_shape);
997
+
998
+ float cell_edge_width = fwidth(distance.x);
999
+ float w = .7 * (clamp(u_edgesSize, 0., 1.) - .1);
1000
+ float edgeSharp = clamp(u_edgesSharpness, 0., 1.);
1001
+ cell_shape = smoothstep(w - cell_edge_width, w + edgeSharp, cell_shape);
1002
+
1003
+ dot_shape *= cell_shape;
1004
+
1005
+ vec4 cell_mix = blend_colors(u_colorCell1, u_colorCell2, u_colorCell3, randomizer);
1006
+
1007
+ vec4 edges = vec4(u_colorEdges.rgb * u_colorEdges.a, u_colorEdges.a);
1008
+
1009
+ vec3 color = mix(edges.rgb, cell_mix.rgb, cell_shape);
1010
+ float opacity = mix(edges.a, cell_mix.a, cell_shape);
1011
+
1012
+ color = mix(color, u_colorMid.rgb * u_colorMid.a, dot_shape);
1013
+ opacity = mix(opacity, u_colorMid.a, dot_shape);
1014
+
1015
+ fragColor = vec4(color, opacity);
1016
+ }
1017
+ `;var T=`#version 300 es
1018
+ precision highp float;
1019
+
1020
+ uniform float u_pixelRatio;
1021
+ uniform vec2 u_resolution;
1022
+
1023
+ uniform float u_scale;
1024
+ uniform float u_rotation;
1025
+
1026
+ uniform vec4 u_color1;
1027
+ uniform vec4 u_color2;
1028
+ uniform float u_shape;
1029
+ uniform float u_frequency;
1030
+ uniform float u_amplitude;
1031
+ uniform float u_spacing;
1032
+ uniform float u_dutyCycle;
1033
+ uniform float u_edgeBlur;
1034
+
1035
+ #define TWO_PI 6.28318530718
1036
+ #define PI 3.14159265358979323846
1037
+
1038
+ out vec4 fragColor;
1039
+
1040
+ vec2 rotate(vec2 uv, float th) {
1041
+ return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;
1042
+ }
1043
+
1044
+ void main() {
1045
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
1046
+
1047
+ uv -= .5;
1048
+ uv *= (.02 * max(0., u_scale) * u_resolution);
1049
+ uv = rotate(uv, u_rotation * .5 * PI);
1050
+ uv /= u_pixelRatio;
1051
+ uv += .5;
1052
+
1053
+ float wave = .5 * cos(uv.x * u_frequency * TWO_PI);
1054
+ float zigzag = 2. * abs(fract(uv.x * u_frequency) - .5);
1055
+ float irregular = sin(uv.x * .25 * u_frequency * TWO_PI) * cos(uv.x * u_frequency * TWO_PI);
1056
+ float irregular2 = .75 * (sin(uv.x * u_frequency * TWO_PI) + .5 * cos(uv.x * .5 * u_frequency * TWO_PI));
1057
+
1058
+ float offset = mix(zigzag, wave, smoothstep(0., 1., u_shape));
1059
+ offset = mix(offset, irregular, smoothstep(1., 2., u_shape));
1060
+ offset = mix(offset, irregular2, smoothstep(2., 3., u_shape));
1061
+ offset *= 2. * u_amplitude;
1062
+
1063
+ float spacing = .02 + .98 * u_spacing;
1064
+ float shape = .5 + .5 * sin((uv.y + offset) * PI / spacing);
1065
+
1066
+ float edge_width = .02 / (1. + abs(shape)) * (.001 + u_scale);
1067
+ edge_width += .5 * max(0., u_edgeBlur);
1068
+ float dc = clamp(u_dutyCycle, 0., 1.);
1069
+ float t = smoothstep(dc - edge_width, dc + edge_width, shape);
1070
+
1071
+ vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, t);
1072
+ float opacity = mix(u_color1.a, u_color2.a, t);
1073
+
1074
+ fragColor = vec4(color, opacity);
442
1075
  }
443
- `;function f(e,r=[0,0,0,1]){if(Array.isArray(e))return e.length===4?e:e.length===3?[...e,1]:f(r);if(typeof e!="string")return f(r);let t,o,i,n=1;if(e.startsWith("#"))[t,o,i,n]=U(e);else if(e.startsWith("rgb"))[t,o,i,n]=I(e);else if(e.startsWith("hsl"))[t,o,i,n]=P(L(e));else return console.error("Unsupported color format",e),f(r);return[l(t,0,1),l(o,0,1),l(i,0,1),l(n,0,1)]}function U(e){e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(n=>n+n).join("")),e.length===6&&(e=e+"ff");let r=parseInt(e.slice(0,2),16)/255,t=parseInt(e.slice(2,4),16)/255,o=parseInt(e.slice(4,6),16)/255,i=parseInt(e.slice(6,8),16)/255;return[r,t,o,i]}function I(e){let r=e.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+))?\s*\)$/i);return r?[parseInt(r[1]??"0")/255,parseInt(r[2]??"0")/255,parseInt(r[3]??"0")/255,r[4]===void 0?1:parseFloat(r[4])]:[0,0,0,1]}function L(e){let r=e.match(/^hsla?\s*\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([0-9.]+))?\s*\)$/i);return r?[parseInt(r[1]??"0"),parseInt(r[2]??"0"),parseInt(r[3]??"0"),r[4]===void 0?1:parseFloat(r[4])]:[0,0,0,1]}function P(e){let[r,t,o,i]=e,n=r/360,u=t/100,a=o/100,h,d,v;if(t===0)h=d=v=a;else{let p=(m,b,s)=>(s<0&&(s+=1),s>1&&(s-=1),s<.16666666666666666?m+(b-m)*6*s:s<.5?b:s<.6666666666666666?m+(b-m)*(.6666666666666666-s)*6:m),c=a<.5?a*(1+u):a+u-a*u,_=2*a-c;h=p(_,c,n+1/3),d=p(_,c,n),v=p(_,c,n-1/3)}return[h,d,v,i]}var l=(e,r,t)=>Math.min(Math.max(e,r),t);export{g as ShaderMount,w as dotsOrbitFragmentShader,f as getShaderColorFromString,F as grainCloudsFragmentShader,A as meshGradientFragmentShader,z as neuroNoiseFragmentShader,S as smokeRingFragmentShader,C as steppedSimplexNoiseFragmentShader};
1076
+ `;function f(e,o=[0,0,0,1]){if(Array.isArray(e))return e.length===4?e:e.length===3?[...e,1]:f(o);if(typeof e!="string")return f(o);let r,t,a,i=1;if(e.startsWith("#"))[r,t,a,i]=W(e);else if(e.startsWith("rgb"))[r,t,a,i]=B(e);else if(e.startsWith("hsl"))[r,t,a,i]=G(L(e));else return console.error("Unsupported color format",e),f(o);return[m(r,0,1),m(t,0,1),m(a,0,1),m(i,0,1)]}function W(e){e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(i=>i+i).join("")),e.length===6&&(e=e+"ff");let o=parseInt(e.slice(0,2),16)/255,r=parseInt(e.slice(2,4),16)/255,t=parseInt(e.slice(4,6),16)/255,a=parseInt(e.slice(6,8),16)/255;return[o,r,t,a]}function B(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 L(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 G(e){let[o,r,t,a]=e,i=o/360,s=r/100,n=t/100,_,d,p;if(r===0)_=d=p=n;else{let v=(l,b,u)=>(u<0&&(u+=1),u>1&&(u-=1),u<.16666666666666666?l+(b-l)*6*u:u<.5?b:u<.6666666666666666?l+(b-l)*(.6666666666666666-u)*6:l),c=n<.5?n*(1+s):n+s-n*s,h=2*n-c;_=v(h,c,i+1/3),d=v(h,c,i),p=v(h,c,i-1/3)}return[_,d,p,a]}var m=(e,o,r)=>Math.min(Math.max(e,o),r);export{k as DotsGridShapes,g as ShaderMount,I as dotsGridFragmentShader,F as dotsOrbitFragmentShader,f as getShaderColorFromString,z as grainCloudsFragmentShader,C as meshGradientFragmentShader,U as metaballsFragmentShader,w as neuroNoiseFragmentShader,A as perlinNoiseFragmentShader,R as smokeRingFragmentShader,P as steppedSimplexNoiseFragmentShader,O as voronoiFragmentShader,T as wavesFragmentShader};
444
1077
  //# sourceMappingURL=index.js.map