@paper-design/shaders 0.0.26 → 0.0.27

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.
Files changed (81) hide show
  1. package/dist/get-shader-color-from-string.d.ts +1 -1
  2. package/dist/get-shader-color-from-string.js +93 -0
  3. package/dist/get-shader-color-from-string.js.map +7 -0
  4. package/dist/get-shader-noise-texture.d.ts +1 -0
  5. package/dist/get-shader-noise-texture.js +23 -0
  6. package/dist/get-shader-noise-texture.js.map +7 -0
  7. package/dist/index.d.ts +30 -16
  8. package/dist/index.js +79 -1767
  9. package/dist/index.js.map +4 -4
  10. package/dist/shader-color-spaces.d.ts +6 -0
  11. package/dist/shader-color-spaces.js +96 -0
  12. package/dist/shader-color-spaces.js.map +7 -0
  13. package/dist/shader-mount.d.ts +48 -17
  14. package/dist/shader-mount.js +568 -0
  15. package/dist/shader-mount.js.map +7 -0
  16. package/dist/shader-sizing.d.ts +35 -0
  17. package/dist/shader-sizing.js +196 -0
  18. package/dist/shader-sizing.js.map +7 -0
  19. package/dist/shader-utils.d.ts +5 -0
  20. package/dist/shader-utils.js +59 -0
  21. package/dist/shader-utils.js.map +7 -0
  22. package/dist/shaders/dithering.d.ts +47 -0
  23. package/dist/shaders/dithering.js +197 -0
  24. package/dist/shaders/dithering.js.map +7 -0
  25. package/dist/shaders/dot-grid.d.ts +33 -20
  26. package/dist/shaders/dot-grid.js +100 -0
  27. package/dist/shaders/dot-grid.js.map +7 -0
  28. package/dist/shaders/dot-orbit.d.ts +27 -18
  29. package/dist/shaders/dot-orbit.js +120 -0
  30. package/dist/shaders/dot-orbit.js.map +7 -0
  31. package/dist/shaders/god-rays.d.ts +35 -26
  32. package/dist/shaders/god-rays.js +134 -0
  33. package/dist/shaders/god-rays.js.map +7 -0
  34. package/dist/shaders/grain-gradient.d.ts +25 -0
  35. package/dist/shaders/grain-gradient.js +219 -0
  36. package/dist/shaders/grain-gradient.js.map +7 -0
  37. package/dist/shaders/liquid-metal.d.ts +19 -0
  38. package/dist/shaders/liquid-metal.js +224 -0
  39. package/dist/shaders/liquid-metal.js.map +7 -0
  40. package/dist/shaders/mesh-gradient.d.ts +23 -13
  41. package/dist/shaders/mesh-gradient.js +97 -0
  42. package/dist/shaders/mesh-gradient.js.map +7 -0
  43. package/dist/shaders/metaballs.d.ts +22 -15
  44. package/dist/shaders/metaballs.js +108 -0
  45. package/dist/shaders/metaballs.js.map +7 -0
  46. package/dist/shaders/neuro-noise.d.ts +13 -8
  47. package/dist/shaders/neuro-noise.js +66 -0
  48. package/dist/shaders/neuro-noise.js.map +7 -0
  49. package/dist/shaders/perlin-noise.d.ts +26 -15
  50. package/dist/shaders/perlin-noise.js +193 -0
  51. package/dist/shaders/perlin-noise.js.map +7 -0
  52. package/dist/shaders/pulsing-border.d.ts +54 -0
  53. package/dist/shaders/pulsing-border.js +218 -0
  54. package/dist/shaders/pulsing-border.js.map +7 -0
  55. package/dist/shaders/simplex-noise.d.ts +29 -0
  56. package/dist/shaders/simplex-noise.js +103 -0
  57. package/dist/shaders/simplex-noise.js.map +7 -0
  58. package/dist/shaders/smoke-ring.d.ts +34 -12
  59. package/dist/shaders/smoke-ring.js +141 -0
  60. package/dist/shaders/smoke-ring.js.map +7 -0
  61. package/dist/shaders/spiral.d.ts +28 -18
  62. package/dist/shaders/spiral.js +75 -0
  63. package/dist/shaders/spiral.js.map +7 -0
  64. package/dist/shaders/swirl.d.ts +26 -0
  65. package/dist/shaders/swirl.js +80 -0
  66. package/dist/shaders/swirl.js.map +7 -0
  67. package/dist/shaders/voronoi.d.ts +39 -29
  68. package/dist/shaders/voronoi.js +143 -0
  69. package/dist/shaders/voronoi.js.map +7 -0
  70. package/dist/shaders/warp.d.ts +43 -32
  71. package/dist/shaders/warp.js +124 -0
  72. package/dist/shaders/warp.js.map +7 -0
  73. package/dist/shaders/waves.d.ts +25 -15
  74. package/dist/shaders/waves.js +60 -0
  75. package/dist/shaders/waves.js.map +7 -0
  76. package/dist/types.d.ts +3 -0
  77. package/dist/types.js +6 -0
  78. package/dist/types.js.map +7 -0
  79. package/package.json +2 -1
  80. package/dist/get-shader-color-from-string.test.d.ts +0 -1
  81. package/dist/shaders/stepped-simplex-noise.d.ts +0 -24
