@paper-design/shaders 0.0.32 → 0.0.34

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 (77) hide show
  1. package/dist/get-shader-color-from-string.js +93 -0
  2. package/dist/get-shader-color-from-string.js.map +7 -0
  3. package/dist/get-shader-noise-texture.js +23 -0
  4. package/dist/get-shader-noise-texture.js.map +7 -0
  5. package/dist/index.d.ts +25 -23
  6. package/dist/index.js +118 -0
  7. package/dist/index.js.map +7 -0
  8. package/dist/shader-color-spaces.js +96 -0
  9. package/dist/shader-color-spaces.js.map +7 -0
  10. package/dist/shader-mount.d.ts +3 -0
  11. package/dist/shader-mount.js +593 -0
  12. package/dist/shader-mount.js.map +7 -0
  13. package/dist/shader-sizing.js +193 -0
  14. package/dist/shader-sizing.js.map +7 -0
  15. package/dist/shader-utils.d.ts +1 -0
  16. package/dist/shader-utils.js +74 -0
  17. package/dist/shader-utils.js.map +7 -0
  18. package/dist/shaders/color-panels.d.ts +47 -0
  19. package/dist/shaders/color-panels.js +210 -0
  20. package/dist/shaders/color-panels.js.map +7 -0
  21. package/dist/shaders/dithering.d.ts +24 -29
  22. package/dist/shaders/dithering.js +221 -0
  23. package/dist/shaders/dithering.js.map +7 -0
  24. package/dist/shaders/dot-grid.d.ts +16 -14
  25. package/dist/shaders/dot-grid.js +108 -0
  26. package/dist/shaders/dot-grid.js.map +7 -0
  27. package/dist/shaders/dot-orbit.d.ts +14 -13
  28. package/dist/shaders/dot-orbit.js +124 -0
  29. package/dist/shaders/dot-orbit.js.map +7 -0
  30. package/dist/shaders/god-rays.d.ts +18 -19
  31. package/dist/shaders/god-rays.js +118 -0
  32. package/dist/shaders/god-rays.js.map +7 -0
  33. package/dist/shaders/grain-gradient.d.ts +24 -4
  34. package/dist/shaders/grain-gradient.js +226 -0
  35. package/dist/shaders/grain-gradient.js.map +7 -0
  36. package/dist/shaders/liquid-metal.d.ts +44 -12
  37. package/dist/shaders/liquid-metal.js +221 -0
  38. package/dist/shaders/liquid-metal.js.map +7 -0
  39. package/dist/shaders/mesh-gradient.d.ts +10 -10
  40. package/dist/shaders/mesh-gradient.js +97 -0
  41. package/dist/shaders/mesh-gradient.js.map +7 -0
  42. package/dist/shaders/metaballs.d.ts +13 -10
  43. package/dist/shaders/metaballs.js +110 -0
  44. package/dist/shaders/metaballs.js.map +7 -0
  45. package/dist/shaders/neuro-noise.d.ts +13 -9
  46. package/dist/shaders/neuro-noise.js +81 -0
  47. package/dist/shaders/neuro-noise.js.map +7 -0
  48. package/dist/shaders/perlin-noise.d.ts +15 -19
  49. package/dist/shaders/perlin-noise.js +201 -0
  50. package/dist/shaders/perlin-noise.js.map +7 -0
  51. package/dist/shaders/pulsing-border.d.ts +17 -18
  52. package/dist/shaders/pulsing-border.js +211 -0
  53. package/dist/shaders/pulsing-border.js.map +7 -0
  54. package/dist/shaders/simplex-noise.d.ts +10 -12
  55. package/dist/shaders/simplex-noise.js +103 -0
  56. package/dist/shaders/simplex-noise.js.map +7 -0
  57. package/dist/shaders/smoke-ring.d.ts +11 -14
  58. package/dist/shaders/smoke-ring.js +124 -0
  59. package/dist/shaders/smoke-ring.js.map +7 -0
  60. package/dist/shaders/spiral.d.ts +16 -22
  61. package/dist/shaders/spiral.js +84 -0
  62. package/dist/shaders/spiral.js.map +7 -0
  63. package/dist/shaders/swirl.d.ts +15 -3
  64. package/dist/shaders/swirl.js +89 -0
  65. package/dist/shaders/swirl.js.map +7 -0
  66. package/dist/shaders/voronoi.d.ts +20 -20
  67. package/dist/shaders/voronoi.js +143 -0
  68. package/dist/shaders/voronoi.js.map +7 -0
  69. package/dist/shaders/warp.d.ts +15 -17
  70. package/dist/shaders/warp.js +108 -0
  71. package/dist/shaders/warp.js.map +7 -0
  72. package/dist/shaders/waves.d.ts +18 -21
  73. package/dist/shaders/waves.js +68 -0
  74. package/dist/shaders/waves.js.map +7 -0
  75. package/dist/types.js +6 -0
  76. package/dist/types.js.map +7 -0
  77. package/package.json +2 -2
