@paper-design/shaders 0.0.14 → 0.0.15

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,3 @@
1
+ /** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGBA array */
2
+ export declare function getShaderColorFromString(colorString: string | [number, number, number] | [number, number, number, number] | undefined, fallback?: string | [number, number, number] | [number, number, number, number]): [number, number, number, number];
3
+ export declare const clamp: (n: number, min: number, max: number) => number;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  /** The core Shader Mounting class. Pass it a canvas element and a fragment shader to get started. */
2
2
  export { ShaderMount } from './shader-mount';
3
- /** An example fragment shader that renders a grainy texture over top of blobby animated clouds */
4
3
  export { grainCloudsFragmentShader, type GrainCloudsUniforms } from './shaders/grain-clouds';
5
4
  /** A shader that renders a mesh gradient with a rotating noise pattern and several layers of fractal noise */
6
5
  export { meshGradientFragmentShader, type MeshGradientUniforms } from './shaders/mesh-gradient';
6
+ /** Fractional Brownian motion (fBm) noise over the polar coordinates, masked with ring shape */
7
+ export { smokeRingFragmentShader, type SmokeRingUniforms } from './shaders/smoke-ring';
7
8
  /** A shader rendering a fractal-like structure made of several layers of since-arches */
8
9
  export { neuroNoiseFragmentShader, type NeuroNoiseUniforms } from './shaders/neuro-noise';
9
- export { getShaderColorFromString } from './shader-mount';
10
+ /** A shader rendering an animated dots pattern based on Voronoi diagram */
11
+ export { dotsOrbitFragmentShader, type DotsOrbitUniforms } from './shaders/dots-orbit';
12
+ /** A shader that calculates a combination of 2 simplex noises with result rendered as a stepped gradient */
13
+ export { steppedSimplexNoiseFragmentShader, type SteppedSimplexNoiseUniforms } from './shaders/stepped-simplex-noise';
14
+ export { getShaderColorFromString } from './get-shader-color-from-string';
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  /***** Paper Shaders: https://github.com/paper-design/shaders *****/
2
- var v=class{canvas;gl;program=null;uniformLocations={};fragmentShader;rafId=null;lastFrameTime=0;totalAnimationTime=0;isAnimated;providedUniforms;hasBeenDisposed=!1;resolutionChanged=!0;constructor(r,t,i={},o,n=!0){this.canvas=r,this.fragmentShader=t,this.providedUniforms=i,this.isAnimated=n;let s=r.getContext("webgl",o);if(!s)throw new Error("WebGL not supported");this.gl=s,this.initWebGL(),this.setupResizeObserver(),this.isAnimated?this.startAnimating():this.render(performance.now())}initWebGL=()=>{let r=x(this.gl,_,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 i=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1];this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(i),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=this.canvas.clientWidth,t=this.canvas.clientHeight;(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=r=>{if(this.hasBeenDisposed)return;let t=r-this.lastFrameTime;this.lastFrameTime=r,this.isAnimated&&(this.totalAnimationTime+=t),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.isAnimated?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 i=this.uniformLocations[r];if(i)if(Array.isArray(t))switch(t.length){case 2:this.gl.uniform2fv(i,t);break;case 3:this.gl.uniform3fv(i,t);break;case 4:this.gl.uniform4fv(i,t);break;default:t.length===9?this.gl.uniformMatrix3fv(i,!1,t):t.length===16?this.gl.uniformMatrix4fv(i,!1,t):console.warn(`Unsupported uniform array length: ${t.length}`)}else typeof t=="number"?this.gl.uniform1f(i,t):typeof t=="boolean"?this.gl.uniform1i(i,t?1:0):console.warn(`Unsupported uniform type for ${r}: ${typeof t}`)})};startAnimating=()=>{this.isAnimated=!0,this.lastFrameTime=performance.now(),this.rafId=requestAnimationFrame(this.render)};stopAnimating=()=>{this.isAnimated=!1,this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null)};setUniforms=r=>{this.providedUniforms={...this.providedUniforms,...r},this.updateProvidedUniforms(),this.render(performance.now())};dispose=()=>{this.hasBeenDisposed=!0,this.stopAnimating(),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={}}},_=`
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
3
  attribute vec4 a_position;
4
4
  void main() {
5
5
  gl_Position = a_position;
6
6
  }
7
- `;function b(e,r,t){let i=e.createShader(r);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 x(e,r,t){let i=b(e,e.VERTEX_SHADER,r),o=b(e,e.FRAGMENT_SHADER,t);if(!i||!o)return null;let n=e.createProgram();return n?(e.attachShader(n,i),e.attachShader(n,o),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS)?(e.detachShader(n,i),e.detachShader(n,o),e.deleteShader(i),e.deleteShader(o),n):(console.error("Unable to initialize the shader program: "+e.getProgramInfoLog(n)),e.deleteProgram(n),e.deleteShader(i),e.deleteShader(o),null)):null}function g(e,r=[0,0,0]){if(Array.isArray(e)&&e.length===3)return e;if(typeof e!="string")return g(r);let t,i,o;if(e.startsWith("#"))[t,i,o]=y(e);else if(e.startsWith("rgb"))[t,i,o]=A(e);else if(e.startsWith("hsl"))[t,i,o]=R(S(e));else return console.error("Unsupported color format",e),g(r);return[t,i,o]}function y(e){e.length===4&&(e=`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`);let r=parseInt(e.slice(1),16),t=(r>>16&255)/255,i=(r>>8&255)/255,o=(r&255)/255;return[t,i,o]}function A(e){let r=e.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);return r?[parseInt(r[1]??"0")/255,parseInt(r[2]??"0")/255,parseInt(r[3]??"0")/255]:[0,0,0]}function S(e){let r=e.match(/^hsl\s*\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)$/i);return r?[parseInt(r[1]??"0"),parseInt(r[2]??"0"),parseInt(r[3]??"0")]:[0,0,0]}function R(e){let[r,t,i]=e,o=r/360,n=t/100,s=i/100,c,l,h;if(t===0)c=l=h=s;else{let f=(u,p,a)=>(a<0&&(a+=1),a>1&&(a-=1),a<.16666666666666666?u+(p-u)*6*a:a<.5?p:a<.6666666666666666?u+(p-u)*(.6666666666666666-a)*6:u),m=s<.5?s*(1+n):s+n-s*n,d=2*s-m;c=f(d,m,o+1/3),l=f(d,m,o),h=f(d,m,o-1/3)}return[c,l,h]}var F=`
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
8
  precision highp float;
9
9
  uniform vec2 u_resolution;
10
10
  uniform float u_time;
11
- uniform vec3 u_color1;
12
- uniform vec3 u_color2;
13
- uniform float u_noiseScale;
14
- uniform float u_noiseSpeed;
11
+
12
+ uniform vec4 u_color1;
13
+ uniform vec4 u_color2;
14
+ uniform float u_scale;
15
15
  uniform float u_grainAmount;
16
16
 
17
17
  // Simplex 2D noise
@@ -63,33 +63,32 @@ var v=class{canvas;gl;program=null;uniformLocations={};fragmentShader;rafId=null
63
63
  }
64
64
 
65
65
  // Create blobby texture
66
- float n = snoise(st * u_noiseScale + u_time * u_noiseSpeed);
67
- n += 0.5 * snoise(st * u_noiseScale * 2.0 - u_time * u_noiseSpeed * 0.5);
68
- n += 0.25 * snoise(st * u_noiseScale * 4.0 + u_time * u_noiseSpeed * 0.25);
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
69
  n = n * 0.5 + 0.5;
70
70
 
71
71
  // Color interpolation
72
- vec3 color = mix(u_color1, u_color2, n);
72
+ vec4 color = mix(u_color1, u_color2, n);
73
73
 
74
74
  // Add grain
75
75
  float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);
76
76
  color += (grain - 0.5) * u_grainAmount;
77
77
 
78
- gl_FragColor = vec4(color, 1.0);
78
+ gl_FragColor = color;
79
79
  }
80
- `;var w=`
80
+ `;var A=`
81
81
  // Mesh Gradient: https://www.shadertoy.com/view/wdyczG
82
82
  #define S(a,b,t) smoothstep(a,b,t)
83
83
 
84
84
  precision highp float;
85
85
 
86
- uniform vec3 u_color1;
87
- uniform vec3 u_color2;
88
- uniform vec3 u_color3;
89
- uniform vec3 u_color4;
86
+ uniform vec4 u_color1;
87
+ uniform vec4 u_color2;
88
+ uniform vec4 u_color3;
89
+ uniform vec4 u_color4;
90
90
  uniform vec2 u_resolution;
91
91
  uniform float u_time;
92
- uniform float u_speed;
93
92
 
94
93
  mat2 Rot(float a)
95
94
  {
@@ -128,7 +127,7 @@ void main() {
128
127
  tuv -= .5;
129
128
 
130
129
  // rotate with Noise
131
- float degree = noise(vec2(u_time * u_speed, tuv.x * tuv.y));
130
+ float degree = noise(vec2(u_time, tuv.x * tuv.y));
132
131
 
133
132
  tuv.y *= 1./ratio;
134
133
  tuv *= Rot(radians((degree-.5)*720.+180.));
@@ -144,23 +143,113 @@ void main() {
144
143
 
145
144
 
146
145
  // draw the image
147
- vec3 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));
148
- vec3 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));
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));
149
148
 
150
- vec3 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));
149
+ vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));
150
+ gl_FragColor = finalComp;
151
+ }
152
+ `;var S=`
151
153
 
152
- vec3 col = finalComp;
154
+ precision highp float;
153
155
 
154
- gl_FragColor = vec4(col,1.0);
155
- }
156
- `;var C=`
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;
163
+
164
+ #define TWO_PI 6.28318530718
165
+ #define PI 3.14159265358979323846
166
+
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
+ }
184
+
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
+ }
192
+
193
+ void main() {
194
+
195
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
196
+ float ratio = u_resolution.x / u_resolution.y;
197
+
198
+ uv -= .5;
199
+ uv *= 2.;
200
+ uv.x *= ratio;
201
+
202
+ float t = u_time;
203
+
204
+ float atg = atan(uv.y, uv.x);
205
+ float angle = (atg + PI) / TWO_PI;
206
+
207
+ vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));
208
+ polar_uv *= u_scale;
209
+
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));
214
+
215
+ float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);
216
+
217
+ float radius = .4 - .25 * u_thickness;
218
+ float thickness = u_thickness;
219
+ thickness = pow(thickness, 2.);
220
+
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;
229
+
230
+ ring_shape_outer *= u_color2.a;
231
+ ring_shape_inner *= u_color1.a;
232
+
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=`
157
247
  precision mediump float;
