@paper-design/shaders 0.0.45 → 0.0.46
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/README.md +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +2 -2
- package/dist/shader-mount.d.ts +1 -0
- package/dist/shader-mount.js +11 -12
- package/dist/shader-mount.js.map +2 -2
- package/dist/shader-sizing.d.ts +2 -2
- package/dist/shader-sizing.js +39 -1
- package/dist/shader-sizing.js.map +2 -2
- package/dist/shader-utils.d.ts +8 -5
- package/dist/shader-utils.js +70 -51
- package/dist/shader-utils.js.map +2 -2
- package/dist/shaders/dithering.js +13 -11
- package/dist/shaders/dithering.js.map +2 -2
- package/dist/shaders/dot-grid.js +2 -2
- package/dist/shaders/dot-grid.js.map +2 -2
- package/dist/shaders/dot-orbit.d.ts +3 -0
- package/dist/shaders/dot-orbit.js +9 -9
- package/dist/shaders/dot-orbit.js.map +2 -2
- package/dist/shaders/fluted-glass.d.ts +72 -0
- package/dist/shaders/fluted-glass.js +188 -0
- package/dist/shaders/fluted-glass.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +2 -0
- package/dist/shaders/god-rays.js +20 -9
- package/dist/shaders/god-rays.js.map +2 -2
- package/dist/shaders/grain-gradient.js +60 -37
- package/dist/shaders/grain-gradient.js.map +2 -2
- package/dist/shaders/image-dithering.d.ts +49 -0
- package/dist/shaders/image-dithering.js +164 -0
- package/dist/shaders/image-dithering.js.map +7 -0
- package/dist/shaders/liquid-metal.js +4 -4
- package/dist/shaders/liquid-metal.js.map +2 -2
- package/dist/shaders/mesh-gradient.js +2 -2
- package/dist/shaders/mesh-gradient.js.map +2 -2
- package/dist/shaders/metaballs.d.ts +3 -0
- package/dist/shaders/metaballs.js +8 -7
- package/dist/shaders/metaballs.js.map +2 -2
- package/dist/shaders/neuro-noise.js +2 -2
- package/dist/shaders/neuro-noise.js.map +2 -2
- package/dist/shaders/paper-texture.d.ts +53 -0
- package/dist/shaders/paper-texture.js +236 -0
- package/dist/shaders/paper-texture.js.map +7 -0
- package/dist/shaders/perlin-noise.js +111 -117
- package/dist/shaders/perlin-noise.js.map +2 -2
- package/dist/shaders/pulsing-border.js +17 -9
- package/dist/shaders/pulsing-border.js.map +2 -2
- package/dist/shaders/simplex-noise.js +2 -2
- package/dist/shaders/simplex-noise.js.map +2 -2
- package/dist/shaders/smoke-ring.js +13 -8
- package/dist/shaders/smoke-ring.js.map +2 -2
- package/dist/shaders/spiral.js +3 -3
- package/dist/shaders/spiral.js.map +2 -2
- package/dist/shaders/static-mesh-gradient.d.ts +2 -0
- package/dist/shaders/static-mesh-gradient.js +15 -14
- package/dist/shaders/static-mesh-gradient.js.map +2 -2
- package/dist/shaders/static-radial-gradient.d.ts +2 -0
- package/dist/shaders/static-radial-gradient.js +15 -13
- package/dist/shaders/static-radial-gradient.js.map +2 -2
- package/dist/shaders/swirl.js +3 -3
- package/dist/shaders/swirl.js.map +2 -2
- package/dist/shaders/voronoi.js +6 -10
- package/dist/shaders/voronoi.js.map +2 -2
- package/dist/shaders/warp.d.ts +3 -0
- package/dist/shaders/warp.js +20 -4
- package/dist/shaders/warp.js.map +2 -2
- package/dist/shaders/water.d.ts +39 -0
- package/dist/shaders/water.js +119 -0
- package/dist/shaders/water.js.map +7 -0
- package/dist/vertex-shader.d.ts +1 -1
- package/dist/vertex-shader.js +53 -15
- package/dist/vertex-shader.js.map +2 -2
- package/package.json +1 -1
package/dist/shader-utils.js
CHANGED
|
@@ -7,34 +7,48 @@ const declarePI = `
|
|
|
7
7
|
#define TWO_PI 6.28318530718
|
|
8
8
|
#define PI 3.14159265358979323846
|
|
9
9
|
`;
|
|
10
|
-
const
|
|
10
|
+
const rotation2 = `
|
|
11
11
|
vec2 rotate(vec2 uv, float th) {
|
|
12
12
|
return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;
|
|
13
13
|
}
|
|
14
14
|
`;
|
|
15
|
-
const
|
|
16
|
-
float
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const proceduralHash11 = `
|
|
16
|
+
float hash11(float p) {
|
|
17
|
+
p = fract(p * 0.3183099) + 0.1;
|
|
18
|
+
p *= p + 19.19;
|
|
19
|
+
return fract(p * p);
|
|
20
|
+
}
|
|
19
21
|
`;
|
|
20
|
-
const
|
|
21
|
-
float
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
vec2
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
22
|
+
const proceduralHash21 = `
|
|
23
|
+
float hash21(vec2 p) {
|
|
24
|
+
p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1;
|
|
25
|
+
p += dot(p, p + 19.19);
|
|
26
|
+
return fract(p.x * p.y);
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const proceduralHash22 = `
|
|
30
|
+
vec2 hash22(vec2 p) {
|
|
31
|
+
p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1;
|
|
32
|
+
p += dot(p, p.yx + 19.19);
|
|
33
|
+
return fract(vec2(p.x * p.y, p.x + p.y));
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
const textureRandomizerR = `
|
|
37
|
+
float randomR(vec2 p) {
|
|
38
|
+
vec2 uv = floor(p) / 100. + .5;
|
|
39
|
+
return texture(u_noiseTexture, fract(uv)).r;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
const textureRandomizerGB = `
|
|
43
|
+
vec2 randomGB(vec2 p) {
|
|
44
|
+
vec2 uv = floor(p) / 100. + .5;
|
|
45
|
+
return texture(u_noiseTexture, fract(uv)).gb;
|
|
46
|
+
}
|
|
33
47
|
`;
|
|
34
48
|
const colorBandingFix = `
|
|
35
49
|
color += 1. / 256. * (fract(sin(dot(.014 * gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123) - .5);
|
|
36
50
|
`;
|
|
37
|
-
const
|
|
51
|
+
const simplexNoise = `
|
|
38
52
|
vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
|
|
39
53
|
float snoise(vec2 v) {
|
|
40
54
|
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
|
|
@@ -63,50 +77,55 @@ float snoise(vec2 v) {
|
|
|
63
77
|
return 130.0 * dot(m, g);
|
|
64
78
|
}
|
|
65
79
|
`;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return vec2(cos(angle), sin(angle));
|
|
80
|
+
const fiberNoise = `
|
|
81
|
+
float fiberRandom(vec2 p) {
|
|
82
|
+
vec2 uv = floor(p) / 100.;
|
|
83
|
+
return texture(u_noiseTexture, fract(uv)).b;
|
|
71
84
|
}
|
|
72
85
|
|
|
73
|
-
float
|
|
74
|
-
vec2 i = floor(
|
|
75
|
-
vec2 f = fract(
|
|
86
|
+
float fiberValueNoise(vec2 st) {
|
|
87
|
+
vec2 i = floor(st);
|
|
88
|
+
vec2 f = fract(st);
|
|
89
|
+
float a = fiberRandom(i);
|
|
90
|
+
float b = fiberRandom(i + vec2(1.0, 0.0));
|
|
91
|
+
float c = fiberRandom(i + vec2(0.0, 1.0));
|
|
92
|
+
float d = fiberRandom(i + vec2(1.0, 1.0));
|
|
76
93
|
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
77
|
-
|
|
78
|
-
float
|
|
79
|
-
|
|
80
|
-
float n01 = dot(grainRandom(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));
|
|
81
|
-
float n11 = dot(grainRandom(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));
|
|
82
|
-
|
|
83
|
-
float nx0 = mix(n00, n10, u.x);
|
|
84
|
-
float nx1 = mix(n01, n11, u.x);
|
|
85
|
-
return mix(nx0, nx1, u.y);
|
|
94
|
+
float x1 = mix(a, b, u.x);
|
|
95
|
+
float x2 = mix(c, d, u.x);
|
|
96
|
+
return mix(x1, x2, u.y);
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
float
|
|
89
|
-
float total = 0.0
|
|
90
|
-
float amp = 0.5;
|
|
91
|
-
float freq = .6;
|
|
92
|
-
|
|
99
|
+
float fiberNoiseFbm(in vec2 n, vec2 seedOffset) {
|
|
100
|
+
float total = 0.0, amplitude = 1.;
|
|
93
101
|
for (int i = 0; i < 4; i++) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
n = rotate(n, .7);
|
|
103
|
+
total += fiberValueNoise(n + seedOffset) * amplitude;
|
|
104
|
+
n *= 2.;
|
|
105
|
+
amplitude *= 0.6;
|
|
97
106
|
}
|
|
107
|
+
return total;
|
|
108
|
+
}
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
float fiberNoise(vec2 uv, vec2 seedOffset) {
|
|
111
|
+
float epsilon = 0.001;
|
|
112
|
+
float n1 = fiberNoiseFbm(uv + vec2(epsilon, 0.0), seedOffset);
|
|
113
|
+
float n2 = fiberNoiseFbm(uv - vec2(epsilon, 0.0), seedOffset);
|
|
114
|
+
float n3 = fiberNoiseFbm(uv + vec2(0.0, epsilon), seedOffset);
|
|
115
|
+
float n4 = fiberNoiseFbm(uv - vec2(0.0, epsilon), seedOffset);
|
|
116
|
+
return length(vec2(n1 - n2, n3 - n4)) / (2.0 * epsilon);
|
|
101
117
|
}
|
|
102
118
|
`;
|
|
103
119
|
export {
|
|
104
120
|
colorBandingFix,
|
|
105
|
-
declareGrainShape,
|
|
106
121
|
declarePI,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
fiberNoise,
|
|
123
|
+
proceduralHash11,
|
|
124
|
+
proceduralHash21,
|
|
125
|
+
proceduralHash22,
|
|
126
|
+
rotation2,
|
|
127
|
+
simplexNoise,
|
|
128
|
+
textureRandomizerGB,
|
|
129
|
+
textureRandomizerR
|
|
111
130
|
};
|
|
112
131
|
//# sourceMappingURL=shader-utils.js.map
|
package/dist/shader-utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/shader-utils.ts"],
|
|
4
|
-
"sourcesContent": ["// language=GLSL\nexport const declarePI = `\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n`;\n\n// language=GLSL\nexport const
|
|
5
|
-
"mappings": ";;;;;AACO,MAAM,YAAY;AAAA;AAAA;AAAA;AAMlB,MAAM,
|
|
4
|
+
"sourcesContent": ["// language=GLSL\nexport const declarePI = `\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n`;\n\n// language=GLSL\nexport const rotation2 = `\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n`;\n\n// language=GLSL\nexport const proceduralHash11 = `\n float hash11(float p) {\n p = fract(p * 0.3183099) + 0.1;\n p *= p + 19.19;\n return fract(p * p);\n }\n`;\n\n// language=GLSL\nexport const proceduralHash21 = `\n float hash21(vec2 p) {\n p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1;\n p += dot(p, p + 19.19);\n return fract(p.x * p.y);\n }\n`;\n\n// language=GLSL\nexport const proceduralHash22 = `\n vec2 hash22(vec2 p) {\n p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1;\n p += dot(p, p.yx + 19.19);\n return fract(vec2(p.x * p.y, p.x + p.y));\n }\n`;\n\n// language=GLSL\nexport const textureRandomizerR = `\n float randomR(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, fract(uv)).r;\n }\n`;\n\n// language=GLSL\nexport const textureRandomizerGB = `\n vec2 randomGB(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, fract(uv)).gb;\n }\n`;\n\n// language=GLSL\nexport const colorBandingFix = `\n color += 1. / 256. * (fract(sin(dot(.014 * gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123) - .5);\n`;\n\n// language=GLSL\nexport const simplexNoise = `\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`;\n\n// language=GLSL\nexport const fiberNoise = `\nfloat fiberRandom(vec2 p) {\n vec2 uv = floor(p) / 100.;\n return texture(u_noiseTexture, fract(uv)).b;\n}\n\nfloat fiberValueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = fiberRandom(i);\n float b = fiberRandom(i + vec2(1.0, 0.0));\n float c = fiberRandom(i + vec2(0.0, 1.0));\n float d = fiberRandom(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\nfloat fiberNoiseFbm(in vec2 n, vec2 seedOffset) {\n float total = 0.0, amplitude = 1.;\n for (int i = 0; i < 4; i++) {\n n = rotate(n, .7);\n total += fiberValueNoise(n + seedOffset) * amplitude;\n n *= 2.;\n amplitude *= 0.6;\n }\n return total;\n}\n\nfloat fiberNoise(vec2 uv, vec2 seedOffset) {\n float epsilon = 0.001;\n float n1 = fiberNoiseFbm(uv + vec2(epsilon, 0.0), seedOffset);\n float n2 = fiberNoiseFbm(uv - vec2(epsilon, 0.0), seedOffset);\n float n3 = fiberNoiseFbm(uv + vec2(0.0, epsilon), seedOffset);\n float n4 = fiberNoiseFbm(uv - vec2(0.0, epsilon), seedOffset);\n return length(vec2(n1 - n2, n3 - n4)) / (2.0 * epsilon);\n}\n`;\n"],
|
|
5
|
+
"mappings": ";;;;;AACO,MAAM,YAAY;AAAA;AAAA;AAAA;AAMlB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAOlB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASzB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASzB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASzB,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3B,MAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ5B,MAAM,kBAAkB;AAAA;AAAA;AAKxB,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BrB,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
sizingUV,
|
|
9
9
|
drawSizingHelpers
|
|
10
10
|
} from "../shader-sizing.js";
|
|
11
|
-
import {
|
|
11
|
+
import { simplexNoise, declarePI, proceduralHash11, proceduralHash21 } from "../shader-utils.js";
|
|
12
12
|
const ditheringFragmentShader = `#version 300 es
|
|
13
13
|
precision mediump float;
|
|
14
14
|
|
|
@@ -26,9 +26,10 @@ uniform float u_pxSize;
|
|
|
26
26
|
|
|
27
27
|
out vec4 fragColor;
|
|
28
28
|
|
|
29
|
-
${
|
|
29
|
+
${simplexNoise}
|
|
30
30
|
${declarePI}
|
|
31
|
-
${
|
|
31
|
+
${proceduralHash11}
|
|
32
|
+
${proceduralHash21}
|
|
32
33
|
|
|
33
34
|
float getSimplexNoise(vec2 uv, float t) {
|
|
34
35
|
float noise = .5 * snoise(uv - vec2(0., .3 * t));
|
|
@@ -82,7 +83,7 @@ void main() {
|
|
|
82
83
|
${sizingUV}
|
|
83
84
|
|
|
84
85
|
vec2 dithering_uv = pxSizeUv;
|
|
85
|
-
vec2 ditheringNoise_uv = uv;
|
|
86
|
+
vec2 ditheringNoise_uv = uv * u_resolution;
|
|
86
87
|
vec2 shape_uv = objectUV;
|
|
87
88
|
if (u_shape < 3.5) {
|
|
88
89
|
shape_uv = patternUV;
|
|
@@ -113,11 +114,10 @@ void main() {
|
|
|
113
114
|
shape_uv *= .05;
|
|
114
115
|
|
|
115
116
|
float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
|
|
116
|
-
float rand =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
shape =
|
|
120
|
-
shape = pow(shape, 6.);
|
|
117
|
+
float rand = hash11(stripeIdx * 10.);
|
|
118
|
+
rand = sign(rand - .5) * pow(.1 + abs(rand), .4);
|
|
119
|
+
shape = sin(shape_uv.x) * cos(shape_uv.y - 5. * rand * t);
|
|
120
|
+
shape = pow(abs(shape), 6.);
|
|
121
121
|
|
|
122
122
|
} else if (u_shape < 4.5) {
|
|
123
123
|
// Sine wave
|
|
@@ -147,9 +147,11 @@ void main() {
|
|
|
147
147
|
// Sphere
|
|
148
148
|
shape_uv *= 2.;
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
float d = 1. - pow(length(shape_uv), 2.);
|
|
151
|
+
vec3 pos = vec3(shape_uv, sqrt(d));
|
|
151
152
|
vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
|
|
152
153
|
shape = .5 + .5 * dot(lightPos, pos);
|
|
154
|
+
shape *= step(0., d);
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
|
|
@@ -158,7 +160,7 @@ void main() {
|
|
|
158
160
|
|
|
159
161
|
switch (type) {
|
|
160
162
|
case 1: {
|
|
161
|
-
dithering = step(
|
|
163
|
+
dithering = step(hash21(ditheringNoise_uv), shape);
|
|
162
164
|
} break;
|
|
163
165
|
case 2:
|
|
164
166
|
dithering = getBayerValue(dithering_uv, 2);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": ";;;;;AACA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,
|
|
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 { simplexNoise, declarePI, proceduralHash11, proceduralHash21 } 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\n// language=GLSL\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${simplexNoise}\n${declarePI}\n${proceduralHash11}\n${proceduralHash21}\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 * u_resolution;\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 = hash11(stripeIdx * 10.);\n rand = sign(rand - .5) * pow(.1 + abs(rand), .4);\n shape = sin(shape_uv.x) * cos(shape_uv.y - 5. * rand * t);\n shape = pow(abs(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 float d = 1. - pow(length(shape_uv), 2.);\n vec3 pos = vec3(shape_uv, sqrt(d));\n vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));\n shape = .5 + .5 * dot(lightPos, pos);\n shape *= step(0., d);\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(hash21(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,cAAc,WAAW,kBAAkB,wBAAwB;AA0BrE,MAAM,0BAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUzB,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,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,IAmDd,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;AAAA,MAkHN,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
6
|
"names": []
|
|
7
7
|
}
|
package/dist/shaders/dot-grid.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
6
|
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
-
import { declarePI,
|
|
7
|
+
import { declarePI, simplexNoise } from "../shader-utils.js";
|
|
8
8
|
const dotGridFragmentShader = `#version 300 es
|
|
9
9
|
precision mediump float;
|
|
10
10
|
|
|
@@ -24,7 +24,7 @@ ${sizingVariablesDeclaration}
|
|
|
24
24
|
out vec4 fragColor;
|
|
25
25
|
|
|
26
26
|
${declarePI}
|
|
27
|
-
${
|
|
27
|
+
${simplexNoise}
|
|
28
28
|
|
|
29
29
|
float polygon(vec2 p, float N, float rot) {
|
|
30
30
|
float a = atan(p.x, p.y) + rot;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/dot-grid.ts"],
|
|
4
|
-
"sourcesContent": ["import { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI,
|
|
5
|
-
"mappings": ";;;;;AAAA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,
|
|
4
|
+
"sourcesContent": ["import { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, simplexNoise } from '../shader-utils.js';\n\n/**\n * Static grid pattern\n *\n * Uniforms:\n * - u_colorBack, u_colorFill, u_colorStroke (vec4 RGBA)\n * - u_dotSize (px): base shape size\n * - u_sizeRange (0..1): randomizes the size of shape between 0 and u_dotSize\n * - u_strokeWidth (px): the stroke (to be added to u_dotSize)\n * - u_gapX, u_gapY (px): pattern spacing\n * - u_opacityRange (0..1): variety of shape opacity\n * - u_shape (float used as integer):\n * ---- 1: circle\n * ---- 2: square\n * ---- 3: triangle\n * ---- 4: diamond\n * ---- 5: cross\n *\n */\n\n// language=GLSL\nexport const dotGridFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFill;\nuniform vec4 u_colorStroke;\nuniform float u_dotSize;\nuniform float u_gapX;\nuniform float u_gapY;\nuniform float u_strokeWidth;\nuniform float u_sizeRange;\nuniform float u_opacityRange;\nuniform float u_shape;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${simplexNoise}\n\nfloat polygon(vec2 p, float N, float rot) {\n float a = atan(p.x, p.y) + rot;\n float r = TWO_PI / float(N);\n\n return cos(floor(.5 + a / r) * r - a) * length(p);\n}\n\nvoid main() {\n\n // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n vec2 shape_uv = 100. * v_patternUV;\n\n vec2 grid = fract(shape_uv / vec2(u_gapX, u_gapY)) + 1e-4;\n vec2 grid_idx = floor(shape_uv / vec2(u_gapX, u_gapY));\n float sizeRandomizer = .5 + .8 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));\n float opacity_randomizer = .5 + .7 * snoise(2. * vec2(grid_idx.y, grid_idx.x));\n\n vec2 center = vec2(0.5) - 1e-3;\n vec2 p = (grid - center) * vec2(u_gapX, u_gapY);\n\n float baseSize = u_dotSize * (1. - sizeRandomizer * u_sizeRange);\n float strokeWidth = u_strokeWidth * (1. - sizeRandomizer * u_sizeRange);\n\n float dist;\n if (u_shape < 0.5) {\n // Circle\n dist = length(p);\n } else if (u_shape < 1.5) {\n // Diamond\n strokeWidth *= 1.5;\n dist = polygon(1.5 * p, 4., .25 * PI);\n } else if (u_shape < 2.5) {\n // Square\n dist = polygon(1.03 * p, 4., 1e-3);\n } else {\n // Triangle\n strokeWidth *= 1.5;\n p = p * 2. - 1.;\n p *= .9;\n p.y = 1. - p.y;\n p.y -= .75 * baseSize;\n dist = polygon(p, 3., 1e-3);\n }\n\n float edgeWidth = fwidth(dist);\n float shapeOuter = smoothstep(baseSize + edgeWidth, baseSize - edgeWidth, dist - strokeWidth);\n float shapeInner = smoothstep(baseSize + edgeWidth, baseSize - edgeWidth, dist);\n float stroke = shapeOuter - shapeInner;\n\n float dotOpacity = max(0., 1. - opacity_randomizer * u_opacityRange);\n stroke *= dotOpacity;\n shapeInner *= dotOpacity;\n\n stroke *= u_colorStroke.a;\n shapeInner *= u_colorFill.a;\n\n vec3 color = vec3(0.);\n color += stroke * u_colorStroke.rgb;\n color += shapeInner * u_colorFill.rgb;\n color += (1. - shapeInner - stroke) * u_colorBack.rgb * u_colorBack.a;\n\n float opacity = 0.;\n opacity += stroke;\n opacity += shapeInner;\n opacity += (1. - opacity) * u_colorBack.a;\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface DotGridUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFill: [number, number, number, number];\n u_colorStroke: [number, number, number, number];\n u_dotSize: number;\n u_gapX: number;\n u_gapY: number;\n u_strokeWidth: number;\n u_sizeRange: number;\n u_opacityRange: number;\n u_shape: (typeof DotGridShapes)[DotGridShape];\n}\n\nexport interface DotGridParams extends ShaderSizingParams {\n colorBack?: string;\n colorFill?: string;\n colorStroke?: string;\n size?: number;\n gapX?: number;\n gapY?: number;\n strokeWidth?: number;\n sizeRange?: number;\n opacityRange?: number;\n shape?: DotGridShape;\n}\n\nexport const DotGridShapes = {\n circle: 0,\n diamond: 1,\n square: 2,\n triangle: 3,\n} as const;\n\nexport type DotGridShape = keyof typeof DotGridShapes;\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,oBAAoB;AAsBjC,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc3C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmGP,MAAM,gBAAgB;AAAA,EAC3B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,6 +15,8 @@ export declare const dotOrbitMeta: {
|
|
|
15
15
|
* - u_sizeRange (0..1): randomizes dot radius between 0 and u_size
|
|
16
16
|
* - u_spreading (0..1): max orbit distance of each dot around the cell center
|
|
17
17
|
*
|
|
18
|
+
* - u_noiseTexture (sampler2D): pre-computed randomizer source
|
|
19
|
+
*
|
|
18
20
|
*/
|
|
19
21
|
export declare const dotOrbitFragmentShader: string;
|
|
20
22
|
export interface DotOrbitUniforms extends ShaderSizingUniforms {
|
|
@@ -25,6 +27,7 @@ export interface DotOrbitUniforms extends ShaderSizingUniforms {
|
|
|
25
27
|
u_sizeRange: number;
|
|
26
28
|
u_spreading: number;
|
|
27
29
|
u_stepsPerColor: number;
|
|
30
|
+
u_noiseTexture?: HTMLImageElement;
|
|
28
31
|
}
|
|
29
32
|
export interface DotOrbitParams extends ShaderSizingParams, ShaderMotionParams {
|
|
30
33
|
colorBack?: string;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
6
|
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
-
import { declarePI,
|
|
7
|
+
import { declarePI, rotation2, textureRandomizerR, textureRandomizerGB } from "../shader-utils.js";
|
|
8
8
|
const dotOrbitMeta = {
|
|
9
9
|
maxColorCount: 10
|
|
10
10
|
};
|
|
@@ -13,6 +13,8 @@ precision mediump float;
|
|
|
13
13
|
|
|
14
14
|
uniform float u_time;
|
|
15
15
|
|
|
16
|
+
uniform sampler2D u_noiseTexture;
|
|
17
|
+
|
|
16
18
|
uniform vec4 u_colorBack;
|
|
17
19
|
uniform vec4 u_colors[${dotOrbitMeta.maxColorCount}];
|
|
18
20
|
uniform float u_colorsCount;
|
|
@@ -26,12 +28,10 @@ ${sizingVariablesDeclaration}
|
|
|
26
28
|
out vec4 fragColor;
|
|
27
29
|
|
|
28
30
|
${declarePI}
|
|
29
|
-
${
|
|
30
|
-
${
|
|
31
|
+
${rotation2}
|
|
32
|
+
${textureRandomizerR}
|
|
33
|
+
${textureRandomizerGB}
|
|
31
34
|
|
|
32
|
-
vec2 random2(vec2 p) {
|
|
33
|
-
return vec2(random(p), random(200. * p));
|
|
34
|
-
}
|
|
35
35
|
|
|
36
36
|
vec3 voronoiShape(vec2 uv, float time) {
|
|
37
37
|
vec2 i_uv = floor(uv);
|
|
@@ -44,11 +44,11 @@ vec3 voronoiShape(vec2 uv, float time) {
|
|
|
44
44
|
for (int y = -1; y <= 1; y++) {
|
|
45
45
|
for (int x = -1; x <= 1; x++) {
|
|
46
46
|
vec2 tileOffset = vec2(float(x), float(y));
|
|
47
|
-
vec2 rand =
|
|
47
|
+
vec2 rand = randomGB(i_uv + tileOffset);
|
|
48
48
|
vec2 cellCenter = vec2(.5 + 1e-4);
|
|
49
49
|
cellCenter += spreading * cos(time + TWO_PI * rand);
|
|
50
50
|
cellCenter -= .5;
|
|
51
|
-
cellCenter = rotate(cellCenter,
|
|
51
|
+
cellCenter = rotate(cellCenter, randomR(vec2(rand.x, rand.y)) + .1 * time);
|
|
52
52
|
cellCenter += .5;
|
|
53
53
|
float dist = length(tileOffset + cellCenter - f_uv);
|
|
54
54
|
if (dist < minDist) {
|
|
@@ -67,7 +67,7 @@ void main() {
|
|
|
67
67
|
vec2 shape_uv = v_patternUV;
|
|
68
68
|
shape_uv *= 1.5;
|
|
69
69
|
|
|
70
|
-
float t = u_time
|
|
70
|
+
float t = u_time - 10.;
|
|
71
71
|
|
|
72
72
|
vec3 voronoi = voronoiShape(shape_uv, t) + 1e-4;
|
|
73
73
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/dot-orbit.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,
|
|
5
|
-
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,
|
|
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, rotation2, textureRandomizerR, textureRandomizerGB } from '../shader-utils.js';\n\nexport const dotOrbitMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Animated dot pattern with dots orbiting around their grid positions\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_size (0..1): dot radius (relative to cell size)\n * - u_sizeRange (0..1): randomizes dot radius between 0 and u_size\n * - u_spreading (0..1): max orbit distance of each dot around the cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n */\n\n// language=GLSL\nexport const dotOrbitFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${dotOrbitMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_stepsPerColor;\nuniform float u_size;\nuniform float u_sizeRange;\nuniform float u_spreading;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${textureRandomizerR}\n${textureRandomizerGB}\n\n\nvec3 voronoiShape(vec2 uv, float time) {\n vec2 i_uv = floor(uv);\n vec2 f_uv = fract(uv);\n\n float spreading = .25 * clamp(u_spreading, 0., 1.);\n\n float minDist = 1.;\n vec2 randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tileOffset = vec2(float(x), float(y));\n vec2 rand = randomGB(i_uv + tileOffset);\n vec2 cellCenter = vec2(.5 + 1e-4);\n cellCenter += spreading * cos(time + TWO_PI * rand);\n cellCenter -= .5;\n cellCenter = rotate(cellCenter, randomR(vec2(rand.x, rand.y)) + .1 * time);\n cellCenter += .5;\n float dist = length(tileOffset + cellCenter - f_uv);\n if (dist < minDist) {\n minDist = dist;\n randomizer = rand;\n }\n minDist = min(minDist, dist);\n }\n }\n\n return vec3(minDist, randomizer);\n}\n\nvoid main() {\n\n vec2 shape_uv = v_patternUV;\n shape_uv *= 1.5;\n\n float t = u_time - 10.;\n\n vec3 voronoi = voronoiShape(shape_uv, t) + 1e-4;\n\n float radius = .25 * clamp(u_size, 0., 1.) - .5 * clamp(u_sizeRange, 0., 1.) * voronoi[2];\n float dist = voronoi[0];\n float edgeWidth = fwidth(dist);\n float dots = smoothstep(radius + edgeWidth, radius - edgeWidth, dist);\n\n float shape = voronoi[1];\n\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 < ${dotOrbitMeta.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 color = gradient.rgb * dots;\n float opacity = gradient.a * dots;\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1. - opacity);\n opacity = opacity + u_colorBack.a * (1. - opacity);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface DotOrbitUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_size: number;\n u_sizeRange: number;\n u_spreading: number;\n u_stepsPerColor: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface DotOrbitParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n size?: number;\n sizeRange?: number;\n spreading?: number;\n stepsPerColor?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,WAAW,oBAAoB,2BAA2B;AAEvE,MAAM,eAAe;AAAA,EAC1B,eAAe;AACjB;AAkBO,MAAM,yBAAiC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAQtB,aAAa,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhD,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAsDG,aAAa,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mimicking glass surface distortion over the image by distorting the texture
|
|
5
|
+
* coordinates within line patterns
|
|
6
|
+
*
|
|
7
|
+
* Uniforms:
|
|
8
|
+
* - u_count, u_angle - number and direction of grid relative to the image
|
|
9
|
+
* - u_shape (float used as integer):
|
|
10
|
+
* ---- 1: uniformly spaced stripes
|
|
11
|
+
* ---- 2: randomly spaced stripes
|
|
12
|
+
* ---- 3: sine wave stripes
|
|
13
|
+
* ---- 4: zigzag stripes
|
|
14
|
+
* ---- 5: wave-based pattern
|
|
15
|
+
* - u_distortion - the power of distortion applied along within each stripe
|
|
16
|
+
* - u_distortionShape (float used as integer):
|
|
17
|
+
* ---- 5 shapes available
|
|
18
|
+
* - u_shift - texture shift in direction opposite to the grid
|
|
19
|
+
* - u_blur - one-directional blur applied over the main distortion
|
|
20
|
+
* - u_highlights - thin color lines along the grid (independent from distortion)
|
|
21
|
+
* - u_marginLeft, u_marginRight, u_marginTop, u_marginBottom - paddings
|
|
22
|
+
* within picture to be shown without any distortion
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export declare const flutedGlassFragmentShader: string;
|
|
26
|
+
export interface FlutedGlassUniforms extends ShaderSizingUniforms {
|
|
27
|
+
u_image: HTMLImageElement | string | undefined;
|
|
28
|
+
u_count: number;
|
|
29
|
+
u_angle: number;
|
|
30
|
+
u_distortion: number;
|
|
31
|
+
u_shift: number;
|
|
32
|
+
u_blur: number;
|
|
33
|
+
u_marginLeft: number;
|
|
34
|
+
u_marginRight: number;
|
|
35
|
+
u_marginTop: number;
|
|
36
|
+
u_marginBottom: number;
|
|
37
|
+
u_highlights: number;
|
|
38
|
+
u_distortionShape: (typeof GlassDistortionShapes)[GlassDistortionShape];
|
|
39
|
+
u_shape: (typeof GlassGridShapes)[GlassGridShape];
|
|
40
|
+
u_noiseTexture?: HTMLImageElement;
|
|
41
|
+
}
|
|
42
|
+
export interface FlutedGlassParams extends ShaderSizingParams, ShaderMotionParams {
|
|
43
|
+
image?: HTMLImageElement | string | undefined;
|
|
44
|
+
count?: number;
|
|
45
|
+
angle?: number;
|
|
46
|
+
distortion?: number;
|
|
47
|
+
shift?: number;
|
|
48
|
+
blur?: number;
|
|
49
|
+
marginLeft?: number;
|
|
50
|
+
marginRight?: number;
|
|
51
|
+
marginTop?: number;
|
|
52
|
+
marginBottom?: number;
|
|
53
|
+
highlights?: number;
|
|
54
|
+
distortionShape?: GlassDistortionShape;
|
|
55
|
+
shape?: GlassGridShape;
|
|
56
|
+
}
|
|
57
|
+
export declare const GlassGridShapes: {
|
|
58
|
+
readonly lines: 1;
|
|
59
|
+
readonly linesIrregular: 2;
|
|
60
|
+
readonly wave: 3;
|
|
61
|
+
readonly zigzag: 4;
|
|
62
|
+
readonly pattern: 5;
|
|
63
|
+
};
|
|
64
|
+
export declare const GlassDistortionShapes: {
|
|
65
|
+
readonly prism: 1;
|
|
66
|
+
readonly lens: 2;
|
|
67
|
+
readonly сontour: 3;
|
|
68
|
+
readonly сascade: 4;
|
|
69
|
+
readonly facete: 5;
|
|
70
|
+
};
|
|
71
|
+
export type GlassDistortionShape = keyof typeof GlassDistortionShapes;
|
|
72
|
+
export type GlassGridShape = keyof typeof GlassGridShapes;
|