@@ -0,0 +1,210 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing.js";
7
+ import { declarePI, colorBandingFix } from "../shader-utils.js";
8
+ const colorPanelsMeta = {
9
+ maxColorCount: 7
10
+ };
11
+ const colorPanelsFragmentShader = `#version 300 es
12
+ precision lowp float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform vec4 u_colors[${colorPanelsMeta.maxColorCount}];
17
+ uniform float u_colorsCount;
18
+ uniform vec4 u_colorBack;
19
+ uniform float u_density;
20
+ uniform float u_angle1;
21
+ uniform float u_angle2;
22
+ uniform float u_length;
23
+ uniform float u_blur;
24
+ uniform float u_fadeIn;
25
+ uniform float u_fadeOut;
26
+ uniform float u_gradient;
27
+
28
+ ${sizingVariablesDeclaration}
29
+
30
+ out vec4 fragColor;
31
+
32
+ ${declarePI}
33
+
34
+ vec2 getPanel(float angle, vec2 uv, float invLength) {
35
+ float sinA = sin(angle);
36
+ float cosA = cos(angle);
37
+
38
+ float denom = sinA - uv.y * cosA;
39
+ if (abs(denom) < 1e-5) return vec2(0.);
40
+
41
+ float z = uv.y / denom;
42
+ float zLimit = 0.5;
43
+
44
+ if (z < 0. || z > zLimit) return vec2(0.);
45
+
46
+ float zRatio = z / zLimit;
47
+ float panelMap = 1.0 - zRatio;
48
+ float x = uv.x * (cosA * z + 1.) * invLength;
49
+
50
+ float zOffset = zRatio - .5;
51
+ float left = -.5 + zOffset * u_angle1;
52
+ float right = .5 - zOffset * u_angle2;
53
+
54
+ float blurFactor = (1. - panelMap) * clamp((abs(angle / TWO_PI - .5) - .01) / (-.01), 0., 1.);;
55
+ float blurX = .15 * blurFactor + panelMap * u_blur;
56
+
57
+ float leftEdge1 = left - .5 * blurX;
58
+ float leftEdge2 = left + blurX;
59
+ float rightEdge1 = right - blurX;
60
+ float rightEdge2 = right + .5 * blurX;
61
+
62
+ float panel = smoothstep(leftEdge1, leftEdge2, x) * (1.0 - smoothstep(rightEdge1, rightEdge2, x));
63
+
64
+ return vec2(panel, clamp(panelMap, 0., 1.));
65
+ }
66
+
67
+ vec4 blendColor(vec4 colorA, float panelMask, float panelMap) {
68
+ float fade = smoothstep(-.2 * (1. - u_fadeOut), u_fadeOut, panelMap)
69
+ * (1. - smoothstep(1. - u_fadeIn, 1., panelMap));
70
+
71
+ vec3 blendedRGB = mix(vec3(0.), colorA.rgb, fade);
72
+ float blendedAlpha = mix(0., colorA.a, fade);
73
+
74
+ return vec4(blendedRGB, blendedAlpha) * panelMask;
75
+ }
76
+
77
+ void main() {
78
+ vec2 uv = v_objectUV;
79
+ uv *= 1.25;
80
+
81
+ float t = .05 * u_time;
82
+ t = fract(t);
83
+ bool reverseTime = (t < 0.5);
84
+
85
+ vec3 color = vec3(0.);
86
+ float opacity = 0.;
87
+
88
+ int colorsCount = int(u_colorsCount);
89
+
90
+ vec4 premultipliedColors[${colorPanelsMeta.maxColorCount}];
91
+ for (int i = 0; i < ${colorPanelsMeta.maxColorCount}; i++) {
92
+ if (i >= colorsCount) break;
93
+ vec4 c = u_colors[i];
94
+ c.rgb *= c.a;
95
+ premultipliedColors[i] = c;
96
+ }
97
+
98
+ float invLength = 1.5 / (u_length + 0.001);
99
+
100
+ float totalColorWeight = 0.;
101
+ int panelsNumber = 12;
102
+
103
+ float densityNormalizer = 1.;
104
+ if (colorsCount == 4) {
105
+ panelsNumber = 16;
106
+ densityNormalizer = 1.34;
107
+ } else if (colorsCount == 5) {
108
+ panelsNumber = 20;
109
+ densityNormalizer = 1.67;
110
+ } else if (colorsCount == 7) {
111
+ panelsNumber = 14;
112
+ densityNormalizer = 1.17;
113
+ }
114
+
115
+ float fPanelsNumber = float(panelsNumber);
116
+
117
+ float totalPanelsShape = 0.;
118
+ float panelGrad = 1. - clamp(u_gradient, 0., 1.);
119
+
120
+ for (int set = 0; set < 2; set++) {
121
+ bool isForward = (set == 0 && !reverseTime) || (set == 1 && reverseTime);
122
+ if (!isForward) continue;
123
+
124
+ for (int i = 0; i <= 20; i++) {
125
+ if (i >= panelsNumber) break;
126
+
127
+ int idx = panelsNumber - 1 - i;
128
+
129
+ float offset = float(idx) / fPanelsNumber;
130
+ if (set == 1) {
131
+ offset += .5;
132
+ }
133
+
134
+ float densityFract = densityNormalizer * fract(t + offset);
135
+ float angleNorm = densityFract / u_density;
136
+ if (densityFract >= .5 || angleNorm >= .3) continue;
137
+
138
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
139
+ float smoothAngle = clamp((.3 - angleNorm) / .05, 0., 1.);
140
+ if (smoothDensity * smoothAngle < .001) continue;
141
+
142
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);
143
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
144
+ if (panelMask <= .001) continue;
145
+ float panelMap = panel[1];
146
+
147
+ int colorIdx = idx % colorsCount;
148
+ int nextColorIdx = (idx + 1) % colorsCount;
149
+
150
+ vec4 colorA = premultipliedColors[colorIdx];
151
+ vec4 colorB = premultipliedColors[nextColorIdx];
152
+
153
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
154
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
155
+ color = blended.rgb + color * (1. - blended.a);
156
+ opacity = blended.a + opacity * (1. - blended.a);
157
+ }
158
+
159
+
160
+ for (int i = 0; i <= 20; i++) {
161
+ if (i >= panelsNumber) break;
162
+
163
+ int idx = panelsNumber - 1 - i;
164
+
165
+ float offset = float(idx) / fPanelsNumber;
166
+ if (set == 0) {
167
+ offset += .5;
168
+ }
169
+
170
+ float densityFract = densityNormalizer * fract(-t + offset);
171
+ float angleNorm = -densityFract / u_density;
172
+ if (densityFract >= .5 || angleNorm < -.3) continue;
173
+
174
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
175
+ float smoothAngle = clamp((angleNorm + .3) / .05, 0., 1.);
176
+ if (smoothDensity * smoothAngle < .001) continue;
177
+
178
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);
179
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
180
+ if (panelMask <= .001) continue;
181
+ float panelMap = panel[1];
182
+
183
+ int colorIdx = (colorsCount - (idx % colorsCount)) % colorsCount;
184
+ if (colorIdx < 0) colorIdx += colorsCount;
185
+ int nextColorIdx = (colorIdx + 1) % colorsCount;
186
+
187
+ vec4 colorA = premultipliedColors[colorIdx];
188
+ vec4 colorB = premultipliedColors[nextColorIdx];
189
+
190
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
191
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
192
+ color = blended.rgb + color * (1. - blended.a);
193
+ opacity = blended.a + opacity * (1. - blended.a);
194
+ }
195
+ }
196
+
197
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
198
+ color = color + bgColor * (1.0 - opacity);
199
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
200
+
201
+ ${colorBandingFix}
202
+
203
+ fragColor = vec4(color, opacity);
204
+ }
205
+ `;
206
+ export {
207
+ colorPanelsFragmentShader,
208
+ colorPanelsMeta
209
+ };
210
+ //# sourceMappingURL=color-panels.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/color-panels.ts"],
4
+ "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, colorBandingFix } from '../shader-utils.js';\n\nexport const colorPanelsMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Pseudo-3D panels rotating around a central axis\n *\n * Uniforms include:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_density: angle between every 2 panels\n * - u_angle1, u_angle2: skew angle applied to all panes\n * - u_length: panel length (relative to total height)\n * - u_blur: side blur (0 for sharp edges)\n * - u_fadeIn: transparency near central axis\n * - u_fadeOut: transparency near viewer\n * - u_gradient: color mixing within panes (0 = single color, 1 = two colors)\n *\n */\n\nexport const colorPanelsFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform float u_time;\n\nuniform vec4 u_colors[${colorPanelsMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform vec4 u_colorBack;\nuniform float u_density;\nuniform float u_angle1;\nuniform float u_angle2;\nuniform float u_length;\nuniform float u_blur;\nuniform float u_fadeIn;\nuniform float u_fadeOut;\nuniform float u_gradient;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 getPanel(float angle, vec2 uv, float invLength) {\n float sinA = sin(angle);\n float cosA = cos(angle);\n\n float denom = sinA - uv.y * cosA;\n if (abs(denom) < 1e-5) return vec2(0.);\n\n float z = uv.y / denom;\n float zLimit = 0.5;\n\n if (z < 0. || z > zLimit) return vec2(0.);\n\n float zRatio = z / zLimit;\n float panelMap = 1.0 - zRatio;\n float x = uv.x * (cosA * z + 1.) * invLength;\n\n float zOffset = zRatio - .5;\n float left = -.5 + zOffset * u_angle1;\n float right = .5 - zOffset * u_angle2;\n\n float blurFactor = (1. - panelMap) * clamp((abs(angle / TWO_PI - .5) - .01) / (-.01), 0., 1.);;\n float blurX = .15 * blurFactor + panelMap * u_blur;\n\n float leftEdge1 = left - .5 * blurX;\n float leftEdge2 = left + blurX;\n float rightEdge1 = right - blurX;\n float rightEdge2 = right + .5 * blurX;\n\n float panel = smoothstep(leftEdge1, leftEdge2, x) * (1.0 - smoothstep(rightEdge1, rightEdge2, x));\n\n return vec2(panel, clamp(panelMap, 0., 1.));\n}\n\nvec4 blendColor(vec4 colorA, float panelMask, float panelMap) {\n float fade = smoothstep(-.2 * (1. - u_fadeOut), u_fadeOut, panelMap)\n * (1. - smoothstep(1. - u_fadeIn, 1., panelMap));\n\n vec3 blendedRGB = mix(vec3(0.), colorA.rgb, fade);\n float blendedAlpha = mix(0., colorA.a, fade);\n\n return vec4(blendedRGB, blendedAlpha) * panelMask;\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv *= 1.25;\n\n float t = .05 * u_time;\n t = fract(t);\n bool reverseTime = (t < 0.5);\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n\n int colorsCount = int(u_colorsCount);\n\n vec4 premultipliedColors[${colorPanelsMeta.maxColorCount}];\n for (int i = 0; i < ${colorPanelsMeta.maxColorCount}; i++) {\n if (i >= colorsCount) break;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n premultipliedColors[i] = c;\n }\n\n float invLength = 1.5 / (u_length + 0.001);\n\n float totalColorWeight = 0.;\n int panelsNumber = 12;\n\n float densityNormalizer = 1.;\n if (colorsCount == 4) {\n panelsNumber = 16;\n densityNormalizer = 1.34;\n } else if (colorsCount == 5) {\n panelsNumber = 20;\n densityNormalizer = 1.67;\n } else if (colorsCount == 7) {\n panelsNumber = 14;\n densityNormalizer = 1.17;\n }\n\n float fPanelsNumber = float(panelsNumber);\n\n float totalPanelsShape = 0.;\n float panelGrad = 1. - clamp(u_gradient, 0., 1.);\n\n for (int set = 0; set < 2; set++) {\n bool isForward = (set == 0 && !reverseTime) || (set == 1 && reverseTime);\n if (!isForward) continue;\n\n for (int i = 0; i <= 20; i++) {\n if (i >= panelsNumber) break;\n\n int idx = panelsNumber - 1 - i;\n\n float offset = float(idx) / fPanelsNumber;\n if (set == 1) {\n offset += .5;\n }\n\n float densityFract = densityNormalizer * fract(t + offset);\n float angleNorm = densityFract / u_density;\n if (densityFract >= .5 || angleNorm >= .3) continue;\n\n float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);\n float smoothAngle = clamp((.3 - angleNorm) / .05, 0., 1.);\n if (smoothDensity * smoothAngle < .001) continue;\n\n vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);\n float panelMask = panel[0] * smoothDensity * smoothAngle;\n if (panelMask <= .001) continue;\n float panelMap = panel[1];\n\n int colorIdx = idx % colorsCount;\n int nextColorIdx = (idx + 1) % colorsCount;\n\n vec4 colorA = premultipliedColors[colorIdx];\n vec4 colorB = premultipliedColors[nextColorIdx];\n\n colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));\n vec4 blended = blendColor(colorA, panelMask, panelMap);\n color = blended.rgb + color * (1. - blended.a);\n opacity = blended.a + opacity * (1. - blended.a);\n }\n\n\n for (int i = 0; i <= 20; i++) {\n if (i >= panelsNumber) break;\n\n int idx = panelsNumber - 1 - i;\n\n float offset = float(idx) / fPanelsNumber;\n if (set == 0) {\n offset += .5;\n }\n\n float densityFract = densityNormalizer * fract(-t + offset);\n float angleNorm = -densityFract / u_density;\n if (densityFract >= .5 || angleNorm < -.3) continue;\n\n float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);\n float smoothAngle = clamp((angleNorm + .3) / .05, 0., 1.);\n if (smoothDensity * smoothAngle < .001) continue;\n\n vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);\n float panelMask = panel[0] * smoothDensity * smoothAngle;\n if (panelMask <= .001) continue;\n float panelMap = panel[1];\n\n int colorIdx = (colorsCount - (idx % colorsCount)) % colorsCount;\n if (colorIdx < 0) colorIdx += colorsCount;\n int nextColorIdx = (colorIdx + 1) % colorsCount;\n\n vec4 colorA = premultipliedColors[colorIdx];\n vec4 colorB = premultipliedColors[nextColorIdx];\n\n colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));\n vec4 blended = blendColor(colorA, panelMask, panelMap);\n color = blended.rgb + color * (1. - blended.a);\n opacity = blended.a + opacity * (1. - blended.a);\n }\n }\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1.0 - opacity);\n opacity = opacity + u_colorBack.a * (1.0 - opacity);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface ColorPanelsUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_colorBack: [number, number, number, number];\n u_angle1: number;\n u_angle2: number;\n u_length: number;\n u_blur: number;\n u_fadeIn: number;\n u_fadeOut: number;\n u_density: number;\n u_gradient: number;\n}\n\nexport interface ColorPanelsParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n colorBack?: string;\n angle1?: number;\n angle2?: number;\n length?: number;\n blur?: number;\n fadeIn?: number;\n fadeOut?: number;\n density?: number;\n gradient?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,uBAAuB;AAEpC,MAAM,kBAAkB;AAAA,EAC7B,eAAe;AACjB;AAkBO,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA,wBAKzB,gBAAgB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYnD,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,6BA0DkB,gBAAgB,aAAa;AAAA,wBAClC,gBAAgB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA8GjD,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,43 +1,38 @@
1
- import type { ShaderMotionParams } from '../shader-mount';
2
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import type { ShaderMotionParams } from '../shader-mount.js';
2
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
3
3
  /**
4
- * Dithering Fragment Shader by Ksenia Kondrashova
5
- * Applies dithering (4 dithering types available) over the
6
- * abstract shapes animation (7 animated shapes available)
4
+ * 2-color dithering effect over animated abstract shapes
7
5
  *
8
- * Uniforms include:
9
- * - u_color1: background color, RGBA
10
- * - u_color2: pixels color, RGBA
11
- *
12
- * - u_shape (float, used as int, 1 to 7):
13
- * --- shape = 1: Simplex noise pattern
14
- * --- shape = 2: Warp noise pattern
15
- * --- shape = 3: Columns if dots moving vertically
16
- * --- shape = 4: Sine wave
17
- * --- shape = 5: Ripple effect
18
- * --- shape = 6: Swirl animation
19
- * --- shape = 7: Rotating sphere
20
- *
21
- * - u_type (float, used as int, 1 to 4):
22
- * --- type = 1: Random dithering
23
- * --- type = 2: 2x2 Bayer matrix
24
- * --- type = 3: 4x4 Bayer matrix
25
- * --- type = 4: 8x8 Bayer matrix
26
- *
27
- * - pxSize (float), relative to canvas resolution
6
+ * Uniforms:
7
+ * - u_colorBack, u_colorFront (RGBA)
8
+ * - pxSize: px size relative to canvas resolution
9
+ * - u_shape (float used as integer):
10
+ * ---- 1: simplex noise pattern
11
+ * ---- 2: warp noise pattern
12
+ * ---- 3: columns if dots moving vertically
13
+ * ---- 4: sine wave
14
+ * ---- 5: ripple effect
15
+ * ---- 6: swirl animation
16
+ * ---- 7: rotating sphere
17
+ * - u_type (float used as integer)
18
+ * ---- 1: random dithering
19
+ * ---- 2: 2x2 Bayer matrix
20
+ * ---- 3: 4x4 Bayer matrix
21
+ * ---- 4: 8x8 Bayer matrix
28
22
  *
23
+ * Note: pixelization is applied to the shapes BEFORE dithering, meaning pixels don't react to scaling and fit
29
24
  */