158
248
 
159
- uniform vec3 u_colorFront;
160
- uniform vec3 u_colorBack;
249
+ uniform vec4 u_colorFront;
250
+ uniform vec4 u_colorBack;
161
251
  uniform float u_scale;
162
252
  uniform float u_brightness;
163
- uniform float u_speed;
164
253
 
165
254
  uniform float u_time;
166
255
  uniform float u_ratio;
@@ -188,26 +277,168 @@ float neuro_shape(vec2 uv, float t) {
188
277
 
189
278
  void main() {
190
279
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
191
- float ratio = u_resolution.x / u_resolution.y;
192
- vec2 uv_r = uv;
193
- uv_r -= .5;
194
- uv_r *= u_scale;
195
- uv_r += .5;
196
- uv_r.x *= ratio;
197
-
198
- float t = u_speed * u_time;
280
+
281
+ uv -= .5;
282
+ uv *= (.001 * u_scale * u_resolution);
283
+ uv += .5;
284
+
285
+ float t = u_time;
199
286
  vec3 color = vec3(0.);
200
287
 
201
- float noise = neuro_shape(uv_r, t);
288
+ float noise = neuro_shape(uv, t);
202
289
 
203
290
  noise = u_brightness * pow(noise, 3.);
204
- noise += pow(noise, 10.);
291
+ noise += pow(noise, 12.);
205
292
  noise = max(.0, noise - .5);
206
- noise *= (1. - length(uv - .5));
207
293
 
208
- color = mix(u_colorBack, u_colorFront, noise);
294
+ gl_FragColor = mix(u_colorBack, u_colorFront, noise);
295
+ }
296
+ `;var w=`
297
+ precision mediump float;
298
+
299
+ uniform vec4 u_color1;
300
+ uniform vec4 u_color2;
301
+ uniform vec4 u_color3;
302
+ uniform vec4 u_color4;
303
+ uniform float u_dotSize;
304
+ uniform float u_dotSizeRange;
305
+ uniform float u_scale;
306
+ uniform float u_spreading;
307
+ uniform float u_time;
308
+ uniform float u_ratio;
309
+ uniform vec2 u_resolution;
310
+
311
+ #define TWO_PI 6.28318530718
312
+ #define PI 3.14159265358979323846
313
+
314
+ 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);
316
+ }
317
+
318
+ vec3 get_voronoi_shape(vec2 _uv, float time) {
319
+ vec2 i_uv = floor(_uv);
320
+ vec2 f_uv = fract(_uv);
321
+
322
+ float min_dist = 1.;
323
+ vec2 cell_randomizer = vec2(0.);
324
+ for (int y = -1; y <= 1; y++) {
325
+ for (int x = -1; x <= 1; x++) {
326
+ vec2 tile_offset = vec2(float(x), float(y));
327
+ vec2 rand = random2(i_uv + tile_offset);
328
+ vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);
329
+ float dist = length(tile_offset + cell_center - f_uv);
330
+ if (dist < min_dist) {
331
+ min_dist = dist;
332
+ cell_randomizer = rand;
333
+ }
334
+ min_dist = min(min_dist, dist);
335
+ }
336
+ }
337
+
338
+ return vec3(min_dist, cell_randomizer);
339
+ }
340
+
341
+ void main() {
342
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
343
+
344
+ uv -= .5;
345
+ uv *= (.001 * u_scale * u_resolution);
346
+ uv += .5;
347
+
348
+ float t = u_time;
349
+
350
+ vec3 voronoi = get_voronoi_shape(uv, t);
351
+ float radius = u_dotSize - u_dotSizeRange * voronoi[2];
352
+
353
+ float radius_smoother = .001 + .001 * (u_scale - 1.);
354
+ float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);
355
+
356
+ 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
+
363
+ gl_FragColor = color * shape;
364
+ }
365
+ `;var C=`
366
+ precision highp float;
367
+
368
+ uniform vec4 u_color1;
369
+ uniform vec4 u_color2;
370
+ uniform vec4 u_color3;
371
+ uniform vec4 u_color4;
372
+ uniform vec4 u_color5;
373
+ uniform float u_scale;
374
+ uniform float u_steps_number;
375
+
376
+ uniform float u_time;
377
+ uniform vec2 u_resolution;
378
+
379
+
380
+ vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
381
+ float snoise(vec2 v) {
382
+ const vec4 C = vec4(0.211324865405187, 0.366025403784439,
383
+ -0.577350269189626, 0.024390243902439);
384
+ vec2 i = floor(v + dot(v, C.yy));
385
+ vec2 x0 = v - i + dot(i, C.xx);
386
+ vec2 i1;
387
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
388
+ vec4 x12 = x0.xyxy + C.xxzz;
389
+ x12.xy -= i1;
390
+ i = mod(i, 289.0);
391
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
392
+ + i.x + vec3(0.0, i1.x, 1.0));
393
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),
394
+ dot(x12.zw, x12.zw)), 0.0);
395
+ m = m * m;
396
+ m = m * m;
397
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
398
+ vec3 h = abs(x) - 0.5;
399
+ vec3 ox = floor(x + 0.5);
400
+ vec3 a0 = x - ox;
401
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
402
+ vec3 g;
403
+ g.x = a0.x * x0.x + h.x * x0.y;
404
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
405
+ return 130.0 * dot(m, g);
406
+ }
209
407
 
210
- gl_FragColor = vec4(color, 1.);
408
+ float get_noise(vec2 uv, float t) {
409
+ float noise = .5 * snoise(uv - vec2(0., .3 * t));
410
+ noise += .5 * snoise(2. * uv + vec2(0., .32 * t));
411
+
412
+ return noise;
413
+ }
414
+
415
+ vec4 getColor(int index) {
416
+ if (index == 0) return u_color1;
417
+ if (index == 1) return u_color2;
418
+ if (index == 2) return u_color3;
419
+ if (index == 3) return u_color4;
420
+ if (index == 4) return u_color5;
421
+ return u_color1;
422
+ }
423
+
424
+ void main() {
425
+ vec2 uv = gl_FragCoord.xy / u_resolution.xy;
426
+
427
+ uv -= .5;
428
+ uv *= (.001 * u_scale * u_resolution);
429
+ uv += .5;
430
+
431
+ float t = u_time;
432
+
433
+ float noise = .5 + .5 * get_noise(uv, t);
434
+ noise = floor(noise * u_steps_number) / u_steps_number;
435
+
436
+ vec4 col = u_color1;
437
+ 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));
440
+ }
441
+ gl_FragColor = col;
211
442
  }
