@paper-design/shaders 0.0.0-canary.390a3d9
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/get-empty-pixel.d.ts +1 -0
- package/dist/get-empty-pixel.js +19 -0
- package/dist/get-empty-pixel.js.map +7 -0
- package/dist/get-shader-color-from-string.d.ts +3 -0
- 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 +19 -0
- package/dist/get-shader-noise-texture.js.map +7 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +7 -0
- 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 +130 -0
- package/dist/shader-mount.js +483 -0
- package/dist/shader-mount.js.map +7 -0
- package/dist/shader-sizing.d.ts +35 -0
- package/dist/shader-sizing.js +230 -0
- package/dist/shader-sizing.js.map +7 -0
- package/dist/shader-utils.d.ts +10 -0
- package/dist/shader-utils.js +131 -0
- package/dist/shader-utils.js.map +7 -0
- package/dist/shaders/color-panels.d.ts +50 -0
- package/dist/shaders/color-panels.js +224 -0
- package/dist/shaders/color-panels.js.map +7 -0
- package/dist/shaders/dithering.d.ts +56 -0
- package/dist/shaders/dithering.js +223 -0
- package/dist/shaders/dithering.js.map +7 -0
- package/dist/shaders/dot-grid.d.ts +51 -0
- package/dist/shaders/dot-grid.js +110 -0
- package/dist/shaders/dot-grid.js.map +7 -0
- package/dist/shaders/dot-orbit.d.ts +39 -0
- package/dist/shaders/dot-orbit.js +124 -0
- package/dist/shaders/dot-orbit.js.map +7 -0
- package/dist/shaders/fluted-glass.d.ts +73 -0
- package/dist/shaders/fluted-glass.js +187 -0
- package/dist/shaders/fluted-glass.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +45 -0
- package/dist/shaders/god-rays.js +133 -0
- package/dist/shaders/god-rays.js.map +7 -0
- package/dist/shaders/grain-gradient.d.ts +58 -0
- package/dist/shaders/grain-gradient.js +289 -0
- package/dist/shaders/grain-gradient.js.map +7 -0
- package/dist/shaders/heatmap.d.ts +31 -0
- package/dist/shaders/heatmap.js +303 -0
- package/dist/shaders/heatmap.js.map +7 -0
- package/dist/shaders/image-dithering.d.ts +49 -0
- package/dist/shaders/image-dithering.js +163 -0
- package/dist/shaders/image-dithering.js.map +7 -0
- package/dist/shaders/image-halftone-dots.d.ts +46 -0
- package/dist/shaders/image-halftone-dots.js +337 -0
- package/dist/shaders/image-halftone-dots.js.map +7 -0
- package/dist/shaders/liquid-metal.d.ts +66 -0
- package/dist/shaders/liquid-metal.js +627 -0
- package/dist/shaders/liquid-metal.js.map +7 -0
- package/dist/shaders/mesh-gradient.d.ts +33 -0
- package/dist/shaders/mesh-gradient.js +136 -0
- package/dist/shaders/mesh-gradient.js.map +7 -0
- package/dist/shaders/metaballs.d.ts +35 -0
- package/dist/shaders/metaballs.js +112 -0
- package/dist/shaders/metaballs.js.map +7 -0
- package/dist/shaders/neuro-noise.d.ts +27 -0
- package/dist/shaders/neuro-noise.js +80 -0
- package/dist/shaders/neuro-noise.js.map +7 -0
- package/dist/shaders/paper-texture.d.ts +53 -0
- package/dist/shaders/paper-texture.js +248 -0
- package/dist/shaders/paper-texture.js.map +7 -0
- package/dist/shaders/perlin-noise.d.ts +33 -0
- package/dist/shaders/perlin-noise.js +195 -0
- package/dist/shaders/perlin-noise.js.map +7 -0
- package/dist/shaders/pulsing-border.d.ts +72 -0
- package/dist/shaders/pulsing-border.js +237 -0
- package/dist/shaders/pulsing-border.js.map +7 -0
- package/dist/shaders/simplex-noise.d.ts +27 -0
- package/dist/shaders/simplex-noise.js +100 -0
- package/dist/shaders/simplex-noise.js.map +7 -0
- package/dist/shaders/smoke-ring.d.ts +39 -0
- package/dist/shaders/smoke-ring.js +130 -0
- package/dist/shaders/smoke-ring.js.map +7 -0
- package/dist/shaders/spiral.d.ts +41 -0
- package/dist/shaders/spiral.js +81 -0
- package/dist/shaders/spiral.js.map +7 -0
- package/dist/shaders/static-mesh-gradient.d.ts +42 -0
- package/dist/shaders/static-mesh-gradient.js +139 -0
- package/dist/shaders/static-mesh-gradient.js.map +7 -0
- package/dist/shaders/static-radial-gradient.d.ts +50 -0
- package/dist/shaders/static-radial-gradient.js +195 -0
- package/dist/shaders/static-radial-gradient.js.map +7 -0
- package/dist/shaders/swirl.d.ts +42 -0
- package/dist/shaders/swirl.js +102 -0
- package/dist/shaders/swirl.js.map +7 -0
- package/dist/shaders/voronoi.d.ts +44 -0
- package/dist/shaders/voronoi.js +139 -0
- package/dist/shaders/voronoi.js.map +7 -0
- package/dist/shaders/warp.d.ts +54 -0
- package/dist/shaders/warp.js +132 -0
- package/dist/shaders/warp.js.map +7 -0
- package/dist/shaders/water.d.ts +39 -0
- package/dist/shaders/water.js +120 -0
- package/dist/shaders/water.js.map +7 -0
- package/dist/shaders/waves.d.ts +38 -0
- package/dist/shaders/waves.js +66 -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/dist/vertex-shader.d.ts +2 -0
- package/dist/vertex-shader.js +211 -0
- package/dist/vertex-shader.js.map +7 -0
- package/package.json +27 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {} from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, rotation2, proceduralHash21 } from "../shader-utils.js";
|
|
8
|
+
const imageHalftoneDotsFragmentShader = `#version 300 es
|
|
9
|
+
precision lowp float;
|
|
10
|
+
|
|
11
|
+
uniform mediump vec2 u_resolution;
|
|
12
|
+
uniform mediump float u_pixelRatio;
|
|
13
|
+
uniform mediump float u_originX;
|
|
14
|
+
uniform mediump float u_originY;
|
|
15
|
+
uniform mediump float u_fit;
|
|
16
|
+
|
|
17
|
+
uniform mediump float u_scale;
|
|
18
|
+
uniform mediump float u_rotation;
|
|
19
|
+
uniform mediump float u_offsetX;
|
|
20
|
+
uniform mediump float u_offsetY;
|
|
21
|
+
|
|
22
|
+
uniform float u_time;
|
|
23
|
+
|
|
24
|
+
uniform vec4 u_colorFront;
|
|
25
|
+
uniform vec4 u_colorBack;
|
|
26
|
+
uniform float u_radius;
|
|
27
|
+
uniform float u_contrast;
|
|
28
|
+
|
|
29
|
+
uniform sampler2D u_image;
|
|
30
|
+
uniform mediump float u_imageAspectRatio;
|
|
31
|
+
|
|
32
|
+
uniform float u_size;
|
|
33
|
+
uniform float u_grainMixer;
|
|
34
|
+
uniform float u_grainOverlay;
|
|
35
|
+
uniform bool u_diagonalGrid;
|
|
36
|
+
uniform bool u_originalColors;
|
|
37
|
+
uniform bool u_inverted;
|
|
38
|
+
uniform float u_type;
|
|
39
|
+
|
|
40
|
+
out vec4 fragColor;
|
|
41
|
+
|
|
42
|
+
${declarePI}
|
|
43
|
+
${rotation2}
|
|
44
|
+
${proceduralHash21}
|
|
45
|
+
|
|
46
|
+
float valueNoise(vec2 st) {
|
|
47
|
+
vec2 i = floor(st);
|
|
48
|
+
vec2 f = fract(st);
|
|
49
|
+
float a = hash21(i);
|
|
50
|
+
float b = hash21(i + vec2(1.0, 0.0));
|
|
51
|
+
float c = hash21(i + vec2(0.0, 1.0));
|
|
52
|
+
float d = hash21(i + vec2(1.0, 1.0));
|
|
53
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
54
|
+
float x1 = mix(a, b, u.x);
|
|
55
|
+
float x2 = mix(c, d, u.x);
|
|
56
|
+
return mix(x1, x2, u.y);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
float lst(float edge0, float edge1, float x) {
|
|
60
|
+
return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
float sst(float edge0, float edge1, float x) {
|
|
64
|
+
return smoothstep(edge0, edge1, x);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
vec2 getImageUV(vec2 uv, vec2 extraScale) {
|
|
68
|
+
vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
|
|
69
|
+
float r = u_rotation * PI / 180.;
|
|
70
|
+
mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
|
|
71
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
72
|
+
|
|
73
|
+
vec2 imageBoxSize;
|
|
74
|
+
if (u_fit == 1.) {
|
|
75
|
+
imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
|
|
76
|
+
} else {
|
|
77
|
+
imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;
|
|
78
|
+
}
|
|
79
|
+
imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;
|
|
80
|
+
vec2 imageBoxScale = u_resolution.xy / imageBoxSize;
|
|
81
|
+
|
|
82
|
+
vec2 imageUV = uv;
|
|
83
|
+
imageUV *= imageBoxScale;
|
|
84
|
+
imageUV += boxOrigin * (imageBoxScale - 1.);
|
|
85
|
+
imageUV += graphicOffset;
|
|
86
|
+
imageUV /= u_scale;
|
|
87
|
+
imageUV *= extraScale;
|
|
88
|
+
imageUV.x *= u_imageAspectRatio;
|
|
89
|
+
imageUV = graphicRotation * imageUV;
|
|
90
|
+
imageUV.x /= u_imageAspectRatio;
|
|
91
|
+
|
|
92
|
+
imageUV += .5;
|
|
93
|
+
imageUV.y = 1. - imageUV.y;
|
|
94
|
+
|
|
95
|
+
return imageUV;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
float getCircle(vec2 uv, float r) {
|
|
99
|
+
r = mix(.25 * u_radius, 0., r);
|
|
100
|
+
float d = length(uv - .5);
|
|
101
|
+
float aa = fwidth(d);
|
|
102
|
+
return 1. - smoothstep(r - aa, r + aa, d);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
float getCell(vec2 uv) {
|
|
106
|
+
float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));
|
|
107
|
+
float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));
|
|
108
|
+
return insideX * insideY;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
float getCircleWithHole(vec2 uv, float r) {
|
|
112
|
+
float cell = getCell(uv);
|
|
113
|
+
|
|
114
|
+
r = mix(.5 * u_radius, 0., r);
|
|
115
|
+
float rMod = mod(r, .25);
|
|
116
|
+
|
|
117
|
+
float d = length(uv - .5);
|
|
118
|
+
float aa = fwidth(d);
|
|
119
|
+
float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);
|
|
120
|
+
if (r < .25) {
|
|
121
|
+
return circle;
|
|
122
|
+
} else {
|
|
123
|
+
return cell - circle;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
float getGooeyBall(vec2 uv, float r) {
|
|
128
|
+
float d = length(uv - .5);
|
|
129
|
+
float sizeRadius = mix((u_diagonalGrid ? .4 : .25) * u_radius, 0., r);
|
|
130
|
+
d = 1. - sst(0., sizeRadius, d);
|
|
131
|
+
|
|
132
|
+
d = pow(d, 2. + u_radius);
|
|
133
|
+
return d;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
float getSoftBall(vec2 uv, float r) {
|
|
137
|
+
float d = length(uv - .5);
|
|
138
|
+
float sizeRadius = clamp(u_radius, 0., 1.);
|
|
139
|
+
sizeRadius = mix(.5 * sizeRadius, 0., r);
|
|
140
|
+
d = 1. - lst(0., sizeRadius, d);
|
|
141
|
+
float powRadius = 1. - lst(0., 2., u_radius);
|
|
142
|
+
d = pow(d, 4. + 3. * powRadius);
|
|
143
|
+
return d;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
float getUvFrame(vec2 uv) {
|
|
147
|
+
float aa = 0.0001;
|
|
148
|
+
|
|
149
|
+
float left = smoothstep(0., aa, uv.x);
|
|
150
|
+
float right = smoothstep(1., 1. - aa, uv.x);
|
|
151
|
+
float bottom = smoothstep(0., aa, uv.y);
|
|
152
|
+
float top = smoothstep(1., 1. - aa, uv.y);
|
|
153
|
+
|
|
154
|
+
return left * right * bottom * top;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
float sigmoid(float x, float k) {
|
|
158
|
+
return 1.0 / (1.0 + exp(-k * (x - 0.5)));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
float getLumAtPx(vec2 uv, float contrast) {
|
|
162
|
+
vec4 tex = texture(u_image, uv);
|
|
163
|
+
vec3 color = vec3(
|
|
164
|
+
sigmoid(tex.r, contrast),
|
|
165
|
+
sigmoid(tex.g, contrast),
|
|
166
|
+
sigmoid(tex.b, contrast)
|
|
167
|
+
);
|
|
168
|
+
float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);
|
|
169
|
+
lum = u_inverted ? (1. - lum) : lum;
|
|
170
|
+
return lum;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
float getLumBall(vec2 p, vec2 pxSize, vec2 inCellOffset, float contrast, out vec4 ballColor) {
|
|
174
|
+
p += inCellOffset;
|
|
175
|
+
vec2 uv_i = floor(p);
|
|
176
|
+
vec2 uv_f = fract(p);
|
|
177
|
+
vec2 samplePx = ((uv_i + .5 - inCellOffset) * pxSize) / u_resolution.xy;
|
|
178
|
+
vec2 samplingUV = getImageUV(samplePx, vec2(1.));
|
|
179
|
+
float outOfFrame = getUvFrame(samplingUV);
|
|
180
|
+
|
|
181
|
+
float lum = getLumAtPx(samplingUV, contrast);
|
|
182
|
+
ballColor = texture(u_image, samplingUV);
|
|
183
|
+
ballColor.rgb *= ballColor.a;
|
|
184
|
+
ballColor *= outOfFrame;
|
|
185
|
+
|
|
186
|
+
float ball = 0.;
|
|
187
|
+
if (u_type < .5) {
|
|
188
|
+
// classic
|
|
189
|
+
ball = getCircle(uv_f, lum);
|
|
190
|
+
} else if (u_type < 1.5) {
|
|
191
|
+
// hole
|
|
192
|
+
ball = getCircleWithHole(uv_f, lum);
|
|
193
|
+
} else if (u_type < 2.5) {
|
|
194
|
+
// gooey
|
|
195
|
+
ball = getGooeyBall(uv_f, lum);
|
|
196
|
+
}else if (u_type < 3.5) {
|
|
197
|
+
// soft
|
|
198
|
+
ball = getSoftBall(uv_f, lum);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return ball * outOfFrame;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void main() {
|
|
205
|
+
|
|
206
|
+
float stepMultiplier = 1.;
|
|
207
|
+
if (u_type < 1.) {
|
|
208
|
+
// classic
|
|
209
|
+
stepMultiplier = 2.;
|
|
210
|
+
} else if (u_type > 1.5) {
|
|
211
|
+
// gooey
|
|
212
|
+
stepMultiplier = 6.;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
vec2 pxSize = vec2(stepMultiplier) * u_size * u_pixelRatio;
|
|
216
|
+
if (u_type == 2. && u_diagonalGrid == true) {
|
|
217
|
+
pxSize *= .6;
|
|
218
|
+
}
|
|
219
|
+
float contrast = mix(0., 15., u_contrast);
|
|
220
|
+
|
|
221
|
+
vec2 uv = gl_FragCoord.xy - .5 * u_resolution;
|
|
222
|
+
vec2 p = uv / pxSize;
|
|
223
|
+
|
|
224
|
+
vec2 uvNormalised = uv / u_resolution.xy;
|
|
225
|
+
vec2 uvOriginal = getImageUV(uvNormalised, vec2(1.));
|
|
226
|
+
vec4 textureOriginal = texture(u_image, uvOriginal);
|
|
227
|
+
|
|
228
|
+
float totalShape = 0.;
|
|
229
|
+
vec3 totalColor = vec3(0.);
|
|
230
|
+
float totalOpacity = 0.;
|
|
231
|
+
|
|
232
|
+
vec4 ballColor;
|
|
233
|
+
float shape;
|
|
234
|
+
float stepSize = 1. / stepMultiplier;
|
|
235
|
+
for (float x = -0.5; x < 0.5; x += stepSize) {
|
|
236
|
+
for (float y = -0.5; y < 0.5; y += stepSize) {
|
|
237
|
+
vec2 offset = vec2(x, y);
|
|
238
|
+
|
|
239
|
+
if (u_diagonalGrid == true) {
|
|
240
|
+
float rowIndex = floor((y + .5) / stepSize);
|
|
241
|
+
float colIndex = floor((x + .5) / stepSize);
|
|
242
|
+
if (stepSize == 1.) {
|
|
243
|
+
rowIndex = floor(p.y + y + 1.);
|
|
244
|
+
if (u_type == 2.) {
|
|
245
|
+
colIndex = floor(p.x + x + 1.);
|
|
246
|
+
}
|
|
247
|
+
if (u_type == 1.) {
|
|
248
|
+
rowIndex = floor(p.y + y + 1.);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (u_type == 2.) {
|
|
252
|
+
if (mod(rowIndex + colIndex, 2.) == 1.) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
if (mod(rowIndex, 2.) == 1.) {
|
|
257
|
+
offset.x += .5 * stepSize;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
shape = getLumBall(p, pxSize, offset, contrast, ballColor);
|
|
263
|
+
totalColor += ballColor.rgb * shape;
|
|
264
|
+
totalShape += shape;
|
|
265
|
+
totalOpacity += ballColor.a * shape;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
totalShape *= textureOriginal.a;
|
|
270
|
+
|
|
271
|
+
const float eps = 1e-4;
|
|
272
|
+
|
|
273
|
+
totalColor /= max(totalShape, eps);
|
|
274
|
+
totalOpacity /= max(totalShape, eps);
|
|
275
|
+
|
|
276
|
+
float finalShape = 0.;
|
|
277
|
+
if (u_type < 1.5) {
|
|
278
|
+
finalShape = min(1., totalShape);
|
|
279
|
+
} else if (u_type < 2.5) {
|
|
280
|
+
float aa = fwidth(totalShape);
|
|
281
|
+
float th = .5;
|
|
282
|
+
finalShape = smoothstep(th - aa, th + aa, totalShape);
|
|
283
|
+
// finalShape = totalShape;
|
|
284
|
+
} else if (u_type < 3.5) {
|
|
285
|
+
finalShape = totalShape;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
vec2 dudx = dFdx(uvOriginal);
|
|
289
|
+
vec2 dudy = dFdy(uvOriginal);
|
|
290
|
+
vec2 grainUV = getImageUV(uvNormalised, .6 / vec2(length(dudx), length(dudy)));
|
|
291
|
+
float grain = valueNoise(grainUV);
|
|
292
|
+
grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);
|
|
293
|
+
grain *= u_grainMixer;
|
|
294
|
+
finalShape = mix(finalShape, 0., grain);
|
|
295
|
+
|
|
296
|
+
vec3 color = vec3(0.);
|
|
297
|
+
float opacity = 0.;
|
|
298
|
+
|
|
299
|
+
if (u_originalColors == true) {
|
|
300
|
+
color = totalColor * finalShape;
|
|
301
|
+
opacity = totalOpacity * finalShape;
|
|
302
|
+
|
|
303
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
304
|
+
color = color + bgColor * (1. - opacity);
|
|
305
|
+
opacity = opacity + u_colorBack.a * (1. - opacity);
|
|
306
|
+
} else {
|
|
307
|
+
vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
|
|
308
|
+
float fgOpacity = u_colorFront.a;
|
|
309
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
310
|
+
float bgOpacity = u_colorBack.a;
|
|
311
|
+
|
|
312
|
+
color = fgColor * finalShape;
|
|
313
|
+
opacity = fgOpacity * finalShape;
|
|
314
|
+
color += bgColor * (1. - opacity);
|
|
315
|
+
opacity += bgOpacity * (1. - opacity);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
float rr = valueNoise(rotate(grainUV, 1.) + vec2(3.));
|
|
319
|
+
float gg = valueNoise(rotate(grainUV, 2.) + vec2(-1.));
|
|
320
|
+
float bb = valueNoise(grainUV + vec2(5.));
|
|
321
|
+
vec3 grainColor = vec3(rr, gg, bb);
|
|
322
|
+
color = mix(color, grainColor, .01 + .5 * u_grainOverlay);
|
|
323
|
+
|
|
324
|
+
fragColor = vec4(color, opacity);
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
const ImageHalftoneDotsTypes = {
|
|
328
|
+
classic: 0,
|
|
329
|
+
hole: 1,
|
|
330
|
+
gooey: 2,
|
|
331
|
+
soft: 3
|
|
332
|
+
};
|
|
333
|
+
export {
|
|
334
|
+
ImageHalftoneDotsTypes,
|
|
335
|
+
imageHalftoneDotsFragmentShader
|
|
336
|
+
};
|
|
337
|
+
//# sourceMappingURL=image-halftone-dots.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/image-halftone-dots.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, proceduralHash21 } from '../shader-utils.js';\n\n/**\n\n\n Uniforms:\n - u_colorBack, u_colorFront, u_colorHighlight (RGBA)\n (u_colorHighlight to be the lighdiagonalGrid parts of u_colorFront pixels)\n - size: px size set relative to canvas resolution\n */\n\n// language=GLSL\nexport const imageHalftoneDotsFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform mediump vec2 u_resolution;\nuniform mediump float u_pixelRatio;\nuniform mediump float u_originX;\nuniform mediump float u_originY;\nuniform mediump float u_fit;\n\nuniform mediump float u_scale;\nuniform mediump float u_rotation;\nuniform mediump float u_offsetX;\nuniform mediump float u_offsetY;\n\nuniform float u_time;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_radius;\nuniform float u_contrast;\n\nuniform sampler2D u_image;\nuniform mediump float u_imageAspectRatio;\n\nuniform float u_size;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\nuniform bool u_diagonalGrid;\nuniform bool u_originalColors;\nuniform bool u_inverted;\nuniform float u_type;\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${proceduralHash21}\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(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 lst(float edge0, float edge1, float x) {\n return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\n}\n\nfloat sst(float edge0, float edge1, float x) {\n return smoothstep(edge0, edge1, x);\n}\n\nvec2 getImageUV(vec2 uv, vec2 extraScale) {\n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n float r = u_rotation * PI / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n vec2 imageBoxSize;\n if (u_fit == 1.) {\n imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n vec2 imageUV = uv;\n imageUV *= imageBoxScale;\n imageUV += boxOrigin * (imageBoxScale - 1.);\n imageUV += graphicOffset;\n imageUV /= u_scale;\n imageUV *= extraScale;\n imageUV.x *= u_imageAspectRatio;\n imageUV = graphicRotation * imageUV;\n imageUV.x /= u_imageAspectRatio;\n\n imageUV += .5;\n imageUV.y = 1. - imageUV.y;\n \n return imageUV;\n}\n\nfloat getCircle(vec2 uv, float r) {\n r = mix(.25 * u_radius, 0., r);\n float d = length(uv - .5);\n float aa = fwidth(d);\n return 1. - smoothstep(r - aa, r + aa, d);\n}\n\nfloat getCell(vec2 uv) {\n float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));\n float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));\n return insideX * insideY;\n}\n\nfloat getCircleWithHole(vec2 uv, float r) {\n float cell = getCell(uv);\n\n r = mix(.5 * u_radius, 0., r);\n float rMod = mod(r, .25);\n \n float d = length(uv - .5);\n float aa = fwidth(d);\n float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);\n if (r < .25) {\n return circle;\n } else {\n return cell - circle;\n }\n}\n\nfloat getGooeyBall(vec2 uv, float r) {\n float d = length(uv - .5);\n float sizeRadius = mix((u_diagonalGrid ? .4 : .25) * u_radius, 0., r);\n d = 1. - sst(0., sizeRadius, d);\n \n d = pow(d, 2. + u_radius);\n return d;\n}\n\nfloat getSoftBall(vec2 uv, float r) {\n float d = length(uv - .5);\n float sizeRadius = clamp(u_radius, 0., 1.);\n sizeRadius = mix(.5 * sizeRadius, 0., r);\n d = 1. - lst(0., sizeRadius, d);\n float powRadius = 1. - lst(0., 2., u_radius);\n d = pow(d, 4. + 3. * powRadius);\n return d;\n}\n\nfloat getUvFrame(vec2 uv) {\n float aa = 0.0001;\n\n float left = smoothstep(0., aa, uv.x);\n float right = smoothstep(1., 1. - aa, uv.x);\n float bottom = smoothstep(0., aa, uv.y);\n float top = smoothstep(1., 1. - aa, uv.y);\n\n return left * right * bottom * top;\n}\n\nfloat sigmoid(float x, float k) {\n return 1.0 / (1.0 + exp(-k * (x - 0.5)));\n}\n\nfloat getLumAtPx(vec2 uv, float contrast) {\n vec4 tex = texture(u_image, uv);\n vec3 color = vec3(\n sigmoid(tex.r, contrast),\n sigmoid(tex.g, contrast),\n sigmoid(tex.b, contrast)\n );\n float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);\n lum = u_inverted ? (1. - lum) : lum;\n return lum;\n}\n\nfloat getLumBall(vec2 p, vec2 pxSize, vec2 inCellOffset, float contrast, out vec4 ballColor) {\n p += inCellOffset;\n vec2 uv_i = floor(p);\n vec2 uv_f = fract(p);\n vec2 samplePx = ((uv_i + .5 - inCellOffset) * pxSize) / u_resolution.xy;\n vec2 samplingUV = getImageUV(samplePx, vec2(1.));\n float outOfFrame = getUvFrame(samplingUV);\n \n float lum = getLumAtPx(samplingUV, contrast);\n ballColor = texture(u_image, samplingUV);\n ballColor.rgb *= ballColor.a;\n ballColor *= outOfFrame;\n\n float ball = 0.;\n if (u_type < .5) {\n // classic\n ball = getCircle(uv_f, lum);\n } else if (u_type < 1.5) {\n // hole\n ball = getCircleWithHole(uv_f, lum);\n } else if (u_type < 2.5) {\n // gooey\n ball = getGooeyBall(uv_f, lum);\n }else if (u_type < 3.5) {\n // soft\n ball = getSoftBall(uv_f, lum);\n }\n\n return ball * outOfFrame;\n}\n\nvoid main() {\n\n float stepMultiplier = 1.;\n if (u_type < 1.) {\n // classic\n stepMultiplier = 2.;\n } else if (u_type > 1.5) {\n // gooey\n stepMultiplier = 6.;\n } \n \n vec2 pxSize = vec2(stepMultiplier) * u_size * u_pixelRatio;\n if (u_type == 2. && u_diagonalGrid == true) {\n pxSize *= .6;\n }\n float contrast = mix(0., 15., u_contrast);\n\n vec2 uv = gl_FragCoord.xy - .5 * u_resolution;\n vec2 p = uv / pxSize;\n \n vec2 uvNormalised = uv / u_resolution.xy;\n vec2 uvOriginal = getImageUV(uvNormalised, vec2(1.));\n vec4 textureOriginal = texture(u_image, uvOriginal);\n\n float totalShape = 0.;\n vec3 totalColor = vec3(0.);\n float totalOpacity = 0.;\n\n vec4 ballColor;\n float shape;\n float stepSize = 1. / stepMultiplier;\n for (float x = -0.5; x < 0.5; x += stepSize) {\n for (float y = -0.5; y < 0.5; y += stepSize) {\n vec2 offset = vec2(x, y);\n\n if (u_diagonalGrid == true) {\n float rowIndex = floor((y + .5) / stepSize);\n float colIndex = floor((x + .5) / stepSize);\n if (stepSize == 1.) {\n rowIndex = floor(p.y + y + 1.);\n if (u_type == 2.) {\n colIndex = floor(p.x + x + 1.);\n } \n if (u_type == 1.) {\n rowIndex = floor(p.y + y + 1.);\n }\n }\n if (u_type == 2.) {\n if (mod(rowIndex + colIndex, 2.) == 1.) {\n continue;\n }\n } else {\n if (mod(rowIndex, 2.) == 1.) {\n offset.x += .5 * stepSize;\n }\n }\n }\n\n shape = getLumBall(p, pxSize, offset, contrast, ballColor);\n totalColor += ballColor.rgb * shape;\n totalShape += shape;\n totalOpacity += ballColor.a * shape;\n }\n }\n \n totalShape *= textureOriginal.a;\n\n const float eps = 1e-4;\n \n totalColor /= max(totalShape, eps);\n totalOpacity /= max(totalShape, eps);\n\n float finalShape = 0.;\n if (u_type < 1.5) {\n finalShape = min(1., totalShape);\n } else if (u_type < 2.5) {\n float aa = fwidth(totalShape);\n float th = .5;\n finalShape = smoothstep(th - aa, th + aa, totalShape);\n// finalShape = totalShape;\n } else if (u_type < 3.5) {\n finalShape = totalShape;\n }\n\n vec2 dudx = dFdx(uvOriginal);\n vec2 dudy = dFdy(uvOriginal);\n vec2 grainUV = getImageUV(uvNormalised, .6 / vec2(length(dudx), length(dudy)));\n float grain = valueNoise(grainUV);\n grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);\n grain *= u_grainMixer;\n finalShape = mix(finalShape, 0., grain);\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n \n if (u_originalColors == true) {\n color = totalColor * finalShape;\n opacity = totalOpacity * finalShape;\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 } else {\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 color = fgColor * finalShape;\n opacity = fgOpacity * finalShape;\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n }\n\n float rr = valueNoise(rotate(grainUV, 1.) + vec2(3.));\n float gg = valueNoise(rotate(grainUV, 2.) + vec2(-1.));\n float bb = valueNoise(grainUV + vec2(5.));\n vec3 grainColor = vec3(rr, gg, bb);\n color = mix(color, grainColor, .01 + .5 * u_grainOverlay);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface ImageHalftoneDotsUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_size: number;\n u_diagonalGrid: boolean;\n u_radius: number;\n u_contrast: number;\n u_originalColors: boolean;\n u_inverted: boolean;\n u_grainMixer: number;\n u_grainOverlay: number;\n u_type: (typeof ImageHalftoneDotsTypes)[ImageHalftoneDotsType];\n}\n\nexport interface ImageHalftoneDotsParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n colorFront?: string;\n colorBack?: string;\n size?: number;\n diagonalGrid?: boolean;\n radius?: number;\n contrast?: number;\n originalColors?: boolean;\n inverted?: boolean;\n grainMixer?: number;\n grainOverlay?: number;\n type?: ImageHalftoneDotsType;\n}\n\nexport const ImageHalftoneDotsTypes = {\n classic: 0,\n hole: 1,\n gooey: 2,\n soft: 3,\n} as const;\n\nexport type ImageHalftoneDotsType = keyof typeof ImageHalftoneDotsTypes;\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,WAAW,wBAAwB;AAYhD,MAAM,kCAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkCrD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0TX,MAAM,yBAAyB;AAAA,EACpC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Fluid motion imitation applied over user image
|
|
6
|
+
* (animated stripe pattern getting distorted with shape edges)
|
|
7
|
+
*
|
|
8
|
+
* Uniforms:
|
|
9
|
+
* - u_colorBack, u_colorTint (RGBA)
|
|
10
|
+
* - u_repetition: density of pattern stripes
|
|
11
|
+
* - u_softness: blur between stripes
|
|
12
|
+
* - u_shiftRed & u_shiftBlue: color dispersion between the stripes
|
|
13
|
+
* - u_distortion: pattern distortion on the whole canvas
|
|
14
|
+
* - u_contour: distortion power over the shape edges
|
|
15
|
+
* - u_shape (float used as integer):
|
|
16
|
+
* ---- 0: canvas-screen rectangle, needs u_worldWidth = u_worldHeight = 0 to be responsive (see vertex shader)
|
|
17
|
+
* ---- 1: static circle
|
|
18
|
+
* ---- 2: animated flower-like polar shape
|
|
19
|
+
* ---- 3: animated metaballs
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const liquidMetalFragmentShader: string;
|
|
23
|
+
export declare const POISSON_CONFIG_OPTIMIZED: {
|
|
24
|
+
measurePerformance: boolean;
|
|
25
|
+
workingSize: number;
|
|
26
|
+
iterations: number;
|
|
27
|
+
};
|
|
28
|
+
export declare function toProcessedLiquidMetal(file: File | string): Promise<{
|
|
29
|
+
imageData: ImageData;
|
|
30
|
+
pngBlob: Blob;
|
|
31
|
+
}>;
|
|
32
|
+
export interface LiquidMetalUniforms extends ShaderSizingUniforms {
|
|
33
|
+
u_colorBack: [number, number, number, number];
|
|
34
|
+
u_colorTint: [number, number, number, number];
|
|
35
|
+
u_image: HTMLImageElement | string | undefined;
|
|
36
|
+
u_repetition: number;
|
|
37
|
+
u_shiftRed: number;
|
|
38
|
+
u_shiftBlue: number;
|
|
39
|
+
u_contour: number;
|
|
40
|
+
u_softness: number;
|
|
41
|
+
u_distortion: number;
|
|
42
|
+
u_angle: number;
|
|
43
|
+
u_shape: (typeof LiquidMetalShapes)[LiquidMetalShape];
|
|
44
|
+
u_isImage: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface LiquidMetalParams extends ShaderSizingParams, ShaderMotionParams {
|
|
47
|
+
colorBack?: string;
|
|
48
|
+
colorTint?: string;
|
|
49
|
+
image?: HTMLImageElement | string | undefined;
|
|
50
|
+
repetition?: number;
|
|
51
|
+
shiftRed?: number;
|
|
52
|
+
shiftBlue?: number;
|
|
53
|
+
contour?: number;
|
|
54
|
+
softness?: number;
|
|
55
|
+
distortion?: number;
|
|
56
|
+
angle?: number;
|
|
57
|
+
shape?: LiquidMetalShape;
|
|
58
|
+
}
|
|
59
|
+
export declare const LiquidMetalShapes: {
|
|
60
|
+
readonly none: 0;
|
|
61
|
+
readonly circle: 1;
|
|
62
|
+
readonly daisy: 2;
|
|
63
|
+
readonly diamond: 3;
|
|
64
|
+
readonly metaballs: 4;
|
|
65
|
+
};
|
|
66
|
+
export type LiquidMetalShape = keyof typeof LiquidMetalShapes;
|