@paper-design/shaders 0.0.32 → 0.0.33

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 (76) 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.js +582 -0
  11. package/dist/shader-mount.js.map +7 -0
  12. package/dist/shader-sizing.js +193 -0
  13. package/dist/shader-sizing.js.map +7 -0
  14. package/dist/shader-utils.d.ts +1 -0
  15. package/dist/shader-utils.js +74 -0
  16. package/dist/shader-utils.js.map +7 -0
  17. package/dist/shaders/color-panels.d.ts +47 -0
  18. package/dist/shaders/color-panels.js +210 -0
  19. package/dist/shaders/color-panels.js.map +7 -0
  20. package/dist/shaders/dithering.d.ts +24 -29
  21. package/dist/shaders/dithering.js +221 -0
  22. package/dist/shaders/dithering.js.map +7 -0
  23. package/dist/shaders/dot-grid.d.ts +16 -14
  24. package/dist/shaders/dot-grid.js +108 -0
  25. package/dist/shaders/dot-grid.js.map +7 -0
  26. package/dist/shaders/dot-orbit.d.ts +14 -13
  27. package/dist/shaders/dot-orbit.js +124 -0
  28. package/dist/shaders/dot-orbit.js.map +7 -0
  29. package/dist/shaders/god-rays.d.ts +18 -19
  30. package/dist/shaders/god-rays.js +118 -0
  31. package/dist/shaders/god-rays.js.map +7 -0
  32. package/dist/shaders/grain-gradient.d.ts +24 -4
  33. package/dist/shaders/grain-gradient.js +226 -0
  34. package/dist/shaders/grain-gradient.js.map +7 -0
  35. package/dist/shaders/liquid-metal.d.ts +44 -12
  36. package/dist/shaders/liquid-metal.js +221 -0
  37. package/dist/shaders/liquid-metal.js.map +7 -0
  38. package/dist/shaders/mesh-gradient.d.ts +10 -10
  39. package/dist/shaders/mesh-gradient.js +97 -0
  40. package/dist/shaders/mesh-gradient.js.map +7 -0
  41. package/dist/shaders/metaballs.d.ts +13 -10
  42. package/dist/shaders/metaballs.js +110 -0
  43. package/dist/shaders/metaballs.js.map +7 -0
  44. package/dist/shaders/neuro-noise.d.ts +13 -9
  45. package/dist/shaders/neuro-noise.js +81 -0
  46. package/dist/shaders/neuro-noise.js.map +7 -0
  47. package/dist/shaders/perlin-noise.d.ts +15 -19
  48. package/dist/shaders/perlin-noise.js +201 -0
  49. package/dist/shaders/perlin-noise.js.map +7 -0
  50. package/dist/shaders/pulsing-border.d.ts +17 -18
  51. package/dist/shaders/pulsing-border.js +211 -0
  52. package/dist/shaders/pulsing-border.js.map +7 -0
  53. package/dist/shaders/simplex-noise.d.ts +10 -12
  54. package/dist/shaders/simplex-noise.js +103 -0
  55. package/dist/shaders/simplex-noise.js.map +7 -0
  56. package/dist/shaders/smoke-ring.d.ts +11 -14
  57. package/dist/shaders/smoke-ring.js +124 -0
  58. package/dist/shaders/smoke-ring.js.map +7 -0
  59. package/dist/shaders/spiral.d.ts +16 -22
  60. package/dist/shaders/spiral.js +84 -0
  61. package/dist/shaders/spiral.js.map +7 -0
  62. package/dist/shaders/swirl.d.ts +15 -3
  63. package/dist/shaders/swirl.js +89 -0
  64. package/dist/shaders/swirl.js.map +7 -0
  65. package/dist/shaders/voronoi.d.ts +20 -20
  66. package/dist/shaders/voronoi.js +143 -0
  67. package/dist/shaders/voronoi.js.map +7 -0
  68. package/dist/shaders/warp.d.ts +15 -17
  69. package/dist/shaders/warp.js +108 -0
  70. package/dist/shaders/warp.js.map +7 -0
  71. package/dist/shaders/waves.d.ts +18 -21
  72. package/dist/shaders/waves.js +68 -0
  73. package/dist/shaders/waves.js.map +7 -0
  74. package/dist/types.js +6 -0
  75. package/dist/types.js.map +7 -0
  76. package/package.json +2 -2
@@ -1,44 +1,44 @@
1
- import type { vec4 } from '../types';
2
- import type { ShaderMotionParams } from '../shader-mount';
3
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import type { vec4 } from '../types.js';
2
+ import type { ShaderMotionParams } from '../shader-mount.js';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
4
4
  export declare const voronoiMeta: {
5
5
  readonly maxColorCount: 5;
6
6
  };
7
7
  /**
8
- * Voronoi pattern by Ksenia Kondrashova
9
- * The variation of Voronoi pattern with cell edges. Big thanks to Inigo Quilez
10
- * https://www.shadertoy.com/view/ldl3W8
8
+ * Double-pass Voronoi pattern cell edges
9
+ * Original algorithm: https://www.shadertoy.com/view/ldl3W8
11
10
  *
12
- * Uniforms include:
11
+ * Uniforms:
12
+ * - u_colorBack, u_colorGlow (RGBA)
13
+ * - u_colors (vec4[]), u_colorsCount (float used as integer)
14
+ * - u_stepsPerColor: discrete color steps between u_colors
15
+ * - u_distortion (0..0.5): max distance the cell center moves away from regular grid
16
+ * - u_gap: width of the stroke between the cells
17
+ * - u_glow: radial glow around each cell center
18
+ *
19
+ * - u_noiseTexture (sampler2D): pre-computed randomizer source
20
+ *
21
+ * Note: gaps can't be removed completely due to artifacts of Voronoi cells
13
22
  *
14
- * - `u_colors` (`vec4[]`): Array of RGBA colors used for cell filling
15
- * - `u_colorsCount` (`float`): Number of active colors in `u_colors`
16
- * - `u_colorBack` (`vec4`): RGBA color for the gaps between cells
17
- * - `u_colorGlow` (`vec4`): RGBA color for the radial shape on the cell edges
18
- * - `u_distortion` (`float`, 0 – 0.5): Controls how far cell centers can be displaced from the regular grid
19
- * - `u_gap` (`float`): Width of the gaps between cells (gaps can't be removed completely due to artifacts of Voronoi cells)
20
- * - `u_innerGlow` (`float`): Controls the size of the radial glow inside each cell
21
- * - `u_stepsPerColor` (`float`): Discretization of the color transition
22
- * - `u_noiseTexture` (`sampler2D`): Replacement of standard hash function, added for better performance
23
23
  */
24
24
  export declare const voronoiFragmentShader: string;
25
25
  export interface VoronoiUniforms extends ShaderSizingUniforms {
26
26
  u_colors: vec4[];
27
27
  u_colorsCount: number;
28
28
  u_stepsPerColor: number;
29
- u_colorBack: [number, number, number, number];
29
+ u_colorGap: [number, number, number, number];
30
30
  u_colorGlow: [number, number, number, number];
31
31
  u_distortion: number;
32
32
  u_gap: number;
33
- u_innerGlow: number;
33
+ u_glow: number;
34
34
  u_noiseTexture?: HTMLImageElement;
35
35
  }
36
36
  export interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {
37
37
  colors?: string[];
38
38
  stepsPerColor?: number;
39
- colorBack?: string;
39
+ colorGap?: string;
40
40
  colorGlow?: string;
41
41
  distortion?: number;
42
42
  gap?: number;
43
- innerGlow?: number;
43
+ glow?: number;
44
44
  }