212
- `;export{v as ShaderMount,g as getShaderColorFromString,F as grainCloudsFragmentShader,w as meshGradientFragmentShader,C as neuroNoiseFragmentShader};
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};
213
444
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/shader-mount.ts", "../src/shaders/grain-clouds.ts", "../src/shaders/mesh-gradient.ts", "../src/shaders/neuro-noise.ts"],
4
- "sourcesContent": ["export class ShaderMount {\n private canvas: HTMLCanvasElement;\n private gl: WebGLRenderingContext;\n private program: WebGLProgram | null = null;\n private uniformLocations: Record<string, WebGLUniformLocation | null> = {};\n /** The fragment shader that we are using */\n private fragmentShader: string;\n /** Stores the RAF for the render loop */\n private rafId: number | null = null;\n /** Time of the last rendered frame */\n private lastFrameTime = 0;\n /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */\n private totalAnimationTime = 0;\n /** Whether we RAF the render or not */\n private isAnimated: boolean;\n /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */\n private providedUniforms: Record<string, number | number[]>;\n /** Just a sanity check to make sure frames don't run after we're disposed */\n private hasBeenDisposed = false;\n /** If the resolution of the canvas has changed since the last render */\n private resolutionChanged = true;\n\n constructor(\n canvas: HTMLCanvasElement,\n fragmentShader: string,\n uniforms: Record<string, number | number[]> = {},\n webGlContextAttributes?: WebGLContextAttributes,\n animated = true\n ) {\n this.canvas = canvas;\n this.fragmentShader = fragmentShader;\n this.providedUniforms = uniforms;\n this.isAnimated = animated;\n\n const gl = canvas.getContext('webgl', webGlContextAttributes);\n if (!gl) {\n throw new Error('WebGL not supported');\n }\n this.gl = gl;\n\n this.initWebGL();\n this.setupResizeObserver();\n if (this.isAnimated) {\n this.startAnimating();\n } else {\n this.render(performance.now());\n }\n }\n\n private initWebGL = () => {\n const program = createProgram(this.gl, vertexShaderSource, this.fragmentShader);\n if (!program) return;\n this.program = program;\n\n this.setupPositionAttribute();\n this.setupUniforms();\n };\n\n private setupPositionAttribute = () => {\n const positionAttributeLocation = this.gl.getAttribLocation(this.program!, 'a_position');\n const positionBuffer = this.gl.createBuffer();\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, positionBuffer);\n const positions = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1];\n this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(positions), this.gl.STATIC_DRAW);\n this.gl.enableVertexAttribArray(positionAttributeLocation);\n this.gl.vertexAttribPointer(positionAttributeLocation, 2, this.gl.FLOAT, false, 0, 0);\n };\n\n private setupUniforms = () => {\n this.uniformLocations = {\n u_time: this.gl.getUniformLocation(this.program!, 'u_time'),\n u_resolution: this.gl.getUniformLocation(this.program!, 'u_resolution'),\n ...Object.fromEntries(\n Object.keys(this.providedUniforms).map((key) => [key, this.gl.getUniformLocation(this.program!, key)])\n ),\n };\n };\n\n private resizeObserver: ResizeObserver | null = null;\n private setupResizeObserver = () => {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n this.resizeObserver.observe(this.canvas);\n this.handleResize();\n };\n\n private handleResize = () => {\n const newWidth = this.canvas.clientWidth;\n const newHeight = this.canvas.clientHeight;\n if (this.canvas.width !== newWidth || this.canvas.height !== newHeight) {\n this.canvas.width = newWidth;\n this.canvas.height = newHeight;\n this.resolutionChanged = true;\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n this.render(performance.now());\n }\n };\n\n private render = (currentTime: number) => {\n if (this.hasBeenDisposed) return;\n\n const dt = currentTime - this.lastFrameTime;\n this.lastFrameTime = currentTime;\n\n if (this.isAnimated) {\n this.totalAnimationTime += dt;\n }\n\n this.gl.useProgram(this.program);\n\n // Update the time uniform\n this.gl.uniform1f(this.uniformLocations.u_time!, this.totalAnimationTime * 0.001);\n // If the resolution has changed, we need to update the uniform\n if (this.resolutionChanged) {\n this.gl.uniform2f(this.uniformLocations.u_resolution!, this.gl.canvas.width, this.gl.canvas.height);\n this.resolutionChanged = false;\n }\n\n this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);\n\n // Loop if we're animating\n\n if (this.isAnimated) {\n this.requestRender();\n } else {\n this.rafId = null;\n }\n };\n\n private requestRender = () => {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n }\n this.rafId = requestAnimationFrame(this.render);\n };\n\n private updateProvidedUniforms = () => {\n this.gl.useProgram(this.program);\n Object.entries(this.providedUniforms).forEach(([key, value]) => {\n const location = this.uniformLocations[key];\n if (location) {\n if (Array.isArray(value)) {\n switch (value.length) {\n case 2:\n this.gl.uniform2fv(location, value);\n break;\n case 3:\n this.gl.uniform3fv(location, value);\n break;\n case 4:\n this.gl.uniform4fv(location, value);\n break;\n default:\n if (value.length === 9) {\n this.gl.uniformMatrix3fv(location, false, value);\n } else if (value.length === 16) {\n this.gl.uniformMatrix4fv(location, false, value);\n } else {\n console.warn(`Unsupported uniform array length: ${value.length}`);\n }\n }\n } else if (typeof value === 'number') {\n this.gl.uniform1f(location, value);\n } else if (typeof value === 'boolean') {\n this.gl.uniform1i(location, value ? 1 : 0);\n } else {\n console.warn(`Unsupported uniform type for ${key}: ${typeof value}`);\n }\n }\n });\n };\n\n /** Start the animation loop, can be called during instantiation or later by an outside source */\n public startAnimating = (): void => {\n this.isAnimated = true;\n this.lastFrameTime = performance.now();\n this.rafId = requestAnimationFrame(this.render);\n };\n\n /** Stop the animation loop */\n public stopAnimating = (): void => {\n this.isAnimated = false;\n if (this.rafId) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n };\n\n /** Update the uniforms that are provided by the outside shader */\n public setUniforms = (newUniforms: Record<string, number | number[]>): void => {\n this.providedUniforms = { ...this.providedUniforms, ...newUniforms };\n\n // If we need to allow users to add uniforms after the shader has been created, we can do that here\n // But right now we're expecting the uniform list to be predictable and static\n // this.setupUniforms();\n\n this.updateProvidedUniforms();\n this.render(performance.now());\n };\n\n /** Dispose of the shader mount, cleaning up all of the WebGL resources */\n public dispose = (): void => {\n this.hasBeenDisposed = true;\n this.stopAnimating();\n if (this.gl && this.program) {\n this.gl.deleteProgram(this.program);\n this.program = null;\n\n // Reset the WebGL context\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);\n this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, null);\n this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null);\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);\n\n // Clear any errors\n this.gl.getError();\n }\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n }\n\n this.uniformLocations = {};\n };\n}\n\n/** Vertex shader for the shader mount */\nconst vertexShaderSource = `\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n`;\n\nfunction createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | null {\n const shader = gl.createShader(type);\n if (!shader) return null;\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n console.error('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader));\n gl.deleteShader(shader);\n return null;\n }\n\n return shader;\n}\n\nfunction createProgram(\n gl: WebGLRenderingContext,\n vertexShaderSource: string,\n fragmentShaderSource: string\n): WebGLProgram | null {\n const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);\n const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);\n\n if (!vertexShader || !fragmentShader) return null;\n\n const program = gl.createProgram();\n if (!program) return null;\n\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n console.error('Unable to initialize the shader program: ' + gl.getProgramInfoLog(program));\n gl.deleteProgram(program);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n return null;\n }\n\n // Clean up shaders after successful linking\n gl.detachShader(program, vertexShader);\n gl.detachShader(program, fragmentShader);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n\n return program;\n}\n\n/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGB array */\nexport function getShaderColorFromString(\n colorString: string | [number, number, number] | undefined,\n fallback: string | [number, number, number] = [0, 0, 0]\n): [number, number, number] {\n // If the color string is already an array of 3 numbers, return it\n // Allowing this pass-through is useful for creating default objects in TypeScript with either syntax\n if (Array.isArray(colorString) && colorString.length === 3) {\n return colorString;\n }\n\n // If the color string is not a string, return the fallback\n if (typeof colorString !== 'string') {\n // Return the fallback color, processed, with no additional fallback argument\n // It'll default to [0, 0, 0] if not parseable\n return getShaderColorFromString(fallback);\n }\n\n let r: number, g: number, b: number;\n if (colorString.startsWith('#')) {\n [r, g, b] = hexToRgb(colorString);\n } else if (colorString.startsWith('rgb')) {\n [r, g, b] = parseRgb(colorString);\n } else if (colorString.startsWith('hsl')) {\n [r, g, b] = hslToRgb(parseHsl(colorString));\n } else {\n console.error('Unsupported color format', colorString);\n // Return the fallback color, processed, with no additional fallback argument\n // It'll default to [0, 0, 0] if not parseable\n return getShaderColorFromString(fallback);\n }\n return [r, g, b];\n}\n\n/** Convert hex to RGB (0 to 1 range) */\nfunction hexToRgb(hex: string): [number, number, number] {\n // Expand three-letter hex to six-letter\n if (hex.length === 4) {\n hex = `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;\n }\n const bigint = parseInt(hex.slice(1), 16);\n const r = ((bigint >> 16) & 255) / 255;\n const g = ((bigint >> 8) & 255) / 255;\n const b = (bigint & 255) / 255;\n return [r, g, b];\n}\n\n/** Parse RGB string to RGB (0 to 1 range) */\nfunction parseRgb(rgb: string): [number, number, number] {\n const match = rgb.match(/^rgb\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/i);\n if (!match) return [0, 0, 0];\n return [parseInt(match[1] ?? '0') / 255, parseInt(match[2] ?? '0') / 255, parseInt(match[3] ?? '0') / 255];\n}\n\n/** Parse HSL string */\nfunction parseHsl(hsl: string): [number, number, number] {\n const match = hsl.match(/^hsl\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*\\)$/i);\n if (!match) return [0, 0, 0];\n return [parseInt(match[1] ?? '0'), parseInt(match[2] ?? '0'), parseInt(match[3] ?? '0')];\n}\n\n/** Convert HSL to RGB (0 to 1 range) */\nfunction hslToRgb(hsl: [number, number, number]): [number, number, number] {\n const [h, s, l] = hsl;\n const hDecimal = h / 360;\n const sDecimal = s / 100;\n const lDecimal = l / 100;\n let r, g, b;\n\n if (s === 0) {\n r = g = b = lDecimal; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;\n const p = 2 * lDecimal - q;\n r = hue2rgb(p, q, hDecimal + 1 / 3);\n g = hue2rgb(p, q, hDecimal);\n b = hue2rgb(p, q, hDecimal - 1 / 3);\n }\n\n return [r, g, b];\n}\n", "export type GrainCloudsUniforms = {\n u_color1: [number, number, number];\n u_color2: [number, number, number];\n u_noiseScale: number;\n u_noiseSpeed: number;\n u_grainAmount: number;\n};\n\n/**\n * Renders a grainy texture over top of blobby animated clouds\n * This is an example shader that we're using to bootstrap the project\n * Generated by Claude 3.5 Sonnet\n *\n * Uniforms include:\n * u_color1: The first color of the clouds\n * u_color2: The second color of the clouds\n * u_noiseScale: The scale of the noise\n * u_noiseSpeed: The speed of the noise\n * u_grainAmount: The amount of grain on the texture\n */\nexport const grainCloudsFragmentShader = `\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n uniform vec3 u_color1;\n uniform vec3 u_color2;\n uniform float u_noiseScale;\n uniform float u_noiseSpeed;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_noiseScale + u_time * u_noiseSpeed);\n n += 0.5 * snoise(st * u_noiseScale * 2.0 - u_time * u_noiseSpeed * 0.5);\n n += 0.25 * snoise(st * u_noiseScale * 4.0 + u_time * u_noiseSpeed * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = vec4(color, 1.0);\n }\n`;\n", "import { getShaderColorFromString } from '../shader-mount';\n\nexport type MeshGradientUniforms = {\n u_color1: [number, number, number];\n u_color2: [number, number, number];\n u_color3: [number, number, number];\n u_color4: [number, number, number];\n u_speed: number;\n};\n\n/**\n * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG\n * Renders a mesh gradient with a rotating noise pattern\n * and several layers of fractal noise\n *\n * Uniforms include:\n * u_color1: The first color of the mesh gradient\n * u_color2: The second color of the mesh gradient\n * u_color3: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n * u_speed: The speed of the noise\n */\n\nexport const meshGradientFragmentShader = `\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec3 u_color1;\nuniform vec3 u_color2;\nuniform vec3 u_color3;\nuniform vec3 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_speed;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time * u_speed, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec3 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec3 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec3 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n\n vec3 col = finalComp;\n\n gl_FragColor = vec4(col,1.0);\n}\n`;\n", "export type NeuroNoiseUniforms = {\n u_colorFront: [number, number, number];\n u_colorBack: [number, number, number];\n u_scale: number;\n u_brightness: number;\n u_speed: number;\n};\n\n/**\n * Neuro Noise Pattern;\n * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova\n * Renders a fractal-like structure made of several layers of since-arches\n *\n * Uniforms include:\n * u_colorFront: The front color of pattern\n * u_colorBack: The back color of pattern\n * u_brightness: The power/brightness of pattern lines\n * u_scale: The scale applied to coordinates\n * u_speed: The speed coefficient for pattern animation\n */\n\nexport const neuroNoiseFragmentShader = `\nprecision mediump float;\n\nuniform vec3 u_colorFront;\nuniform vec3 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\nuniform float u_speed;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n vec2 uv_r = uv;\n uv_r -= .5;\n uv_r *= u_scale;\n uv_r += .5;\n uv_r.x *= ratio;\n\n float t = u_speed * u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv_r, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 10.);\n noise = max(.0, noise - .5);\n noise *= (1. - length(uv - .5));\n\n color = mix(u_colorBack, u_colorFront, noise);\n\n gl_FragColor = vec4(color, 1.);\n}\n`;\n"],
5
- "mappings": ";AAAO,IAAMA,EAAN,KAAkB,CACf,OACA,GACA,QAA+B,KAC/B,iBAAgE,CAAC,EAEjE,eAEA,MAAuB,KAEvB,cAAgB,EAEhB,mBAAqB,EAErB,WAEA,iBAEA,gBAAkB,GAElB,kBAAoB,GAE5B,YACEC,EACAC,EACAC,EAA8C,CAAC,EAC/CC,EACAC,EAAW,GACX,CACA,KAAK,OAASJ,EACd,KAAK,eAAiBC,EACtB,KAAK,iBAAmBC,EACxB,KAAK,WAAaE,EAElB,IAAMC,EAAKL,EAAO,WAAW,QAASG,CAAsB,EAC5D,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,qBAAqB,EAEvC,KAAK,GAAKA,EA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AAA;AAAA;AAAA;AAAA;AAAA;ECGlC,IAAMC,EAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ECFnC,IAAMC,EAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
- "names": ["ShaderMount", "canvas", "fragmentShader", "uniforms", "webGlContextAttributes", "animated", "gl", "program", "createProgram", "vertexShaderSource", "positionAttributeLocation", "positionBuffer", "positions", "key", "newWidth", "newHeight", "currentTime", "dt", "value", "location", "newUniforms", "createShader", "type", "source", "shader", "fragmentShaderSource", "vertexShader", "getShaderColorFromString", "colorString", "fallback", "r", "g", "b", "hexToRgb", "parseRgb", "hslToRgb", "parseHsl", "hex", "bigint", "rgb", "match", "hsl", "h", "s", "l", "hDecimal", "sDecimal", "lDecimal", "hue2rgb", "p", "q", "t", "grainCloudsFragmentShader", "meshGradientFragmentShader", "neuroNoiseFragmentShader"]
3
+ "sources": ["../src/shader-mount.ts", "../src/shaders/grain-clouds.ts", "../src/shaders/mesh-gradient.ts", "../src/shaders/smoke-ring.ts", "../src/shaders/neuro-noise.ts", "../src/shaders/dots-orbit.ts", "../src/shaders/stepped-simplex-noise.ts", "../src/get-shader-color-from-string.ts"],
4
+ "sourcesContent": ["export class ShaderMount {\n private canvas: HTMLCanvasElement;\n private gl: WebGLRenderingContext;\n private program: WebGLProgram | null = null;\n private uniformLocations: Record<string, WebGLUniformLocation | null> = {};\n /** The fragment shader that we are using */\n private fragmentShader: string;\n /** Stores the RAF for the render loop */\n private rafId: number | null = null;\n /** Time of the last rendered frame */\n private lastFrameTime = 0;\n /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */\n private totalAnimationTime = 0;\n /** The current speed that we progress through animation time (multiplies by delta time every update). Allows negatives to play in reverse. If set to 0, rAF will stop entirely so static shaders have no recurring performance costs */\n private speed = 1;\n /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */\n private providedUniforms: Record<string, number | number[]>;\n /** Just a sanity check to make sure frames don't run after we're disposed */\n private hasBeenDisposed = false;\n /** If the resolution of the canvas has changed since the last render */\n private resolutionChanged = true;\n\n constructor(\n canvas: HTMLCanvasElement,\n fragmentShader: string,\n uniforms: Record<string, number | number[]> = {},\n webGlContextAttributes?: WebGLContextAttributes,\n speed = 1\n ) {\n this.canvas = canvas;\n this.fragmentShader = fragmentShader;\n this.providedUniforms = uniforms;\n\n const gl = canvas.getContext('webgl', webGlContextAttributes);\n if (!gl) {\n throw new Error('WebGL not supported');\n }\n this.gl = gl;\n\n this.initWebGL();\n this.setupResizeObserver();\n\n // Set the animation speed after everything is ready to go\n this.setSpeed(speed);\n\n // Mark canvas as paper shader mount\n this.canvas.setAttribute('data-paper-shaders', 'true');\n }\n\n private initWebGL = () => {\n const program = createProgram(this.gl, vertexShaderSource, this.fragmentShader);\n if (!program) return;\n this.program = program;\n\n this.setupPositionAttribute();\n this.setupUniforms();\n };\n\n private setupPositionAttribute = () => {\n const positionAttributeLocation = this.gl.getAttribLocation(this.program!, 'a_position');\n const positionBuffer = this.gl.createBuffer();\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, positionBuffer);\n const positions = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1];\n this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(positions), this.gl.STATIC_DRAW);\n this.gl.enableVertexAttribArray(positionAttributeLocation);\n this.gl.vertexAttribPointer(positionAttributeLocation, 2, this.gl.FLOAT, false, 0, 0);\n };\n\n private setupUniforms = () => {\n this.uniformLocations = {\n u_time: this.gl.getUniformLocation(this.program!, 'u_time'),\n u_resolution: this.gl.getUniformLocation(this.program!, 'u_resolution'),\n ...Object.fromEntries(\n Object.keys(this.providedUniforms).map((key) => [key, this.gl.getUniformLocation(this.program!, key)])\n ),\n };\n };\n\n private resizeObserver: ResizeObserver | null = null;\n private setupResizeObserver = () => {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n this.resizeObserver.observe(this.canvas);\n this.handleResize();\n };\n\n private handleResize = () => {\n const pxRatio = Math.min(2, window.devicePixelRatio);\n const newWidth = this.canvas.clientWidth * pxRatio;\n const newHeight = this.canvas.clientHeight * pxRatio;\n if (this.canvas.width !== newWidth || this.canvas.height !== newHeight) {\n this.canvas.width = newWidth;\n this.canvas.height = newHeight;\n this.resolutionChanged = true;\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n this.render(performance.now());\n }\n };\n\n private render = (currentTime: number) => {\n if (this.hasBeenDisposed) return;\n\n // Calculate the delta time\n const dt = currentTime - this.lastFrameTime;\n this.lastFrameTime = currentTime;\n // Increase the total animation time by dt * animationSpeed\n if (this.speed !== 0) {\n this.totalAnimationTime += dt * this.speed;\n }\n\n // Update uniforms\n this.gl.useProgram(this.program);\n\n // Update the time uniform\n this.gl.uniform1f(this.uniformLocations.u_time!, this.totalAnimationTime * 0.001);\n\n // If the resolution has changed, we need to update the uniform\n if (this.resolutionChanged) {\n this.gl.uniform2f(this.uniformLocations.u_resolution!, this.gl.canvas.width, this.gl.canvas.height);\n this.resolutionChanged = false;\n }\n\n this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);\n\n // Loop if we're animating\n if (this.speed !== 0) {\n this.requestRender();\n } else {\n this.rafId = null;\n }\n };\n\n private requestRender = () => {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n }\n this.rafId = requestAnimationFrame(this.render);\n };\n\n private updateProvidedUniforms = () => {\n this.gl.useProgram(this.program);\n Object.entries(this.providedUniforms).forEach(([key, value]) => {\n const location = this.uniformLocations[key];\n if (location) {\n if (Array.isArray(value)) {\n switch (value.length) {\n case 2:\n this.gl.uniform2fv(location, value);\n break;\n case 3:\n this.gl.uniform3fv(location, value);\n break;\n case 4:\n this.gl.uniform4fv(location, value);\n break;\n default:\n if (value.length === 9) {\n this.gl.uniformMatrix3fv(location, false, value);\n } else if (value.length === 16) {\n this.gl.uniformMatrix4fv(location, false, value);\n } else {\n console.warn(`Unsupported uniform array length: ${value.length}`);\n }\n }\n } else if (typeof value === 'number') {\n this.gl.uniform1f(location, value);\n } else if (typeof value === 'boolean') {\n this.gl.uniform1i(location, value ? 1 : 0);\n } else {\n console.warn(`Unsupported uniform type for ${key}: ${typeof value}`);\n }\n }\n });\n };\n\n /** Set an animation speed (or 0 to stop animation) */\n public setSpeed = (newSpeed: number = 1): void => {\n // Set the new animation speed\n this.speed = newSpeed;\n\n if (this.rafId === null && newSpeed !== 0) {\n // Moving from 0 to animating, kick off a new rAF loop\n this.lastFrameTime = performance.now();\n this.rafId = requestAnimationFrame(this.render);\n }\n\n if (this.rafId !== null && newSpeed === 0) {\n // Moving from animating to not animating, cancel the rAF loop\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n };\n\n /** Update the uniforms that are provided by the outside shader */\n public setUniforms = (newUniforms: Record<string, number | number[]>): void => {\n this.providedUniforms = { ...this.providedUniforms, ...newUniforms };\n\n // If we need to allow users to add uniforms after the shader has been created, we can do that here\n // But right now we're expecting the uniform list to be predictable and static\n // this.setupUniforms();\n\n this.updateProvidedUniforms();\n this.render(performance.now());\n };\n\n /** Dispose of the shader mount, cleaning up all of the WebGL resources */\n public dispose = (): void => {\n // Immediately mark as disposed to prevent future renders from leaking in\n this.hasBeenDisposed = true;\n\n // Cancel the rAF loop\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n\n if (this.gl && this.program) {\n this.gl.deleteProgram(this.program);\n this.program = null;\n\n // Reset the WebGL context\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);\n this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, null);\n this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null);\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);\n\n // Clear any errors\n this.gl.getError();\n }\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n }\n\n this.uniformLocations = {};\n };\n}\n\n/** Vertex shader for the shader mount */\nconst vertexShaderSource = `\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n`;\n\nfunction createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | null {\n const shader = gl.createShader(type);\n if (!shader) return null;\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n console.error('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader));\n gl.deleteShader(shader);\n return null;\n }\n\n return shader;\n}\n\nfunction createProgram(\n gl: WebGLRenderingContext,\n vertexShaderSource: string,\n fragmentShaderSource: string\n): WebGLProgram | null {\n const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);\n const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);\n\n if (!vertexShader || !fragmentShader) return null;\n\n const program = gl.createProgram();\n if (!program) return null;\n\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n console.error('Unable to initialize the shader program: ' + gl.getProgramInfoLog(program));\n gl.deleteProgram(program);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n return null;\n }\n\n // Clean up shaders after successful linking\n gl.detachShader(program, vertexShader);\n gl.detachShader(program, fragmentShader);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n\n return program;\n}\n", "export type GrainCloudsUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_scale: number;\n u_grainAmount: number;\n};\n\n/**\n * Renders a grainy texture over top of blobby animated clouds\n * This is an example shader that we're using to bootstrap the project\n * Generated by Claude 3.5 Sonnet\n *\n * Uniforms include:\n * u_color1: The first color of the clouds\n * u_color2: The second color of the clouds\n * u_scale: The scale of the noise\n * u_grainAmount: The amount of grain on the texture\n */\nexport const grainCloudsFragmentShader = `\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_scale + u_time);\n n += 0.5 * snoise(st * u_scale * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(st * u_scale * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec4 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = color;\n }\n`;\n", "export type MeshGradientUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n};\n\n/**\n * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG\n * Renders a mesh gradient with a rotating noise pattern\n * and several layers of fractal noise\n *\n * Uniforms include:\n * u_color1: The first color of the mesh gradient\n * u_color2: The second color of the mesh gradient\n * u_color3: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n */\n\nexport const meshGradientFragmentShader = `\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec4 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec4 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n gl_FragColor = finalComp;\n}\n`;\n", "export type SmokeRingUniforms = {\n u_colorBack: [number, number, number, number];\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_scale: number;\n u_thickness: number;\n};\n\n/**\n * Smoke Ring, based on https://codepen.io/ksenia-k/full/zYyqRWE\n * Renders a fractional Brownian motion (fBm) noise over the\n * polar coordinates masked with ring shape\n *\n * Uniforms include:\n * u_colorBack: The back color of the scene\n * u_color1: Main color of the ring\n * u_color2: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n * u_scale: The scale of the noise\n * u_thickness: The thickness of the ring\n */\n\nexport const smokeRingFragmentShader = `\n\n precision highp float;\n\n uniform vec4 u_colorBack;\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_thickness;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n #define TWO_PI 6.28318530718\n #define PI 3.14159265358979323846\n\n float rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n }\n float noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n }\n float fbm(vec2 n) {\n float total = 0.0, amplitude = .4;\n for (int i = 0; i < 12; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n }\n\n float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {\n float distance = length(uv);\n float line_width = outerRadius - innerRadius;\n float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);\n ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);\n return clamp(ringValue, 0., 1.);\n }\n\n void main() {\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv *= 2.;\n uv.x *= ratio;\n\n float t = u_time;\n\n float atg = atan(uv.y, uv.x);\n float angle = (atg + PI) / TWO_PI;\n\n vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));\n polar_uv *= u_scale;\n\n float noise_left = fbm(polar_uv + .05 * t);\n polar_uv.x = mod(polar_uv.x, u_scale * TWO_PI);\n float noise_right = fbm(polar_uv + .05 * t);\n float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));\n\n float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);\n\n float radius = .4 - .25 * u_thickness;\n float thickness = u_thickness;\n thickness = pow(thickness, 2.);\n\n float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);\n ring_shape = clamp(ring_shape, 0., 1.);\n \n float ring_shape_outer = 1. - pow(ring_shape, 7.);\n ring_shape_outer *= ring_shape;\n \n float ring_shape_inner = ring_shape - ring_shape_outer;\n ring_shape_inner *= ring_shape;\n\n ring_shape_outer *= u_color2.a;\n ring_shape_inner *= u_color1.a;\n\n float background = 1. - ring_shape;\n background *= u_colorBack.a;\n \n vec3 color = u_color2.rgb * ring_shape_outer;\n color += u_color1.rgb * ring_shape_inner;\n color += u_colorBack.rgb * background;\n \n float opacity = ring_shape_outer;\n opacity += ring_shape_inner;\n opacity += background;\n \n gl_FragColor = vec4(color, opacity);\n }\n`;\n", "export type NeuroNoiseUniforms = {\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_scale: number;\n u_brightness: number;\n};\n\n/**\n * Neuro Noise Pattern;\n * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova\n * Renders a fractal-like structure made of several layers of since-arches\n *\n * Uniforms include:\n * u_colorFront: The front color of pattern\n * u_colorBack: The back color of pattern\n * u_brightness: The power/brightness of pattern lines\n * u_scale: The scale applied to coordinates\n */\n\nexport const neuroNoiseFragmentShader = `\nprecision mediump float;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n gl_FragColor = mix(u_colorBack, u_colorFront, noise);\n}\n`;\n", "export type DotsOrbitUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_scale: number;\n u_dotSize: number;\n u_dotSizeRange: number;\n u_spreading: number;\n};\n\n/**\n * Dots Pattern with dots moving around their grid position\n * The artwork by Ksenia Kondrashova\n * Renders a dot pattern with dots placed in the center of each cell of animated Voronoi diagram\n *\n * Uniforms include:\n * u_color1: The first dots color\n * u_color2: The second dots color\n * u_color3: The third dots color\n * u_color4: The fourth dots color\n * u_scale: The scale applied to pattern\n * u_dotSize: The base dot radius (relative to cell size)\n * u_dotSizeRange: Dot radius to vary between the cells\n * u_spreading: How far dots are moving around the straight grid\n */\n\nexport const dotsOrbitFragmentShader = `\nprecision mediump float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_scale;\nuniform float u_spreading;\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nvec2 random2(vec2 p) {\n return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t);\n float radius = u_dotSize - u_dotSizeRange * voronoi[2];\n\n float radius_smoother = .001 + .001 * (u_scale - 1.);\n float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);\n\n float color_randomizer = voronoi[1];\n vec4 color =\n u_color1 * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2 * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3 * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4 * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n gl_FragColor = color * shape;\n}\n`;\n", "export type SteppedSimplexNoiseUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_color5: [number, number, number, number];\n u_scale: number;\n u_steps_number: number;\n};\n\n/**\n * Stepped Simplex Noise by Ksenia Kondrashova\n * Calculates a combination of 2 simplex noises with result rendered as a stepped gradient\n *\n * Uniforms include:\n * u_color1: The first color\n * u_color2: The second color\n * u_color3: The third color\n * u_color4: The fourth color\n * u_color5: The fifth color\n * u_scale: The scale applied to coordinates\n * u_steps_number: The number of colors to show as a stepped gradient\n */\n\nexport const steppedSimplexNoiseFragmentShader = `\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec4 u_color5;\nuniform float u_scale;\nuniform float u_steps_number;\n\nuniform float u_time;\nuniform vec2 u_resolution;\n\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat get_noise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nvec4 getColor(int index) {\n if (index == 0) return u_color1;\n if (index == 1) return u_color2;\n if (index == 2) return u_color3;\n if (index == 3) return u_color4;\n if (index == 4) return u_color5;\n return u_color1;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n float noise = .5 + .5 * get_noise(uv, t);\n noise = floor(noise * u_steps_number) / u_steps_number;\n\n vec4 col = u_color1;\n for (int i = 0; i < 5; i++) {\n vec4 next_col = getColor(i + 1);\n col = mix(col, next_col, smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise));\n }\n gl_FragColor = col;\n}\n`;\n", "/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGBA array */\nexport function getShaderColorFromString(\n colorString: string | [number, number, number] | [number, number, number, number] | undefined,\n fallback: string | [number, number, number] | [number, number, number, number] = [0, 0, 0, 1]\n): [number, number, number, number] {\n // If the color string is already an array of 3 or 4 numbers, return it (with alpha=1 if needed)\n if (Array.isArray(colorString)) {\n if (colorString.length === 4) return colorString as [number, number, number, number];\n if (colorString.length === 3) return [...colorString, 1];\n return getShaderColorFromString(fallback);\n }\n\n // If the color string is not a string, return the fallback\n if (typeof colorString !== 'string') {\n return getShaderColorFromString(fallback);\n }\n\n let r: number,\n g: number,\n b: number,\n a = 1;\n if (colorString.startsWith('#')) {\n [r, g, b, a] = hexToRgba(colorString);\n } else if (colorString.startsWith('rgb')) {\n [r, g, b, a] = parseRgba(colorString);\n } else if (colorString.startsWith('hsl')) {\n [r, g, b, a] = hslaToRgba(parseHsla(colorString));\n } else {\n console.error('Unsupported color format', colorString);\n return getShaderColorFromString(fallback);\n }\n\n return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];\n}\n\n/** Convert hex to RGBA (0 to 1 range) */\nfunction hexToRgba(hex: string): [number, number, number, number] {\n // Remove # if present\n hex = hex.replace(/^#/, '');\n\n // Expand three-letter hex to six-letter\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('');\n }\n // Expand six-letter hex to eight-letter (add full opacity if no alpha)\n if (hex.length === 6) {\n hex = hex + 'ff';\n }\n\n // Parse the components\n const r = parseInt(hex.slice(0, 2), 16) / 255;\n const g = parseInt(hex.slice(2, 4), 16) / 255;\n const b = parseInt(hex.slice(4, 6), 16) / 255;\n const a = parseInt(hex.slice(6, 8), 16) / 255;\n\n return [r, g, b, a];\n}\n\n/** Parse RGBA string to RGBA (0 to 1 range) */\nfunction parseRgba(rgba: string): [number, number, number, number] {\n // Match both rgb and rgba patterns\n const match = rgba.match(/^rgba?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0') / 255,\n parseInt(match[2] ?? '0') / 255,\n parseInt(match[3] ?? '0') / 255,\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Parse HSLA string */\nfunction parseHsla(hsla: string): [number, number, number, number] {\n const match = hsla.match(/^hsla?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0'),\n parseInt(match[2] ?? '0'),\n parseInt(match[3] ?? '0'),\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Convert HSLA to RGBA (0 to 1 range) */\nfunction hslaToRgba(hsla: [number, number, number, number]): [number, number, number, number] {\n const [h, s, l, a] = hsla;\n const hDecimal = h / 360;\n const sDecimal = s / 100;\n const lDecimal = l / 100;\n let r, g, b;\n\n if (s === 0) {\n r = g = b = lDecimal; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;\n const p = 2 * lDecimal - q;\n r = hue2rgb(p, q, hDecimal + 1 / 3);\n g = hue2rgb(p, q, hDecimal);\n b = hue2rgb(p, q, hDecimal - 1 / 3);\n }\n\n return [r, g, b, a];\n}\n\nexport const clamp = (n: number, min: number, max: number): number => Math.min(Math.max(n, min), max);\n"],
5
+ "mappings": ";AAAO,IAAMA,EAAN,KAAkB,CACf,OACA,GACA,QAA+B,KAC/B,iBAAgE,CAAC,EAEjE,eAEA,MAAuB,KAEvB,cAAgB,EAEhB,mBAAqB,EAErB,MAAQ,EAER,iBAEA,gBAAkB,GAElB,kBAAoB,GAE5B,YACEC,EACAC,EACAC,EAA8C,CAAC,EAC/CC,EACAC,EAAQ,EACR,CACA,KAAK,OAASJ,EACd,KAAK,eAAiBC,EACtB,KAAK,iBAAmBC,EAExB,IAAMG,EAAKL,EAAO,WAAW,QAASG,CAAsB,EAC5D,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,qBAAqB,EAEvC,KAAK,GAAKA,EAEV,KAAK,UAAU,EACf,KAAK,oBAAoB,EAGzB,KAAK,SAASD,CAAK,EAGnB,KAAK,OAAO,aAAa,qBAAsB,MAAM,CACvD,CAEQ,UAAY,IAAM,CACxB,IAAME,EAAUC,EAAc,KAAK,GAAIC,EAAoB,KAAK,cAAc,EACzEF,IACL,KAAK,QAAUA,EAEf,KAAK,uBAAuB,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WD,EAClFG,EAAI,EAAIF,EAAWG,EACzBtB,EAAIoB,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,EAClChB,EAAImB,EAAQC,EAAGC,EAAGL,CAAQ,EAC1Bf,EAAIkB,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,CACpC,CAEA,MAAO,CAACjB,EAAGC,EAAGC,EAAGC,CAAC,CACpB,CAEO,IAAMK,EAAQ,CAACgB,EAAWC,EAAaC,IAAwB,KAAK,IAAI,KAAK,IAAIF,EAAGC,CAAG,EAAGC,CAAG",
6
+ "names": ["ShaderMount", "canvas", "fragmentShader", "uniforms", "webGlContextAttributes", "speed", "gl", "program", "createProgram", "vertexShaderSource", "positionAttributeLocation", "positionBuffer", "positions", "key", "pxRatio", "newWidth", "newHeight", "currentTime", "dt", "value", "location", "newSpeed", "newUniforms", "createShader", "type", "source", "shader", "fragmentShaderSource", "vertexShader", "grainCloudsFragmentShader", "meshGradientFragmentShader", "smokeRingFragmentShader", "neuroNoiseFragmentShader", "dotsOrbitFragmentShader", "steppedSimplexNoiseFragmentShader", "getShaderColorFromString", "colorString", "fallback", "r", "g", "b", "a", "hexToRgba", "parseRgba", "hslaToRgba", "parseHsla", "clamp", "hex", "char", "rgba", "match", "hsla", "h", "s", "l", "hDecimal", "sDecimal", "lDecimal", "hue2rgb", "p", "q", "t", "n", "min", "max"]
7
7
  }
