shaders-oneshot 0.0.81-shared.1

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 (129) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +7 -0
  4. package/dist/empty-pixel.d.ts +1 -0
  5. package/dist/empty-pixel.js +10 -0
  6. package/dist/empty-pixel.js.map +7 -0
  7. package/dist/get-shader-color-from-string.d.ts +3 -0
  8. package/dist/get-shader-color-from-string.js +101 -0
  9. package/dist/get-shader-color-from-string.js.map +7 -0
  10. package/dist/get-shader-color-from-string.test.d.ts +1 -0
  11. package/dist/get-shader-color-from-string.test.js +69 -0
  12. package/dist/get-shader-noise-texture.d.ts +1 -0
  13. package/dist/get-shader-noise-texture.js +18 -0
  14. package/dist/get-shader-noise-texture.js.map +7 -0
  15. package/dist/index.d.ts +68 -0
  16. package/dist/index.js +194 -0
  17. package/dist/index.js.map +7 -0
  18. package/dist/shader-color-spaces.d.ts +6 -0
  19. package/dist/shader-color-spaces.js +96 -0
  20. package/dist/shader-color-spaces.js.map +7 -0
  21. package/dist/shader-mount.d.ts +199 -0
  22. package/dist/shader-mount.js +735 -0
  23. package/dist/shader-mount.js.map +7 -0
  24. package/dist/shader-sizing.d.ts +30 -0
  25. package/dist/shader-sizing.js +38 -0
  26. package/dist/shader-sizing.js.map +7 -0
  27. package/dist/shader-utils.d.ts +10 -0
  28. package/dist/shader-utils.js +131 -0
  29. package/dist/shader-utils.js.map +7 -0
  30. package/dist/shaders/color-panels.d.ts +70 -0
  31. package/dist/shaders/color-panels.js +224 -0
  32. package/dist/shaders/color-panels.js.map +7 -0
  33. package/dist/shaders/dithering.d.ts +62 -0
  34. package/dist/shaders/dithering.js +271 -0
  35. package/dist/shaders/dithering.js.map +7 -0
  36. package/dist/shaders/dot-grid.d.ts +65 -0
  37. package/dist/shaders/dot-grid.js +110 -0
  38. package/dist/shaders/dot-grid.js.map +7 -0
  39. package/dist/shaders/dot-orbit.d.ts +57 -0
  40. package/dist/shaders/dot-orbit.js +123 -0
  41. package/dist/shaders/dot-orbit.js.map +7 -0
  42. package/dist/shaders/fluted-glass.d.ts +112 -0
  43. package/dist/shaders/fluted-glass.js +361 -0
  44. package/dist/shaders/fluted-glass.js.map +7 -0
  45. package/dist/shaders/gem-smoke.d.ts +96 -0
  46. package/dist/shaders/gem-smoke.js +573 -0
  47. package/dist/shaders/gem-smoke.js.map +7 -0
  48. package/dist/shaders/god-rays.d.ts +67 -0
  49. package/dist/shaders/god-rays.js +133 -0
  50. package/dist/shaders/god-rays.js.map +7 -0
  51. package/dist/shaders/grain-gradient.d.ts +80 -0
  52. package/dist/shaders/grain-gradient.js +301 -0
  53. package/dist/shaders/grain-gradient.js.map +7 -0
  54. package/dist/shaders/halftone-cmyk.d.ts +104 -0
  55. package/dist/shaders/halftone-cmyk.js +295 -0
  56. package/dist/shaders/halftone-cmyk.js.map +7 -0
  57. package/dist/shaders/halftone-dots.d.ts +80 -0
  58. package/dist/shaders/halftone-dots.js +321 -0
  59. package/dist/shaders/halftone-dots.js.map +7 -0
  60. package/dist/shaders/heatmap.d.ts +66 -0
  61. package/dist/shaders/heatmap.js +384 -0
  62. package/dist/shaders/heatmap.js.map +7 -0
  63. package/dist/shaders/image-dithering.d.ts +64 -0
  64. package/dist/shaders/image-dithering.js +199 -0
  65. package/dist/shaders/image-dithering.js.map +7 -0
  66. package/dist/shaders/lens-distortion.d.ts +97 -0
  67. package/dist/shaders/lens-distortion.js +276 -0
  68. package/dist/shaders/lens-distortion.js.map +7 -0
  69. package/dist/shaders/liquid-metal.d.ts +89 -0
  70. package/dist/shaders/liquid-metal.js +633 -0
  71. package/dist/shaders/liquid-metal.js.map +7 -0
  72. package/dist/shaders/mesh-gradient.d.ts +52 -0
  73. package/dist/shaders/mesh-gradient.js +131 -0
  74. package/dist/shaders/mesh-gradient.js.map +7 -0
  75. package/dist/shaders/metaballs.d.ts +51 -0
  76. package/dist/shaders/metaballs.js +111 -0
  77. package/dist/shaders/metaballs.js.map +7 -0
  78. package/dist/shaders/neuro-noise.d.ts +47 -0
  79. package/dist/shaders/neuro-noise.js +77 -0
  80. package/dist/shaders/neuro-noise.js.map +7 -0
  81. package/dist/shaders/paper-texture.d.ts +109 -0
  82. package/dist/shaders/paper-texture.js +527 -0
  83. package/dist/shaders/paper-texture.js.map +7 -0
  84. package/dist/shaders/perlin-noise.d.ts +52 -0
  85. package/dist/shaders/perlin-noise.js +167 -0
  86. package/dist/shaders/perlin-noise.js.map +7 -0
  87. package/dist/shaders/pulsing-border.d.ts +98 -0
  88. package/dist/shaders/pulsing-border.js +239 -0
  89. package/dist/shaders/pulsing-border.js.map +7 -0
  90. package/dist/shaders/simplex-noise.d.ts +45 -0
  91. package/dist/shaders/simplex-noise.js +92 -0
  92. package/dist/shaders/simplex-noise.js.map +7 -0
  93. package/dist/shaders/smoke-ring.d.ts +61 -0
  94. package/dist/shaders/smoke-ring.js +133 -0
  95. package/dist/shaders/smoke-ring.js.map +7 -0
  96. package/dist/shaders/spiral.d.ts +61 -0
  97. package/dist/shaders/spiral.js +83 -0
  98. package/dist/shaders/spiral.js.map +7 -0
  99. package/dist/shaders/static-mesh-gradient.d.ts +63 -0
  100. package/dist/shaders/static-mesh-gradient.js +131 -0
  101. package/dist/shaders/static-mesh-gradient.js.map +7 -0
  102. package/dist/shaders/static-radial-gradient.d.ts +72 -0
  103. package/dist/shaders/static-radial-gradient.js +188 -0
  104. package/dist/shaders/static-radial-gradient.js.map +7 -0
  105. package/dist/shaders/swirl.d.ts +63 -0
  106. package/dist/shaders/swirl.js +104 -0
  107. package/dist/shaders/swirl.js.map +7 -0
  108. package/dist/shaders/voronoi.d.ts +65 -0
  109. package/dist/shaders/voronoi.js +139 -0
  110. package/dist/shaders/voronoi.js.map +7 -0
  111. package/dist/shaders/warp.d.ts +70 -0
  112. package/dist/shaders/warp.js +130 -0
  113. package/dist/shaders/warp.js.map +7 -0
  114. package/dist/shaders/water.d.ts +59 -0
  115. package/dist/shaders/water.js +122 -0
  116. package/dist/shaders/water.js.map +7 -0
  117. package/dist/shaders/waves.d.ts +53 -0
  118. package/dist/shaders/waves.js +66 -0
  119. package/dist/shaders/waves.js.map +7 -0
  120. package/dist/shared-webgl-renderer.d.ts +63 -0
  121. package/dist/shared-webgl-renderer.js +262 -0
  122. package/dist/shared-webgl-renderer.js.map +7 -0
  123. package/dist/types.d.ts +3 -0
  124. package/dist/types.js +6 -0
  125. package/dist/types.js.map +7 -0
  126. package/dist/vertex-shader.d.ts +2 -0
  127. package/dist/vertex-shader.js +160 -0
  128. package/dist/vertex-shader.js.map +7 -0
  129. package/package.json +29 -0
