@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,219 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declareSimplexNoise, declarePI, declareRandom, colorBandingFix } from "../shader-utils";
8
+ const grainGradientMeta = {
9
+ maxColorCount: 7
10
+ };
11
+ const grainGradientFragmentShader = `#version 300 es
12
+ precision highp float;
13
+
14
+ uniform float u_time;
15
+ uniform vec2 u_resolution;
16
+ uniform float u_pixelRatio;
17
+
18
+ uniform vec4 u_colors[${grainGradientMeta.maxColorCount}];
19
+ uniform float u_colorsCount;
20
+ uniform float u_softness;
21
+ uniform float u_intensity;
22
+ uniform float u_noise;
23
+ uniform float u_shape;
24
+
25
+ ${sizingVariablesDeclaration}
26
+
27
+ out vec4 fragColor;
28
+
29
+ ${declarePI}
30
+ ${declareSimplexNoise}
31
+ ${declareRandom}
32
+
33
+
34
+ float noisenoise(vec2 st) {
35
+ vec2 i = floor(st);
36
+ vec2 f = fract(st);
37
+ float a = random(i);
38
+ float b = random(i + vec2(1.0, 0.0));
39
+ float c = random(i + vec2(0.0, 1.0));
40
+ float d = random(i + vec2(1.0, 1.0));
41
+
42
+ // Smoothstep for interpolation
43
+ vec2 u = f * f * (3.0 - 2.0 * f);
44
+
45
+ // Do the interpolation as two nested mix operations
46
+ // If you try to do this in one big operation, there's enough precision loss to be off by 1px at cell boundaries
47
+ float x1 = mix(a, b, u.x);
48
+ float x2 = mix(c, d, u.x);
49
+ return mix(x1, x2, u.y);
50
+ }
51
+
52
+ float rand(vec2 n) {
53
+ return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
54
+ }
55
+ float noise(vec2 n) {
56
+ const vec2 d = vec2(0.0, 1.0);
57
+ vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
58
+ return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
59
+ }
60
+ float fbm_4(vec2 n) {
61
+ float total = 0.0, amplitude = .2;
62
+ for (int i = 0; i < 4; i++) {
63
+ total += noise(n) * amplitude;
64
+ n += n;
65
+ amplitude *= 0.6;
66
+ }
67
+ return total;
68
+ }
69
+
70
+
71
+ vec2 truchet(vec2 uv, float idx){
72
+ idx = fract(((idx - .5) * 2.));
73
+ if (idx > 0.75) {
74
+ uv = vec2(1.0) - uv;
75
+ } else if (idx > 0.5) {
76
+ uv = vec2(1.0 - uv.x, uv.y);
77
+ } else if (idx > 0.25) {
78
+ uv = 1.0 - vec2(1.0 - uv.x, uv.y);
79
+ }
80
+ return uv;
81
+ }
82
+
83
+ void main() {
84
+
85
+ float t = .1 * u_time;
86
+
87
+ vec2 grain_uv = (gl_FragCoord.xy - .5 * u_resolution) / u_pixelRatio;
88
+ vec2 shape_uv = v_objectUV;
89
+ if (u_shape < 3.5) {
90
+ shape_uv = v_patternUV * .005;
91
+ }
92
+
93
+
94
+ float shape = 0.;
95
+
96
+ if (u_shape < 1.5) {
97
+ // Sine wave
98
+
99
+ float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));
100
+ shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
101
+
102
+ } else if (u_shape < 2.5) {
103
+ // Grid (dots)
104
+
105
+ float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
106
+ float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);
107
+
108
+ float speed = sign(rand - .5) * ceil(2. + rand);
109
+ shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
110
+ shape = pow(shape, 4.);
111
+
112
+ } else if (u_shape < 3.5) {
113
+ // Truchet pattern
114
+
115
+ float n2 = noisenoise(shape_uv * .4 - 2.5 * t);
116
+ shape_uv.x += 10.;
117
+ shape_uv *= .6;
118
+
119
+ vec2 tile = truchet(fract(shape_uv), random(floor(shape_uv)));
120
+
121
+ float distance1 = length(tile);
122
+ float distance2 = length(tile - vec2(1.));
123
+
124
+ n2 -= .5;
125
+ n2 *= .1;
126
+ shape = smoothstep(.2, .55, distance1 + n2) * smoothstep(.8, .45, distance1 - n2);
127
+ shape += smoothstep(.2, .55, distance2 + n2) * smoothstep(.8, .45, distance2 - n2);
128
+
129
+ shape = pow(shape, 1.5);
130
+
131
+ } else if (u_shape < 4.5) {
132
+ // Corners
133
+
134
+ shape_uv *= .6;
135
+ vec2 outer = vec2(.5);
136
+
137
+ vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * sin(3. * t)));
138
+ vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
139
+ shape = 1. - bl.x * bl.y * tr.x * tr.y;
140
+
141
+ shape_uv = -shape_uv;
142
+ bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * cos(3. * t)));
143
+ tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
144
+ shape -= bl.x * bl.y * tr.x * tr.y;
145
+
146
+ shape = 1. - smoothstep(0., 1., shape);
147
+
148
+ } else if (u_shape < 5.5) {
149
+ // Ripple
150
+
151
+ shape_uv *= 2.;
152
+ float dist = length(.4 * shape_uv);
153
+ float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;
154
+ shape = waves;
155
+
156
+ } else if (u_shape < 6.5) {
157
+ // Blob
158
+
159
+ t *= 2.;
160
+
161
+ vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));
162
+ vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));
163
+ vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));
164
+ vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));
165
+
166
+ shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);
167
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);
168
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);
169
+ shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);
170
+
171
+ shape = smoothstep(.0, .9, shape);
172
+ float edge = smoothstep(.25, .3, shape);
173
+ shape = mix(.0, shape, edge);
174
+
175
+ } else {
176
+ // Sphere
177
+
178
+ shape_uv *= 2.;
179
+ float d = length(shape_uv);
180
+ float z = sqrt(1.0 - clamp(pow(d, 2.0), 0.0, 1.0));
181
+ vec3 pos = vec3(shape_uv, z);
182
+ vec3 lightPos = normalize(vec3(cos(3. * t), 0.8, sin(2.5 * t)));
183
+ float lighting = dot(lightPos, pos);
184
+ float edge = smoothstep(1., .97, d);
185
+ shape = mix(.1, .5 + .5 * lighting, edge);
186
+ }
187
+
188
+ float snoise05 = snoise(grain_uv * .5);
189
+ float grainDist = snoise(grain_uv * .2) * snoise05 - fbm_4(.002 * grain_uv + 10.) - fbm_4(.003 * grain_uv);
190
+ float noise = clamp(.6 * snoise05 - fbm_4(.4 * grain_uv) - fbm_4(.001 * grain_uv), 0., 1.);
191
+
192
+ shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);
193
+ shape += u_noise * 10. / u_colorsCount * noise;
194
+
195
+ float edge_w = fwidth(shape);
196
+
197
+ float mixer = shape;
198
+ vec3 gradient = u_colors[0].rgb;
199
+ for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {
200
+ if (i >= int(u_colorsCount)) break;
201
+
202
+ vec2 borders = vec2(float(i) - u_softness, float(i) + u_softness + edge_w) / u_colorsCount;
203
+ float localT = smoothstep(borders[0], borders[1], mixer);
204
+ gradient = mix(gradient, u_colors[i].rgb, localT);
205
+ }
206
+
207
+ vec3 color = gradient;
208
+ float opacity = 1.;
209
+
210
+ ${colorBandingFix}
211
+
212
+ fragColor = vec4(color, opacity);
213
+ }
214
+ `;
215
+ export {
216
+ grainGradientFragmentShader,
217
+ grainGradientMeta
218
+ };
219
+ //# sourceMappingURL=grain-gradient.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/grain-gradient.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, declareRandom, colorBandingFix } from '../shader-utils';\n\nexport const grainGradientMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Grainy Gradient Ksenia Kondrashova\n */\nexport const grainGradientFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\nuniform vec4 u_colors[${grainGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_softness;\nuniform float u_intensity;\nuniform float u_noise;\nuniform float u_shape;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n${declareRandom}\n\n\nfloat noisenoise(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\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\nfloat 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}\nfloat fbm_4(vec2 n) {\n float total = 0.0, amplitude = .2;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n}\n\n\nvec2 truchet(vec2 uv, float idx){\n idx = fract(((idx - .5) * 2.));\n if (idx > 0.75) {\n uv = vec2(1.0) - uv;\n } else if (idx > 0.5) {\n uv = vec2(1.0 - uv.x, uv.y);\n } else if (idx > 0.25) {\n uv = 1.0 - vec2(1.0 - uv.x, uv.y);\n }\n return uv;\n}\n\nvoid main() {\n \n float t = .1 * u_time;\n \n vec2 grain_uv = (gl_FragCoord.xy - .5 * u_resolution) / u_pixelRatio;\n vec2 shape_uv = v_objectUV;\n if (u_shape < 3.5) {\n shape_uv = v_patternUV * .005;\n }\n \n \n float shape = 0.;\n \n if (u_shape < 1.5) {\n // Sine wave\n \n float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));\n shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);\n \n } else if (u_shape < 2.5) {\n // Grid (dots)\n\n float stripeIdx = floor(2. * shape_uv.x / TWO_PI);\n float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);\n\n float speed = sign(rand - .5) * ceil(2. + rand);\n shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t); \n shape = pow(shape, 4.);\n \n } else if (u_shape < 3.5) {\n // Truchet pattern\n \n float n2 = noisenoise(shape_uv * .4 - 2.5 * t);\n shape_uv.x += 10.;\n shape_uv *= .6;\n\n vec2 tile = truchet(fract(shape_uv), random(floor(shape_uv)));\n\n float distance1 = length(tile);\n float distance2 = length(tile - vec2(1.));\n\n n2 -= .5;\n n2 *= .1;\n shape = smoothstep(.2, .55, distance1 + n2) * smoothstep(.8, .45, distance1 - n2);\n shape += smoothstep(.2, .55, distance2 + n2) * smoothstep(.8, .45, distance2 - n2);\n \n shape = pow(shape, 1.5);\n \n } else if (u_shape < 4.5) { \n // Corners\n\n shape_uv *= .6;\n vec2 outer = vec2(.5);\n \n vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * sin(3. * t)));\n vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape = 1. - bl.x * bl.y * tr.x * tr.y;\n \n shape_uv = -shape_uv;\n bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * cos(3. * t)));\n tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape -= bl.x * bl.y * tr.x * tr.y; \n \n shape = 1. - smoothstep(0., 1., shape);\n \n } else if (u_shape < 5.5) { \n // Ripple\n \n shape_uv *= 2.;\n float dist = length(.4 * shape_uv);\n float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;\n shape = waves;\n\n } else if (u_shape < 6.5) {\n // Blob\n\n t *= 2.;\n \n vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));\n vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));\n vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));\n vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));\n \n shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);\n \n shape = smoothstep(.0, .9, shape);\n float edge = smoothstep(.25, .3, shape);\n shape = mix(.0, shape, edge);\n \n } else {\n // Sphere\n\n shape_uv *= 2.;\n float d = length(shape_uv);\n float z = sqrt(1.0 - clamp(pow(d, 2.0), 0.0, 1.0));\n vec3 pos = vec3(shape_uv, z);\n vec3 lightPos = normalize(vec3(cos(3. * t), 0.8, sin(2.5 * t)));\n float lighting = dot(lightPos, pos);\n float edge = smoothstep(1., .97, d);\n shape = mix(.1, .5 + .5 * lighting, edge);\n }\n \n float snoise05 = snoise(grain_uv * .5);\n float grainDist = snoise(grain_uv * .2) * snoise05 - fbm_4(.002 * grain_uv + 10.) - fbm_4(.003 * grain_uv);\n float noise = clamp(.6 * snoise05 - fbm_4(.4 * grain_uv) - fbm_4(.001 * grain_uv), 0., 1.);\n\n shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);\n shape += u_noise * 10. / u_colorsCount * noise; \n\n float edge_w = fwidth(shape);\n \n float mixer = shape;\n vec3 gradient = u_colors[0].rgb;\n for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 borders = vec2(float(i) - u_softness, float(i) + u_softness + edge_w) / u_colorsCount;\n float localT = smoothstep(borders[0], borders[1], mixer);\n gradient = mix(gradient, u_colors[i].rgb, localT);\n }\n\n vec3 color = gradient;\n float opacity = 1.;\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface GrainGradientUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_softness: number;\n u_intensity: number;\n u_noise: number;\n u_shape: number;\n}\n\nexport interface GrainGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n softness?: number;\n intensity?: number;\n noise?: number;\n shape?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AACjB;AAKO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAO3B,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOrD,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;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;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,wBAwKS,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWnD,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ import type { ShaderMotionParams } from '../shader-mount';
2
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
3
+ /**
4
+ */
5
+ export declare const liquidMetalFragmentShader: string;
6
+ export interface LiquidMetalUniforms extends ShaderSizingUniforms {
7
+ u_patternBlur: number;
8
+ u_patternScale: number;
9
+ u_dispersion: number;
10
+ u_liquid: number;
11
+ u_shape: number;
12
+ }
13
+ export interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {
14
+ patternBlur?: number;
15
+ patternScale?: number;
16
+ dispersion?: number;
17
+ liquid?: number;
18
+ shape?: number;
19
+ }
@@ -0,0 +1,224 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from "../shader-utils";
8
+ const liquidMetalFragmentShader = `#version 300 es
9
+ precision highp float;
10
+
11
+ uniform float u_time;
12
+
13
+ uniform float u_patternBlur;
14
+ uniform float u_patternScale;
15
+ uniform float u_dispersion;
16
+ uniform float u_liquid;
17
+ uniform float u_shape;
18
+
19
+ ${sizingVariablesDeclaration}
20
+
21
+ out vec4 fragColor;
22
+
23
+ ${declarePI}
24
+ ${declareRotate}
25
+ ${declareSimplexNoise}
26
+
27
+ float get_color_channel(float c1, float c2, float stripe_p, vec3 w, float extra_blur, float bump) {
28
+
29
+ float ch = c2;
30
+ float border = 0.;
31
+ float blur = u_patternBlur + extra_blur;
32
+
33
+ if (u_shape < 1.) {
34
+ blur += .1 * smoothstep(-.4, -.6, v_responsiveUV.y);
35
+ }
36
+
37
+ ch = mix(ch, c1, smoothstep(.0, blur, stripe_p));
38
+
39
+ border = w[0];
40
+ ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));
41
+
42
+ bump = smoothstep(.2, .8, bump);
43
+ border = w[0] + .4 * (1. - bump) * w[1];
44
+ ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));
45
+
46
+ border = w[0] + .5 * (1. - bump) * w[1];
47
+ ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));
48
+
49
+ border = w[0] + w[1];
50
+ ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));
51
+
52
+ float gradient_t = (stripe_p - w[0] - w[1]) / w[2];
53
+ float gradient = mix(c1, c2, smoothstep(0., 1., gradient_t));
54
+ ch = mix(ch, gradient, smoothstep(border - blur, border + blur, stripe_p));
55
+
56
+ return ch;
57
+ }
58
+
59
+ void main() {
60
+
61
+ float t = .1 * u_time;
62
+
63
+ vec2 uv = v_objectUV;
64
+ uv += .5;
65
+ uv.y = 1. - uv.y;
66
+
67
+ float cycleWidth = .5 * u_patternScale;
68
+
69
+ float mask = 1.;
70
+ if (u_shape < 1.) {
71
+
72
+ vec2 borderUV = v_responsiveUV + .5;
73
+ float ratio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
74
+ vec2 edge = min(borderUV, 1. - borderUV);
75
+ vec2 pixel_thickness = 250. / v_responsiveBoxGivenSize;
76
+ float maskX = smoothstep(0.0, pixel_thickness.x, edge.x);
77
+ float maskY = smoothstep(0.0, pixel_thickness.y, edge.y);
78
+ maskX = pow(maskX, .25);
79
+ maskY = pow(maskY, .25);
80
+ mask = clamp(1. - maskX * maskY, 0., 1.);
81
+
82
+ uv = v_responsiveUV;
83
+ if (ratio > 1.) {
84
+ uv.y /= ratio;
85
+ } else {
86
+ uv.x *= ratio;
87
+ }
88
+ uv += .5;
89
+ uv.y = 1. - uv.y;
90
+
91
+ cycleWidth *= 2.;
92
+
93
+ } else if (u_shape < 2.) {
94
+ vec2 shapeUV = uv - .5;
95
+ shapeUV *= .67;
96
+ mask = pow(clamp(3. * length(shapeUV), 0., 1.), 8.);
97
+
98
+ uv *= 1.3;
99
+ } else if (u_shape < 3.) {
100
+ vec2 shapeUV = uv - .5;
101
+ shapeUV *= 1.68;
102
+
103
+ float r = length(shapeUV) * 2.;
104
+ float a = atan(shapeUV.y, shapeUV.x) + .2;
105
+ r *= (1. + .05 * sin(3. * a + 2. * t));
106
+ float f = abs(cos(a * 3.));
107
+ mask = smoothstep(f, f + .7, r);
108
+
109
+ uv *= .8;
110
+ cycleWidth *= 1.6;
111
+
112
+ } else if (u_shape < 4.) {
113
+ vec2 shapeUV = uv - .5;
114
+ shapeUV *= 1.3;
115
+ mask = 0.;
116
+ for (int i = 0; i < 5; i++) {
117
+ float fi = float(i);
118
+ float speed = 4.5 + 2. * sin(fi * 12.345);
119
+ float angle = -fi * 1.5;
120
+ vec2 dir1 = vec2(cos(angle), sin(angle));
121
+ vec2 dir2 = vec2(cos(angle + 1.57), sin(angle + 1.));
122
+ vec2 traj = .4 * (dir1 * sin(t * speed + fi * 1.23) + dir2 * cos(t * (speed * 0.7) + fi * 2.17));
123
+ float d = length(shapeUV + traj);
124
+ mask += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);
125
+ }
126
+ mask = 1. - smoothstep(.85, 1., mask);
127
+
128
+ uv *= 1.3;
129
+ uv.y += .2;
130
+ }
131
+
132
+ float contour = smoothstep(0., 1., mask) * smoothstep(1., 0., mask);
133
+
134
+
135
+ float diagBLtoTR = uv.x - uv.y;
136
+ float diagTLtoBR = uv.x + uv.y;
137
+
138
+ vec3 color = vec3(0.);
139
+ float opacity = 1.;
140
+
141
+ vec3 color1 = vec3(.98, 0.98, 1.);
142
+ vec3 color2 = vec3(.1, .1, .1 + .1 * smoothstep(.7, 1.3, diagTLtoBR));
143
+
144
+ vec2 grad_uv = uv - .5;
145
+
146
+ float dist = length(grad_uv + vec2(0., .2 * diagBLtoTR));
147
+ grad_uv = rotate(grad_uv, (.25 - .2 * diagBLtoTR) * PI);
148
+ float direction = grad_uv.x;
149
+
150
+ float bump = pow(1.8 * dist, 1.2);
151
+ bump = 1. - bump;
152
+ bump *= pow(uv.y, .3);
153
+
154
+
155
+ float thin_strip_1_ratio = .12 / cycleWidth * (1. - .4 * bump);
156
+ float thin_strip_2_ratio = .07 / cycleWidth * (1. + .4 * bump);
157
+ float wide_strip_ratio = (1. - thin_strip_1_ratio - thin_strip_2_ratio);
158
+
159
+ float thin_strip_1_width = cycleWidth * thin_strip_1_ratio;
160
+ float thin_strip_2_width = cycleWidth * thin_strip_2_ratio;
161
+
162
+ opacity = 1. - smoothstep(.9, .92, mask);
163
+
164
+ float noise = snoise(uv - t);
165
+
166
+ mask += (1. - mask) * u_liquid * noise;
167
+
168
+ float colorDispersion = 0.;
169
+ colorDispersion += (1. - bump);
170
+ colorDispersion = clamp(colorDispersion, 0., 1.);
171
+
172
+ direction += diagBLtoTR;
173
+
174
+ direction -= 2. * noise * contour;
175
+
176
+ bump *= clamp(pow(uv.y, .1), .3, 1.);
177
+ direction *= (.1 + (1.1 - mask) * bump);
178
+ direction *= smoothstep(1., .7, mask);
179
+
180
+ float ridge = .2 * (smoothstep(.0, .15, uv.y) * smoothstep(.4, .15, uv.y));
181
+ ridge += .03 * (smoothstep(.1, .2, 1. - uv.y) * smoothstep(.4, .2, 1. - uv.y));
182
+ direction += ridge;
183
+
184
+ direction *= (.5 + .5 * pow(uv.y, 2.));
185
+
186
+ direction *= cycleWidth;
187
+
188
+ direction -= t;
189
+
190
+ float dispersionRed = colorDispersion;
191
+ dispersionRed += .03 * bump * noise;
192
+ float dispersionBlue = 1.3 * colorDispersion;
193
+
194
+ dispersionRed += 5. * (smoothstep(-.1, .2, uv.y) * smoothstep(.5, .1, uv.y)) * (smoothstep(.4, .6, bump) * smoothstep(1., .4, bump));
195
+ dispersionRed -= diagBLtoTR;
196
+
197
+ dispersionBlue += (smoothstep(0., .4, uv.y) * smoothstep(.8, .1, uv.y)) * (smoothstep(.4, .6, bump) * smoothstep(.8, .4, bump));
198
+ dispersionBlue -= .2 * mask;
199
+
200
+ dispersionRed *= u_dispersion;
201
+ dispersionBlue *= u_dispersion;
202
+
203
+ vec3 w = vec3(thin_strip_1_width, thin_strip_2_width, wide_strip_ratio);
204
+ w[1] -= .02 * smoothstep(.0, 1., mask + bump);
205
+ float extraBlur = bump;
206
+ float stripe_r = mod(direction + dispersionRed, 1.);
207
+ float r = get_color_channel(color1.r, color2.r, stripe_r, w, 0.02 + .03 * u_dispersion * bump, extraBlur);
208
+ float stripe_g = mod(direction, 1.);
209
+ float g = get_color_channel(color1.g, color2.g, stripe_g, w, 0.01 / (1. - 0. * diagBLtoTR), extraBlur);
210
+ float stripe_b = mod(direction - dispersionBlue, 1.);
211
+ float b = get_color_channel(color1.b, color2.b, stripe_b, w, .01, extraBlur);
212
+
213
+ color = vec3(r, g, b);
214
+ color *= opacity;
215
+
216
+ ${colorBandingFix}
217
+
218
+ fragColor = vec4(color, opacity);
219
+ }
220
+ `;
221
+ export {
222
+ liquidMetalFragmentShader
223
+ };
224
+ //# sourceMappingURL=liquid-metal.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/liquid-metal.ts"],
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from '../shader-utils';\n\n/**\n */\n\nexport const liquidMetalFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\n\nuniform float u_patternBlur;\nuniform float u_patternScale;\nuniform float u_dispersion;\nuniform float u_liquid;\nuniform float u_shape;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n${declareSimplexNoise}\n\nfloat get_color_channel(float c1, float c2, float stripe_p, vec3 w, float extra_blur, float bump) {\n\n float ch = c2;\n float border = 0.;\n float blur = u_patternBlur + extra_blur;\n \n if (u_shape < 1.) {\n blur += .1 * smoothstep(-.4, -.6, v_responsiveUV.y);\n }\n\n ch = mix(ch, c1, smoothstep(.0, blur, stripe_p));\n\n border = w[0];\n ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));\n\n bump = smoothstep(.2, .8, bump);\n border = w[0] + .4 * (1. - bump) * w[1];\n ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));\n\n border = w[0] + .5 * (1. - bump) * w[1];\n ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));\n\n border = w[0] + w[1];\n ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));\n\n float gradient_t = (stripe_p - w[0] - w[1]) / w[2];\n float gradient = mix(c1, c2, smoothstep(0., 1., gradient_t));\n ch = mix(ch, gradient, smoothstep(border - blur, border + blur, stripe_p));\n\n return ch;\n}\n\nvoid main() {\n \n float t = .1 * u_time;\n\n vec2 uv = v_objectUV;\n uv += .5;\n uv.y = 1. - uv.y;\n\n float cycleWidth = .5 * u_patternScale; \n \n float mask = 1.;\n if (u_shape < 1.) {\n \n vec2 borderUV = v_responsiveUV + .5;\n float ratio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n vec2 edge = min(borderUV, 1. - borderUV);\n vec2 pixel_thickness = 250. / v_responsiveBoxGivenSize;\n float maskX = smoothstep(0.0, pixel_thickness.x, edge.x);\n float maskY = smoothstep(0.0, pixel_thickness.y, edge.y);\n maskX = pow(maskX, .25);\n maskY = pow(maskY, .25);\n mask = clamp(1. - maskX * maskY, 0., 1.);\n \n uv = v_responsiveUV;\n if (ratio > 1.) {\n uv.y /= ratio;\n } else {\n uv.x *= ratio;\n }\n uv += .5;\n uv.y = 1. - uv.y;\n \n cycleWidth *= 2.;\n\n } else if (u_shape < 2.) { \n vec2 shapeUV = uv - .5;\n shapeUV *= .67;\n mask = pow(clamp(3. * length(shapeUV), 0., 1.), 8.);\n \n uv *= 1.3;\n } else if (u_shape < 3.) {\n vec2 shapeUV = uv - .5;\n shapeUV *= 1.68;\n \n float r = length(shapeUV) * 2.;\n float a = atan(shapeUV.y, shapeUV.x) + .2;\n r *= (1. + .05 * sin(3. * a + 2. * t));\n float f = abs(cos(a * 3.));\n mask = smoothstep(f, f + .7, r);\n \n uv *= .8;\n cycleWidth *= 1.6;\n\n } else if (u_shape < 4.) {\n vec2 shapeUV = uv - .5;\n shapeUV *= 1.3;\n mask = 0.;\n for (int i = 0; i < 5; i++) {\n float fi = float(i);\n float speed = 4.5 + 2. * sin(fi * 12.345);\n float angle = -fi * 1.5;\n vec2 dir1 = vec2(cos(angle), sin(angle));\n vec2 dir2 = vec2(cos(angle + 1.57), sin(angle + 1.));\n vec2 traj = .4 * (dir1 * sin(t * speed + fi * 1.23) + dir2 * cos(t * (speed * 0.7) + fi * 2.17));\n float d = length(shapeUV + traj);\n mask += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);\n }\n mask = 1. - smoothstep(.85, 1., mask);\n \n uv *= 1.3;\n uv.y += .2;\n }\n\n float contour = smoothstep(0., 1., mask) * smoothstep(1., 0., mask);\n\n\n float diagBLtoTR = uv.x - uv.y; \n float diagTLtoBR = uv.x + uv.y;\n\n vec3 color = vec3(0.);\n float opacity = 1.;\n\n vec3 color1 = vec3(.98, 0.98, 1.);\n vec3 color2 = vec3(.1, .1, .1 + .1 * smoothstep(.7, 1.3, diagTLtoBR));\n\n vec2 grad_uv = uv - .5;\n \n float dist = length(grad_uv + vec2(0., .2 * diagBLtoTR));\n grad_uv = rotate(grad_uv, (.25 - .2 * diagBLtoTR) * PI);\n float direction = grad_uv.x;\n\n float bump = pow(1.8 * dist, 1.2);\n bump = 1. - bump;\n bump *= pow(uv.y, .3);\n\n\n float thin_strip_1_ratio = .12 / cycleWidth * (1. - .4 * bump);\n float thin_strip_2_ratio = .07 / cycleWidth * (1. + .4 * bump);\n float wide_strip_ratio = (1. - thin_strip_1_ratio - thin_strip_2_ratio);\n\n float thin_strip_1_width = cycleWidth * thin_strip_1_ratio;\n float thin_strip_2_width = cycleWidth * thin_strip_2_ratio;\n\n opacity = 1. - smoothstep(.9, .92, mask);\n\n float noise = snoise(uv - t);\n\n mask += (1. - mask) * u_liquid * noise;\n\n float colorDispersion = 0.;\n colorDispersion += (1. - bump);\n colorDispersion = clamp(colorDispersion, 0., 1.);\n\n direction += diagBLtoTR;\n\n direction -= 2. * noise * contour;\n\n bump *= clamp(pow(uv.y, .1), .3, 1.);\n direction *= (.1 + (1.1 - mask) * bump);\n direction *= smoothstep(1., .7, mask);\n\n float ridge = .2 * (smoothstep(.0, .15, uv.y) * smoothstep(.4, .15, uv.y));\n ridge += .03 * (smoothstep(.1, .2, 1. - uv.y) * smoothstep(.4, .2, 1. - uv.y));\n direction += ridge;\n\n direction *= (.5 + .5 * pow(uv.y, 2.));\n\n direction *= cycleWidth;\n\n direction -= t;\n\n float dispersionRed = colorDispersion;\n dispersionRed += .03 * bump * noise;\n float dispersionBlue = 1.3 * colorDispersion;\n\n dispersionRed += 5. * (smoothstep(-.1, .2, uv.y) * smoothstep(.5, .1, uv.y)) * (smoothstep(.4, .6, bump) * smoothstep(1., .4, bump));\n dispersionRed -= diagBLtoTR;\n\n dispersionBlue += (smoothstep(0., .4, uv.y) * smoothstep(.8, .1, uv.y)) * (smoothstep(.4, .6, bump) * smoothstep(.8, .4, bump));\n dispersionBlue -= .2 * mask;\n\n dispersionRed *= u_dispersion;\n dispersionBlue *= u_dispersion;\n\n vec3 w = vec3(thin_strip_1_width, thin_strip_2_width, wide_strip_ratio);\n w[1] -= .02 * smoothstep(.0, 1., mask + bump);\n float extraBlur = bump;\n float stripe_r = mod(direction + dispersionRed, 1.);\n float r = get_color_channel(color1.r, color2.r, stripe_r, w, 0.02 + .03 * u_dispersion * bump, extraBlur);\n float stripe_g = mod(direction, 1.);\n float g = get_color_channel(color1.g, color2.g, stripe_g, w, 0.01 / (1. - 0. * diagBLtoTR), extraBlur);\n float stripe_b = mod(direction - dispersionBlue, 1.);\n float b = get_color_channel(color1.b, color2.b, stripe_b, w, .01, extraBlur);\n\n color = vec3(r, g, b);\n color *= opacity;\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface LiquidMetalUniforms extends ShaderSizingUniforms {\n u_patternBlur: number;\n u_patternScale: number;\n u_dispersion: number;\n u_liquid: number;\n u_shape: number;\n}\n\nexport interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {\n patternBlur?: number;\n patternScale?: number;\n dispersion?: number;\n liquid?: number;\n shape?: number;\n}\n"],
5
+ "mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,eAAe,qBAAqB,uBAAuB;AAKxE,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,aAAa;AAAA,EACb,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;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;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;AAAA;AAAA;AAAA;AAAA,IA+LjB,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,18 +1,28 @@
1
- export type MeshGradientUniforms = {
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];
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 meshGradientMeta: {
5
+ readonly maxColorCount: 10;
6
6
  };