@@ -0,0 +1,75 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declareSimplexNoise, declarePI, colorBandingFix } from "../shader-utils";
8
+ const spiralFragmentShader = `#version 300 es
9
+ precision highp float;
10
+
11
+ uniform float u_time;
12
+
13
+ uniform vec4 u_color1;
14
+ uniform vec4 u_color2;
15
+ uniform float u_spiralDensity;
16
+ uniform float u_spiralDistortion;
17
+ uniform float u_strokeWidth;
18
+ uniform float u_strokeCap;
19
+ uniform float u_strokeTaper;
20
+
21
+ uniform float u_noiseFreq;
22
+ uniform float u_noisePower;
23
+ uniform float u_softness;
24
+
25
+ ${sizingVariablesDeclaration}
26
+
27
+ out vec4 fragColor;
28
+
29
+ ${declarePI}
30
+ ${declareSimplexNoise}
31
+
32
+ void main() {
33
+ vec2 shape_uv = v_patternUV * .02;
34
+
35
+ float t = u_time;
36
+
37
+ float l = length(shape_uv);
38
+ float angle = atan(shape_uv.y, shape_uv.x) - 2. * t;
39
+ float angle_norm = angle / TWO_PI;
40
+
41
+ angle_norm += .125 * u_noisePower * snoise(.5 * u_noiseFreq * shape_uv);
42
+
43
+ float offset = pow(l, 1. - clamp(u_spiralDensity, 0., 1.)) + angle_norm;
44
+
45
+ float stripe_map = fract(offset);
46
+ stripe_map -= .5 * u_strokeTaper * l;
47
+
48
+ stripe_map += .25 * u_noisePower * snoise(u_noiseFreq * shape_uv);
49
+
50
+ float shape = 2. * abs(stripe_map - .5);
51
+
52
+ shape *= (1. + u_spiralDistortion * sin(4. * l - t) * cos(PI + l + t));
53
+
54
+ float stroke_width = clamp(u_strokeWidth, fwidth(l), 1. - fwidth(l));
55
+
56
+ float edge_width = min(fwidth(l), fwidth(offset));
57
+
58
+ float mid = 1. - smoothstep(.0, .9, l);
59
+ mid = pow(mid, 2.);
60
+ shape -= .5 * u_strokeCap * mid;
61
+
62
+ shape = smoothstep(stroke_width - edge_width - u_softness, stroke_width + edge_width + u_softness, shape);
63
+
64
+ vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, shape);
65
+ float opacity = mix(u_color1.a, u_color2.a, shape);
66
+
67
+ ${colorBandingFix}
68
+
69
+ fragColor = vec4(color, opacity);
70
+ }
71
+ `;
72
+ export {
73
+ spiralFragmentShader
74
+ };
75
+ //# sourceMappingURL=spiral.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/spiral.ts"],
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declareSimplexNoise, declarePI, colorBandingFix } from '../shader-utils';\n\n/**\n * Spiral shape by Ksenia Kondrashova\n * Generates a dynamic spiral shape with configurable parameters\n *\n * Uniforms include:\n *\n * u_scale - controls the overall scale of the spiral (u_scale = 1 makes it fit the viewport height)\n * u_offsetX - left / right pan\n * u_offsetY - up / down pan\n * u_color1 - the first color used in the spiral (stroke)\n * u_color2 - the second color used in the spiral (back)\n * u_spiralDensity (0 .. 1) - the spacing of the spiral arms\n * u_spiralDistortion (0 .. 1) - adds a wavy distortion effect to the spiral arms\n * u_strokeWidth (0 .. 1) - defines the thickness of the spiral lines.\n * u_strokeCap (0 .. 1) - adjusts the fading of the spiral edges.\n * u_strokeTaper (0 .. 1) - controls the tapering effect along the spiral arms.\n * u_noiseFreq - frequency of the noise applied to the spiral.\n * u_noisePower (0 .. 1) - strength of the noise effect.\n * u_softness - softens the edges of the spiral for a smoother appearance.\n */\nexport const spiralFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_spiralDensity;\nuniform float u_spiralDistortion;\nuniform float u_strokeWidth;\nuniform float u_strokeCap;\nuniform float u_strokeTaper;\n\nuniform float u_noiseFreq;\nuniform float u_noisePower;\nuniform float u_softness;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n\nvoid main() {\n vec2 shape_uv = v_patternUV * .02;\n\n float t = u_time;\n\n float l = length(shape_uv);\n float angle = atan(shape_uv.y, shape_uv.x) - 2. * t;\n float angle_norm = angle / TWO_PI;\n\n angle_norm += .125 * u_noisePower * snoise(.5 * u_noiseFreq * shape_uv);\n\n float offset = pow(l, 1. - clamp(u_spiralDensity, 0., 1.)) + angle_norm;\n\n float stripe_map = fract(offset);\n stripe_map -= .5 * u_strokeTaper * l;\n\n stripe_map += .25 * u_noisePower * snoise(u_noiseFreq * shape_uv);\n\n float shape = 2. * abs(stripe_map - .5);\n\n shape *= (1. + u_spiralDistortion * sin(4. * l - t) * cos(PI + l + t));\n\n float stroke_width = clamp(u_strokeWidth, fwidth(l), 1. - fwidth(l));\n\n float edge_width = min(fwidth(l), fwidth(offset));\n\n float mid = 1. - smoothstep(.0, .9, l);\n mid = pow(mid, 2.);\n shape -= .5 * u_strokeCap * mid;\n\n shape = smoothstep(stroke_width - edge_width - u_softness, stroke_width + edge_width + u_softness, shape);\n\n vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, shape);\n float opacity = mix(u_color1.a, u_color2.a, shape);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SpiralUniforms extends ShaderSizingUniforms {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_spiralDensity: number;\n u_spiralDistortion: number;\n u_strokeWidth: number;\n u_strokeTaper: number;\n u_strokeCap: number;\n u_noiseFreq: number;\n u_noisePower: number;\n u_softness: number;\n}\n\nexport interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {\n color1?: string;\n color2?: string;\n spiralDensity?: number;\n spiralDistortion?: number;\n strokeWidth?: number;\n strokeTaper?: number;\n strokeCap?: number;\n noiseFreq?: number;\n noisePower?: number;\n softness?: number;\n}\n"],
5
+ "mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,uBAAuB;AAsBzD,MAAM,uBAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiB1C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;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,IAqCjB,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,26 @@
1
+ import type { vec4 } from '../types';
2
+ import type { ShaderMotionParams } from '../shader-mount';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
4
+ export declare const swirlMeta: {
5
+ readonly maxColorCount: 10;
6
+ };
7
+ /**
8
+ */
9
+ export declare const swirlFragmentShader: string;
10
+ export interface SwirlUniforms extends ShaderSizingUniforms {
11
+ u_colors: vec4[];
12
+ u_colorsCount: number;
13
+ u_bandCount: number;
14
+ u_twist: number;
15
+ u_softness: number;
16
+ u_noiseFreq: number;
17
+ u_noisePower: number;
18
+ }
19
+ export interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {
20
+ colors?: string[];
21
+ bandCount?: number;
22
+ twist?: number;
23
+ softness?: number;
24
+ noiseFreq?: number;
25
+ noisePower?: number;
26
+ }
@@ -0,0 +1,80 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declareSimplexNoise, declarePI, declareRotate, colorBandingFix } from "../shader-utils";
8
+ const swirlMeta = {
9
+ maxColorCount: 10
10
+ };
11
+ const swirlFragmentShader = `#version 300 es
12
+ precision highp float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform vec4 u_colors[${swirlMeta.maxColorCount}];
17
+ uniform float u_colorsCount;
18
+ uniform float u_bandCount;
19
+ uniform float u_twist;
20
+ uniform float u_softness;
21
+ uniform float u_noisePower;
22
+ uniform float u_noiseFreq;
23
+
24
+ ${sizingVariablesDeclaration}
25
+
26
+ out vec4 fragColor;
27
+
28
+ ${declarePI}
29
+ ${declareSimplexNoise}
30
+ ${declareRotate}
31
+
32
+ void main() {
33
+ vec2 shape_uv = v_objectUV;
34
+
35
+ float l = length(shape_uv);
36
+
37
+ float t = u_time;
38
+
39
+ float angle = ceil(u_bandCount) * atan(shape_uv.y, shape_uv.x) + t;
40
+ float angle_norm = angle / TWO_PI;
41
+
42
+ float twist = 3. * clamp(u_twist, 0., 1.);
43
+ float offset = pow(l, -twist) + angle_norm;
44
+
45
+ float shape = fract(offset);
46
+ shape = 1. - abs(2. * shape - 1.);
47
+ shape += u_noisePower * snoise(pow(u_noiseFreq, 2.) * shape_uv);
48
+
49
+ float mid = smoothstep(.2, .4, pow(l, twist));
50
+ shape = mix(0., shape, mid);
51
+
52
+ float mixer = shape * (u_colorsCount - 1.);
53
+ float softness = u_softness + (.1 + .012 * u_colorsCount) * smoothstep(.6, .2, pow(l, twist));
54
+
55
+ vec4 gradient = u_colors[0];
56
+ gradient.rgb *= gradient.a;
57
+ for (int i = 1; i < ${swirlMeta.maxColorCount}; i++) {
58
+ if (i >= int(u_colorsCount)) break;
59
+
60
+ float localT = clamp(mixer - float(i - 1), 0., 1.);
61
+ localT = smoothstep(.5 - .5 * u_softness, .5 + .5 * u_softness, localT);
62
+
63
+ vec4 c = u_colors[i];
64
+ c.rgb *= c.a;
65
+ gradient = mix(gradient, c, localT);
66
+ }
67
+
68
+ vec3 color = gradient.rgb;
69
+ float opacity = gradient.a;
70
+
71
+ ${colorBandingFix}
72
+
73
+ fragColor = vec4(color, opacity);
74
+ }
75
+ `;
76
+ export {
77
+ swirlFragmentShader,
78
+ swirlMeta
79
+ };
80
+ //# sourceMappingURL=swirl.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/swirl.ts"],
4
+ "sourcesContent": ["import type { vec4 } from '../types';\nimport type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declareSimplexNoise, declarePI, declareRotate, colorBandingFix } from '../shader-utils';\n\nexport const swirlMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n */\nexport const swirlFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\n\nuniform vec4 u_colors[${swirlMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_bandCount;\nuniform float u_twist;\nuniform float u_softness;\nuniform float u_noisePower;\nuniform float u_noiseFreq;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n${declareRotate}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n \n float l = length(shape_uv);\n\n float t = u_time;\n\n float angle = ceil(u_bandCount) * atan(shape_uv.y, shape_uv.x) + t;\n float angle_norm = angle / TWO_PI; \n \n float twist = 3. * clamp(u_twist, 0., 1.);\n float offset = pow(l, -twist) + angle_norm;\n \n float shape = fract(offset);\n shape = 1. - abs(2. * shape - 1.);\n shape += u_noisePower * snoise(pow(u_noiseFreq, 2.) * shape_uv);\n\n float mid = smoothstep(.2, .4, pow(l, twist));\n shape = mix(0., shape, mid);\n \n float mixer = shape * (u_colorsCount - 1.);\n float softness = u_softness + (.1 + .012 * u_colorsCount) * smoothstep(.6, .2, pow(l, twist));\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${swirlMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n \n float localT = clamp(mixer - float(i - 1), 0., 1.); \n localT = smoothstep(.5 - .5 * u_softness, .5 + .5 * u_softness, localT);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n \n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n \n ${colorBandingFix}\n \n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SwirlUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_bandCount: number;\n u_twist: number;\n u_softness: number;\n u_noiseFreq: number;\n u_noisePower: number;\n}\n\nexport interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n bandCount?: number;\n twist?: number;\n softness?: number;\n noiseFreq?: number;\n noisePower?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,YAAY;AAAA,EACvB,eAAe;AACjB;AAIO,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA,wBAKnB,UAAU,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,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,wBA2BS,UAAU,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAc3C,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,34 +1,44 @@
1
- export type VoronoiUniforms = {
2
- u_scale: number;
3
- u_colorCell1: [number, number, number, number];
4
- u_colorCell2: [number, number, number, number];
5
- u_colorCell3: [number, number, number, number];
6
- u_colorMid: [number, number, number, number];
7
- u_colorGradient: number;
8
- u_distance: number;
9
- u_edgesSize: number;
10
- u_edgesSoftness: number;
11
- u_middleSize: number;
12
- u_middleSoftness: number;
1
+ import type { vec4 } from '../types';
2
+ import type { ShaderMotionParams } from '../shader-mount';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
4
+ export declare const voronoiMeta: {
5
+ readonly maxColorCount: 5;
13
6
  };
14
7
  /**
15
- * Voronoi pattern
16
- * The artwork by Ksenia Kondrashova
17
- * Renders a number of circular shapes with gooey effect applied
8
+ * Voronoi pattern by Ksenia Kondrashova
9
+ * The variation of Voronoi pattern with cell edges. Big thanks to Inigo Quilez
10
+ * https://www.shadertoy.com/view/ldl3W8
18
11
  *
19
12
  * Uniforms include:
20
- * u_scale - the scale applied to user space
21
- * u_colorCell1 - color #1 of mix used to fill the cell shape
22
- * u_colorCell2 - color #2 of mix used to fill the cell shape
23
- * u_colorCell3 - color #3 of mix used to fill the cell shape
24
- * u_colorMid - color used to fill the radial shape in the center of each cell
25
- * u_colorGradient (0 .. 1) - if the cell color is a gradient of palette colors or one color selection
26
- * u_distance (0 ... 0.5) - how far the cell center can move from regular square grid
27
- * u_edgesSize (0 .. 1) - the size of borders
28
- * (can be set to zero but the edge may get glitchy due to nature of Voronoi diagram)
29
- * u_edgesSoftness (0 .. 1) - the blur/sharp for cell border
30
- * u_middleSize (0 .. 1) - the size of shape in the center of each cell
31
- * u_middleSoftness (0 .. 1) - the smoothness of shape in the center of each cell
32
- * (vary from cell color gradient to sharp dot in the middle)
13
+ *
14
+ * - `u_colors` (`vec4[]`): Array of RGBA colors used for cell filling
15
+ * - `u_colorsCount` (`float`): Number of active colors in `u_colors`
16
+ * - `u_colorBack` (`vec4`): RGBA color for the gaps between cells
17
+ * - `u_colorGlow` (`vec4`): RGBA color for the radial shape on the cell edges
18
+ * - `u_distortion` (`float`, 0 – 0.5): Controls how far cell centers can be displaced from the regular grid
19
+ * - `u_gap` (`float`): Width of the gaps between cells (gaps can't be removed completely due to artifacts of Voronoi cells)
20
+ * - `u_innerGlow` (`float`): Controls the size of the radial glow inside each cell
21
+ * - `u_stepsPerColor` (`float`): Discretization of the color transition
22
+ * - `u_noiseTexture` (`sampler2D`): Replacement of standard hash function, added for better performance
33
23
  */
34
- export declare const voronoiFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\n\nuniform vec4 u_colorCell1;\nuniform vec4 u_colorCell2;\nuniform vec4 u_colorCell3;\nuniform vec4 u_colorMid;\n\nuniform float u_colorGradient;\nuniform float u_distance;\nuniform float u_edgesSize;\nuniform float u_edgesSoftness;\nuniform float u_middleSize;\nuniform float u_middleSoftness;\n\n#define TWO_PI 6.28318530718\n\nout vec4 fragColor;\n\nvec2 hash(vec2 p) {\n p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));\n return fract(sin(p) * 18.5453);\n}\n\nfloat smin(float angle, float b, float k) {\n float h = clamp(.5 + .5 * (b - angle) / k, 0., 1.);\n return mix(b, angle, h) - k * h * (1. - h);\n}\n\nvec4 blend_colors(vec4 c1, vec4 c2, vec4 c3, vec2 randomizer) {\n vec3 color1 = c1.rgb * c1.a;\n vec3 color2 = c2.rgb * c2.a;\n vec3 color3 = c3.rgb * c3.a;\n\n float mixer = clamp(u_colorGradient, 0., 1.);\n float r1 = smoothstep(.5 - .5 * mixer, .5 + .5 * mixer, randomizer[0]);\n float r2 = smoothstep(.6 - .6 * mixer, .6 + .4 * mixer, randomizer[1]);\n vec3 blended_color_2 = mix(color1, color2, r1);\n float blended_opacity_2 = mix(c1.a, c2.a, r1);\n vec3 c = mix(blended_color_2, color3, r2);\n float o = mix(blended_opacity_2, c3.a, r2);\n \n return vec4(c, o);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float t = u_time;\n uv -= .5;\n uv *= (.01 * u_scale * u_resolution);\n uv /= u_pixelRatio;\n uv += .5;\n\n vec2 i_uv = floor(uv);\n vec2 f_uv = fract(uv);\n\n vec2 randomizer = vec2(0.);\n vec3 distance = vec3(1.);\n\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 o = hash(i_uv + tile_offset);\n tile_offset += (.5 + clamp(u_distance, 0., .5) * sin(t + TWO_PI * o)) - f_uv;\n\n float dist = dot(tile_offset, tile_offset);\n float old_min_dist = distance.x;\n\n distance.z = max(distance.x, max(distance.y, min(distance.z, dist)));\n distance.y = max(distance.x, min(distance.y, dist));\n distance.x = min(distance.x, dist);\n\n if (old_min_dist > distance.x) {\n randomizer = o;\n }\n }\n }\n\n distance = sqrt(distance);\n\n distance = sqrt(distance);\n float cell_shape = min(smin(distance.z, distance.y, .1) - distance.x, 1.);\n\n float dot_shape = pow(distance.x, 2.) / (2. * clamp(u_middleSize, 0., 1.) + 1e-4);\n float dot_edge_width = fwidth(dot_shape);\n float dotSharp = clamp(1. - u_middleSoftness, 0., 1.);\n dot_shape = 1. - smoothstep(.5 * dotSharp - dot_edge_width, 1. - .5 * dotSharp, dot_shape);\n\n float cell_edge_width = fwidth(distance.x);\n float w = .7 * (clamp(u_edgesSize, 0., 1.) - .1);\n float edgeSharp = clamp(u_edgesSoftness, 0., 1.);\n cell_shape = smoothstep(w - cell_edge_width, w + edgeSharp, cell_shape);\n\n dot_shape *= cell_shape;\n\n vec4 cell_mix = blend_colors(u_colorCell1, u_colorCell2, u_colorCell3, randomizer);\n \n vec3 color = cell_mix.rgb * cell_shape;\n float opacity = cell_mix.a * cell_shape;\n\n color = mix(color, u_colorMid.rgb * u_colorMid.a, dot_shape);\n opacity = mix(opacity, u_colorMid.a, dot_shape);\n\n fragColor = vec4(color, opacity);\n}\n";
24
+ export declare const voronoiFragmentShader: string;
25
+ export interface VoronoiUniforms extends ShaderSizingUniforms {
26
+ u_colors: vec4[];
27
+ u_colorsCount: number;
28
+ u_stepsPerColor: number;
29
+ u_colorBack: [number, number, number, number];
30
+ u_colorGlow: [number, number, number, number];
31
+ u_distortion: number;
32
+ u_gap: number;
33
+ u_innerGlow: number;
34
+ u_noiseTexture?: HTMLImageElement;
35
+ }
36
+ export interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {
37
+ colors?: string[];
38
+ stepsPerColor?: number;
39
+ colorBack?: string;
40
+ colorGlow?: string;
41
+ distortion?: number;
42
+ gap?: number;
43
+ innerGlow?: number;
44
+ }
@@ -0,0 +1,143 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declarePI } from "../shader-utils";
8
+ const voronoiMeta = {
9
+ maxColorCount: 5
10
+ };
11
+ const voronoiFragmentShader = `#version 300 es
12
+ precision highp float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform float u_scale;
17
+
18
+ uniform sampler2D u_noiseTexture;
19
+
20
+ uniform vec4 u_colors[${voronoiMeta.maxColorCount}];
21
+ uniform float u_colorsCount;
22
+
23
+ uniform float u_stepsPerColor;
24
+ uniform vec4 u_colorGlow;
25
+ uniform vec4 u_colorBack;
26
+ uniform float u_distortion;
27
+ uniform float u_gap;
28
+ uniform float u_innerGlow;
29
+
30
+ ${sizingVariablesDeclaration}
31
+
32
+ out vec4 fragColor;
33
+
34
+ ${declarePI}
35
+
36
+ vec2 hash(vec2 p) {
37
+ vec2 uv = floor(p) / 100. + .5;
38
+ return texture(u_noiseTexture, uv).gb;
39
+ }
40
+
41
+ vec4 voronoi(vec2 x, float t) {
42
+ vec2 ip = floor(x);
43
+ vec2 fp = fract(x);
44
+
45
+ vec2 mg, mr;
46
+ float md = 8.;
47
+ float rand = 0.;
48
+
49
+ for (int j = -1; j <= 1; j++) {
50
+ for (int i = -1; i <= 1; i++) {
51
+ vec2 g = vec2(float(i), float(j));
52
+ vec2 raw_hash = hash(ip + g);
53
+ vec2 o = hash(ip + g);
54
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
55
+ vec2 r = g + o - fp;
56
+ float d = dot(r, r);
57
+
58
+ if (d < md) {
59
+ md = d;
60
+ mr = r;
61
+ mg = g;
62
+ rand = raw_hash.x;
63
+ }
64
+ }
65
+ }
66
+
67
+ md = 8.;
68
+ for (int j = -2; j <= 2; j++) {
69
+ for (int i = -2; i <= 2; i++) {
70
+ vec2 g = mg + vec2(float(i), float(j));
71
+ vec2 o = hash(ip + g);
72
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
73
+ vec2 r = g + o - fp;
74
+ if (dot(mr - r, mr - r) > .00001) {
75
+ md = min(md, dot(.5 * (mr + r), normalize(r - mr)));
76
+ }
77
+ }
78
+ }
79
+
80
+ return vec4(md, mr, rand);
81
+ }
82
+
83
+ void main() {
84
+ vec2 shape_uv = v_patternUV;
85
+ shape_uv *= .0125;
86
+
87
+ float t = u_time;
88
+
89
+ vec4 voronoiRes = voronoi(shape_uv, t);
90
+
91
+ float shape = clamp(voronoiRes.w, 0., 1.);
92
+ float mixer = shape * (u_colorsCount - 1.);
93
+ mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
94
+ float steps = max(1., u_stepsPerColor);
95
+
96
+ vec4 gradient = u_colors[0];
97
+ gradient.rgb *= gradient.a;
98
+ for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {
99
+ if (i >= int(u_colorsCount)) break;
100
+ float localT = clamp(mixer - float(i - 1), 0.0, 1.0);
101
+ localT = round(localT * steps) / steps;
102
+ vec4 c = u_colors[i];
103
+ c.rgb *= c.a;
104
+ gradient = mix(gradient, c, localT);
105
+ }
106
+
107
+ if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {
108
+ float localT = mixer + 1.;
109
+ if (mixer > (u_colorsCount - 1.)) {
110
+ localT = mixer - (u_colorsCount - 1.);
111
+ }
112
+ localT = round(localT * steps) / steps;
113
+ vec4 cFst = u_colors[0];
114
+ cFst.rgb *= cFst.a;
115
+ vec4 cLast = u_colors[int(u_colorsCount - 1.)];
116
+ cLast.rgb *= cLast.a;
117
+ gradient = mix(cLast, cFst, localT);
118
+ }
119
+
120
+ vec3 cellColor = gradient.rgb;
121
+ float cellOpacity = gradient.a;
122
+
123
+ float innerGlows = length(voronoiRes.yz * u_innerGlow + .1);
124
+ innerGlows = pow(innerGlows, 1.5);
125
+
126
+ vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * innerGlows);
127
+ float opacity = cellOpacity + u_colorGlow.a * innerGlows;
128
+
129
+ float edge = voronoiRes.x;
130
+ float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);
131
+ edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);
132
+
133
+ color = mix(u_colorBack.rgb * u_colorBack.a, color, edge);
134
+ opacity = mix(u_colorBack.a, opacity, edge);
135
+
136
+ fragColor = vec4(color, opacity);
137
+ }
138
+ `;
139
+ export {
140
+ voronoiFragmentShader,
141
+ voronoiMeta
142
+ };
143
+ //# sourceMappingURL=voronoi.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/voronoi.ts"],
4
+ "sourcesContent": ["import type { vec4 } from '../types';\nimport type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declarePI } from '../shader-utils';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Voronoi pattern by Ksenia Kondrashova\n * The variation of Voronoi pattern with cell edges. Big thanks to Inigo Quilez\n * https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms include:\n *\n * - `u_colors` (`vec4[]`): Array of RGBA colors used for cell filling\n * - `u_colorsCount` (`float`): Number of active colors in `u_colors`\n * - `u_colorBack` (`vec4`): RGBA color for the gaps between cells\n * - `u_colorGlow` (`vec4`): RGBA color for the radial shape on the cell edges\n * - `u_distortion` (`float`, 0 \u2013 0.5): Controls how far cell centers can be displaced from the regular grid\n * - `u_gap` (`float`): Width of the gaps between cells (gaps can't be removed completely due to artifacts of Voronoi cells)\n * - `u_innerGlow` (`float`): Controls the size of the radial glow inside each cell\n * - `u_stepsPerColor` (`float`): Discretization of the color transition\n * - `u_noiseTexture` (`sampler2D`): Replacement of standard hash function, added for better performance\n */\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorBack;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_innerGlow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 hash(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, uv).gb;\n}\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 raw_hash = hash(ip + g);\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash.x;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .0125;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float innerGlows = length(voronoiRes.yz * u_innerGlow + .1);\n innerGlows = pow(innerGlows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * innerGlows);\n float opacity = cellOpacity + u_colorGlow.a * innerGlows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorBack.rgb * u_colorBack.a, color, edge);\n opacity = mix(u_colorBack.a, opacity, edge);\n\n fragColor = vec4(color, opacity); \n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorBack: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_innerGlow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorBack?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n innerGlow?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,iBAAiB;AAEnB,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AAmBO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASrB,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;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,wBAgEa,YAAY,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": []
7
+ }
@@ -1,42 +1,53 @@
1
- export declare const PatternShapes: {
2
- readonly Checks: 0;
3
- readonly Stripes: 1;
4
- readonly Edge: 2;
5
- };
6
- export type PatternShape = (typeof PatternShapes)[keyof typeof PatternShapes];
7
- export type WarpUniforms = {
8
- u_scale: number;
9
- u_rotation: number;
10
- u_color1: [number, number, number, number];
11
- u_color2: [number, number, number, number];
12
- u_color3: [number, number, number, number];
13
- u_proportion: number;
14
- u_softness: number;
15
- u_shape: PatternShape;
16
- u_shapeScale: number;
17
- u_distortion: number;
18
- u_swirl: number;
19
- u_swirlIterations: number;
1
+ import type { vec4 } from '../types';
2
+ import type { ShaderMotionParams } from '../shader-mount';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
4
+ export declare const warpMeta: {
5
+ readonly maxColorCount: 10;
20
6
  };
21
7
  /**
22
8
  * 3d Perlin noise with exposed parameters
23
9
  *
24
10
  * Uniforms include:
25
- * u_scale - the scale applied to user space
26
- * u_rotation - the rotation applied to user space
27
- * u_color1 - the first pattern color
28
- * u_color2 - the second pattern color
29
- * u_color3 - the third pattern color
30
- * u_proportion (0 .. 1) - the proportion between colors (on 0.5 colors are equally distributed)
31
- * u_softness (0 .. 1) - the color blur (0 for pronounced edges, 1 for gradient)
32
- * u_shape (0 ... 2) - the color pattern to be distorted with noise & swirl
11
+ * - u_colors (vec4[]): Input RGBA colors
12
+ * - u_colorsCount (float): Number of active colors (`u_colors` length)
13
+ * - u_proportion (0 .. 1): the proportion between colors (on 0.5 colors are equally distributed)
14
+ * - u_softness (0 .. 1): the color blur (0 for pronounced edges, 1 for gradient)
15
+ * - u_shape (0 ... 2): the color pattern to be distorted with noise & swirl
33
16
  * - u_shape = 0 is checks
34
17
  * - u_shape = 1 is stripes
35
18
  * - u_shape = 2 is 2 halves of canvas (mapping the canvas height regardless of resolution)
36
- * u_shapeScale - the scale of color pattern (appies over the global scaling)
37
- * u_distortion - the noisy distortion over the UV coordinate (applied before the overlapping swirl)
38
- * u_swirl - the power of swirly distortion
39
- * u_swirlIterations - the number of swirl iterations (layering curves effect)
19
+ * - u_shapeScale: the scale of color pattern (appies over the global scaling)
20
+ * - u_distortion: the noisy distortion over the UV coordinate (applied before the overlapping swirl)
21
+ * - u_swirl: the power of swirly distortion
22
+ * - u_swirlIterations: the number of swirl iterations (layering curves effect)
40
23
  *
41
24
  */
42
- export declare const warpFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform float u_proportion;\nuniform float u_softness;\nuniform float u_shape;\nuniform float u_shapeScale;\nuniform float u_distortion;\nuniform float u_swirl;\nuniform float u_swirlIterations;\n\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat random(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\nfloat noise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = random(i);\n float b = random(i + vec2(1.0, 0.0));\n float c = random(i + vec2(0.0, 1.0));\n float d = random(i + vec2(1.0, 1.0));\n\n // Smoothstep for interpolation\n vec2 u = f * f * (3.0 - 2.0 * f);\n\n // Do the interpolation as two nested mix operations\n // If you try to do this in one big operation, there's enough precision loss to be off by 1px at cell boundaries\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n\n}\n\nvec4 blend_colors(vec4 c1, vec4 c2, vec4 c3, float mixer, float edgesWidth, float edge_blur) {\n vec3 color1 = c1.rgb * c1.a;\n vec3 color2 = c2.rgb * c2.a;\n vec3 color3 = c3.rgb * c3.a;\n\n float r1 = smoothstep(.0 + .35 * edgesWidth, .7 - .35 * edgesWidth + .5 * edge_blur, mixer);\n float r2 = smoothstep(.3 + .35 * edgesWidth, 1. - .35 * edgesWidth + edge_blur, mixer);\n\n vec3 blended_color_2 = mix(color1, color2, r1);\n float blended_opacity_2 = mix(c1.a, c2.a, r1);\n\n vec3 c = mix(blended_color_2, color3, r2);\n float o = mix(blended_opacity_2, c3.a, r2);\n return vec4(c, o);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n vec2 uv_original = uv;\n\n float t = .5 * u_time;\n\n float noise_scale = .0005 + .006 * u_scale;\n\n uv -= .5;\n uv *= (noise_scale * u_resolution);\n uv = rotate(uv, u_rotation * .5 * PI);\n uv /= u_pixelRatio;\n uv += .5;\n\n float n1 = noise(uv * 1. + t);\n float n2 = noise(uv * 2. - t);\n float angle = n1 * TWO_PI;\n uv.x += 4. * u_distortion * n2 * cos(angle);\n uv.y += 4. * u_distortion * n2 * sin(angle);\n\n float iterations_number = ceil(clamp(u_swirlIterations, 1., 30.));\n for (float i = 1.; i <= iterations_number; i++) {\n uv.x += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1.5 * uv.y);\n uv.y += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1. * uv.x);\n }\n\n float proportion = clamp(u_proportion, 0., 1.);\n\n float shape = 0.;\n float mixer = 0.;\n if (u_shape < .5) {\n vec2 checks_shape_uv = uv * (.5 + 3.5 * u_shapeScale);\n shape = .5 + .5 * sin(checks_shape_uv.x) * cos(checks_shape_uv.y);\n mixer = shape + .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else if (u_shape < 1.5) {\n vec2 stripes_shape_uv = uv * (.25 + 3. * u_shapeScale);\n float f = fract(stripes_shape_uv.y);\n shape = smoothstep(.0, .55, f) * smoothstep(1., .45, f);\n mixer = shape + .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else {\n float sh = 1. - uv.y;\n sh -= .5;\n sh /= (noise_scale * u_resolution.y);\n sh += .5;\n float shape_scaling = .2 * (1. - u_shapeScale);\n shape = smoothstep(.45 - shape_scaling, .55 + shape_scaling, sh + .3 * (proportion - .5));\n mixer = shape;\n }\n\n vec4 color_mix = blend_colors(u_color1, u_color2, u_color3, mixer, 1. - clamp(u_softness, 0., 1.), .01 + .01 * u_scale);\n\n fragColor = vec4(color_mix.rgb, color_mix.a);\n}\n";
25
+ export declare const warpFragmentShader: string;
26
+ export interface WarpUniforms extends ShaderSizingUniforms {
27
+ u_colors: vec4[];
28
+ u_colorsCount: number;
29
+ u_proportion: number;
30
+ u_softness: number;
31
+ u_shape: (typeof WarpPatterns)[WarpPattern];
32
+ u_shapeScale: number;
33
+ u_distortion: number;
34
+ u_swirl: number;
35
+ u_swirlIterations: number;
36
+ }
37
+ export interface WarpParams extends ShaderSizingParams, ShaderMotionParams {
38
+ colors?: string[];
39
+ rotation?: number;
40
+ proportion?: number;
41
+ softness?: number;
42
+ shape?: WarpPattern;
43
+ shapeScale?: number;
44
+ distortion?: number;
45
+ swirl?: number;
46
+ swirlIterations?: number;
47
+ }
48
+ export declare const WarpPatterns: {
49
+ readonly checks: 0;
50
+ readonly stripes: 1;
51
+ readonly edge: 2;
52
+ };
53
+ export type WarpPattern = keyof typeof WarpPatterns;