@@ -11,15 +11,15 @@ export declare class ShaderMount {
11
11
  private lastFrameTime;
12
12
  /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */
13
13
  private totalAnimationTime;
14
- /** Whether we RAF the render or not */
15
- private isAnimated;
14
+ /** The current speed that we progress through animation time (multiplies by delta time every update). Allows negatives to play in reverse. If set to 0, rAF will stop entirely so static shaders have no recurring performance costs */
15
+ private speed;
16
16
  /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */
17
17
  private providedUniforms;
18
18
  /** Just a sanity check to make sure frames don't run after we're disposed */
19
19
  private hasBeenDisposed;
20
20
  /** If the resolution of the canvas has changed since the last render */
21
21
  private resolutionChanged;
22
- constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes, animated?: boolean);
22
+ constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes, speed?: number);
23
23
  private initWebGL;
24
24
  private setupPositionAttribute;
25
25
  private setupUniforms;
@@ -29,14 +29,10 @@ export declare class ShaderMount {
29
29
  private render;
30
30
  private requestRender;
31
31
  private updateProvidedUniforms;
32
- /** Start the animation loop, can be called during instantiation or later by an outside source */
33
- startAnimating: () => void;
34
- /** Stop the animation loop */
35
- stopAnimating: () => void;
32
+ /** Set an animation speed (or 0 to stop animation) */
33
+ setSpeed: (newSpeed?: number) => void;
36
34
  /** Update the uniforms that are provided by the outside shader */
37
35
  setUniforms: (newUniforms: Record<string, number | number[]>) => void;
38
36
  /** Dispose of the shader mount, cleaning up all of the WebGL resources */
39
37
  dispose: () => void;
40
38
  }