7
7
  /**
8
- * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG
9
- * Renders a mesh gradient with a rotating noise pattern
10
- * and several layers of fractal noise
8
+ * Mesh Gradient Ksenia Kondrashova
9
+ * Smooth, animated mesh gradient using a dynamic list of colors
11
10
  *
12
11
  * Uniforms include:
13
- * u_color1: The first color of the mesh gradient
14
- * u_color2: The second color of the mesh gradient
15
- * u_color3: The third color of the mesh gradient
16
- * u_color4: The fourth color of the mesh gradient
12
+ * - u_colors (vec4[]): Input RGBA colors
13
+ * - u_colorsCount (float): Number of active colors (`u_colors` length)
14
+ * - u_distortion (float): Amount of animated wavy distortion applied to UV coordinates
15
+ * - u_swirl (float): Amount of radial swirl distortion applied to UV coordinates
17
16
  */
18
- export declare const meshGradientFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\n\nout vec4 fragColor;\n\n#define S(a,b,t) smoothstep(a,b,t)\n\nmat2 Rot(float a) {\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\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 vec2 i = floor( p );\n vec2 f = fract( p );\n vec2 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 return 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 uv /= u_pixelRatio;\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 tuv.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 tuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n float proportion_1 = S(-.3, .2, (tuv*Rot(radians(-5.))).x);\n vec3 layer1_color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, proportion_1);\n float layer1_opacity = mix(u_color1.a, u_color2.a, proportion_1);\n vec3 layer2_color = mix(u_color3.rgb * u_color3.a, u_color4.rgb * u_color4.a, proportion_1);\n float layer2_opacity = mix(u_color3.a, u_color4.a, proportion_1);\n\n float proportion_2 = S(.5, -.3, tuv.y);\n vec3 color = mix(layer1_color, layer2_color, proportion_2);\n float opacity = mix(layer1_opacity, layer2_opacity, proportion_2);\n \n fragColor = vec4(color, opacity);\n}\n";
17
+ export declare const meshGradientFragmentShader: string;
18
+ export interface MeshGradientUniforms extends ShaderSizingUniforms {
19
+ u_colors: vec4[];
20
+ u_colorsCount: number;
21
+ u_distortion: number;
22
+ u_swirl: number;
23
+ }
24
+ export interface MeshGradientParams extends ShaderSizingParams, ShaderMotionParams {
25
+ colors?: string[];
26
+ distortion?: number;
27
+ swirl?: number;
28
+ }
@@ -0,0 +1,97 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing";
7
+ import { declarePI, declareRotate, colorBandingFix } from "../shader-utils";
8
+ const meshGradientMeta = {
9
+ maxColorCount: 10
10
+ };
11
+ const meshGradientFragmentShader = `#version 300 es
12
+ precision highp float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform vec4 u_colors[${meshGradientMeta.maxColorCount}];
17
+ uniform float u_colorsCount;
18
+
19
+ uniform float u_distortion;
20
+ uniform float u_swirl;
21
+
22
+ ${sizingVariablesDeclaration}
23
+
24
+ out vec4 fragColor;
25
+
26
+ ${declarePI}
27
+ ${declareRotate}
28
+
29
+ vec2 getPosition(int i, float t) {
30
+ float a = float(i) * .37;
31
+ float b = .6 + mod(float(i), 3.) * .3;
32
+ float c = .8 + mod(float(i + 1), 4.) * 0.25;
33
+
34
+ float x = sin(t * b + a);
35
+ float y = cos(t * c + a * 1.5);
36
+
37
+ return .5 + .5 * vec2(x, y);
38
+ }
39
+
40
+ void main() {
41
+ vec2 shape_uv = v_objectUV;
42
+
43
+ shape_uv += .5;
44
+
45
+ float t = .5 * u_time;
46
+
47
+ float radius = smoothstep(0., 1., length(shape_uv - .5));
48
+ float center = 1. - radius;
49
+ for (float i = 1.; i <= 2.; i++) {
50
+ shape_uv.x += u_distortion * center / i * sin(t + i * .4 * smoothstep(.0, 1., shape_uv.y)) * cos(.2 * t + i * 2.4 * smoothstep(.0, 1., shape_uv.y));
51
+ shape_uv.y += u_distortion * center / i * cos(t + i * 2. * smoothstep(.0, 1., shape_uv.x));
52
+ }
53
+
54
+ vec2 uvRotated = shape_uv;
55
+ uvRotated -= vec2(.5);
56
+ float angle = 3. * u_swirl * radius;
57
+ uvRotated = rotate(uvRotated, -angle);
58
+ uvRotated += vec2(.5);
59
+
60
+ vec3 color = vec3(0.);
61
+ float opacity = 0.;
62
+ float totalWeight = 0.;
63
+
64
+ for (int i = 0; i < ${meshGradientMeta.maxColorCount}; i++) {
65
+ if (i >= int(u_colorsCount)) break;
66
+
67
+ vec2 pos = getPosition(i, t);
68
+ vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
69
+ float opacityFraction = u_colors[i].a;
70
+
71
+ float dist = 0.;
72
+ if (mod(float(i), 2.) > 1.) {
73
+ dist = length(shape_uv - pos);
74
+ } else {
75
+ dist = length(uvRotated - pos);
76
+ }
77
+
78
+ dist = pow(dist, 3.5);
79
+ float weight = 1. / (dist + 1e-3);
80
+ color += colorFraction * weight;
81
+ opacity += opacityFraction * weight;
82
+ totalWeight += weight;
83
+ }
84
+
85
+ color /= totalWeight;
86
+ opacity /= totalWeight;
87
+
88
+ ${colorBandingFix}
89
+
90
+ fragColor = vec4(color, opacity);
91
+ }
92
+ `;
93
+ export {
94
+ meshGradientFragmentShader,
95
+ meshGradientMeta
96
+ };
97
+ //# sourceMappingURL=mesh-gradient.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/mesh-gradient.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, declareRotate, colorBandingFix } from '../shader-utils';\n\nexport const meshGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Mesh Gradient Ksenia Kondrashova\n * Smooth, animated mesh gradient using a dynamic list of colors\n *\n * Uniforms include:\n * - u_colors (vec4[]): Input RGBA colors\n * - u_colorsCount (float): Number of active colors (`u_colors` length)\n * - u_distortion (float): Amount of animated wavy distortion applied to UV coordinates\n * - u_swirl (float): Amount of radial swirl distortion applied to UV coordinates\n */\nexport const meshGradientFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\n\nuniform vec4 u_colors[${meshGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_distortion;\nuniform float u_swirl;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n\n shape_uv += .5;\n\n float t = .5 * u_time;\n\n float radius = smoothstep(0., 1., length(shape_uv - .5));\n float center = 1. - radius;\n for (float i = 1.; i <= 2.; i++) {\n shape_uv.x += u_distortion * center / i * sin(t + i * .4 * smoothstep(.0, 1., shape_uv.y)) * cos(.2 * t + i * 2.4 * smoothstep(.0, 1., shape_uv.y));\n shape_uv.y += u_distortion * center / i * cos(t + i * 2. * smoothstep(.0, 1., shape_uv.x));\n }\n\n vec2 uvRotated = shape_uv;\n uvRotated -= vec2(.5);\n float angle = 3. * u_swirl * radius;\n uvRotated = rotate(uvRotated, -angle);\n uvRotated += vec2(.5);\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n float totalWeight = 0.;\n \n for (int i = 0; i < ${meshGradientMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n \n vec2 pos = getPosition(i, t);\n vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;\n float opacityFraction = u_colors[i].a;\n \n float dist = 0.;\n if (mod(float(i), 2.) > 1.) {\n dist = length(shape_uv - pos);\n } else {\n dist = length(uvRotated - pos);\n }\n\n dist = pow(dist, 3.5);\n float weight = 1. / (dist + 1e-3);\n color += colorFraction * weight;\n opacity += opacityFraction * weight;\n totalWeight += weight;\n }\n\n color /= totalWeight;\n opacity /= totalWeight;\n \n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface MeshGradientUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_distortion: number;\n u_swirl: number;\n}\n\nexport interface MeshGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n distortion?: number;\n swirl?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,eAAe,uBAAuB;AAEnD,MAAM,mBAAmB;AAAA,EAC9B,eAAe;AACjB;AAYO,MAAM,6BAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,wBAK1B,iBAAiB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpD,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,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,wBAqCS,iBAAiB,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,IAwBlD,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }