@paper-design/shaders 0.0.29 → 0.0.31
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 +7 -4
- package/dist/index.d.ts +25 -23
- package/dist/index.js +44 -23
- package/dist/index.js.map +2 -2
- package/dist/shader-mount.d.ts +5 -1
- package/dist/shader-mount.js +15 -2
- package/dist/shader-mount.js.map +2 -2
- package/dist/shader-sizing.d.ts +1 -1
- package/dist/shader-sizing.js +2 -5
- package/dist/shader-sizing.js.map +2 -2
- package/dist/shaders/color-panels.d.ts +48 -0
- package/dist/shaders/color-panels.js +213 -0
- package/dist/shaders/color-panels.js.map +7 -0
- package/dist/shaders/dithering.d.ts +29 -15
- package/dist/shaders/dithering.js +85 -61
- package/dist/shaders/dithering.js.map +2 -2
- package/dist/shaders/dot-grid.d.ts +1 -1
- package/dist/shaders/dot-grid.js +20 -13
- package/dist/shaders/dot-grid.js.map +2 -2
- package/dist/shaders/dot-orbit.d.ts +6 -3
- package/dist/shaders/dot-orbit.js +15 -11
- package/dist/shaders/dot-orbit.js.map +2 -2
- package/dist/shaders/god-rays.d.ts +9 -6
- package/dist/shaders/god-rays.js +15 -16
- package/dist/shaders/god-rays.js.map +2 -2
- package/dist/shaders/grain-gradient.d.ts +17 -5
- package/dist/shaders/grain-gradient.js +61 -37
- package/dist/shaders/grain-gradient.js.map +2 -2
- package/dist/shaders/liquid-metal.d.ts +27 -12
- package/dist/shaders/liquid-metal.js +64 -67
- package/dist/shaders/liquid-metal.js.map +2 -2
- package/dist/shaders/mesh-gradient.d.ts +3 -3
- package/dist/shaders/mesh-gradient.js +7 -7
- package/dist/shaders/mesh-gradient.js.map +1 -1
- package/dist/shaders/metaballs.d.ts +6 -3
- package/dist/shaders/metaballs.js +12 -11
- package/dist/shaders/metaballs.js.map +2 -2
- package/dist/shaders/neuro-noise.d.ts +12 -6
- package/dist/shaders/neuro-noise.js +27 -12
- package/dist/shaders/neuro-noise.js.map +2 -2
- package/dist/shaders/perlin-noise.d.ts +10 -10
- package/dist/shaders/perlin-noise.js +30 -22
- package/dist/shaders/perlin-noise.js.map +2 -2
- package/dist/shaders/pulsing-border.d.ts +3 -3
- package/dist/shaders/pulsing-border.js +25 -25
- package/dist/shaders/pulsing-border.js.map +1 -1
- package/dist/shaders/simplex-noise.d.ts +3 -3
- package/dist/shaders/simplex-noise.js +13 -13
- package/dist/shaders/simplex-noise.js.map +1 -1
- package/dist/shaders/smoke-ring.d.ts +3 -3
- package/dist/shaders/smoke-ring.js +7 -7
- package/dist/shaders/smoke-ring.js.map +1 -1
- package/dist/shaders/spiral.d.ts +8 -8
- package/dist/shaders/spiral.js +16 -8
- package/dist/shaders/spiral.js.map +2 -2
- package/dist/shaders/swirl.d.ts +5 -3
- package/dist/shaders/swirl.js +30 -19
- package/dist/shaders/swirl.js.map +2 -2
- package/dist/shaders/voronoi.d.ts +8 -8
- package/dist/shaders/voronoi.js +12 -12
- package/dist/shaders/voronoi.js.map +1 -1
- package/dist/shaders/warp.d.ts +3 -3
- package/dist/shaders/warp.js +32 -28
- package/dist/shaders/warp.js.map +2 -2
- package/dist/shaders/waves.d.ts +7 -7
- package/dist/shaders/waves.js +17 -9
- package/dist/shaders/waves.js.map +2 -2
- package/package.json +1 -1
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
* https://github.com/paper-design/shaders *
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
|
-
import { sizingVariablesDeclaration } from "../shader-sizing";
|
|
7
|
-
import { declareSimplexNoise, declarePI, declareRandom, colorBandingFix } from "../shader-utils";
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { declareSimplexNoise, declarePI, declareRandom, colorBandingFix } from "../shader-utils.js";
|
|
8
8
|
const grainGradientMeta = {
|
|
9
9
|
maxColorCount: 7
|
|
10
10
|
};
|
|
11
11
|
const grainGradientFragmentShader = `#version 300 es
|
|
12
|
-
precision
|
|
12
|
+
precision mediump float;
|
|
13
13
|
|
|
14
14
|
uniform float u_time;
|
|
15
15
|
uniform vec2 u_resolution;
|
|
16
16
|
uniform float u_pixelRatio;
|
|
17
17
|
|
|
18
|
+
uniform vec4 u_colorBack;
|
|
18
19
|
uniform vec4 u_colors[${grainGradientMeta.maxColorCount}];
|
|
19
20
|
uniform float u_colorsCount;
|
|
20
21
|
uniform float u_softness;
|
|
@@ -81,24 +82,24 @@ vec2 truchet(vec2 uv, float idx){
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
void main() {
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
float t = .1 * u_time;
|
|
86
|
-
|
|
87
|
+
|
|
87
88
|
vec2 grain_uv = (gl_FragCoord.xy - .5 * u_resolution) / u_pixelRatio;
|
|
88
89
|
vec2 shape_uv = v_objectUV;
|
|
89
90
|
if (u_shape < 3.5) {
|
|
90
91
|
shape_uv = v_patternUV * .005;
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
|
|
94
95
|
float shape = 0.;
|
|
95
|
-
|
|
96
|
+
|
|
96
97
|
if (u_shape < 1.5) {
|
|
97
98
|
// Sine wave
|
|
98
|
-
|
|
99
|
+
|
|
99
100
|
float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));
|
|
100
101
|
shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
} else if (u_shape < 2.5) {
|
|
103
104
|
// Grid (dots)
|
|
104
105
|
|
|
@@ -106,12 +107,12 @@ void main() {
|
|
|
106
107
|
float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);
|
|
107
108
|
|
|
108
109
|
float speed = sign(rand - .5) * ceil(2. + rand);
|
|
109
|
-
shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
|
|
110
|
+
shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
|
|
110
111
|
shape = pow(shape, 4.);
|
|
111
|
-
|
|
112
|
+
|
|
112
113
|
} else if (u_shape < 3.5) {
|
|
113
114
|
// Truchet pattern
|
|
114
|
-
|
|
115
|
+
|
|
115
116
|
float n2 = noisenoise(shape_uv * .4 - 2.5 * t);
|
|
116
117
|
shape_uv.x += 10.;
|
|
117
118
|
shape_uv *= .6;
|
|
@@ -125,29 +126,29 @@ void main() {
|
|
|
125
126
|
n2 *= .1;
|
|
126
127
|
shape = smoothstep(.2, .55, distance1 + n2) * smoothstep(.8, .45, distance1 - n2);
|
|
127
128
|
shape += smoothstep(.2, .55, distance2 + n2) * smoothstep(.8, .45, distance2 - n2);
|
|
128
|
-
|
|
129
|
+
|
|
129
130
|
shape = pow(shape, 1.5);
|
|
130
|
-
|
|
131
|
-
} else if (u_shape < 4.5) {
|
|
131
|
+
|
|
132
|
+
} else if (u_shape < 4.5) {
|
|
132
133
|
// Corners
|
|
133
134
|
|
|
134
135
|
shape_uv *= .6;
|
|
135
136
|
vec2 outer = vec2(.5);
|
|
136
|
-
|
|
137
|
+
|
|
137
138
|
vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * sin(3. * t)));
|
|
138
139
|
vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
|
|
139
140
|
shape = 1. - bl.x * bl.y * tr.x * tr.y;
|
|
140
|
-
|
|
141
|
+
|
|
141
142
|
shape_uv = -shape_uv;
|
|
142
143
|
bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * cos(3. * t)));
|
|
143
144
|
tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
|
|
144
|
-
shape -= bl.x * bl.y * tr.x * tr.y;
|
|
145
|
-
|
|
145
|
+
shape -= bl.x * bl.y * tr.x * tr.y;
|
|
146
|
+
|
|
146
147
|
shape = 1. - smoothstep(0., 1., shape);
|
|
147
|
-
|
|
148
|
-
} else if (u_shape < 5.5) {
|
|
148
|
+
|
|
149
|
+
} else if (u_shape < 5.5) {
|
|
149
150
|
// Ripple
|
|
150
|
-
|
|
151
|
+
|
|
151
152
|
shape_uv *= 2.;
|
|
152
153
|
float dist = length(.4 * shape_uv);
|
|
153
154
|
float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;
|
|
@@ -157,21 +158,21 @@ void main() {
|
|
|
157
158
|
// Blob
|
|
158
159
|
|
|
159
160
|
t *= 2.;
|
|
160
|
-
|
|
161
|
+
|
|
161
162
|
vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));
|
|
162
163
|
vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));
|
|
163
164
|
vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));
|
|
164
165
|
vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));
|
|
165
|
-
|
|
166
|
+
|
|
166
167
|
shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);
|
|
167
168
|
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);
|
|
168
169
|
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);
|
|
169
170
|
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);
|
|
170
|
-
|
|
171
|
+
|
|
171
172
|
shape = smoothstep(.0, .9, shape);
|
|
172
173
|
float edge = smoothstep(.25, .3, shape);
|
|
173
174
|
shape = mix(.0, shape, edge);
|
|
174
|
-
|
|
175
|
+
|
|
175
176
|
} else {
|
|
176
177
|
// Sphere
|
|
177
178
|
|
|
@@ -184,35 +185,58 @@ void main() {
|
|
|
184
185
|
float edge = smoothstep(1., .97, d);
|
|
185
186
|
shape = mix(.1, .5 + .5 * lighting, edge);
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
|
|
188
189
|
float snoise05 = snoise(grain_uv * .5);
|
|
189
190
|
float grainDist = snoise(grain_uv * .2) * snoise05 - fbm_4(.002 * grain_uv + 10.) - fbm_4(.003 * grain_uv);
|
|
190
191
|
float noise = clamp(.6 * snoise05 - fbm_4(.4 * grain_uv) - fbm_4(.001 * grain_uv), 0., 1.);
|
|
191
192
|
|
|
192
193
|
shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);
|
|
193
|
-
shape += u_noise * 10. / u_colorsCount * noise;
|
|
194
|
+
shape += u_noise * 10. / u_colorsCount * noise;
|
|
194
195
|
|
|
195
196
|
float edge_w = fwidth(shape);
|
|
196
|
-
|
|
197
|
-
float mixer = shape;
|
|
198
|
-
|
|
197
|
+
|
|
198
|
+
float mixer = shape * (u_colorsCount + 1.) / u_colorsCount;
|
|
199
|
+
vec4 gradient = u_colors[0];
|
|
200
|
+
gradient.rgb *= gradient.a;
|
|
201
|
+
|
|
199
202
|
for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {
|
|
200
|
-
if (i
|
|
203
|
+
if (i > int(u_colorsCount) - 1) break;
|
|
201
204
|
|
|
202
|
-
vec2 borders = vec2(float(i) - u_softness, float(i) + u_softness + edge_w) / u_colorsCount;
|
|
205
|
+
vec2 borders = vec2(float(i + 1) - u_softness - edge_w, float(i + 1) + u_softness + edge_w) / u_colorsCount;
|
|
203
206
|
float localT = smoothstep(borders[0], borders[1], mixer);
|
|
204
|
-
|
|
207
|
+
vec4 c = u_colors[i];
|
|
208
|
+
c.rgb *= c.a;
|
|
209
|
+
gradient = mix(gradient, c, localT);
|
|
205
210
|
}
|
|
206
211
|
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
vec2 borders = vec2(2. / (u_colorsCount - 1.));
|
|
213
|
+
borders = vec2(borders[0] - u_softness - edge_w, borders[1] + u_softness + edge_w) / u_colorsCount;
|
|
214
|
+
borders[0] = max(0., borders[0]);
|
|
215
|
+
float gradientShape = smoothstep(borders[0], borders[1], mixer);
|
|
216
|
+
|
|
217
|
+
vec3 color = gradient.rgb * gradientShape;
|
|
218
|
+
float opacity = gradient.a * gradientShape;
|
|
219
|
+
|
|
220
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
221
|
+
color = color + bgColor * (1.0 - opacity);
|
|
222
|
+
opacity = opacity + u_colorBack.a * (1.0 - opacity);
|
|
209
223
|
|
|
210
224
|
${colorBandingFix}
|
|
211
225
|
|
|
212
226
|
fragColor = vec4(color, opacity);
|
|
213
227
|
}
|
|
214
228
|
`;
|
|
229
|
+
const GrainGradientShapes = {
|
|
230
|
+
wave: 1,
|
|
231
|
+
dots: 2,
|
|
232
|
+
truchet: 3,
|
|
233
|
+
corners: 4,
|
|
234
|
+
ripple: 5,
|
|
235
|
+
blob: 6,
|
|
236
|
+
sphere: 7
|
|
237
|
+
};
|
|
215
238
|
export {
|
|
239
|
+
GrainGradientShapes,
|
|
216
240
|
grainGradientFragmentShader,
|
|
217
241
|
grainGradientMeta
|
|
218
242
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/grain-gradient.ts"],
|
|
4
|
-
"sourcesContent": ["import type { vec4 } from '../types';\nimport type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declareSimplexNoise, declarePI, declareRandom, colorBandingFix } from '../shader-utils';\n\nexport const grainGradientMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Grainy Gradient Ksenia Kondrashova\n */\nexport const grainGradientFragmentShader: string = `#version 300 es\nprecision
|
|
5
|
-
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AACjB;AAKO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
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 { declareSimplexNoise, declarePI, declareRandom, colorBandingFix } from '../shader-utils.js';\n\nexport const grainGradientMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Grainy Gradient Ksenia Kondrashova\n */\nexport const grainGradientFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${grainGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_softness;\nuniform float u_intensity;\nuniform float u_noise;\nuniform float u_shape;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n${declareRandom}\n\n\nfloat noisenoise(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\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\nfloat fbm_4(vec2 n) {\n float total = 0.0, amplitude = .2;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n}\n\n\nvec2 truchet(vec2 uv, float idx){\n idx = fract(((idx - .5) * 2.));\n if (idx > 0.75) {\n uv = vec2(1.0) - uv;\n } else if (idx > 0.5) {\n uv = vec2(1.0 - uv.x, uv.y);\n } else if (idx > 0.25) {\n uv = 1.0 - vec2(1.0 - uv.x, uv.y);\n }\n return uv;\n}\n\nvoid main() {\n\n float t = .1 * u_time;\n\n vec2 grain_uv = (gl_FragCoord.xy - .5 * u_resolution) / u_pixelRatio;\n vec2 shape_uv = v_objectUV;\n if (u_shape < 3.5) {\n shape_uv = v_patternUV * .005;\n }\n\n\n float shape = 0.;\n\n if (u_shape < 1.5) {\n // Sine wave\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 < 2.5) {\n // Grid (dots)\n\n float stripeIdx = floor(2. * shape_uv.x / TWO_PI);\n float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);\n\n float speed = sign(rand - .5) * ceil(2. + rand);\n shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);\n shape = pow(shape, 4.);\n\n } else if (u_shape < 3.5) {\n // Truchet pattern\n\n float n2 = noisenoise(shape_uv * .4 - 2.5 * t);\n shape_uv.x += 10.;\n shape_uv *= .6;\n\n vec2 tile = truchet(fract(shape_uv), random(floor(shape_uv)));\n\n float distance1 = length(tile);\n float distance2 = length(tile - vec2(1.));\n\n n2 -= .5;\n n2 *= .1;\n shape = smoothstep(.2, .55, distance1 + n2) * smoothstep(.8, .45, distance1 - n2);\n shape += smoothstep(.2, .55, distance2 + n2) * smoothstep(.8, .45, distance2 - n2);\n\n shape = pow(shape, 1.5);\n\n } else if (u_shape < 4.5) {\n // Corners\n\n shape_uv *= .6;\n vec2 outer = vec2(.5);\n\n vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * sin(3. * t)));\n vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape = 1. - bl.x * bl.y * tr.x * tr.y;\n\n shape_uv = -shape_uv;\n bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(2. * t), .2 - .1 * cos(3. * t)));\n tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape -= bl.x * bl.y * tr.x * tr.y;\n\n shape = 1. - smoothstep(0., 1., shape);\n\n } else if (u_shape < 5.5) {\n // Ripple\n\n shape_uv *= 2.;\n float dist = length(.4 * shape_uv);\n float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;\n shape = waves;\n\n } else if (u_shape < 6.5) {\n // Blob\n\n t *= 2.;\n\n vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));\n vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));\n vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));\n vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));\n\n shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);\n\n shape = smoothstep(.0, .9, shape);\n float edge = smoothstep(.25, .3, shape);\n shape = mix(.0, shape, edge);\n\n } else {\n // Sphere\n\n shape_uv *= 2.;\n float d = length(shape_uv);\n float z = sqrt(1.0 - clamp(pow(d, 2.0), 0.0, 1.0));\n vec3 pos = vec3(shape_uv, z);\n vec3 lightPos = normalize(vec3(cos(3. * t), 0.8, sin(2.5 * t)));\n float lighting = dot(lightPos, pos);\n float edge = smoothstep(1., .97, d);\n shape = mix(.1, .5 + .5 * lighting, edge);\n }\n\n float snoise05 = snoise(grain_uv * .5);\n float grainDist = snoise(grain_uv * .2) * snoise05 - fbm_4(.002 * grain_uv + 10.) - fbm_4(.003 * grain_uv);\n float noise = clamp(.6 * snoise05 - fbm_4(.4 * grain_uv) - fbm_4(.001 * grain_uv), 0., 1.);\n\n shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);\n shape += u_noise * 10. / u_colorsCount * noise;\n\n float edge_w = fwidth(shape);\n\n float mixer = shape * (u_colorsCount + 1.) / u_colorsCount;\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n\n for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {\n if (i > int(u_colorsCount) - 1) break;\n\n vec2 borders = vec2(float(i + 1) - u_softness - edge_w, float(i + 1) + u_softness + edge_w) / u_colorsCount;\n float localT = smoothstep(borders[0], borders[1], mixer);\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n vec2 borders = vec2(2. / (u_colorsCount - 1.));\n borders = vec2(borders[0] - u_softness - edge_w, borders[1] + u_softness + edge_w) / u_colorsCount;\n borders[0] = max(0., borders[0]);\n float gradientShape = smoothstep(borders[0], borders[1], mixer);\n\n vec3 color = gradient.rgb * gradientShape;\n float opacity = gradient.a * gradientShape;\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1.0 - opacity);\n opacity = opacity + u_colorBack.a * (1.0 - opacity);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface GrainGradientUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_softness: number;\n u_intensity: number;\n u_noise: number;\n u_shape: (typeof GrainGradientShapes)[GrainGradientShape];\n}\n\nexport interface GrainGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n softness?: number;\n intensity?: number;\n noise?: number;\n shape?: GrainGradientShape;\n}\n\nexport const GrainGradientShapes = {\n wave: 1,\n dots: 2,\n truchet: 3,\n corners: 4,\n ripple: 5,\n blob: 6,\n sphere: 7,\n};\n\nexport type GrainGradientShape = keyof typeof GrainGradientShapes;\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AACjB;AAKO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAQ3B,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOrD,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA0KS,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAsBnD,eAAe;AAAA;AAAA;AAAA;AAAA;AAyBZ,MAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AACV;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import type { ShaderMotionParams } from '../shader-mount';
|
|
2
|
-
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
3
|
/**
|
|
4
4
|
*/
|
|
5
5
|
export declare const liquidMetalFragmentShader: string;
|
|
6
6
|
export interface LiquidMetalUniforms extends ShaderSizingUniforms {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
u_colorBack: [number, number, number, number];
|
|
8
|
+
u_colorTint: [number, number, number, number];
|
|
9
|
+
u_softness: number;
|
|
10
|
+
u_repetition: number;
|
|
11
|
+
u_shiftRed: number;
|
|
12
|
+
u_shiftBlue: number;
|
|
13
|
+
u_distortion: number;
|
|
14
|
+
u_contour: number;
|
|
15
|
+
u_shape: (typeof LiquidMetalShapes)[LiquidMetalShape];
|
|
12
16
|
}
|
|
13
17
|
export interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
colorBack?: string;
|
|
19
|
+
colorTint?: string;
|
|
20
|
+
softness?: number;
|
|
21
|
+
repetition?: number;
|
|
22
|
+
shiftRed?: number;
|
|
23
|
+
shiftBlue?: number;
|
|
24
|
+
distortion?: number;
|
|
25
|
+
contour?: number;
|
|
26
|
+
shape?: LiquidMetalShape;
|
|
19
27
|
}
|
|
28
|
+
export declare const LiquidMetalShapes: {
|
|
29
|
+
readonly none: 0;
|
|
30
|
+
readonly circle: 1;
|
|
31
|
+
readonly daisy: 2;
|
|
32
|
+
readonly metaballs: 3;
|
|
33
|
+
};
|
|
34
|
+
export type LiquidMetalShape = keyof typeof LiquidMetalShapes;
|
|
@@ -3,17 +3,22 @@
|
|
|
3
3
|
* https://github.com/paper-design/shaders *
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
|
-
import { sizingVariablesDeclaration } from "../shader-sizing";
|
|
7
|
-
import { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from "../shader-utils";
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from "../shader-utils.js";
|
|
8
8
|
const liquidMetalFragmentShader = `#version 300 es
|
|
9
|
-
precision
|
|
9
|
+
precision mediump float;
|
|
10
10
|
|
|
11
11
|
uniform float u_time;
|
|
12
12
|
|
|
13
|
-
uniform
|
|
14
|
-
uniform
|
|
15
|
-
|
|
16
|
-
uniform float
|
|
13
|
+
uniform vec4 u_colorBack;
|
|
14
|
+
uniform vec4 u_colorTint;
|
|
15
|
+
|
|
16
|
+
uniform float u_softness;
|
|
17
|
+
uniform float u_repetition;
|
|
18
|
+
uniform float u_shiftRed;
|
|
19
|
+
uniform float u_shiftBlue;
|
|
20
|
+
uniform float u_distortion;
|
|
21
|
+
uniform float u_contour;
|
|
17
22
|
uniform float u_shape;
|
|
18
23
|
|
|
19
24
|
${sizingVariablesDeclaration}
|
|
@@ -24,22 +29,13 @@ ${declarePI}
|
|
|
24
29
|
${declareRotate}
|
|
25
30
|
${declareSimplexNoise}
|
|
26
31
|
|
|
27
|
-
float
|
|
28
|
-
|
|
29
|
-
float ch = c2;
|
|
30
|
-
float border = 0.;
|
|
31
|
-
float blur = u_patternBlur + extra_blur;
|
|
32
|
-
|
|
33
|
-
if (u_shape < 1.) {
|
|
34
|
-
blur += .1 * smoothstep(-.4, -.6, v_responsiveUV.y);
|
|
35
|
-
}
|
|
32
|
+
float getColorChanges(float c1, float c2, float stripe_p, vec3 w, float blur, float bump, float tint) {
|
|
36
33
|
|
|
37
|
-
ch = mix(
|
|
34
|
+
float ch = mix(c2, c1, smoothstep(.0, blur, stripe_p));
|
|
38
35
|
|
|
39
|
-
border = w[0];
|
|
36
|
+
float border = w[0];
|
|
40
37
|
ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));
|
|
41
38
|
|
|
42
|
-
bump = smoothstep(.2, .8, bump);
|
|
43
39
|
border = w[0] + .4 * (1. - bump) * w[1];
|
|
44
40
|
ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));
|
|
45
41
|
|
|
@@ -53,22 +49,26 @@ float get_color_channel(float c1, float c2, float stripe_p, vec3 w, float extra_
|
|
|
53
49
|
float gradient = mix(c1, c2, smoothstep(0., 1., gradient_t));
|
|
54
50
|
ch = mix(ch, gradient, smoothstep(border - blur, border + blur, stripe_p));
|
|
55
51
|
|
|
52
|
+
// ch = 1. - min(1., (1. - ch) / max(tint, .0001));
|
|
53
|
+
ch = mix(ch, 1. - min(1., (1. - ch) / max(tint, 0.0001)), u_colorTint.a);
|
|
56
54
|
return ch;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
void main() {
|
|
60
|
-
|
|
58
|
+
|
|
61
59
|
float t = .1 * u_time;
|
|
62
60
|
|
|
63
61
|
vec2 uv = v_objectUV;
|
|
64
62
|
uv += .5;
|
|
65
63
|
uv.y = 1. - uv.y;
|
|
66
64
|
|
|
67
|
-
float cycleWidth = .5 *
|
|
68
|
-
|
|
65
|
+
float cycleWidth = .5 * u_repetition;
|
|
66
|
+
|
|
69
67
|
float mask = 1.;
|
|
68
|
+
float contOffset = 1.;
|
|
69
|
+
|
|
70
70
|
if (u_shape < 1.) {
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
vec2 borderUV = v_responsiveUV + .5;
|
|
73
73
|
float ratio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;
|
|
74
74
|
vec2 edge = min(borderUV, 1. - borderUV);
|
|
@@ -78,7 +78,7 @@ void main() {
|
|
|
78
78
|
maskX = pow(maskX, .25);
|
|
79
79
|
maskY = pow(maskY, .25);
|
|
80
80
|
mask = clamp(1. - maskX * maskY, 0., 1.);
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
uv = v_responsiveUV;
|
|
83
83
|
if (ratio > 1.) {
|
|
84
84
|
uv.y /= ratio;
|
|
@@ -87,25 +87,25 @@ void main() {
|
|
|
87
87
|
}
|
|
88
88
|
uv += .5;
|
|
89
89
|
uv.y = 1. - uv.y;
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
cycleWidth *= 2.;
|
|
92
|
+
contOffset = 1.5;
|
|
92
93
|
|
|
93
|
-
} else if (u_shape < 2.) {
|
|
94
|
+
} else if (u_shape < 2.) {
|
|
94
95
|
vec2 shapeUV = uv - .5;
|
|
95
96
|
shapeUV *= .67;
|
|
96
|
-
mask = pow(clamp(3. * length(shapeUV), 0., 1.),
|
|
97
|
-
|
|
98
|
-
uv *= 1.3;
|
|
97
|
+
mask = pow(clamp(3. * length(shapeUV), 0., 1.), 18.);
|
|
99
98
|
} else if (u_shape < 3.) {
|
|
100
99
|
vec2 shapeUV = uv - .5;
|
|
101
100
|
shapeUV *= 1.68;
|
|
102
|
-
|
|
101
|
+
|
|
103
102
|
float r = length(shapeUV) * 2.;
|
|
104
103
|
float a = atan(shapeUV.y, shapeUV.x) + .2;
|
|
105
104
|
r *= (1. + .05 * sin(3. * a + 2. * t));
|
|
106
105
|
float f = abs(cos(a * 3.));
|
|
107
106
|
mask = smoothstep(f, f + .7, r);
|
|
108
|
-
|
|
107
|
+
mask = pow(mask, 2.);
|
|
108
|
+
|
|
109
109
|
uv *= .8;
|
|
110
110
|
cycleWidth *= 1.6;
|
|
111
111
|
|
|
@@ -123,26 +123,25 @@ void main() {
|
|
|
123
123
|
float d = length(shapeUV + traj);
|
|
124
124
|
mask += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);
|
|
125
125
|
}
|
|
126
|
-
mask = 1. - smoothstep(.
|
|
127
|
-
|
|
128
|
-
uv *= 1.3;
|
|
129
|
-
uv.y += .2;
|
|
126
|
+
mask = 1. - smoothstep(.65, .9, mask);
|
|
127
|
+
mask = pow(mask, 4.);
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
float
|
|
130
|
+
float opacity = 1. - smoothstep(.8, .82, mask);
|
|
133
131
|
|
|
132
|
+
float ridge = .15 * (smoothstep(.0, .15, uv.y) * smoothstep(.4, .15, uv.y));
|
|
133
|
+
ridge += .05 * (smoothstep(.1, .2, 1. - uv.y) * smoothstep(.4, .2, 1. - uv.y));
|
|
134
|
+
mask += ridge;
|
|
134
135
|
|
|
135
|
-
float diagBLtoTR = uv.x - uv.y;
|
|
136
|
+
float diagBLtoTR = uv.x - uv.y;
|
|
136
137
|
float diagTLtoBR = uv.x + uv.y;
|
|
137
138
|
|
|
138
139
|
vec3 color = vec3(0.);
|
|
139
|
-
float opacity = 1.;
|
|
140
|
-
|
|
141
140
|
vec3 color1 = vec3(.98, 0.98, 1.);
|
|
142
141
|
vec3 color2 = vec3(.1, .1, .1 + .1 * smoothstep(.7, 1.3, diagTLtoBR));
|
|
143
142
|
|
|
144
143
|
vec2 grad_uv = uv - .5;
|
|
145
|
-
|
|
144
|
+
|
|
146
145
|
float dist = length(grad_uv + vec2(0., .2 * diagBLtoTR));
|
|
147
146
|
grad_uv = rotate(grad_uv, (.25 - .2 * diagBLtoTR) * PI);
|
|
148
147
|
float direction = grad_uv.x;
|
|
@@ -159,66 +158,64 @@ void main() {
|
|
|
159
158
|
float thin_strip_1_width = cycleWidth * thin_strip_1_ratio;
|
|
160
159
|
float thin_strip_2_width = cycleWidth * thin_strip_2_ratio;
|
|
161
160
|
|
|
162
|
-
opacity = 1. - smoothstep(.9, .92, mask);
|
|
163
|
-
|
|
164
161
|
float noise = snoise(uv - t);
|
|
165
162
|
|
|
166
|
-
mask += (1. - mask) *
|
|
167
|
-
|
|
168
|
-
float colorDispersion = 0.;
|
|
169
|
-
colorDispersion += (1. - bump);
|
|
170
|
-
colorDispersion = clamp(colorDispersion, 0., 1.);
|
|
163
|
+
mask += (1. - mask) * u_distortion * noise;
|
|
171
164
|
|
|
172
165
|
direction += diagBLtoTR;
|
|
173
166
|
|
|
174
|
-
|
|
167
|
+
float contour = u_contour * smoothstep(0., contOffset, mask) * smoothstep(contOffset, 0., mask);
|
|
168
|
+
direction -= 14. * noise * contour;
|
|
175
169
|
|
|
176
170
|
bump *= clamp(pow(uv.y, .1), .3, 1.);
|
|
177
171
|
direction *= (.1 + (1.1 - mask) * bump);
|
|
178
|
-
direction *= smoothstep(1., .
|
|
172
|
+
direction *= smoothstep(1., .2, mask);
|
|
179
173
|
|
|
180
|
-
float ridge = .2 * (smoothstep(.0, .15, uv.y) * smoothstep(.4, .15, uv.y));
|
|
181
|
-
ridge += .03 * (smoothstep(.1, .2, 1. - uv.y) * smoothstep(.4, .2, 1. - uv.y));
|
|
182
|
-
direction += ridge;
|
|
183
174
|
|
|
184
175
|
direction *= (.5 + .5 * pow(uv.y, 2.));
|
|
185
|
-
|
|
186
176
|
direction *= cycleWidth;
|
|
187
|
-
|
|
188
177
|
direction -= t;
|
|
189
178
|
|
|
190
|
-
float dispersionRed = colorDispersion;
|
|
191
|
-
dispersionRed += .03 * bump * noise;
|
|
192
|
-
float dispersionBlue = 1.3 * colorDispersion;
|
|
193
179
|
|
|
194
|
-
|
|
195
|
-
dispersionRed
|
|
180
|
+
float colorDispersion = (1. - bump);
|
|
181
|
+
float dispersionRed = colorDispersion;
|
|
182
|
+
dispersionRed += bump * noise;
|
|
183
|
+
float dispersionBlue = colorDispersion;
|
|
196
184
|
|
|
197
|
-
|
|
198
|
-
dispersionBlue
|
|
185
|
+
dispersionRed *= (u_shiftRed / 20.);
|
|
186
|
+
dispersionBlue *= (u_shiftBlue / 20.);
|
|
199
187
|
|
|
200
|
-
|
|
201
|
-
dispersionBlue *= u_dispersion;
|
|
188
|
+
float blur = u_softness / 15. + .3 * contour;
|
|
202
189
|
|
|
203
190
|
vec3 w = vec3(thin_strip_1_width, thin_strip_2_width, wide_strip_ratio);
|
|
204
191
|
w[1] -= .02 * smoothstep(.0, 1., mask + bump);
|
|
205
|
-
float extraBlur = bump;
|
|
206
192
|
float stripe_r = mod(direction + dispersionRed, 1.);
|
|
207
|
-
float r =
|
|
193
|
+
float r = getColorChanges(color1.r, color2.r, stripe_r, w, blur, bump, u_colorTint.r);
|
|
208
194
|
float stripe_g = mod(direction, 1.);
|
|
209
|
-
float g =
|
|
195
|
+
float g = getColorChanges(color1.g, color2.g, stripe_g, w, blur, bump, u_colorTint.g);
|
|
210
196
|
float stripe_b = mod(direction - dispersionBlue, 1.);
|
|
211
|
-
float b =
|
|
197
|
+
float b = getColorChanges(color1.b, color2.b, stripe_b, w, blur, bump, u_colorTint.b);
|
|
212
198
|
|
|
213
199
|
color = vec3(r, g, b);
|
|
214
200
|
color *= opacity;
|
|
215
201
|
|
|
202
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
203
|
+
color = color + bgColor * (1. - opacity);
|
|
204
|
+
opacity = opacity + u_colorBack.a * (1. - opacity);
|
|
205
|
+
|
|
216
206
|
${colorBandingFix}
|
|
217
207
|
|
|
218
208
|
fragColor = vec4(color, opacity);
|
|
219
209
|
}
|
|
220
210
|
`;
|
|
211
|
+
const LiquidMetalShapes = {
|
|
212
|
+
none: 0,
|
|
213
|
+
circle: 1,
|
|
214
|
+
daisy: 2,
|
|
215
|
+
metaballs: 3
|
|
216
|
+
};
|
|
221
217
|
export {
|
|
218
|
+
LiquidMetalShapes,
|
|
222
219
|
liquidMetalFragmentShader
|
|
223
220
|
};
|
|
224
221
|
//# sourceMappingURL=liquid-metal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/liquid-metal.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';\nimport { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from '../shader-utils';\n\n/**\n */\n\nexport const liquidMetalFragmentShader: string = `#version 300 es\nprecision
|
|
5
|
-
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,eAAe,qBAAqB,uBAAuB;AAKxE,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, declareRotate, declareSimplexNoise, colorBandingFix } from '../shader-utils.js';\n\n/**\n */\n\nexport const liquidMetalFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorTint;\n\nuniform float u_softness;\nuniform float u_repetition;\nuniform float u_shiftRed;\nuniform float u_shiftBlue;\nuniform float u_distortion;\nuniform float u_contour;\nuniform float u_shape;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n${declareSimplexNoise}\n\nfloat getColorChanges(float c1, float c2, float stripe_p, vec3 w, float blur, float bump, float tint) {\n\n float ch = mix(c2, c1, smoothstep(.0, blur, stripe_p));\n\n float border = w[0];\n ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));\n\n border = w[0] + .4 * (1. - bump) * w[1];\n ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));\n\n border = w[0] + .5 * (1. - bump) * w[1];\n ch = mix(ch, c2, smoothstep(border - blur, border + blur, stripe_p));\n\n border = w[0] + w[1];\n ch = mix(ch, c1, smoothstep(border - blur, border + blur, stripe_p));\n\n float gradient_t = (stripe_p - w[0] - w[1]) / w[2];\n float gradient = mix(c1, c2, smoothstep(0., 1., gradient_t));\n ch = mix(ch, gradient, smoothstep(border - blur, border + blur, stripe_p));\n\n // ch = 1. - min(1., (1. - ch) / max(tint, .0001));\n ch = mix(ch, 1. - min(1., (1. - ch) / max(tint, 0.0001)), u_colorTint.a);\n return ch;\n}\n\nvoid main() {\n\n float t = .1 * u_time;\n\n vec2 uv = v_objectUV;\n uv += .5;\n uv.y = 1. - uv.y;\n\n float cycleWidth = .5 * u_repetition;\n\n float mask = 1.;\n float contOffset = 1.;\n\n if (u_shape < 1.) {\n\n vec2 borderUV = v_responsiveUV + .5;\n float ratio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n vec2 edge = min(borderUV, 1. - borderUV);\n vec2 pixel_thickness = 250. / v_responsiveBoxGivenSize;\n float maskX = smoothstep(0.0, pixel_thickness.x, edge.x);\n float maskY = smoothstep(0.0, pixel_thickness.y, edge.y);\n maskX = pow(maskX, .25);\n maskY = pow(maskY, .25);\n mask = clamp(1. - maskX * maskY, 0., 1.);\n\n uv = v_responsiveUV;\n if (ratio > 1.) {\n uv.y /= ratio;\n } else {\n uv.x *= ratio;\n }\n uv += .5;\n uv.y = 1. - uv.y;\n\n cycleWidth *= 2.;\n contOffset = 1.5;\n\n } else if (u_shape < 2.) {\n vec2 shapeUV = uv - .5;\n shapeUV *= .67;\n mask = pow(clamp(3. * length(shapeUV), 0., 1.), 18.);\n } else if (u_shape < 3.) {\n vec2 shapeUV = uv - .5;\n shapeUV *= 1.68;\n\n float r = length(shapeUV) * 2.;\n float a = atan(shapeUV.y, shapeUV.x) + .2;\n r *= (1. + .05 * sin(3. * a + 2. * t));\n float f = abs(cos(a * 3.));\n mask = smoothstep(f, f + .7, r);\n mask = pow(mask, 2.);\n\n uv *= .8;\n cycleWidth *= 1.6;\n\n } else if (u_shape < 4.) {\n vec2 shapeUV = uv - .5;\n shapeUV *= 1.3;\n mask = 0.;\n for (int i = 0; i < 5; i++) {\n float fi = float(i);\n float speed = 4.5 + 2. * sin(fi * 12.345);\n float angle = -fi * 1.5;\n vec2 dir1 = vec2(cos(angle), sin(angle));\n vec2 dir2 = vec2(cos(angle + 1.57), sin(angle + 1.));\n vec2 traj = .4 * (dir1 * sin(t * speed + fi * 1.23) + dir2 * cos(t * (speed * 0.7) + fi * 2.17));\n float d = length(shapeUV + traj);\n mask += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);\n }\n mask = 1. - smoothstep(.65, .9, mask);\n mask = pow(mask, 4.);\n }\n\n float opacity = 1. - smoothstep(.8, .82, mask);\n\n float ridge = .15 * (smoothstep(.0, .15, uv.y) * smoothstep(.4, .15, uv.y));\n ridge += .05 * (smoothstep(.1, .2, 1. - uv.y) * smoothstep(.4, .2, 1. - uv.y));\n mask += ridge;\n\n float diagBLtoTR = uv.x - uv.y;\n float diagTLtoBR = uv.x + uv.y;\n\n vec3 color = vec3(0.);\n vec3 color1 = vec3(.98, 0.98, 1.);\n vec3 color2 = vec3(.1, .1, .1 + .1 * smoothstep(.7, 1.3, diagTLtoBR));\n\n vec2 grad_uv = uv - .5;\n\n float dist = length(grad_uv + vec2(0., .2 * diagBLtoTR));\n grad_uv = rotate(grad_uv, (.25 - .2 * diagBLtoTR) * PI);\n float direction = grad_uv.x;\n\n float bump = pow(1.8 * dist, 1.2);\n bump = 1. - bump;\n bump *= pow(uv.y, .3);\n\n\n float thin_strip_1_ratio = .12 / cycleWidth * (1. - .4 * bump);\n float thin_strip_2_ratio = .07 / cycleWidth * (1. + .4 * bump);\n float wide_strip_ratio = (1. - thin_strip_1_ratio - thin_strip_2_ratio);\n\n float thin_strip_1_width = cycleWidth * thin_strip_1_ratio;\n float thin_strip_2_width = cycleWidth * thin_strip_2_ratio;\n\n float noise = snoise(uv - t);\n\n mask += (1. - mask) * u_distortion * noise;\n\n direction += diagBLtoTR;\n\n float contour = u_contour * smoothstep(0., contOffset, mask) * smoothstep(contOffset, 0., mask);\n direction -= 14. * noise * contour;\n\n bump *= clamp(pow(uv.y, .1), .3, 1.);\n direction *= (.1 + (1.1 - mask) * bump);\n direction *= smoothstep(1., .2, mask);\n\n\n direction *= (.5 + .5 * pow(uv.y, 2.));\n direction *= cycleWidth;\n direction -= t;\n\n\n float colorDispersion = (1. - bump);\n float dispersionRed = colorDispersion;\n dispersionRed += bump * noise;\n float dispersionBlue = colorDispersion;\n\n dispersionRed *= (u_shiftRed / 20.);\n dispersionBlue *= (u_shiftBlue / 20.);\n\n float blur = u_softness / 15. + .3 * contour;\n\n vec3 w = vec3(thin_strip_1_width, thin_strip_2_width, wide_strip_ratio);\n w[1] -= .02 * smoothstep(.0, 1., mask + bump);\n float stripe_r = mod(direction + dispersionRed, 1.);\n float r = getColorChanges(color1.r, color2.r, stripe_r, w, blur, bump, u_colorTint.r);\n float stripe_g = mod(direction, 1.);\n float g = getColorChanges(color1.g, color2.g, stripe_g, w, blur, bump, u_colorTint.g);\n float stripe_b = mod(direction - dispersionBlue, 1.);\n float b = getColorChanges(color1.b, color2.b, stripe_b, w, blur, bump, u_colorTint.b);\n\n color = vec3(r, g, b);\n color *= opacity;\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 ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface LiquidMetalUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorTint: [number, number, number, number];\n u_softness: number;\n u_repetition: number;\n u_shiftRed: number;\n u_shiftBlue: number;\n u_distortion: number;\n u_contour: number;\n u_shape: (typeof LiquidMetalShapes)[LiquidMetalShape];\n}\n\nexport interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorTint?: string;\n softness?: number;\n repetition?: number;\n shiftRed?: number;\n shiftBlue?: number;\n distortion?: number;\n contour?: number;\n shape?: LiquidMetalShape;\n}\n\nexport const LiquidMetalShapes = {\n none: 0,\n circle: 1,\n daisy: 2,\n metaballs: 3,\n} as const;\n\nexport type LiquidMetalShape = keyof typeof LiquidMetalShapes;\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,eAAe,qBAAqB,uBAAuB;AAKxE,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,aAAa;AAAA,EACb,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAgLjB,eAAe;AAAA;AAAA;AAAA;AAAA;AA8BZ,MAAM,oBAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
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 meshGradientMeta: {
|
|
5
5
|
readonly maxColorCount: 10;
|
|
6
6
|
};
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* https://github.com/paper-design/shaders *
|
|
4
4
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
5
|
|
|
6
|
-
import { sizingVariablesDeclaration } from "../shader-sizing";
|
|
7
|
-
import { declarePI, declareRotate, colorBandingFix } from "../shader-utils";
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, declareRotate, colorBandingFix } from "../shader-utils.js";
|
|
8
8
|
const meshGradientMeta = {
|
|
9
9
|
maxColorCount: 10
|
|
10
10
|
};
|
|
11
11
|
const meshGradientFragmentShader = `#version 300 es
|
|
12
|
-
precision
|
|
12
|
+
precision mediump float;
|
|
13
13
|
|
|
14
14
|
uniform float u_time;
|
|
15
15
|
|
|
@@ -60,14 +60,14 @@ void main() {
|
|
|
60
60
|
vec3 color = vec3(0.);
|
|
61
61
|
float opacity = 0.;
|
|
62
62
|
float totalWeight = 0.;
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
for (int i = 0; i < ${meshGradientMeta.maxColorCount}; i++) {
|
|
65
65
|
if (i >= int(u_colorsCount)) break;
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
vec2 pos = getPosition(i, t);
|
|
68
68
|
vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
|
|
69
69
|
float opacityFraction = u_colors[i].a;
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
float dist = 0.;
|
|
72
72
|
if (mod(float(i), 2.) > 1.) {
|
|
73
73
|
dist = length(shape_uv - pos);
|
|
@@ -84,7 +84,7 @@ void main() {
|
|
|
84
84
|
|
|
85
85
|
color /= totalWeight;
|
|
86
86
|
opacity /= totalWeight;
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
${colorBandingFix}
|
|
89
89
|
|
|
90
90
|
fragColor = vec4(color, opacity);
|