@@ -0,0 +1,143 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing.js";
7
+ import { declarePI } from "../shader-utils.js";
8
+ const voronoiMeta = {
9
+ maxColorCount: 5
10
+ };
11
+ const voronoiFragmentShader = `#version 300 es
12
+ precision mediump float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform float u_scale;
17
+
18
+ uniform sampler2D u_noiseTexture;
19
+
20
+ uniform vec4 u_colors[${voronoiMeta.maxColorCount}];
21
+ uniform float u_colorsCount;
22
+
23
+ uniform float u_stepsPerColor;
24
+ uniform vec4 u_colorGlow;
25
+ uniform vec4 u_colorGap;
26
+ uniform float u_distortion;
27
+ uniform float u_gap;
28
+ uniform float u_glow;
29
+
30
+ ${sizingVariablesDeclaration}
31
+
32
+ out vec4 fragColor;
33
+
34
+ ${declarePI}
35
+
36
+ vec2 hash(vec2 p) {
37
+ vec2 uv = floor(p) / 100. + .5;
38
+ return texture(u_noiseTexture, uv).gb;
39
+ }
40
+
41
+ vec4 voronoi(vec2 x, float t) {
42
+ vec2 ip = floor(x);
43
+ vec2 fp = fract(x);
44
+
45
+ vec2 mg, mr;
46
+ float md = 8.;
47
+ float rand = 0.;
48
+
49
+ for (int j = -1; j <= 1; j++) {
50
+ for (int i = -1; i <= 1; i++) {
51
+ vec2 g = vec2(float(i), float(j));
52
+ vec2 raw_hash = hash(ip + g);
53
+ vec2 o = hash(ip + g);
54
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
55
+ vec2 r = g + o - fp;
56
+ float d = dot(r, r);
57
+
58
+ if (d < md) {
59
+ md = d;
60
+ mr = r;
61
+ mg = g;
62
+ rand = raw_hash.x;
63
+ }
64
+ }
65
+ }
66
+
67
+ md = 8.;
68
+ for (int j = -2; j <= 2; j++) {
69
+ for (int i = -2; i <= 2; i++) {
70
+ vec2 g = mg + vec2(float(i), float(j));
71
+ vec2 o = hash(ip + g);
72
+ o = .5 + u_distortion * sin(t + TWO_PI * o);
73
+ vec2 r = g + o - fp;
74
+ if (dot(mr - r, mr - r) > .00001) {
75
+ md = min(md, dot(.5 * (mr + r), normalize(r - mr)));
76
+ }
77
+ }
78
+ }
79
+
80
+ return vec4(md, mr, rand);
81
+ }
82
+
83
+ void main() {
84
+ vec2 shape_uv = v_patternUV;
85
+ shape_uv *= .0125;
86
+
87
+ float t = u_time;
88
+
89
+ vec4 voronoiRes = voronoi(shape_uv, t);
90
+
91
+ float shape = clamp(voronoiRes.w, 0., 1.);
92
+ float mixer = shape * (u_colorsCount - 1.);
93
+ mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
94
+ float steps = max(1., u_stepsPerColor);
95
+
96
+ vec4 gradient = u_colors[0];
97
+ gradient.rgb *= gradient.a;
98
+ for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {
99
+ if (i >= int(u_colorsCount)) break;
100
+ float localT = clamp(mixer - float(i - 1), 0.0, 1.0);
101
+ localT = round(localT * steps) / steps;
102
+ vec4 c = u_colors[i];
103
+ c.rgb *= c.a;
104
+ gradient = mix(gradient, c, localT);
105
+ }
106
+
107
+ if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {
108
+ float localT = mixer + 1.;
109
+ if (mixer > (u_colorsCount - 1.)) {
110
+ localT = mixer - (u_colorsCount - 1.);
111
+ }
112
+ localT = round(localT * steps) / steps;
113
+ vec4 cFst = u_colors[0];
114
+ cFst.rgb *= cFst.a;
115
+ vec4 cLast = u_colors[int(u_colorsCount - 1.)];
116
+ cLast.rgb *= cLast.a;
117
+ gradient = mix(cLast, cFst, localT);
118
+ }
119
+
120
+ vec3 cellColor = gradient.rgb;
121
+ float cellOpacity = gradient.a;
122
+
123
+ float glows = length(voronoiRes.yz * u_glow + .1);
124
+ glows = pow(glows, 1.5);
125
+
126
+ vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);
127
+ float opacity = cellOpacity + u_colorGlow.a * glows;
128
+
129
+ float edge = voronoiRes.x;
130
+ float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);
131
+ edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);
132
+
133
+ color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);
134
+ opacity = mix(u_colorGap.a, opacity, edge);
135
+
136
+ fragColor = vec4(color, opacity);
137
+ }
138
+ `;
139
+ export {
140
+ voronoiFragmentShader,
141
+ voronoiMeta
142
+ };
143
+ //# sourceMappingURL=voronoi.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/voronoi.ts"],
4
+ "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Double-pass Voronoi pattern cell edges\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms:\n * - u_colorBack, u_colorGlow (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_distortion (0..0.5): max distance the cell center moves away from regular grid\n * - u_gap: width of the stroke between the cells\n * - u_glow: radial glow around each cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: gaps can't be removed completely due to artifacts of Voronoi cells\n *\n */\n\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 hash(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, uv).gb;\n}\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 raw_hash = hash(ip + g);\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash.x;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .0125;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float glows = length(voronoiRes.yz * u_glow + .1);\n glows = pow(glows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);\n float opacity = cellOpacity + u_colorGlow.a * glows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);\n opacity = mix(u_colorGap.a, opacity, edge);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorGap: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_glow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorGap?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n glow?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,iBAAiB;AAEnB,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AAoBO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASrB,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAgEa,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,25 +1,23 @@
1
- import type { vec4 } from '../types';
2
- import type { ShaderMotionParams } from '../shader-mount';
3
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import type { vec4 } from '../types.js';
2
+ import type { ShaderMotionParams } from '../shader-mount.js';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
4
4
  export declare const warpMeta: {
5
5
  readonly maxColorCount: 10;
6
6
  };