30
25
  export declare const ditheringFragmentShader: string;
31
26
  export interface DitheringUniforms extends ShaderSizingUniforms {
32
- u_color1: [number, number, number, number];
33
- u_color2: [number, number, number, number];
27
+ u_colorBack: [number, number, number, number];
28
+ u_colorFront: [number, number, number, number];
34
29
  u_shape: (typeof DitheringShapes)[DitheringShape];
35
30
  u_type: (typeof DitheringTypes)[DitheringType];
36
31
  u_pxSize: number;
37
32
  }
38
33
  export interface DitheringParams extends ShaderSizingParams, ShaderMotionParams {
39
- color1?: string;
40
- color2?: string;
34
+ colorBack?: string;
35
+ colorFront?: string;
41
36
  shape?: DitheringShape;
42
37
  type?: DitheringType;
43
38
  pxSize?: number;
@@ -0,0 +1,221 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import {
7
+ sizingUniformsDeclaration,
8
+ sizingUV,
9
+ drawSizingHelpers
10
+ } from "../shader-sizing.js";
11
+ import { declareSimplexNoise, declarePI, declareRandom } from "../shader-utils.js";
12
+ const ditheringFragmentShader = `#version 300 es
13
+ precision mediump float;
14
+
15
+ uniform float u_time;
16
+ uniform vec2 u_resolution;
17
+ uniform float u_pixelRatio;
18
+
19
+ ${sizingUniformsDeclaration}
20
+
21
+ uniform vec4 u_colorBack;
22
+ uniform vec4 u_colorFront;
23
+ uniform float u_shape;
24
+ uniform float u_type;
25
+ uniform float u_pxSize;
26
+
27
+ out vec4 fragColor;
28
+
29
+ ${declareSimplexNoise}
30
+ ${declarePI}
31
+ ${declareRandom}
32
+
33
+ float getSimplexNoise(vec2 uv, float t) {
34
+ float noise = .5 * snoise(uv - vec2(0., .3 * t));
35
+ noise += .5 * snoise(2. * uv + vec2(0., .32 * t));
36
+
37
+ return noise;
38
+ }
39
+
40
+ const int bayer2x2[4] = int[4](0, 2, 3, 1);
41
+ const int bayer4x4[16] = int[16](
42
+ 0, 8, 2, 10,
43
+ 12, 4, 14, 6,
44
+ 3, 11, 1, 9,
45
+ 15, 7, 13, 5
46
+ );
47
+
48
+ const int bayer8x8[64] = int[64](
49
+ 0, 32, 8, 40, 2, 34, 10, 42,
50
+ 48, 16, 56, 24, 50, 18, 58, 26,
51
+ 12, 44, 4, 36, 14, 46, 6, 38,
52
+ 60, 28, 52, 20, 62, 30, 54, 22,
53
+ 3, 35, 11, 43, 1, 33, 9, 41,
54
+ 51, 19, 59, 27, 49, 17, 57, 25,
55
+ 15, 47, 7, 39, 13, 45, 5, 37,
56
+ 63, 31, 55, 23, 61, 29, 53, 21
57
+ );
58
+
59
+ float getBayerValue(vec2 uv, int size) {
60
+ ivec2 pos = ivec2(mod(uv, float(size)));
61
+ int index = pos.y * size + pos.x;
62
+
63
+ if (size == 2) {
64
+ return float(bayer2x2[index]) / 4.0;
65
+ } else if (size == 4) {
66
+ return float(bayer4x4[index]) / 16.0;
67
+ } else if (size == 8) {
68
+ return float(bayer8x8[index]) / 64.0;
69
+ }
70
+ return 0.0;
71
+ }
72
+
73
+
74
+ void main() {
75
+ float t = .5 * u_time;
76
+
77
+ #define USE_PATTERN_SIZING
78
+ #define USE_OBJECT_SIZING
79
+ #define USE_PIXELIZATION
80
+ // #define ADD_HELPERS
81
+
82
+ ${sizingUV}
83
+
84
+ vec2 dithering_uv = pxSizeUv;
85
+ vec2 ditheringNoise_uv = uv;
86
+ vec2 shape_uv = objectUV;
87
+ if (u_shape < 3.5) {
88
+ shape_uv = patternUV;
89
+ }
90
+
91
+ float shape = 0.;
92
+ if (u_shape < 1.5) {
93
+ // Simplex noise
94
+ shape_uv *= .001;
95
+
96
+ shape = 0.5 + 0.5 * getSimplexNoise(shape_uv, t);
97
+ shape = smoothstep(0.3, 0.9, shape);
98
+
99
+ } else if (u_shape < 2.5) {
100
+ // Warp
101
+ shape_uv *= .003;
102
+
103
+ for (float i = 1.0; i < 6.0; i++) {
104
+ shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);
105
+ shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);
106
+ }
107
+
108
+ shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));
109
+ shape = smoothstep(0.02, 1., shape);
110
+
111
+ } else if (u_shape < 3.5) {
112
+ // Dots
113
+ shape_uv *= .05;
114
+
115
+ float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
116
+ float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);
117
+
118
+ float speed = sign(rand - .5) * ceil(2. + rand);
119
+ shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
120
+ shape = pow(shape, 6.);
121
+
122
+ } else if (u_shape < 4.5) {
123
+ // Sine wave
124
+ shape_uv *= 4.;
125
+
126
+ float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));
127
+ shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
128
+
129
+ } else if (u_shape < 5.5) {
130
+ // Ripple
131
+
132
+ float dist = length(shape_uv);
133
+ float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;
134
+ shape = waves;
135
+
136
+ } else if (u_shape < 6.5) {
137
+ // Swirl
138
+
139
+ float l = length(shape_uv);
140
+ float angle = 6. * atan(shape_uv.y, shape_uv.x) + 4. * t;
141
+ float twist = 1.2;
142
+ float offset = pow(l, -twist) + angle / TWO_PI;
143
+ float mid = smoothstep(0., 1., pow(l, twist));
144
+ shape = mix(0., fract(offset), mid);
145
+
146
+ } else {
147
+ // Sphere
148
+ shape_uv *= 2.;
149
+
150
+ vec3 pos = vec3(shape_uv, sqrt(1. - pow(length(shape_uv), 2.)));
151
+ vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
152
+ shape = .5 + .5 * dot(lightPos, pos);
153
+ }
154
+
155
+
156
+ int type = int(floor(u_type));
157
+ float dithering = 0.0;
158
+
159
+ switch (type) {
160
+ case 1: {
161
+ dithering = step(random(ditheringNoise_uv), shape);
162
+ } break;
163
+ case 2:
164
+ dithering = getBayerValue(dithering_uv, 2);
165
+ break;
166
+ case 3:
167
+ dithering = getBayerValue(dithering_uv, 4);
168
+ break;
169
+ default:
170
+ dithering = getBayerValue(dithering_uv, 8);
171
+ break;
172
+ }
173
+
174
+ dithering -= .5;
175
+ float res = step(.5, shape + dithering);
176
+
177
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
178
+ float fgOpacity = u_colorFront.a;
179
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
180
+ float bgOpacity = u_colorBack.a;
181
+
182
+ vec3 color = fgColor * res;
183
+ float opacity = fgOpacity * res;
184
+
185
+ color += bgColor * (1. - opacity);
186
+ opacity += bgOpacity * (1. - opacity);
187
+
188
+ #ifdef ADD_HELPERS
189
+ vec2 helperBox = objectHelperBox;
190
+ vec2 boxSize = objectBoxSize;
191
+ if (u_shape < 3.5) {
192
+ helperBox = patternHelperBox;
193
+ boxSize = patternBoxSize;
194
+ }
195
+ ${drawSizingHelpers}
196
+ #endif
197
+
198
+ fragColor = vec4(color, opacity);
199
+ }
200
+ `;
201
+ const DitheringShapes = {
202
+ simplex: 1,
203
+ warp: 2,
204
+ dots: 3,
205
+ wave: 4,
206
+ ripple: 5,
207
+ swirl: 6,
208
+ sphere: 7
209
+ };
210
+ const DitheringTypes = {
211
+ "random": 1,
212
+ "2x2": 2,
213
+ "4x4": 3,
214
+ "8x8": 4
215
+ };
216
+ export {
217
+ DitheringShapes,
218
+ DitheringTypes,
219
+ ditheringFragmentShader
220
+ };
221
+ //# sourceMappingURL=dithering.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/dithering.ts"],
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n sizingUV,\n drawSizingHelpers,\n} from '../shader-sizing.js';\nimport { declareSimplexNoise, declarePI, declareRandom } from '../shader-utils.js';\n\n/**\n * 2-color dithering effect over animated abstract shapes\n *\n * Uniforms:\n * - u_colorBack, u_colorFront (RGBA)\n * - pxSize: px size relative to canvas resolution\n * - u_shape (float used as integer):\n * ---- 1: simplex noise pattern\n * ---- 2: warp noise pattern\n * ---- 3: columns if dots moving vertically\n * ---- 4: sine wave\n * ---- 5: ripple effect\n * ---- 6: swirl animation\n * ---- 7: rotating sphere\n * - u_type (float used as integer)\n * ---- 1: random dithering\n * ---- 2: 2x2 Bayer matrix\n * ---- 3: 4x4 Bayer matrix\n * ---- 4: 8x8 Bayer matrix\n *\n * Note: pixelization is applied to the shapes BEFORE dithering, meaning pixels don't react to scaling and fit\n */\n\nexport const ditheringFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\n${sizingUniformsDeclaration}\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFront;\nuniform float u_shape;\nuniform float u_type;\nuniform float u_pxSize;\n\nout vec4 fragColor;\n\n${declareSimplexNoise}\n${declarePI}\n${declareRandom}\n\nfloat getSimplexNoise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nconst int bayer2x2[4] = int[4](0, 2, 3, 1);\nconst int bayer4x4[16] = int[16](\n 0, 8, 2, 10,\n 12, 4, 14, 6,\n 3, 11, 1, 9,\n 15, 7, 13, 5\n);\n\nconst int bayer8x8[64] = int[64](\n 0, 32, 8, 40, 2, 34, 10, 42,\n 48, 16, 56, 24, 50, 18, 58, 26,\n 12, 44, 4, 36, 14, 46, 6, 38,\n 60, 28, 52, 20, 62, 30, 54, 22,\n 3, 35, 11, 43, 1, 33, 9, 41,\n 51, 19, 59, 27, 49, 17, 57, 25,\n 15, 47, 7, 39, 13, 45, 5, 37,\n 63, 31, 55, 23, 61, 29, 53, 21\n);\n\nfloat getBayerValue(vec2 uv, int size) {\n ivec2 pos = ivec2(mod(uv, float(size)));\n int index = pos.y * size + pos.x;\n\n if (size == 2) {\n return float(bayer2x2[index]) / 4.0;\n } else if (size == 4) {\n return float(bayer4x4[index]) / 16.0;\n } else if (size == 8) {\n return float(bayer8x8[index]) / 64.0;\n }\n return 0.0;\n}\n\n\nvoid main() {\n float t = .5 * u_time;\n\n #define USE_PATTERN_SIZING\n #define USE_OBJECT_SIZING\n #define USE_PIXELIZATION\n // #define ADD_HELPERS\n\n ${sizingUV}\n\n vec2 dithering_uv = pxSizeUv;\n vec2 ditheringNoise_uv = uv;\n vec2 shape_uv = objectUV;\n if (u_shape < 3.5) {\n shape_uv = patternUV;\n }\n\n float shape = 0.;\n if (u_shape < 1.5) {\n // Simplex noise\n shape_uv *= .001;\n\n shape = 0.5 + 0.5 * getSimplexNoise(shape_uv, t);\n shape = smoothstep(0.3, 0.9, shape);\n\n } else if (u_shape < 2.5) {\n // Warp\n shape_uv *= .003;\n\n for (float i = 1.0; i < 6.0; i++) {\n shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);\n shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);\n }\n\n shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));\n shape = smoothstep(0.02, 1., shape);\n\n } else if (u_shape < 3.5) {\n // Dots\n shape_uv *= .05;\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, 6.);\n\n } else if (u_shape < 4.5) {\n // Sine wave\n shape_uv *= 4.;\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 < 5.5) {\n // Ripple\n\n float dist = length(shape_uv);\n float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;\n shape = waves;\n\n } else if (u_shape < 6.5) {\n // Swirl\n\n float l = length(shape_uv);\n float angle = 6. * atan(shape_uv.y, shape_uv.x) + 4. * t;\n float twist = 1.2;\n float offset = pow(l, -twist) + angle / TWO_PI;\n float mid = smoothstep(0., 1., pow(l, twist));\n shape = mix(0., fract(offset), mid);\n\n } else {\n // Sphere\n shape_uv *= 2.;\n\n vec3 pos = vec3(shape_uv, sqrt(1. - pow(length(shape_uv), 2.)));\n vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));\n shape = .5 + .5 * dot(lightPos, pos);\n }\n\n\n int type = int(floor(u_type));\n float dithering = 0.0;\n\n switch (type) {\n case 1: {\n dithering = step(random(ditheringNoise_uv), shape);\n } break;\n case 2:\n dithering = getBayerValue(dithering_uv, 2);\n break;\n case 3:\n dithering = getBayerValue(dithering_uv, 4);\n break;\n default:\n dithering = getBayerValue(dithering_uv, 8);\n break;\n }\n\n dithering -= .5;\n float res = step(.5, shape + dithering);\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n #ifdef ADD_HELPERS\n vec2 helperBox = objectHelperBox;\n vec2 boxSize = objectBoxSize;\n if (u_shape < 3.5) {\n helperBox = patternHelperBox;\n boxSize = patternBoxSize;\n }\n ${drawSizingHelpers}\n #endif\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface DitheringUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_shape: (typeof DitheringShapes)[DitheringShape];\n u_type: (typeof DitheringTypes)[DitheringType];\n u_pxSize: number;\n}\n\nexport interface DitheringParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n shape?: DitheringShape;\n type?: DitheringType;\n pxSize?: number;\n}\n\nexport const DitheringShapes = {\n simplex: 1,\n warp: 2,\n dots: 3,\n wave: 4,\n ripple: 5,\n swirl: 6,\n sphere: 7,\n} as const;\n\nexport type DitheringShape = keyof typeof DitheringShapes;\n\nexport const DitheringTypes = {\n 'random': 1,\n '2x2': 2,\n '4x4': 3,\n '8x8': 4,\n} as const;\n\nexport type DitheringType = keyof typeof DitheringTypes;\n"],
5
+ "mappings": ";;;;;AACA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB,WAAW,qBAAqB;AAyBvD,MAAM,0BAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUzB,mBAAmB;AAAA,EACnB,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmDX,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAiHN,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBhB,MAAM,kBAAkB;AAAA,EAC7B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AACV;AAIO,MAAM,iBAAiB;AAAA,EAC5B,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,19 +1,21 @@
1
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
2
2
  /**
3
- * Dot Grid Pattern
4
- * (the size parameters are set in pixels)
3
+ * Static grid pattern
4
+ *
5
+ * Uniforms:
6
+ * - u_colorBack, u_colorFill, u_colorStroke (vec4 RGBA)
7
+ * - u_dotSize (px): base shape size
8
+ * - u_sizeRange (0..1): randomizes the size of shape between 0 and u_dotSize
9
+ * - u_strokeWidth (px): the stroke (to be added to u_dotSize)
10
+ * - u_gapX, u_gapY (px): pattern spacing
11
+ * - u_opacityRange (0..1): variety of shape opacity
12
+ * - u_shape (float used as integer):
13
+ * ---- 1: circle
14
+ * ---- 2: square
15
+ * ---- 3: triangle
16
+ * ---- 4: diamond
17
+ * ---- 5: cross
5
18
  *
6
- * Uniforms include:
7
- * u_colorBack - the background color
8
- * u_colorFill - the fill color
9
- * u_colorStroke - the stroke color
10
- * u_dotSize (px) - the base dot radius
11
- * u_strokeWidth (px) - the stroke (to be subtracted from u_dotSize)
12
- * u_gapX (px) - horizontal grid spacing
13
- * u_gapY (px) - vertical grid spacing
14
- * u_sizeRange (0 .. 1) - variety of dot size
15
- * u_opacityRange(0 .. 1) - variety of dot opacity to be applied equally to fill and stroke
16
- * u_shape - shape code (0 - circle, 1 - diamond, 2 - square, 3 - triangle)
17
19
  */
18
20
  export declare const dotGridFragmentShader: string;
19
21
  export interface DotGridUniforms extends ShaderSizingUniforms {
@@ -0,0 +1,108 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing.js";
7
+ import { declarePI, declareSimplexNoise } from "../shader-utils.js";
8
+ const dotGridFragmentShader = `#version 300 es
9
+ precision mediump float;
10
+
11
+ uniform vec4 u_colorBack;
12
+ uniform vec4 u_colorFill;
13
+ uniform vec4 u_colorStroke;
14
+ uniform float u_dotSize;
15
+ uniform float u_gapX;
16
+ uniform float u_gapY;
17
+ uniform float u_strokeWidth;
18
+ uniform float u_sizeRange;
19
+ uniform float u_opacityRange;
20
+ uniform float u_shape;
21
+
22
+ ${sizingVariablesDeclaration}
23
+
24
+ out vec4 fragColor;
25
+
26
+ ${declarePI}
27
+ ${declareSimplexNoise}
28
+
29
+ float polygon(vec2 p, float N, float rot) {
30
+ float a = atan(p.x, p.y) + rot;
31
+ float r = TWO_PI / float(N);
32
+
33
+ return cos(floor(.5 + a / r) * r - a) * length(p);
34
+ }
35
+
36
+ void main() {
37
+
38
+ vec2 shape_uv = v_patternUV;
39
+ shape_uv += .5;
40
+
41
+ vec2 grid = fract(shape_uv / vec2(u_gapX, u_gapY)) + 1e-4;
42
+ vec2 grid_idx = floor(shape_uv / vec2(u_gapX, u_gapY));
43
+ float sizeRandomizer = .5 + .8 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));
44
+ float opacity_randomizer = .5 + .7 * snoise(2. * vec2(grid_idx.y, grid_idx.x));
45
+
46
+ vec2 center = vec2(0.5) - 1e-3;
47
+ vec2 p = (grid - center) * vec2(u_gapX, u_gapY);
48
+
49
+ float baseSize = u_dotSize * (1. - sizeRandomizer * u_sizeRange);
50
+ float strokeWidth = u_strokeWidth * (1. - sizeRandomizer * u_sizeRange);
51
+
52
+ float dist;
53
+ if (u_shape < 0.5) {
54
+ // Circle
55
+ dist = length(p);
56
+ } else if (u_shape < 1.5) {
57
+ // Diamond
58
+ strokeWidth *= 1.5;
59
+ dist = polygon(1.5 * p, 4., .25 * PI);
60
+ } else if (u_shape < 2.5) {
61
+ // Square
62
+ dist = polygon(1.03 * p, 4., 1e-3);
63
+ } else {
64
+ // Triangle
65
+ strokeWidth *= 1.5;
66
+ p = p * 2. - 1.;
67
+ p *= .9;
68
+ p.y = 1. - p.y;
69
+ p.y -= .75 * baseSize;
70
+ dist = polygon(p, 3., 1e-3);
71
+ }
72
+
73
+ float edgeWidth = fwidth(dist);
74
+ float shapeOuter = smoothstep(baseSize + edgeWidth, baseSize - edgeWidth, dist - strokeWidth);
75
+ float shapeInner = smoothstep(baseSize + edgeWidth, baseSize - edgeWidth, dist);
76
+ float stroke = shapeOuter - shapeInner;
77
+
78
+ float dotOpacity = max(0., 1. - opacity_randomizer * u_opacityRange);
79
+ stroke *= dotOpacity;
80
+ shapeInner *= dotOpacity;
81
+
82
+ stroke *= u_colorStroke.a;
83
+ shapeInner *= u_colorFill.a;
84
+
85
+ vec3 color = vec3(0.);
86
+ color += stroke * u_colorStroke.rgb;
87
+ color += shapeInner * u_colorFill.rgb;
88
+ color += (1. - shapeInner - stroke) * u_colorBack.rgb * u_colorBack.a;
89
+
90
+ float opacity = 0.;
91
+ opacity += stroke;
92
+ opacity += shapeInner;
93
+ opacity += (1. - opacity) * u_colorBack.a;
94
+
95
+ fragColor = vec4(color, opacity);
96
+ }
97
+ `;
98
+ const DotGridShapes = {
99
+ circle: 0,
100
+ diamond: 1,
101
+ square: 2,
102
+ triangle: 3
103
+ };
104
+ export {
105
+ DotGridShapes,
106
+ dotGridFragmentShader
107
+ };
108
+ //# sourceMappingURL=dot-grid.js.map