@@ -0,0 +1,321 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import {} from "../shader-sizing.js";
7
+ import { declarePI, rotation2, proceduralHash21 } from "../shader-utils.js";
8
+ const halftoneDotsFragmentShader = `#version 300 es
9
+ precision mediump float;
10
+
11
+ uniform vec4 u_colorFront;
12
+ uniform vec4 u_colorBack;
13
+ uniform float u_radius;
14
+ uniform float u_contrast;
15
+
16
+ uniform sampler2D u_image;
17
+ uniform float u_imageAspectRatio;
18
+
19
+ uniform float u_size;
20
+ uniform float u_grainMixer;
21
+ uniform float u_grainOverlay;
22
+ uniform float u_grainSize;
23
+ uniform float u_grid;
24
+ uniform bool u_originalColors;
25
+ uniform bool u_inverted;
26
+ uniform float u_type;
27
+
28
+ in vec2 v_imageUV;
29
+
30
+ out vec4 fragColor;
31
+
32
+ ${declarePI}
33
+ ${rotation2}
34
+ ${proceduralHash21}
35
+
36
+ float valueNoise(vec2 st) {
37
+ vec2 i = floor(st);
38
+ vec2 f = fract(st);
39
+ float a = hash21(i);
40
+ float b = hash21(i + vec2(1.0, 0.0));
41
+ float c = hash21(i + vec2(0.0, 1.0));
42
+ float d = hash21(i + vec2(1.0, 1.0));
43
+ vec2 u = f * f * (3.0 - 2.0 * f);
44
+ float x1 = mix(a, b, u.x);
45
+ float x2 = mix(c, d, u.x);
46
+ return mix(x1, x2, u.y);
47
+ }
48
+
49
+ float lst(float edge0, float edge1, float x) {
50
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
51
+ }
52
+
53
+ float sst(float edge0, float edge1, float x) {
54
+ return smoothstep(edge0, edge1, x);
55
+ }
56
+
57
+ float getCircle(vec2 uv, float r, float baseR) {
58
+ r = mix(.25 * baseR, 0., r);
59
+ float d = length(uv - .5);
60
+ float aa = fwidth(d);
61
+ return 1. - smoothstep(r - aa, r + aa, d);
62
+ }
63
+
64
+ float getCell(vec2 uv) {
65
+ float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));
66
+ float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));
67
+ return insideX * insideY;
68
+ }
69
+
70
+ float getCircleWithHole(vec2 uv, float r, float baseR) {
71
+ float cell = getCell(uv);
72
+
73
+ r = mix(.75 * baseR, 0., r);
74
+ float rMod = mod(r, .5);
75
+
76
+ float d = length(uv - .5);
77
+ float aa = fwidth(d);
78
+ float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);
79
+ if (r < .5) {
80
+ return circle;
81
+ } else {
82
+ return cell - circle;
83
+ }
84
+ }
85
+
86
+ float getGooeyBall(vec2 uv, float r, float baseR) {
87
+ float d = length(uv - .5);
88
+ float sizeRadius = .3;
89
+ if (u_grid == 1.) {
90
+ sizeRadius = .42;
91
+ }
92
+ sizeRadius = mix(sizeRadius * baseR, 0., r);
93
+ d = 1. - sst(0., sizeRadius, d);
94
+
95
+ d = pow(d, 2. + baseR);
96
+ return d;
97
+ }
98
+
99
+ float getSoftBall(vec2 uv, float r, float baseR) {
100
+ float d = length(uv - .5);
101
+ float sizeRadius = clamp(baseR, 0., 1.);
102
+ sizeRadius = mix(.5 * sizeRadius, 0., r);
103
+ d = 1. - lst(0., sizeRadius, d);
104
+ float powRadius = 1. - lst(0., 2., baseR);
105
+ d = pow(d, 4. + 3. * powRadius);
106
+ return d;
107
+ }
108
+
109
+ float getUvFrame(vec2 uv, vec2 pad) {
110
+ float aa = 0.0001;
111
+
112
+ float left = smoothstep(-pad.x, -pad.x + aa, uv.x);
113
+ float right = smoothstep(1.0 + pad.x, 1.0 + pad.x - aa, uv.x);
114
+ float bottom = smoothstep(-pad.y, -pad.y + aa, uv.y);
115
+ float top = smoothstep(1.0 + pad.y, 1.0 + pad.y - aa, uv.y);
116
+
117
+ return left * right * bottom * top;
118
+ }
119
+
120
+ float sigmoid(float x, float k) {
121
+ return 1.0 / (1.0 + exp(-k * (x - 0.5)));
122
+ }
123
+
124
+ float getLumAtPx(vec2 uv, float contrast) {
125
+ vec4 tex = texture(u_image, uv);
126
+ vec3 color = vec3(
127
+ sigmoid(tex.r, contrast),
128
+ sigmoid(tex.g, contrast),
129
+ sigmoid(tex.b, contrast)
130
+ );
131
+ float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);
132
+ lum = mix(1., lum, tex.a);
133
+ lum = u_inverted ? (1. - lum) : lum;
134
+ return lum;
135
+ }
136
+
137
+ float getLumBall(vec2 p, vec2 pad, vec2 inCellOffset, float contrast, float baseR, float stepSize, out vec4 ballColor) {
138
+ p += inCellOffset;
139
+ vec2 uv_i = floor(p);
140
+ vec2 uv_f = fract(p);
141
+ vec2 samplingUV = (uv_i + .5 - inCellOffset) * pad + vec2(.5);
142
+ float outOfFrame = getUvFrame(samplingUV, pad * stepSize);
143
+
144
+ float lum = getLumAtPx(samplingUV, contrast);
145
+ ballColor = texture(u_image, samplingUV);
146
+ ballColor.rgb *= ballColor.a;
147
+ ballColor *= outOfFrame;
148
+
149
+ float ball = 0.;
150
+ if (u_type == 0.) {
151
+ // classic
152
+ ball = getCircle(uv_f, lum, baseR);
153
+ } else if (u_type == 1.) {
154
+ // gooey
155
+ ball = getGooeyBall(uv_f, lum, baseR);
156
+ } else if (u_type == 2.) {
157
+ // holes
158
+ ball = getCircleWithHole(uv_f, lum, baseR);
159
+ } else if (u_type == 3.) {
160
+ // soft
161
+ ball = getSoftBall(uv_f, lum, baseR);
162
+ }
163
+
164
+ return ball * outOfFrame;
165
+ }
166
+
167
+
168
+ void main() {
169
+
170
+ float stepMultiplier = 1.;
171
+ if (u_type == 0.) {
172
+ // classic
173
+ stepMultiplier = 2.;
174
+ } else if (u_type == 1. || u_type == 3.) {
175
+ // gooey & soft
176
+ stepMultiplier = 6.;
177
+ }
178
+
179
+ float cellsPerSide = mix(300., 7., pow(u_size, .7));
180
+ cellsPerSide /= stepMultiplier;
181
+ float cellSizeY = 1. / cellsPerSide;
182
+ vec2 pad = cellSizeY * vec2(1. / u_imageAspectRatio, 1.);
183
+ if (u_type == 1. && u_grid == 1.) {
184
+ // gooey diagonal grid works differently
185
+ pad *= .7;
186
+ }
187
+
188
+ vec2 uv = v_imageUV;
189
+ uv -= vec2(.5);
190
+ uv /= pad;
191
+
192
+ float contrast = mix(0., 15., pow(u_contrast, 1.5));
193
+ float baseRadius = u_radius;
194
+ if (u_originalColors == true) {
195
+ contrast = mix(.1, 4., pow(u_contrast, 2.));
196
+ baseRadius = 2. * pow(.5 * u_radius, .3);
197
+ }
198
+
199
+ float totalShape = 0.;
200
+ vec3 totalColor = vec3(0.);
201
+ float totalOpacity = 0.;
202
+
203
+ vec4 ballColor;
204
+ float shape;
205
+ float stepSize = 1. / stepMultiplier;
206
+ for (float x = -0.5; x < 0.5; x += stepSize) {
207
+ for (float y = -0.5; y < 0.5; y += stepSize) {
208
+ vec2 offset = vec2(x, y);
209
+
210
+ if (u_grid == 1.) {
211
+ float rowIndex = floor((y + .5) / stepSize);
212
+ float colIndex = floor((x + .5) / stepSize);
213
+ if (stepSize == 1.) {
214
+ rowIndex = floor(uv.y + y + 1.);
215
+ if (u_type == 1.) {
216
+ colIndex = floor(uv.x + x + 1.);
217
+ }
218
+ }
219
+ if (u_type == 1.) {
220
+ if (mod(rowIndex + colIndex, 2.) == 1.) {
221
+ continue;
222
+ }
223
+ } else {
224
+ if (mod(rowIndex, 2.) == 1.) {
225
+ offset.x += .5 * stepSize;
226
+ }
227
+ }
228
+ }
229
+
230
+ shape = getLumBall(uv, pad, offset, contrast, baseRadius, stepSize, ballColor);
231
+ totalColor += ballColor.rgb * shape;
232
+ totalShape += shape;
233
+ totalOpacity += shape;
234
+ }
235
+ }
236
+
237
+ const float eps = 1e-4;
238
+
239
+ totalColor /= max(totalShape, eps);
240
+ totalOpacity /= max(totalShape, eps);
241
+
242
+ float finalShape = 0.;
243
+ if (u_type == 0.) {
244
+ finalShape = min(1., totalShape);
245
+ } else if (u_type == 1.) {
246
+ float aa = fwidth(totalShape);
247
+ float th = .5;
248
+ finalShape = smoothstep(th - aa, th + aa, totalShape);
249
+ } else if (u_type == 2.) {
250
+ finalShape = min(1., totalShape);
251
+ } else if (u_type == 3.) {
252
+ finalShape = totalShape;
253
+ }
254
+
255
+ vec2 grainSize = mix(2000., 200., u_grainSize) * vec2(1., 1. / u_imageAspectRatio);
256
+ vec2 grainUV = v_imageUV - .5;
257
+ grainUV *= grainSize;
258
+ grainUV += .5;
259
+ if (u_grainMixer > 0.) {
260
+ float grain = valueNoise(grainUV);
261
+ grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);
262
+ grain *= u_grainMixer;
263
+ finalShape = mix(finalShape, 0., grain);
264
+ }
265
+
266
+ vec3 color = vec3(0.);
267
+ float opacity = 0.;
268
+
269
+ if (u_originalColors == true) {
270
+ color = totalColor * finalShape;
271
+ opacity = totalOpacity * finalShape;
272
+
273
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
274
+ color = color + bgColor * (1. - opacity);
275
+ opacity = opacity + u_colorBack.a * (1. - opacity);
276
+ } else {
277
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
278
+ float fgOpacity = u_colorFront.a;
279
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
280
+ float bgOpacity = u_colorBack.a;
281
+
282
+ color = fgColor * finalShape;
283
+ opacity = fgOpacity * finalShape;
284
+ color += bgColor * (1. - opacity);
285
+ opacity += bgOpacity * (1. - opacity);
286
+ }
287
+
288
+ if (u_grainOverlay > 0.) {
289
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
290
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
291
+ grainOverlay = pow(grainOverlay, 1.3);
292
+
293
+ float grainOverlayV = grainOverlay * 2. - 1.;
294
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
295
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
296
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
297
+ color = mix(color, grainOverlayColor, .5 * grainOverlayStrength);
298
+
299
+ opacity += .5 * grainOverlayStrength;
300
+ }
301
+ opacity = clamp(opacity, 0., 1.);
302
+
303
+ fragColor = vec4(color, opacity);
304
+ }
305
+ `;
306
+ const HalftoneDotsTypes = {
307
+ classic: 0,
308
+ gooey: 1,
309
+ holes: 2,
310
+ soft: 3
311
+ };
312
+ const HalftoneDotsGrids = {
313
+ square: 0,
314
+ hex: 1
315
+ };
316
+ export {
317
+ HalftoneDotsGrids,
318
+ HalftoneDotsTypes,
319
+ halftoneDotsFragmentShader
320
+ };
321
+ //# sourceMappingURL=halftone-dots.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/halftone-dots.ts"],
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\r\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\r\nimport { declarePI, rotation2, proceduralHash21 } from '../shader-utils.js';\r\n\r\n/**\r\n * A halftone-dot image filter featuring customizable grids, color palettes, and dot styles.\r\n *\r\n * Fragment shader uniforms:\r\n * - u_image (sampler2D): Source image texture\r\n * - u_imageAspectRatio (float): Aspect ratio of the source image\r\n * - u_colorFront (vec4): Foreground color in RGBA, needs originalColors off\r\n * - u_colorBack (vec4): Background color in RGBA\r\n * - u_originalColors (bool): Use sampled image's original colors instead of colorFront\r\n * - u_type (float): Dot style (0 = classic, 1 = gooey, 2 = holes, 3 = soft)\r\n * - u_inverted (bool): Inverts the image luminance, doesn't affect the color scheme, needs contrast > 0\r\n * - u_grid (float): Grid type (0 = square, 1 = hex)\r\n * - u_size (float): Grid size relative to the image box (0 to 1)\r\n * - u_radius (float): Maximum dot size relative to grid cell (0 to 2)\r\n * - u_contrast (float): Contrast applied to the sampled image, at 0 the luminance is flat so all the dots get equal size (0 to 1)\r\n * - u_grainMixer (float): Strength of grain distortion applied to shape edges (0 to 1)\r\n * - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)\r\n * - u_grainSize (float): Scale applied to both grain distortion and grain overlay, needs grainMixer or grainOverlay > 0 (0 to 1)\r\n *\r\n * Vertex shader outputs (used in fragment shader):\r\n * - v_imageUV (vec2): Image UV coordinates with global sizing (rotation, scale, offset, etc) applied\r\n *\r\n * Vertex shader uniforms:\r\n * - u_resolution (vec2): Canvas resolution in pixels\r\n * - u_pixelRatio (float): Device pixel ratio\r\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\r\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\r\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\r\n * - u_scale (float): Overall zoom level of the graphics (0.1 to 4)\r\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\r\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\r\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\r\n * - u_imageAspectRatio (float): Aspect ratio of the source image\r\n *\r\n */\r\n\r\n// language=GLSL\r\nexport const halftoneDotsFragmentShader: string = `#version 300 es\r\nprecision mediump float;\r\n\r\nuniform vec4 u_colorFront;\r\nuniform vec4 u_colorBack;\r\nuniform float u_radius;\r\nuniform float u_contrast;\r\n\r\nuniform sampler2D u_image;\r\nuniform float u_imageAspectRatio;\r\n\r\nuniform float u_size;\r\nuniform float u_grainMixer;\r\nuniform float u_grainOverlay;\r\nuniform float u_grainSize;\r\nuniform float u_grid;\r\nuniform bool u_originalColors;\r\nuniform bool u_inverted;\r\nuniform float u_type;\r\n\r\nin vec2 v_imageUV;\r\n\r\nout vec4 fragColor;\r\n\r\n${ declarePI }\r\n${ rotation2 }\r\n${ proceduralHash21 }\r\n\r\nfloat valueNoise(vec2 st) {\r\n vec2 i = floor(st);\r\n vec2 f = fract(st);\r\n float a = hash21(i);\r\n float b = hash21(i + vec2(1.0, 0.0));\r\n float c = hash21(i + vec2(0.0, 1.0));\r\n float d = hash21(i + vec2(1.0, 1.0));\r\n vec2 u = f * f * (3.0 - 2.0 * f);\r\n float x1 = mix(a, b, u.x);\r\n float x2 = mix(c, d, u.x);\r\n return mix(x1, x2, u.y);\r\n}\r\n\r\nfloat lst(float edge0, float edge1, float x) {\r\n return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\r\n}\r\n\r\nfloat sst(float edge0, float edge1, float x) {\r\n return smoothstep(edge0, edge1, x);\r\n}\r\n\r\nfloat getCircle(vec2 uv, float r, float baseR) {\r\n r = mix(.25 * baseR, 0., r);\r\n float d = length(uv - .5);\r\n float aa = fwidth(d);\r\n return 1. - smoothstep(r - aa, r + aa, d);\r\n}\r\n\r\nfloat getCell(vec2 uv) {\r\n float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));\r\n float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));\r\n return insideX * insideY;\r\n}\r\n\r\nfloat getCircleWithHole(vec2 uv, float r, float baseR) {\r\n float cell = getCell(uv);\r\n\r\n r = mix(.75 * baseR, 0., r);\r\n float rMod = mod(r, .5);\r\n\r\n float d = length(uv - .5);\r\n float aa = fwidth(d);\r\n float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);\r\n if (r < .5) {\r\n return circle;\r\n } else {\r\n return cell - circle;\r\n }\r\n}\r\n\r\nfloat getGooeyBall(vec2 uv, float r, float baseR) {\r\n float d = length(uv - .5);\r\n float sizeRadius = .3;\r\n if (u_grid == 1.) {\r\n sizeRadius = .42;\r\n }\r\n sizeRadius = mix(sizeRadius * baseR, 0., r);\r\n d = 1. - sst(0., sizeRadius, d);\r\n\r\n d = pow(d, 2. + baseR);\r\n return d;\r\n}\r\n\r\nfloat getSoftBall(vec2 uv, float r, float baseR) {\r\n float d = length(uv - .5);\r\n float sizeRadius = clamp(baseR, 0., 1.);\r\n sizeRadius = mix(.5 * sizeRadius, 0., r);\r\n d = 1. - lst(0., sizeRadius, d);\r\n float powRadius = 1. - lst(0., 2., baseR);\r\n d = pow(d, 4. + 3. * powRadius);\r\n return d;\r\n}\r\n\r\nfloat getUvFrame(vec2 uv, vec2 pad) {\r\n float aa = 0.0001;\r\n\r\n float left = smoothstep(-pad.x, -pad.x + aa, uv.x);\r\n float right = smoothstep(1.0 + pad.x, 1.0 + pad.x - aa, uv.x);\r\n float bottom = smoothstep(-pad.y, -pad.y + aa, uv.y);\r\n float top = smoothstep(1.0 + pad.y, 1.0 + pad.y - aa, uv.y);\r\n\r\n return left * right * bottom * top;\r\n}\r\n\r\nfloat sigmoid(float x, float k) {\r\n return 1.0 / (1.0 + exp(-k * (x - 0.5)));\r\n}\r\n\r\nfloat getLumAtPx(vec2 uv, float contrast) {\r\n vec4 tex = texture(u_image, uv);\r\n vec3 color = vec3(\r\n sigmoid(tex.r, contrast),\r\n sigmoid(tex.g, contrast),\r\n sigmoid(tex.b, contrast)\r\n );\r\n float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);\r\n lum = mix(1., lum, tex.a);\r\n lum = u_inverted ? (1. - lum) : lum;\r\n return lum;\r\n}\r\n\r\nfloat getLumBall(vec2 p, vec2 pad, vec2 inCellOffset, float contrast, float baseR, float stepSize, out vec4 ballColor) {\r\n p += inCellOffset;\r\n vec2 uv_i = floor(p);\r\n vec2 uv_f = fract(p);\r\n vec2 samplingUV = (uv_i + .5 - inCellOffset) * pad + vec2(.5);\r\n float outOfFrame = getUvFrame(samplingUV, pad * stepSize);\r\n\r\n float lum = getLumAtPx(samplingUV, contrast);\r\n ballColor = texture(u_image, samplingUV);\r\n ballColor.rgb *= ballColor.a;\r\n ballColor *= outOfFrame;\r\n\r\n float ball = 0.;\r\n if (u_type == 0.) {\r\n // classic\r\n ball = getCircle(uv_f, lum, baseR);\r\n } else if (u_type == 1.) {\r\n // gooey\r\n ball = getGooeyBall(uv_f, lum, baseR);\r\n } else if (u_type == 2.) {\r\n // holes\r\n ball = getCircleWithHole(uv_f, lum, baseR);\r\n } else if (u_type == 3.) {\r\n // soft\r\n ball = getSoftBall(uv_f, lum, baseR);\r\n }\r\n\r\n return ball * outOfFrame;\r\n}\r\n\r\n\r\nvoid main() {\r\n\r\n float stepMultiplier = 1.;\r\n if (u_type == 0.) {\r\n // classic\r\n stepMultiplier = 2.;\r\n } else if (u_type == 1. || u_type == 3.) {\r\n // gooey & soft\r\n stepMultiplier = 6.;\r\n }\r\n\r\n float cellsPerSide = mix(300., 7., pow(u_size, .7));\r\n cellsPerSide /= stepMultiplier;\r\n float cellSizeY = 1. / cellsPerSide;\r\n vec2 pad = cellSizeY * vec2(1. / u_imageAspectRatio, 1.);\r\n if (u_type == 1. && u_grid == 1.) {\r\n // gooey diagonal grid works differently\r\n pad *= .7;\r\n }\r\n\r\n vec2 uv = v_imageUV;\r\n uv -= vec2(.5);\r\n uv /= pad;\r\n\r\n float contrast = mix(0., 15., pow(u_contrast, 1.5));\r\n float baseRadius = u_radius;\r\n if (u_originalColors == true) {\r\n contrast = mix(.1, 4., pow(u_contrast, 2.));\r\n baseRadius = 2. * pow(.5 * u_radius, .3);\r\n }\r\n\r\n float totalShape = 0.;\r\n vec3 totalColor = vec3(0.);\r\n float totalOpacity = 0.;\r\n\r\n vec4 ballColor;\r\n float shape;\r\n float stepSize = 1. / stepMultiplier;\r\n for (float x = -0.5; x < 0.5; x += stepSize) {\r\n for (float y = -0.5; y < 0.5; y += stepSize) {\r\n vec2 offset = vec2(x, y);\r\n\r\n if (u_grid == 1.) {\r\n float rowIndex = floor((y + .5) / stepSize);\r\n float colIndex = floor((x + .5) / stepSize);\r\n if (stepSize == 1.) {\r\n rowIndex = floor(uv.y + y + 1.);\r\n if (u_type == 1.) {\r\n colIndex = floor(uv.x + x + 1.);\r\n }\r\n }\r\n if (u_type == 1.) {\r\n if (mod(rowIndex + colIndex, 2.) == 1.) {\r\n continue;\r\n }\r\n } else {\r\n if (mod(rowIndex, 2.) == 1.) {\r\n offset.x += .5 * stepSize;\r\n }\r\n }\r\n }\r\n\r\n shape = getLumBall(uv, pad, offset, contrast, baseRadius, stepSize, ballColor);\r\n totalColor += ballColor.rgb * shape;\r\n totalShape += shape;\r\n totalOpacity += shape;\r\n }\r\n }\r\n\r\n const float eps = 1e-4;\r\n\r\n totalColor /= max(totalShape, eps);\r\n totalOpacity /= max(totalShape, eps);\r\n\r\n float finalShape = 0.;\r\n if (u_type == 0.) {\r\n finalShape = min(1., totalShape);\r\n } else if (u_type == 1.) {\r\n float aa = fwidth(totalShape);\r\n float th = .5;\r\n finalShape = smoothstep(th - aa, th + aa, totalShape);\r\n } else if (u_type == 2.) {\r\n finalShape = min(1., totalShape);\r\n } else if (u_type == 3.) {\r\n finalShape = totalShape;\r\n }\r\n\r\n vec2 grainSize = mix(2000., 200., u_grainSize) * vec2(1., 1. / u_imageAspectRatio);\r\n vec2 grainUV = v_imageUV - .5;\r\n grainUV *= grainSize;\r\n grainUV += .5;\r\n if (u_grainMixer > 0.) {\r\n float grain = valueNoise(grainUV);\r\n grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);\r\n grain *= u_grainMixer;\r\n finalShape = mix(finalShape, 0., grain);\r\n }\r\n\r\n vec3 color = vec3(0.);\r\n float opacity = 0.;\r\n\r\n if (u_originalColors == true) {\r\n color = totalColor * finalShape;\r\n opacity = totalOpacity * finalShape;\r\n\r\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\r\n color = color + bgColor * (1. - opacity);\r\n opacity = opacity + u_colorBack.a * (1. - opacity);\r\n } else {\r\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\r\n float fgOpacity = u_colorFront.a;\r\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\r\n float bgOpacity = u_colorBack.a;\r\n\r\n color = fgColor * finalShape;\r\n opacity = fgOpacity * finalShape;\r\n color += bgColor * (1. - opacity);\r\n opacity += bgOpacity * (1. - opacity);\r\n }\r\n\r\n if (u_grainOverlay > 0.) {\r\n float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));\r\n grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);\r\n grainOverlay = pow(grainOverlay, 1.3);\r\n\r\n float grainOverlayV = grainOverlay * 2. - 1.;\r\n vec3 grainOverlayColor = vec3(step(0., grainOverlayV));\r\n float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);\r\n grainOverlayStrength = pow(grainOverlayStrength, .8);\r\n color = mix(color, grainOverlayColor, .5 * grainOverlayStrength);\r\n\r\n opacity += .5 * grainOverlayStrength;\r\n }\r\n opacity = clamp(opacity, 0., 1.);\r\n\r\n fragColor = vec4(color, opacity);\r\n}\r\n`;\r\n\r\nexport interface HalftoneDotsUniforms extends ShaderSizingUniforms {\r\n u_image: HTMLImageElement | string | undefined;\r\n u_colorFront: [number, number, number, number];\r\n u_colorBack: [number, number, number, number];\r\n u_size: number;\r\n u_grid: (typeof HalftoneDotsGrids)[HalftoneDotsGrid];\r\n u_radius: number;\r\n u_contrast: number;\r\n u_originalColors: boolean;\r\n u_inverted: boolean;\r\n u_grainMixer: number;\r\n u_grainOverlay: number;\r\n u_grainSize: number;\r\n u_type: (typeof HalftoneDotsTypes)[HalftoneDotsType];\r\n}\r\n\r\nexport interface HalftoneDotsParams extends ShaderSizingParams, ShaderMotionParams {\r\n image?: HTMLImageElement | string;\r\n colorFront?: string;\r\n colorBack?: string;\r\n size?: number;\r\n grid?: HalftoneDotsGrid;\r\n radius?: number;\r\n contrast?: number;\r\n originalColors?: boolean;\r\n inverted?: boolean;\r\n grainMixer?: number;\r\n grainOverlay?: number;\r\n grainSize?: number;\r\n type?: HalftoneDotsType;\r\n}\r\n\r\nexport const HalftoneDotsTypes = {\r\n classic: 0,\r\n gooey: 1,\r\n holes: 2,\r\n soft: 3,\r\n} as const;\r\n\r\nexport type HalftoneDotsType = keyof typeof HalftoneDotsTypes;\r\n\r\nexport const HalftoneDotsGrids = {\r\n square: 0,\r\n hex: 1,\r\n} as const;\r\n\r\nexport type HalftoneDotsGrid = keyof typeof HalftoneDotsGrids;\r\n"],
5
+ "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,WAAW,wBAAwB;AAuChD,MAAM,6BAAqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwB/C,SAAU;AAAA,EACV,SAAU;AAAA,EACV,gBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiTb,MAAM,oBAAoB;AAAA,EAC/B,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AACR;AAIO,MAAM,oBAAoB;AAAA,EAC/B,QAAQ;AAAA,EACR,KAAK;AACP;",
6
+ "names": []
7
+ }
@@ -0,0 +1,66 @@
1
+ import type { vec4 } from '../types.js';
2
+ import type { ShaderMotionParams } from '../shader-mount.js';
3
+ import type { ShaderSizingParams, ShaderSizingUniforms } from '../shader-sizing.js';
4
+ export declare const heatmapMeta: {
5
+ readonly maxColorCount: 10;
6
+ };
7
+ /**
8
+ * A glowing gradient of colors flowing through an input shape.
9
+ * The effect creates a smoothly animated wave of intensity across the image.
10
+ *
11
+ * Fragment shader uniforms:
12
+ * - u_time (float): Animation time
13
+ * - u_image (sampler2D): Pre-processed source image texture (R = contour, G = outer blur, B = inner blur)
14
+ * - u_colorBack (vec4): Background color in RGBA
15
+ * - u_colors (vec4[]): Up to 10 heatmap colors in RGBA
16
+ * - u_colorsCount (float): Number of active colors
17
+ * - u_contour (float): Heat intensity near the edges of the input shape (0 to 1)
18
+ * - u_angle (float): Direction of the heatwaves in degrees, needs innerGlow or outerGlow > 0 (0 to 360)
19
+ * - u_noise (float): Grain applied across the entire graphic (0 to 1)
20
+ * - u_innerGlow (float): Size of the heated area inside the input shape (0 to 1)
21
+ * - u_outerGlow (float): Size of the heated area outside the input shape (0 to 1)
22
+ *
23
+ * Vertex shader outputs (used in fragment shader):
24
+ * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied
25
+ * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, etc) applied
26
+ *
27
+ * Vertex shader uniforms:
28
+ * - u_resolution (vec2): Canvas resolution in pixels
29
+ * - u_pixelRatio (float): Device pixel ratio
30
+ * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
31
+ * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
32
+ * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas
33
+ * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas
34
+ * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
35
+ * - u_scale (float): Overall zoom level of the graphics (0.1 to 4)
36
+ * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
37
+ * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
38
+ * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
39
+ * - u_imageAspectRatio (float): Aspect ratio of the source image
40
+ *
41
+ */
42
+ export declare const heatmapFragmentShader: string;
43
+ export declare function toProcessedHeatmap(file: File | string): Promise<{
44
+ blob: Blob;
45
+ }>;
46
+ export interface HeatmapUniforms extends ShaderSizingUniforms {
47
+ u_image: HTMLImageElement | string;
48
+ u_contour: number;
49
+ u_angle: number;
50
+ u_noise: number;
51
+ u_innerGlow: number;
52
+ u_outerGlow: number;
53
+ u_colorBack: [number, number, number, number];
54
+ u_colors: vec4[];
55
+ u_colorsCount: number;
56
+ }
57
+ export interface HeatmapParams extends ShaderSizingParams, ShaderMotionParams {
58
+ image: HTMLImageElement | string;
59
+ contour?: number;
60
+ angle?: number;
61
+ noise?: number;
62
+ innerGlow?: number;
63
+ outerGlow?: number;
64
+ colorBack?: string;
65
+ colors?: string[];
66
+ }