41
- /** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGB array */
42
- export declare function getShaderColorFromString(colorString: string | [number, number, number] | undefined, fallback?: string | [number, number, number]): [number, number, number];
@@ -0,0 +1,26 @@
1
+ export type DotsOrbitUniforms = {
2
+ u_color1: [number, number, number, number];
3
+ u_color2: [number, number, number, number];
4
+ u_color3: [number, number, number, number];
5
+ u_color4: [number, number, number, number];
6
+ u_scale: number;
7
+ u_dotSize: number;
8
+ u_dotSizeRange: number;
9
+ u_spreading: number;
10
+ };
11
+ /**
12
+ * Dots Pattern with dots moving around their grid position
13
+ * The artwork by Ksenia Kondrashova
14
+ * Renders a dot pattern with dots placed in the center of each cell of animated Voronoi diagram
15
+ *
16
+ * Uniforms include:
17
+ * u_color1: The first dots color
18
+ * u_color2: The second dots color
19
+ * u_color3: The third dots color
20
+ * u_color4: The fourth dots color
21
+ * u_scale: The scale applied to pattern
22
+ * u_dotSize: The base dot radius (relative to cell size)
23
+ * u_dotSizeRange: Dot radius to vary between the cells
24
+ * u_spreading: How far dots are moving around the straight grid
25
+ */
26
+ export declare const dotsOrbitFragmentShader = "\nprecision mediump float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_scale;\nuniform float u_spreading;\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nvec2 random2(vec2 p) {\n return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t);\n float radius = u_dotSize - u_dotSizeRange * voronoi[2];\n\n float radius_smoother = .001 + .001 * (u_scale - 1.);\n float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);\n\n float color_randomizer = voronoi[1];\n vec4 color =\n u_color1 * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2 * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3 * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4 * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n gl_FragColor = color * shape;\n}\n";
@@ -1,8 +1,7 @@
1
1
  export type GrainCloudsUniforms = {
2
- u_color1: [number, number, number];
3
- u_color2: [number, number, number];
4
- u_noiseScale: number;
5
- u_noiseSpeed: number;
2
+ u_color1: [number, number, number, number];
3
+ u_color2: [number, number, number, number];
4
+ u_scale: number;
6
5
  u_grainAmount: number;
7
6
  };
8
7
  /**
@@ -13,8 +12,7 @@ export type GrainCloudsUniforms = {
13
12
  * Uniforms include:
14
13
  * u_color1: The first color of the clouds
15
14
  * u_color2: The second color of the clouds
16
- * u_noiseScale: The scale of the noise
17
- * u_noiseSpeed: The speed of the noise
15
+ * u_scale: The scale of the noise
18
16
  * u_grainAmount: The amount of grain on the texture
19
17
  */
20
- export declare const grainCloudsFragmentShader = "\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n uniform vec3 u_color1;\n uniform vec3 u_color2;\n uniform float u_noiseScale;\n uniform float u_noiseSpeed;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_noiseScale + u_time * u_noiseSpeed);\n n += 0.5 * snoise(st * u_noiseScale * 2.0 - u_time * u_noiseSpeed * 0.5);\n n += 0.25 * snoise(st * u_noiseScale * 4.0 + u_time * u_noiseSpeed * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = vec4(color, 1.0);\n }\n";
18
+ export declare const grainCloudsFragmentShader = "\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_scale + u_time);\n n += 0.5 * snoise(st * u_scale * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(st * u_scale * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec4 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = color;\n }\n";
@@ -1,9 +1,8 @@
1
1
  export type MeshGradientUniforms = {
2
- u_color1: [number, number, number];
3
- u_color2: [number, number, number];
4
- u_color3: [number, number, number];
5
- u_color4: [number, number, number];
6
- u_speed: number;
2
+ u_color1: [number, number, number, number];
3
+ u_color2: [number, number, number, number];
4
+ u_color3: [number, number, number, number];
5
+ u_color4: [number, number, number, number];
7
6
  };