7
7
  /**
8
- * 3d Perlin noise with exposed parameters
8
+ * Iterative layered + swirl-based distortion applied over different layouts (shapes)
9
9
  *
10
- * Uniforms include:
11
- * - u_colors (vec4[]): Input RGBA colors
12
- * - u_colorsCount (float): Number of active colors (`u_colors` length)
13
- * - u_proportion (0 .. 1): the proportion between colors (on 0.5 colors are equally distributed)
14
- * - u_softness (0 .. 1): the color blur (0 for pronounced edges, 1 for gradient)
15
- * - u_shape (0 ... 2): the color pattern to be distorted with noise & swirl
16
- * - u_shape = 0 is checks
17
- * - u_shape = 1 is stripes
18
- * - u_shape = 2 is 2 halves of canvas (mapping the canvas height regardless of resolution)
19
- * - u_shapeScale: the scale of color pattern (appies over the global scaling)
20
- * - u_distortion: the noisy distortion over the UV coordinate (applied before the overlapping swirl)
21
- * - u_swirl: the power of swirly distortion
22
- * - u_swirlIterations: the number of swirl iterations (layering curves effect)
10
+ * Uniforms:
11
+ * - u_colors (vec4[]), u_colorsCount (float used as integer)
12
+ * - u_proportion: (0..1) blend point between 2 colors (0.5 = equal distribution)
13
+ * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)
14
+ * - u_shape (float used as integer):
15
+ * ---- 0: checks
16
+ * ---- 1: stripes
17
+ * ---- 2: 2x halves of canvas (mapping the canvas height regardless of resolution)
18
+ * - u_shapeScale: the scale of layouts (underlying shapes)
19
+ * - u_distortion: value noise distortion over the UV coordinate
20
+ * - u_swirl, u_swirlIterations: swirly distortion (layering curves effect)
23
21
  *
24
22
  */
25
23
  export declare const warpFragmentShader: string;
@@ -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, declareRandom, declareValueNoise, declareRotate, colorBandingFix } from "../shader-utils.js";
8
+ const warpMeta = {
9
+ maxColorCount: 10
10
+ };
11
+ const warpFragmentShader = `#version 300 es
12
+ precision mediump float;
13
+
14
+ uniform float u_time;
15
+ uniform float u_scale;
16
+
17
+ uniform vec4 u_colors[${warpMeta.maxColorCount}];
18
+ uniform float u_colorsCount;
19
+ uniform float u_proportion;
20
+ uniform float u_softness;
21
+ uniform float u_shape;
22
+ uniform float u_shapeScale;
23
+ uniform float u_distortion;
24
+ uniform float u_swirl;
25
+ uniform float u_swirlIterations;
26
+
27
+ ${sizingVariablesDeclaration}
28
+
29
+ out vec4 fragColor;
30
+
31
+ ${declarePI}
32
+ ${declareRandom}
33
+ ${declareRotate}
34
+ ${declareValueNoise}
35
+
36
+
37
+ void main() {
38
+ vec2 uv = v_patternUV;
39
+ uv *= .005;
40
+
41
+ float t = .01 * u_time;
42
+
43
+ float n1 = valueNoise(uv * 1. + t);
44
+ float n2 = valueNoise(uv * 2. - t);
45
+ float angle = n1 * TWO_PI;
46
+ uv.x += 4. * u_distortion * n2 * cos(angle);
47
+ uv.y += 4. * u_distortion * n2 * sin(angle);
48
+
49
+ float iterationsNumber = ceil(clamp(u_swirlIterations, 1., 30.));
50
+ for (float i = 1.; i <= iterationsNumber; i++) {
51
+ uv.x += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1.5 * uv.y);
52
+ uv.y += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1. * uv.x);
53
+ }
54
+
55
+ float proportion = clamp(u_proportion, 0., 1.);
56
+
57
+ float shape = 0.;
58
+ if (u_shape < .5) {
59
+ vec2 checksShape_uv = uv * (.5 + 3.5 * u_shapeScale);
60
+ shape = .5 + .5 * sin(checksShape_uv.x) * cos(checksShape_uv.y);
61
+ shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
62
+ } else if (u_shape < 1.5) {
63
+ vec2 stripesShape_uv = uv * (2. * u_shapeScale);
64
+ float f = fract(stripesShape_uv.y);
65
+ shape = smoothstep(.0, .55, f) * smoothstep(1., .45, f);
66
+ shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
67
+ } else {
68
+ float shapeScaling = 5. * (1. - u_shapeScale);
69
+ shape = smoothstep(.45 - shapeScaling, .55 + shapeScaling, 1. - uv.y + .3 * (proportion - .5));
70
+ }
71
+
72
+ float mixer = shape * (u_colorsCount - 1.);
73
+ vec4 gradient = u_colors[0];
74
+ gradient.rgb *= gradient.a;
75
+ for (int i = 1; i < ${warpMeta.maxColorCount}; i++) {
76
+ if (i >= int(u_colorsCount)) break;
77
+ float localMixer = clamp(mixer - float(i - 1), 0.0, 1.0);
78
+
79
+ float localMixerStart = floor(localMixer);
80
+ float smoothed = smoothstep(.5 - u_softness * .5, .5 + u_softness * .5, localMixer - localMixerStart);
81
+ float localTStepped = localMixerStart + smoothed;
82
+
83
+ localMixer = mix(localTStepped, localMixer, u_softness);
84
+
85
+ vec4 c = u_colors[i];
86
+ c.rgb *= c.a;
87
+ gradient = mix(gradient, c, localMixer);
88
+ }
89
+
90
+ vec3 color = gradient.rgb;
91
+ float opacity = gradient.a;
92
+
93
+ ${colorBandingFix}
94
+
95
+ fragColor = vec4(color, opacity);
96
+ }
97
+ `;
98
+ const WarpPatterns = {
99
+ checks: 0,
100
+ stripes: 1,
101
+ edge: 2
102
+ };
103
+ export {
104
+ WarpPatterns,
105
+ warpFragmentShader,
106
+ warpMeta
107
+ };
108
+ //# sourceMappingURL=warp.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/warp.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, declareRandom, declareValueNoise, declareRotate, colorBandingFix } from '../shader-utils.js';\n\nexport const warpMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Iterative layered + swirl-based distortion applied over different layouts (shapes)\n *\n * Uniforms:\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_proportion: (0..1) blend point between 2 colors (0.5 = equal distribution)\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n * - u_shape (float used as integer):\n * ---- 0: checks\n * ---- 1: stripes\n * ---- 2: 2x halves of canvas (mapping the canvas height regardless of resolution)\n * - u_shapeScale: the scale of layouts (underlying shapes)\n * - u_distortion: value noise distortion over the UV coordinate\n * - u_swirl, u_swirlIterations: swirly distortion (layering curves effect)\n *\n */\n\nexport const warpFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\nuniform float u_scale;\n\nuniform vec4 u_colors[${warpMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_proportion;\nuniform float u_softness;\nuniform float u_shape;\nuniform float u_shapeScale;\nuniform float u_distortion;\nuniform float u_swirl;\nuniform float u_swirlIterations;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRandom}\n${declareRotate}\n${declareValueNoise}\n\n\nvoid main() {\n vec2 uv = v_patternUV;\n uv *= .005;\n\n float t = .01 * u_time;\n\n float n1 = valueNoise(uv * 1. + t);\n float n2 = valueNoise(uv * 2. - t);\n float angle = n1 * TWO_PI;\n uv.x += 4. * u_distortion * n2 * cos(angle);\n uv.y += 4. * u_distortion * n2 * sin(angle);\n\n float iterationsNumber = ceil(clamp(u_swirlIterations, 1., 30.));\n for (float i = 1.; i <= iterationsNumber; i++) {\n uv.x += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1.5 * uv.y);\n uv.y += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1. * uv.x);\n }\n\n float proportion = clamp(u_proportion, 0., 1.);\n\n float shape = 0.;\n if (u_shape < .5) {\n vec2 checksShape_uv = uv * (.5 + 3.5 * u_shapeScale);\n shape = .5 + .5 * sin(checksShape_uv.x) * cos(checksShape_uv.y);\n shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else if (u_shape < 1.5) {\n vec2 stripesShape_uv = uv * (2. * u_shapeScale);\n float f = fract(stripesShape_uv.y);\n shape = smoothstep(.0, .55, f) * smoothstep(1., .45, f);\n shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else {\n float shapeScaling = 5. * (1. - u_shapeScale);\n shape = smoothstep(.45 - shapeScaling, .55 + shapeScaling, 1. - uv.y + .3 * (proportion - .5));\n }\n\n float mixer = shape * (u_colorsCount - 1.);\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${warpMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float localMixer = clamp(mixer - float(i - 1), 0.0, 1.0);\n\n float localMixerStart = floor(localMixer);\n float smoothed = smoothstep(.5 - u_softness * .5, .5 + u_softness * .5, localMixer - localMixerStart);\n float localTStepped = localMixerStart + smoothed;\n\n localMixer = mix(localTStepped, localMixer, u_softness);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localMixer);\n }\n\n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WarpUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_proportion: number;\n u_softness: number;\n u_shape: (typeof WarpPatterns)[WarpPattern];\n u_shapeScale: number;\n u_distortion: number;\n u_swirl: number;\n u_swirlIterations: number;\n}\n\nexport interface WarpParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n rotation?: number;\n proportion?: number;\n softness?: number;\n shape?: WarpPattern;\n shapeScale?: number;\n distortion?: number;\n swirl?: number;\n swirlIterations?: number;\n}\n\nexport const WarpPatterns = {\n checks: 0,\n stripes: 1,\n edge: 2,\n} as const;\n\nexport type WarpPattern = keyof typeof WarpPatterns;\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,eAAe,mBAAmB,eAAe,uBAAuB;AAErF,MAAM,WAAW;AAAA,EACtB,eAAe;AACjB;AAmBO,MAAM,qBAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAMlB,SAAS,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU5C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,aAAa;AAAA,EACb,aAAa;AAAA,EACb,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAyCK,SAAS,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkB1C,eAAe;AAAA;AAAA;AAAA;AAAA;AA8BZ,MAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;",
6
+ "names": []
7
+ }
@@ -1,26 +1,23 @@
1
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
2
2
  /**
3
- * Waves static pattern on the transparent background
3
+ * Waveform pattern
4
4
  *
5
- * Uniforms include:
6
- * u_color1 - the first color
7
- * u_color2 - the second color
8
- * u_shape (0 ... 3) - the line shaping coefficient, non-integer
9
- values allowed and produce mixed shapes
10
- - u_shape = 0 is zigzag
11
- - u_shape = 1 is perfect sine wave
12
- - u_shape = 2 is irregular wave #1
13
- - u_shape = 3 is irregular wave #2
14
- * u_frequency - the wave frequency
15
- * u_amplitude - the wave amplitude
16
- * u_spacing - the density of pattern lines
17
- * u_proportion (0 ... 1) - the proportion of stroke width to the pattern step
18
- * u_softness (0 ... 1) - the blur applied to the lines edges
19
- */
5
+ * Uniforms:
6
+ * - u_colorBack, u_colorFront (RGBA)
7
+ * - u_shape (float, fractional numbers allowed):
8
+ * ---- 0: zigzag
9
+ * ---- 1: sine wave
10
+ * ---- 2: irregular wave
11
+ * ---- 3: irregular wave
12
+ * - u_amplitude, u_frequency, u_spacing: wave settings
13
+ * - u_proportion: (0..1) blend point between 2 colors (0.5 = equal distribution)
14
+ * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)
15
+ *
16
+ * */
20
17
  export declare const wavesFragmentShader: string;
21
18
  export interface WavesUniforms extends ShaderSizingUniforms {
22
- u_color1: [number, number, number, number];
23
- u_color2: [number, number, number, number];
19
+ u_colorFront: [number, number, number, number];
20
+ u_colorBack: [number, number, number, number];
24
21
  u_shape: number;
25
22
  u_frequency: number;
26
23
  u_amplitude: number;
@@ -29,8 +26,8 @@ export interface WavesUniforms extends ShaderSizingUniforms {
29
26
  u_softness: number;
30
27
  }
31
28
  export interface WavesParams extends ShaderSizingParams {
32
- color1?: string;
33
- color2?: string;
29
+ colorFront?: string;
30
+ colorBack?: string;
34
31
  rotation?: number;
35
32
  shape?: number;
36
33
  frequency?: number;
@@ -0,0 +1,68 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing.js";
7
+ import { declarePI, declareRotate } from "../shader-utils.js";
8
+ const wavesFragmentShader = `#version 300 es
9
+ precision mediump float;
10
+
11
+ uniform float u_scale;
12
+
13
+ uniform vec4 u_colorFront;
14
+ uniform vec4 u_colorBack;
15
+ uniform float u_shape;
16
+ uniform float u_frequency;
17
+ uniform float u_amplitude;
18
+ uniform float u_spacing;
19
+ uniform float u_proportion;
20
+ uniform float u_softness;
21
+
22
+ ${sizingVariablesDeclaration}
23
+
24
+ out vec4 fragColor;
25
+
26
+ ${declarePI}
27
+ ${declareRotate}
28
+
29
+ void main() {
30
+ vec2 shape_uv = v_patternUV;
31
+ shape_uv *= .05;
32
+
33
+ float wave = .5 * cos(shape_uv.x * u_frequency * TWO_PI);
34
+ float zigzag = 2. * abs(fract(shape_uv.x * u_frequency) - .5);
35
+ float irregular = sin(shape_uv.x * .25 * u_frequency * TWO_PI) * cos(shape_uv.x * u_frequency * TWO_PI);
36
+ float irregular2 = .75 * (sin(shape_uv.x * u_frequency * TWO_PI) + .5 * cos(shape_uv.x * .5 * u_frequency * TWO_PI));
37
+
38
+ float offset = mix(zigzag, wave, smoothstep(0., 1., u_shape));
39
+ offset = mix(offset, irregular, smoothstep(1., 2., u_shape));
40
+ offset = mix(offset, irregular2, smoothstep(2., 3., u_shape));
41
+ offset *= 2. * u_amplitude;
42
+
43
+ float spacing = .02 + .98 * u_spacing;
44
+ float shape = .5 + .5 * sin((shape_uv.y + offset) * PI / spacing);
45
+
46
+ float edge_width = .02 / (1. + abs(shape)) * (.001 + u_scale);
47
+ edge_width += .5 * max(0., u_softness);
48
+ float dc = 1. - clamp(u_proportion, 0., 1.);
49
+ float res = smoothstep(dc - edge_width, dc + edge_width, shape);
50
+
51
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
52
+ float fgOpacity = u_colorFront.a;
53
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
54
+ float bgOpacity = u_colorBack.a;
55
+
56
+ vec3 color = fgColor * res;
57
+ float opacity = fgOpacity * res;
58
+
59
+ color += bgColor * (1. - opacity);
60
+ opacity += bgOpacity * (1. - opacity);
61
+
62
+ fragColor = vec4(color, opacity);
63
+ }
64
+ `;
65
+ export {
66
+ wavesFragmentShader
67
+ };
68
+ //# sourceMappingURL=waves.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/waves.ts"],
4
+ "sourcesContent": ["import { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, declareRotate } from '../shader-utils.js';\n\n/**\n * Waveform pattern\n *\n * Uniforms:\n * - u_colorBack, u_colorFront (RGBA)\n * - u_shape (float, fractional numbers allowed):\n * ---- 0: zigzag\n * ---- 1: sine wave\n * ---- 2: irregular wave\n * ---- 3: irregular wave\n * - u_amplitude, u_frequency, u_spacing: wave settings\n * - u_proportion: (0..1) blend point between 2 colors (0.5 = equal distribution)\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n *\n * */\n\nexport const wavesFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_scale;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_shape;\nuniform float u_frequency;\nuniform float u_amplitude;\nuniform float u_spacing;\nuniform float u_proportion;\nuniform float u_softness;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .05;\n\n float wave = .5 * cos(shape_uv.x * u_frequency * TWO_PI);\n float zigzag = 2. * abs(fract(shape_uv.x * u_frequency) - .5);\n float irregular = sin(shape_uv.x * .25 * u_frequency * TWO_PI) * cos(shape_uv.x * u_frequency * TWO_PI);\n float irregular2 = .75 * (sin(shape_uv.x * u_frequency * TWO_PI) + .5 * cos(shape_uv.x * .5 * u_frequency * TWO_PI));\n\n float offset = mix(zigzag, wave, smoothstep(0., 1., u_shape));\n offset = mix(offset, irregular, smoothstep(1., 2., u_shape));\n offset = mix(offset, irregular2, smoothstep(2., 3., u_shape));\n offset *= 2. * u_amplitude;\n\n float spacing = .02 + .98 * u_spacing;\n float shape = .5 + .5 * sin((shape_uv.y + offset) * PI / spacing);\n\n float edge_width = .02 / (1. + abs(shape)) * (.001 + u_scale);\n edge_width += .5 * max(0., u_softness);\n float dc = 1. - clamp(u_proportion, 0., 1.);\n float res = smoothstep(dc - edge_width, dc + edge_width, shape);\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 fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WavesUniforms extends ShaderSizingUniforms {\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_shape: number;\n u_frequency: number;\n u_amplitude: number;\n u_spacing: number;\n u_proportion: number;\n u_softness: number;\n}\n\nexport interface WavesParams extends ShaderSizingParams {\n colorFront?: string;\n colorBack?: string;\n rotation?: number;\n shape?: number;\n frequency?: number;\n amplitude?: number;\n spacing?: number;\n proportion?: number;\n softness?: number;\n}\n"],
5
+ "mappings": ";;;;;AAAA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,qBAAqB;AAkBlC,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,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;",
6
+ "names": []
7
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paper-design/shaders",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -24,4 +24,4 @@
24
24
  "type-check": "tsc --project tsconfig.json"
25
25
  },
26
26
  "dependencies": {}
27
- }
27
+ }