@paper-design/shaders 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get-shader-color-from-string.d.ts +1 -1
- package/dist/get-shader-color-from-string.js +93 -0
- package/dist/get-shader-color-from-string.js.map +7 -0
- package/dist/get-shader-noise-texture.d.ts +1 -0
- package/dist/get-shader-noise-texture.js +23 -0
- package/dist/get-shader-noise-texture.js.map +7 -0
- package/dist/index.d.ts +30 -16
- package/dist/index.js +96 -1315
- package/dist/index.js.map +4 -4
- package/dist/shader-color-spaces.d.ts +6 -0
- package/dist/shader-color-spaces.js +96 -0
- package/dist/shader-color-spaces.js.map +7 -0
- package/dist/shader-mount.d.ts +48 -17
- package/dist/shader-mount.js +568 -0
- package/dist/shader-mount.js.map +7 -0
- package/dist/shader-sizing.d.ts +35 -0
- package/dist/shader-sizing.js +196 -0
- package/dist/shader-sizing.js.map +7 -0
- package/dist/shader-utils.d.ts +5 -0
- package/dist/shader-utils.js +59 -0
- package/dist/shader-utils.js.map +7 -0
- package/dist/shaders/dithering.d.ts +47 -0
- package/dist/shaders/dithering.js +197 -0
- package/dist/shaders/dithering.js.map +7 -0
- package/dist/shaders/dot-grid.d.ts +33 -20
- package/dist/shaders/dot-grid.js +100 -0
- package/dist/shaders/dot-grid.js.map +7 -0
- package/dist/shaders/dot-orbit.d.ts +27 -18
- package/dist/shaders/dot-orbit.js +120 -0
- package/dist/shaders/dot-orbit.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +35 -26
- package/dist/shaders/god-rays.js +134 -0
- package/dist/shaders/god-rays.js.map +7 -0
- package/dist/shaders/grain-gradient.d.ts +25 -0
- package/dist/shaders/grain-gradient.js +219 -0
- package/dist/shaders/grain-gradient.js.map +7 -0
- package/dist/shaders/liquid-metal.d.ts +19 -0
- package/dist/shaders/liquid-metal.js +224 -0
- package/dist/shaders/liquid-metal.js.map +7 -0
- package/dist/shaders/mesh-gradient.d.ts +23 -13
- package/dist/shaders/mesh-gradient.js +97 -0
- package/dist/shaders/mesh-gradient.js.map +7 -0
- package/dist/shaders/metaballs.d.ts +22 -15
- package/dist/shaders/metaballs.js +108 -0
- package/dist/shaders/metaballs.js.map +7 -0
- package/dist/shaders/neuro-noise.d.ts +13 -8
- package/dist/shaders/neuro-noise.js +66 -0
- package/dist/shaders/neuro-noise.js.map +7 -0
- package/dist/shaders/perlin-noise.d.ts +26 -15
- package/dist/shaders/perlin-noise.js +193 -0
- package/dist/shaders/perlin-noise.js.map +7 -0
- package/dist/shaders/pulsing-border.d.ts +54 -0
- package/dist/shaders/pulsing-border.js +218 -0
- package/dist/shaders/pulsing-border.js.map +7 -0
- package/dist/shaders/simplex-noise.d.ts +29 -0
- package/dist/shaders/simplex-noise.js +103 -0
- package/dist/shaders/simplex-noise.js.map +7 -0
- package/dist/shaders/smoke-ring.d.ts +34 -12
- package/dist/shaders/smoke-ring.js +141 -0
- package/dist/shaders/smoke-ring.js.map +7 -0
- package/dist/shaders/spiral.d.ts +28 -18
- package/dist/shaders/spiral.js +75 -0
- package/dist/shaders/spiral.js.map +7 -0
- package/dist/shaders/swirl.d.ts +26 -0
- package/dist/shaders/swirl.js +80 -0
- package/dist/shaders/swirl.js.map +7 -0
- package/dist/shaders/voronoi.d.ts +39 -29
- package/dist/shaders/voronoi.js +143 -0
- package/dist/shaders/voronoi.js.map +7 -0
- package/dist/shaders/warp.d.ts +43 -32
- package/dist/shaders/warp.js +124 -0
- package/dist/shaders/warp.js.map +7 -0
- package/dist/shaders/waves.d.ts +25 -15
- package/dist/shaders/waves.js +60 -0
- package/dist/shaders/waves.js.map +7 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +7 -0
- package/package.json +2 -1
- package/dist/get-shader-color-from-string.test.d.ts +0 -1
- package/dist/shaders/stepped-simplex-noise.d.ts +0 -24
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing";
|
|
7
|
+
import { declarePI, declareRandom, declareRotate, colorBandingFix } from "../shader-utils";
|
|
8
|
+
const warpMeta = {
|
|
9
|
+
maxColorCount: 10
|
|
10
|
+
};
|
|
11
|
+
const warpFragmentShader = `#version 300 es
|
|
12
|
+
precision highp float;
|
|
13
|
+
|
|
14
|
+
uniform float u_time;
|
|
15
|
+
uniform float u_scale;
|
|
16
|
+
uniform vec2 u_resolution;
|
|
17
|
+
|
|
18
|
+
uniform vec4 u_colors[${warpMeta.maxColorCount}];
|
|
19
|
+
uniform float u_colorsCount;
|
|
20
|
+
uniform float u_proportion;
|
|
21
|
+
uniform float u_softness;
|
|
22
|
+
uniform float u_shape;
|
|
23
|
+
uniform float u_shapeScale;
|
|
24
|
+
uniform float u_distortion;
|
|
25
|
+
uniform float u_swirl;
|
|
26
|
+
uniform float u_swirlIterations;
|
|
27
|
+
|
|
28
|
+
${sizingVariablesDeclaration}
|
|
29
|
+
|
|
30
|
+
out vec4 fragColor;
|
|
31
|
+
|
|
32
|
+
${declarePI}
|
|
33
|
+
${declareRandom}
|
|
34
|
+
${declareRotate}
|
|
35
|
+
|
|
36
|
+
float noise(vec2 st) {
|
|
37
|
+
vec2 i = floor(st);
|
|
38
|
+
vec2 f = fract(st);
|
|
39
|
+
float a = random(i);
|
|
40
|
+
float b = random(i + vec2(1.0, 0.0));
|
|
41
|
+
float c = random(i + vec2(0.0, 1.0));
|
|
42
|
+
float d = random(i + vec2(1.0, 1.0));
|
|
43
|
+
|
|
44
|
+
// Smoothstep for interpolation
|
|
45
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
46
|
+
|
|
47
|
+
// Do the interpolation as two nested mix operations
|
|
48
|
+
// If you try to do this in one big operation, there's enough precision loss to be off by 1px at cell boundaries
|
|
49
|
+
float x1 = mix(a, b, u.x);
|
|
50
|
+
float x2 = mix(c, d, u.x);
|
|
51
|
+
return mix(x1, x2, u.y);
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void main() {
|
|
56
|
+
vec2 shape_uv = v_patternUV;
|
|
57
|
+
shape_uv *= .0025;
|
|
58
|
+
|
|
59
|
+
float t = .01 * u_time;
|
|
60
|
+
|
|
61
|
+
float noise_scale = .0005 + .006 * u_scale;
|
|
62
|
+
|
|
63
|
+
float n1 = noise(shape_uv * 1. + t);
|
|
64
|
+
float n2 = noise(shape_uv * 2. - t);
|
|
65
|
+
float angle = n1 * TWO_PI;
|
|
66
|
+
shape_uv.x += 4. * u_distortion * n2 * cos(angle);
|
|
67
|
+
shape_uv.y += 4. * u_distortion * n2 * sin(angle);
|
|
68
|
+
|
|
69
|
+
float iterations_number = ceil(clamp(u_swirlIterations, 1., 30.));
|
|
70
|
+
for (float i = 1.; i <= iterations_number; i++) {
|
|
71
|
+
shape_uv.x += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1.5 * shape_uv.y);
|
|
72
|
+
shape_uv.y += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1. * shape_uv.x);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
float proportion = clamp(u_proportion, 0., 1.);
|
|
76
|
+
|
|
77
|
+
float shape = 0.;
|
|
78
|
+
if (u_shape < .5) {
|
|
79
|
+
vec2 checks_shape_uv = shape_uv * (.5 + 3.5 * u_shapeScale);
|
|
80
|
+
shape = .5 + .5 * sin(checks_shape_uv.x) * cos(checks_shape_uv.y);
|
|
81
|
+
shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
|
|
82
|
+
} else if (u_shape < 1.5) {
|
|
83
|
+
vec2 stripes_shape_uv = shape_uv * (.25 + 3. * u_shapeScale);
|
|
84
|
+
float f = fract(stripes_shape_uv.y);
|
|
85
|
+
shape = smoothstep(.0, .55, f) * smoothstep(1., .45, f);
|
|
86
|
+
shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);
|
|
87
|
+
} else {
|
|
88
|
+
float sh = 1. - shape_uv.y;
|
|
89
|
+
float shape_scaling = 5. * (1. - u_shapeScale);
|
|
90
|
+
shape = smoothstep(.45 - shape_scaling, .55 + shape_scaling, sh + .3 * (proportion - .5));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
float mixer = shape * (u_colorsCount - 1.);
|
|
94
|
+
mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
|
|
95
|
+
vec4 gradient = u_colors[0];
|
|
96
|
+
gradient.rgb *= gradient.a;
|
|
97
|
+
for (int i = 1; i < ${warpMeta.maxColorCount}; i++) {
|
|
98
|
+
if (i >= int(u_colorsCount)) break;
|
|
99
|
+
float localT = clamp(mixer - float(i - 1), 0.0, 1.0);
|
|
100
|
+
localT = smoothstep(.5 - .5 * u_softness, .5 + .5 * u_softness, localT);
|
|
101
|
+
vec4 c = u_colors[i];
|
|
102
|
+
c.rgb *= c.a;
|
|
103
|
+
gradient = mix(gradient, c, localT);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
vec3 color = gradient.rgb;
|
|
107
|
+
float opacity = gradient.a;
|
|
108
|
+
|
|
109
|
+
${colorBandingFix}
|
|
110
|
+
|
|
111
|
+
fragColor = vec4(color, opacity);
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
const WarpPatterns = {
|
|
115
|
+
checks: 0,
|
|
116
|
+
stripes: 1,
|
|
117
|
+
edge: 2
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
WarpPatterns,
|
|
121
|
+
warpFragmentShader,
|
|
122
|
+
warpMeta
|
|
123
|
+
};
|
|
124
|
+
//# 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';\nimport type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declarePI, declareRandom, declareRotate, colorBandingFix } from '../shader-utils';\n\nexport const warpMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * 3d Perlin noise with exposed parameters\n *\n * Uniforms include:\n * - u_colors (vec4[]): Input RGBA colors\n * - u_colorsCount (float): Number of active colors (`u_colors` length)\n * - u_proportion (0 .. 1): the proportion between colors (on 0.5 colors are equally distributed)\n * - u_softness (0 .. 1): the color blur (0 for pronounced edges, 1 for gradient)\n * - u_shape (0 ... 2): the color pattern to be distorted with noise & swirl\n * - u_shape = 0 is checks\n * - u_shape = 1 is stripes\n * - u_shape = 2 is 2 halves of canvas (mapping the canvas height regardless of resolution)\n * - u_shapeScale: the scale of color pattern (appies over the global scaling)\n * - u_distortion: the noisy distortion over the UV coordinate (applied before the overlapping swirl)\n * - u_swirl: the power of swirly distortion\n * - u_swirlIterations: the number of swirl iterations (layering curves effect)\n *\n */\nexport const warpFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_scale;\nuniform vec2 u_resolution;\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\nfloat noise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = random(i);\n float b = random(i + vec2(1.0, 0.0));\n float c = random(i + vec2(0.0, 1.0));\n float d = random(i + vec2(1.0, 1.0));\n\n // Smoothstep for interpolation\n vec2 u = f * f * (3.0 - 2.0 * f);\n\n // Do the interpolation as two nested mix operations\n // If you try to do this in one big operation, there's enough precision loss to be off by 1px at cell boundaries\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .0025;\n\n float t = .01 * u_time;\n\n float noise_scale = .0005 + .006 * u_scale;\n\n float n1 = noise(shape_uv * 1. + t);\n float n2 = noise(shape_uv * 2. - t);\n float angle = n1 * TWO_PI;\n shape_uv.x += 4. * u_distortion * n2 * cos(angle);\n shape_uv.y += 4. * u_distortion * n2 * sin(angle);\n\n float iterations_number = ceil(clamp(u_swirlIterations, 1., 30.));\n for (float i = 1.; i <= iterations_number; i++) {\n shape_uv.x += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1.5 * shape_uv.y);\n shape_uv.y += clamp(u_swirl, 0., 2.) / i * cos(t + i * 1. * shape_uv.x);\n }\n\n float proportion = clamp(u_proportion, 0., 1.);\n\n float shape = 0.;\n if (u_shape < .5) {\n vec2 checks_shape_uv = shape_uv * (.5 + 3.5 * u_shapeScale);\n shape = .5 + .5 * sin(checks_shape_uv.x) * cos(checks_shape_uv.y);\n shape += .48 * sign(proportion - .5) * pow(abs(proportion - .5), .5);\n } else if (u_shape < 1.5) {\n vec2 stripes_shape_uv = shape_uv * (.25 + 3. * u_shapeScale);\n float f = fract(stripes_shape_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 sh = 1. - shape_uv.y;\n float shape_scaling = 5. * (1. - u_shapeScale);\n shape = smoothstep(.45 - shape_scaling, .55 + shape_scaling, sh + .3 * (proportion - .5));\n }\n\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\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 localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = smoothstep(.5 - .5 * u_softness, .5 + .5 * u_softness, localT);\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface 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,eAAe,uBAAuB;AAElE,MAAM,WAAW;AAAA,EACtB,eAAe;AACjB;AAoBO,MAAM,qBAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAOlB,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA+DS,SAAS,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAY1C,eAAe;AAAA;AAAA;AAAA;AAAA;AA8BZ,MAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/shaders/waves.d.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
u_scale: number;
|
|
3
|
-
u_rotation: number;
|
|
4
|
-
u_color: [number, number, number, number];
|
|
5
|
-
u_shape: number;
|
|
6
|
-
u_frequency: number;
|
|
7
|
-
u_amplitude: number;
|
|
8
|
-
u_spacing: number;
|
|
9
|
-
u_dutyCycle: number;
|
|
10
|
-
u_softness: number;
|
|
11
|
-
};
|
|
1
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
|
|
12
2
|
/**
|
|
13
3
|
* Waves static pattern on the transparent background
|
|
14
4
|
*
|
|
15
5
|
* Uniforms include:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* u_color - the wave color
|
|
6
|
+
* u_color1 - the first color
|
|
7
|
+
* u_color2 - the second color
|
|
19
8
|
* u_shape (0 ... 3) - the line shaping coefficient, non-integer
|
|
20
9
|
values allowed and produce mixed shapes
|
|
21
10
|
- u_shape = 0 is zigzag
|
|
@@ -28,4 +17,25 @@ export type WavesUniforms = {
|
|
|
28
17
|
* u_dutyCycle (0 ... 1) - the proportion of stroke width to the pattern step
|
|
29
18
|
* u_softness (0 ... 1) - the blur applied to the lines edges
|
|
30
19
|
*/
|
|
31
|
-
export declare const wavesFragmentShader
|
|
20
|
+
export declare const wavesFragmentShader: string;
|
|
21
|
+
export interface WavesUniforms extends ShaderSizingUniforms {
|
|
22
|
+
u_color1: [number, number, number, number];
|
|
23
|
+
u_color2: [number, number, number, number];
|
|
24
|
+
u_shape: number;
|
|
25
|
+
u_frequency: number;
|
|
26
|
+
u_amplitude: number;
|
|
27
|
+
u_spacing: number;
|
|
28
|
+
u_dutyCycle: number;
|
|
29
|
+
u_softness: number;
|
|
30
|
+
}
|
|
31
|
+
export interface WavesParams extends ShaderSizingParams {
|
|
32
|
+
color1?: string;
|
|
33
|
+
color2?: string;
|
|
34
|
+
rotation?: number;
|
|
35
|
+
shape?: number;
|
|
36
|
+
frequency?: number;
|
|
37
|
+
amplitude?: number;
|
|
38
|
+
spacing?: number;
|
|
39
|
+
dutyCycle?: number;
|
|
40
|
+
softness?: number;
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing";
|
|
7
|
+
import { declarePI, declareRotate } from "../shader-utils";
|
|
8
|
+
const wavesFragmentShader = `#version 300 es
|
|
9
|
+
precision highp float;
|
|
10
|
+
|
|
11
|
+
uniform float u_scale;
|
|
12
|
+
|
|
13
|
+
uniform vec4 u_color1;
|
|
14
|
+
uniform vec4 u_color2;
|
|
15
|
+
uniform float u_shape;
|
|
16
|
+
uniform float u_frequency;
|
|
17
|
+
uniform float u_amplitude;
|
|
18
|
+
uniform float u_spacing;
|
|
19
|
+
uniform float u_dutyCycle;
|
|
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 = clamp(u_dutyCycle, 0., 1.);
|
|
49
|
+
float t = smoothstep(dc - edge_width, dc + edge_width, shape);
|
|
50
|
+
|
|
51
|
+
vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, t);
|
|
52
|
+
float opacity = mix(u_color1.a, u_color2.a, t);
|
|
53
|
+
|
|
54
|
+
fragColor = vec4(color, opacity);
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
export {
|
|
58
|
+
wavesFragmentShader
|
|
59
|
+
};
|
|
60
|
+
//# 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';\nimport { declarePI, declareRotate } from '../shader-utils';\n\n/**\n * Waves static pattern on the transparent background\n *\n * Uniforms include:\n * u_color1 - the first color\n * u_color2 - the second color\n * u_shape (0 ... 3) - the line shaping coefficient, non-integer\n values allowed and produce mixed shapes\n - u_shape = 0 is zigzag\n - u_shape = 1 is perfect sine wave\n - u_shape = 2 is irregular wave #1\n - u_shape = 3 is irregular wave #2\n * u_frequency - the wave frequency\n * u_amplitude - the wave amplitude\n * u_spacing - the density of pattern lines\n * u_dutyCycle (0 ... 1) - the proportion of stroke width to the pattern step\n * u_softness (0 ... 1) - the blur applied to the lines edges\n */\nexport const wavesFragmentShader: string = `#version 300 es\nprecision highp float;\n\nuniform float u_scale;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_shape;\nuniform float u_frequency;\nuniform float u_amplitude;\nuniform float u_spacing;\nuniform float u_dutyCycle;\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 = clamp(u_dutyCycle, 0., 1.);\n float t = smoothstep(dc - edge_width, dc + edge_width, shape);\n\n vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, t);\n float opacity = mix(u_color1.a, u_color2.a, t);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WavesUniforms extends ShaderSizingUniforms {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_shape: number;\n u_frequency: number;\n u_amplitude: number;\n u_spacing: number;\n u_dutyCycle: number;\n u_softness: number;\n}\n\nexport interface WavesParams extends ShaderSizingParams {\n color1?: string;\n color2?: string;\n rotation?: number;\n shape?: number;\n frequency?: number;\n amplitude?: number;\n spacing?: number;\n dutyCycle?: number;\n softness?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,qBAAqB;AAoBlC,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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type SteppedSimplexNoiseUniforms = {
|
|
2
|
-
u_scale: number;
|
|
3
|
-
u_color1: [number, number, number, number];
|
|
4
|
-
u_color2: [number, number, number, number];
|
|
5
|
-
u_color3: [number, number, number, number];
|
|
6
|
-
u_color4: [number, number, number, number];
|
|
7
|
-
u_color5: [number, number, number, number];
|
|
8
|
-
u_steps_number: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Stepped Simplex Noise by Ksenia Kondrashova
|
|
12
|
-
* Calculates a combination of 2 simplex noises with result rendered as
|
|
13
|
-
* an X-stepped 5-colored gradient
|
|
14
|
-
*
|
|
15
|
-
* Uniforms include:
|
|
16
|
-
* u_scale - the scale applied to user space
|
|
17
|
-
* u_color1 - the first gradient color
|
|
18
|
-
* u_color2 - the second gradient color
|
|
19
|
-
* u_color3 - the third gradient color
|
|
20
|
-
* u_color4 - the fourth gradient color
|
|
21
|
-
* u_color5 - the fifth gradient color
|
|
22
|
-
* u_steps_number - the number of solid colors to show as a stepped gradient
|
|
23
|
-
*/
|
|
24
|
-
export declare const steppedSimplexNoiseFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec4 u_color5;\nuniform float u_steps_number;\n\nout vec4 fragColor;\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat get_noise(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\nvec4 getColor(int index) {\n if (index == 0) return u_color1;\n if (index == 1) return u_color2;\n if (index == 2) return u_color3;\n if (index == 3) return u_color4;\n if (index == 4) return u_color5;\n return u_color1;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.0008 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n float noise = .5 + .5 * get_noise(uv, t);\n noise = floor(noise * u_steps_number) / u_steps_number;\n\n vec3 color = u_color1.rgb * u_color1.a;\n float opacity = u_color1.a;\n for (int i = 0; i < 5; i++) {\n vec4 next_c = getColor(i + 1);\n float proportion = smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise);\n color = mix(color, next_c.rgb * next_c.a, proportion);\n opacity = mix(opacity, next_c.a, proportion);\n }\n fragColor = vec4(color, opacity);\n}\n";
|