8
7
  /**
9
8
  * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG
@@ -15,6 +14,5 @@ export type MeshGradientUniforms = {
15
14
  * u_color2: The second color of the mesh gradient
16
15
  * u_color3: The third color of the mesh gradient
17
16
  * u_color4: The fourth color of the mesh gradient
18
- * u_speed: The speed of the noise
19
17
  */
20
- export declare const meshGradientFragmentShader = "\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec3 u_color1;\nuniform vec3 u_color2;\nuniform vec3 u_color3;\nuniform vec3 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_speed;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time * u_speed, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec3 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec3 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec3 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n\n vec3 col = finalComp;\n\n gl_FragColor = vec4(col,1.0);\n}\n";
18
+ export declare const meshGradientFragmentShader = "\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec4 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec4 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n gl_FragColor = finalComp;\n}\n";
@@ -1,9 +1,8 @@
1
1
  export type NeuroNoiseUniforms = {
2
- u_colorFront: [number, number, number];
3
- u_colorBack: [number, number, number];
2
+ u_colorFront: [number, number, number, number];
3
+ u_colorBack: [number, number, number, number];
4
4
  u_scale: number;
5
5
  u_brightness: number;
6
- u_speed: number;
7
6
  };
8
7
  /**
9
8
  * Neuro Noise Pattern;
@@ -15,6 +14,5 @@ export type NeuroNoiseUniforms = {
15
14
  * u_colorBack: The back color of pattern
16
15
  * u_brightness: The power/brightness of pattern lines
17
16
  * u_scale: The scale applied to coordinates
18
- * u_speed: The speed coefficient for pattern animation
19
17
  */
20
- export declare const neuroNoiseFragmentShader = "\nprecision mediump float;\n\nuniform vec3 u_colorFront;\nuniform vec3 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\nuniform float u_speed;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n vec2 uv_r = uv;\n uv_r -= .5;\n uv_r *= u_scale;\n uv_r += .5;\n uv_r.x *= ratio;\n\n float t = u_speed * u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv_r, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 10.);\n noise = max(.0, noise - .5);\n noise *= (1. - length(uv - .5));\n\n color = mix(u_colorBack, u_colorFront, noise);\n\n gl_FragColor = vec4(color, 1.);\n}\n";
18
+ export declare const neuroNoiseFragmentShader = "\nprecision mediump float;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n gl_FragColor = mix(u_colorBack, u_colorFront, noise);\n}\n";
@@ -0,0 +1,21 @@
1
+ export type SmokeRingUniforms = {
2
+ u_colorBack: [number, number, number, number];
3
+ u_color1: [number, number, number, number];
4
+ u_color2: [number, number, number, number];
5
+ u_scale: number;
6
+ u_thickness: number;
7
+ };
8
+ /**
9
+ * Smoke Ring, based on https://codepen.io/ksenia-k/full/zYyqRWE
10
+ * Renders a fractional Brownian motion (fBm) noise over the
11
+ * polar coordinates masked with ring shape
12
+ *
13
+ * Uniforms include:
14
+ * u_colorBack: The back color of the scene
15
+ * u_color1: Main color of the ring
16
+ * u_color2: The third color of the mesh gradient
17
+ * u_color4: The fourth color of the mesh gradient
18
+ * u_scale: The scale of the noise
19
+ * u_thickness: The thickness of the ring
20
+ */
21
+ export declare const smokeRingFragmentShader = "\n\n precision highp float;\n\n uniform vec4 u_colorBack;\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_thickness;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n #define TWO_PI 6.28318530718\n #define PI 3.14159265358979323846\n\n float rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n }\n float noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n }\n float fbm(vec2 n) {\n float total = 0.0, amplitude = .4;\n for (int i = 0; i < 12; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n }\n\n float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {\n float distance = length(uv);\n float line_width = outerRadius - innerRadius;\n float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);\n ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);\n return clamp(ringValue, 0., 1.);\n }\n\n void main() {\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv *= 2.;\n uv.x *= ratio;\n\n float t = u_time;\n\n float atg = atan(uv.y, uv.x);\n float angle = (atg + PI) / TWO_PI;\n\n vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));\n polar_uv *= u_scale;\n\n float noise_left = fbm(polar_uv + .05 * t);\n polar_uv.x = mod(polar_uv.x, u_scale * TWO_PI);\n float noise_right = fbm(polar_uv + .05 * t);\n float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));\n\n float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);\n\n float radius = .4 - .25 * u_thickness;\n float thickness = u_thickness;\n thickness = pow(thickness, 2.);\n\n float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);\n ring_shape = clamp(ring_shape, 0., 1.);\n \n float ring_shape_outer = 1. - pow(ring_shape, 7.);\n ring_shape_outer *= ring_shape;\n \n float ring_shape_inner = ring_shape - ring_shape_outer;\n ring_shape_inner *= ring_shape;\n\n ring_shape_outer *= u_color2.a;\n ring_shape_inner *= u_color1.a;\n\n float background = 1. - ring_shape;\n background *= u_colorBack.a;\n \n vec3 color = u_color2.rgb * ring_shape_outer;\n color += u_color1.rgb * ring_shape_inner;\n color += u_colorBack.rgb * background;\n \n float opacity = ring_shape_outer;\n opacity += ring_shape_inner;\n opacity += background;\n \n gl_FragColor = vec4(color, opacity);\n }\n";
@@ -0,0 +1,23 @@
1
+ export type SteppedSimplexNoiseUniforms = {
2
+ u_color1: [number, number, number, number];
3
+ u_color2: [number, number, number, number];
4
+ u_color3: [number, number, number, number];
5
+ u_color4: [number, number, number, number];
6
+ u_color5: [number, number, number, number];
7
+ u_scale: number;
8
+ u_steps_number: number;
9
+ };
10
+ /**
11
+ * Stepped Simplex Noise by Ksenia Kondrashova
12
+ * Calculates a combination of 2 simplex noises with result rendered as a stepped gradient
13
+ *
14
+ * Uniforms include:
15
+ * u_color1: The first color
16
+ * u_color2: The second color
17
+ * u_color3: The third color
18
+ * u_color4: The fourth color
19
+ * u_color5: The fifth color
20
+ * u_scale: The scale applied to coordinates
21
+ * u_steps_number: The number of colors to show as a stepped gradient
22
+ */
23
+ export declare const steppedSimplexNoiseFragmentShader = "\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec4 u_color5;\nuniform float u_scale;\nuniform float u_steps_number;\n\nuniform float u_time;\nuniform vec2 u_resolution;\n\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat get_noise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nvec4 getColor(int index) {\n if (index == 0) return u_color1;\n if (index == 1) return u_color2;\n if (index == 2) return u_color3;\n if (index == 3) return u_color4;\n if (index == 4) return u_color5;\n return u_color1;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n float noise = .5 + .5 * get_noise(uv, t);\n noise = floor(noise * u_steps_number) / u_steps_number;\n\n vec4 col = u_color1;\n for (int i = 0; i < 5; i++) {\n vec4 next_col = getColor(i + 1);\n col = mix(col, next_col, smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise));\n }\n gl_FragColor = col;\n}\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paper-design/shaders",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {