procedural-paper 0.0.0-stage → 0.1.0
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 +205 -2
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/dist/cards.d.ts +42 -0
- package/dist/color.d.ts +5 -0
- package/dist/composition/assets.d.ts +7 -0
- package/dist/composition/cords.d.ts +43 -0
- package/dist/composition/filters.d.ts +1 -0
- package/dist/composition/fit.d.ts +58 -0
- package/dist/composition/index.d.ts +27 -0
- package/dist/composition/index.js +1247 -0
- package/dist/composition/index.js.map +1 -0
- package/dist/composition/model.d.ts +72 -0
- package/dist/composition/motion-spec.d.ts +98 -0
- package/dist/composition/motion.d.ts +36 -0
- package/dist/composition/motion.js +291 -0
- package/dist/composition/motion.js.map +1 -0
- package/dist/composition/nodes.d.ts +7 -0
- package/dist/composition/pen.d.ts +6 -0
- package/dist/composition/photos.d.ts +41 -0
- package/dist/composition/props.d.ts +32 -0
- package/dist/composition/react.d.ts +10 -0
- package/dist/composition/react.js +22 -0
- package/dist/composition/react.js.map +1 -0
- package/dist/composition/renderer.d.ts +77 -0
- package/dist/composition/rng.d.ts +11 -0
- package/dist/composition/scene.d.ts +77 -0
- package/dist/composition/unrotate.d.ts +3 -0
- package/dist/composition.css +78 -0
- package/dist/cpu/compose.d.ts +7 -0
- package/dist/cpu/field.d.ts +10 -0
- package/dist/cpu/noise.d.ts +7 -0
- package/dist/cpu/overlays.d.ts +12 -0
- package/dist/cpu/renderer.d.ts +16 -0
- package/dist/cpu/strands.d.ts +33 -0
- package/dist/dom.d.ts +110 -0
- package/dist/dom.js +65 -0
- package/dist/dom.js.map +1 -0
- package/dist/export.d.ts +20 -0
- package/dist/gl/renderer.d.ts +61 -0
- package/dist/gl/shaders.d.ts +10 -0
- package/dist/gl/sheet-shader.d.ts +1 -0
- package/dist/hash.d.ts +12 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +2415 -0
- package/dist/index.js.map +1 -0
- package/dist/params.d.ts +169 -0
- package/dist/presets.d.ts +11 -0
- package/dist/react.d.ts +20 -0
- package/dist/react.js +50 -0
- package/dist/react.js.map +1 -0
- package/dist/resolve.d.ts +125 -0
- package/dist/sheet.d.ts +167 -0
- package/dist/stocks.d.ts +12 -0
- package/dist/styles.css +13 -0
- package/licenses/Apache-2.0.txt +201 -0
- package/package.json +116 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,2415 @@
|
|
|
1
|
+
function M(r) {
|
|
2
|
+
const o = Math.imul(r >>> 0, 747796405) + 2891336453 >>> 0, i = Math.imul((o >>> (o >>> 28) + 4 ^ o) >>> 0, 277803737) >>> 0;
|
|
3
|
+
return (i >>> 22 ^ i) >>> 0;
|
|
4
|
+
}
|
|
5
|
+
function I(r, o, i) {
|
|
6
|
+
return M(r + M(o + M(i) >>> 0) >>> 0);
|
|
7
|
+
}
|
|
8
|
+
function k(r) {
|
|
9
|
+
return (r >>> 8) * (1 / 16777216);
|
|
10
|
+
}
|
|
11
|
+
function O(r, o) {
|
|
12
|
+
return M((M(r >>> 0) ^ Math.imul(o, 2654435769)) >>> 0);
|
|
13
|
+
}
|
|
14
|
+
const pe = 32, Ke = new Float64Array(pe), Ze = new Float64Array(pe);
|
|
15
|
+
for (let r = 0; r < pe; r++) {
|
|
16
|
+
const o = r / pe * Math.PI * 2;
|
|
17
|
+
Ke[r] = Math.cos(o), Ze[r] = Math.sin(o);
|
|
18
|
+
}
|
|
19
|
+
const R = (r, o) => (r % o + o) % o, Ie = (r) => r * r * r * (r * (r * 6 - 15) + 10);
|
|
20
|
+
function ye(r, o, i, t, e, a, n) {
|
|
21
|
+
const c = I(R(r, i), R(o, t), e) & pe - 1;
|
|
22
|
+
return Ke[c] * a + Ze[c] * n;
|
|
23
|
+
}
|
|
24
|
+
function Ce(r, o, i, t, e) {
|
|
25
|
+
const a = Math.floor(r), n = Math.floor(o), c = r - a, s = o - n, l = ye(a, n, i, t, e, c, s), u = ye(a + 1, n, i, t, e, c - 1, s), d = ye(a, n + 1, i, t, e, c, s - 1), g = ye(a + 1, n + 1, i, t, e, c - 1, s - 1), h = Ie(c), f = Ie(s), y = l + (u - l) * h, p = d + (g - d) * h;
|
|
26
|
+
return (y + (p - y) * f) * 1.4142;
|
|
27
|
+
}
|
|
28
|
+
function j(r, o, i, t, e, a, n) {
|
|
29
|
+
let c = 0, s = 1, l = 0, u = 1;
|
|
30
|
+
for (let d = 0; d < e; d++)
|
|
31
|
+
c += s * Ce(r * u, o * u, i * u, t * u, n + d >>> 0), l += s, s *= a, u *= 2;
|
|
32
|
+
return c / l;
|
|
33
|
+
}
|
|
34
|
+
function ut(r, o, i, t, e, a) {
|
|
35
|
+
const n = Math.floor(r), c = Math.floor(o);
|
|
36
|
+
let s = 9, l = 9, u = 0;
|
|
37
|
+
for (let d = -1; d <= 1; d++)
|
|
38
|
+
for (let g = -1; g <= 1; g++) {
|
|
39
|
+
const h = n + g, f = c + d, y = I(R(h, i), R(f, t), e), p = h + k(y) - r, m = f + k(M(y)) - o, w = Math.sqrt(p * p + m * m);
|
|
40
|
+
u += Math.exp(-10 * w), w < s ? (l = s, s = w) : w < l && (l = w);
|
|
41
|
+
}
|
|
42
|
+
a[0] = Math.max(0, -Math.log(u) / 10), a[1] = l;
|
|
43
|
+
}
|
|
44
|
+
const ue = Math.PI * 2, Qe = (r) => r < 0 ? 0 : r > 1 ? 1 : r, ft = (r, o, i) => {
|
|
45
|
+
const t = Qe((i - r) / (o - r));
|
|
46
|
+
return t * t * (3 - 2 * t);
|
|
47
|
+
}, ve = new Float64Array(2);
|
|
48
|
+
function ht(r, o, i) {
|
|
49
|
+
const t = r.structure, e = t.vertical ? o : i, a = t.vertical ? i : o, n = t.vertical ? r.width : r.height, c = t.vertical ? r.height : r.width, s = Math.max(1, Math.round(t.per[0] / 4)), l = Math.max(1, Math.round(t.per[1] / 4)), u = e * t.per[0] + t.warp * 0.6 * Ce(e * s, a * l, s, l, t.seed), d = a * t.per[1], g = t.sharpness;
|
|
50
|
+
switch (t.type) {
|
|
51
|
+
case 1: {
|
|
52
|
+
const h = 0.5 + 0.5 * Math.cos(ue * u);
|
|
53
|
+
return Math.pow(h, 1 + 5 * g) * 2 - 1;
|
|
54
|
+
}
|
|
55
|
+
case 2: {
|
|
56
|
+
const h = Math.pow(0.5 + 0.5 * Math.cos(ue * d), 8 + 60 * g);
|
|
57
|
+
return 0.6 * Math.cos(ue * u) + 1.2 * h - 0.1;
|
|
58
|
+
}
|
|
59
|
+
case 3: {
|
|
60
|
+
const h = n / t.per[0], f = c / t.per[1], y = Math.min(h, f), p = Math.floor(u);
|
|
61
|
+
let m = 9;
|
|
62
|
+
for (let v = -1; v <= 1; v++) {
|
|
63
|
+
const x = p + v, S = R(x, 2) === 1 ? 0.5 : 0, C = Math.floor(d - S);
|
|
64
|
+
for (let F = -1; F <= 1; F++) {
|
|
65
|
+
const W = (u - (x + 0.5)) * h, T = (d - (C + F + S + 0.5)) * f, z = Math.sqrt(T * T + W * W) / y;
|
|
66
|
+
z < m && (m = z);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const w = 0.45 + (0.08 - 0.45) * g;
|
|
70
|
+
return ft(0.35 - w, 0.35 + w, m) * 2 - 1;
|
|
71
|
+
}
|
|
72
|
+
case 4: {
|
|
73
|
+
const h = Math.cos(ue * u) * Math.cos(ue * d);
|
|
74
|
+
return Math.sign(h) * Math.pow(Math.abs(h), 1 - 0.7 * g);
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function dt(r, o, i, t) {
|
|
81
|
+
const e = o / r.width, a = i / r.height, n = r.mottle;
|
|
82
|
+
let c = e * n.per[0], s = a * n.per[1];
|
|
83
|
+
if (n.warp > 0) {
|
|
84
|
+
const S = j(c, s, n.per[0], n.per[1], 3, 0.5, n.warpSeed), C = j(c + 5.2, s + 1.3, n.per[0], n.per[1], 3, 0.5, n.warpSeed);
|
|
85
|
+
c += n.warp * S, s += n.warp * C;
|
|
86
|
+
}
|
|
87
|
+
const l = j(c, s, n.per[0], n.per[1], n.octaves, 0.5, n.seed), u = r.tintAmount > 0 ? j(e * n.per[0], a * n.per[1], n.per[0], n.per[1], n.octaves, 0.5, n.tintSeed) : 0, d = r.grain, g = d.strength > 0 ? j(e * d.per[0], a * d.per[1], d.per[0], d.per[1], d.octaves, d.roughness, d.seed) : 0, h = r.cells;
|
|
88
|
+
let f = 0;
|
|
89
|
+
if (h.strength > 0) {
|
|
90
|
+
let S = e * h.per[0], C = a * h.per[1];
|
|
91
|
+
h.warp > 0 && (S += h.warp * j(S, C, h.per[0], h.per[1], 2, 0.5, h.warpSeed), C += h.warp * j(S + 3.7, C + 8.1, h.per[0], h.per[1], 2, 0.5, h.warpSeed)), ut(S, C, h.per[0], h.per[1], h.seed, ve);
|
|
92
|
+
const F = 0.5 - ve[0], W = ve[1] - ve[0] - 0.4;
|
|
93
|
+
f = (F + (W - F) * h.ridge) * 2;
|
|
94
|
+
}
|
|
95
|
+
const y = r.streaks, p = y.strength > 0 ? j(e * y.per[0], a * y.per[1], y.per[0], y.per[1], y.octaves, 0.5, y.seed) : 0, m = r.structure.strength > 0 ? ht(r, e, a) : 0, w = d.strength * g + h.strength * f + y.strength * p + r.structure.strength * m;
|
|
96
|
+
t.height = n.relief * l + w;
|
|
97
|
+
const v = r.tintAmount * Qe(0.5 + u), x = 1 + r.variation * 2 * l + r.grainTone * w;
|
|
98
|
+
return t.r = (r.base[0] + (r.tint[0] - r.base[0]) * v) * x, t.g = (r.base[1] + (r.tint[1] - r.base[1]) * v) * x, t.b = (r.base[2] + (r.tint[2] - r.base[2]) * v) * x, t;
|
|
99
|
+
}
|
|
100
|
+
const ke = Math.PI * 2, ge = 6, Je = (r, o, i, t) => M(I(r, o, i) + Math.imul(t, 2654435769) >>> 0);
|
|
101
|
+
function pt(r, o, i, t, e, a, n) {
|
|
102
|
+
const c = r.fibers;
|
|
103
|
+
let s = Je(o, i, c.seed, a);
|
|
104
|
+
if (k(s) >= Math.min(1, Math.max(0, c.count - a))) return !1;
|
|
105
|
+
s = M(s);
|
|
106
|
+
const l = k(s);
|
|
107
|
+
s = M(s);
|
|
108
|
+
const u = k(s);
|
|
109
|
+
s = M(s);
|
|
110
|
+
const d = k(s);
|
|
111
|
+
s = M(s);
|
|
112
|
+
const g = k(s);
|
|
113
|
+
s = M(s);
|
|
114
|
+
const h = k(s);
|
|
115
|
+
s = M(s);
|
|
116
|
+
const f = k(s);
|
|
117
|
+
s = M(s);
|
|
118
|
+
const y = k(s);
|
|
119
|
+
s = M(s);
|
|
120
|
+
const p = k(s);
|
|
121
|
+
s = M(s);
|
|
122
|
+
const m = k(s), w = (t + l) * c.cell[0], v = (e + u) * c.cell[1], x = d * ke, S = Math.cos(x), C = Math.sin(x), F = c.length * (0.4 + 0.6 * g), W = (h * 2 - 1) * c.curl * F, T = (f * 2 - 1) * c.curl * F, z = w - S * F * 0.5, E = v - C * F * 0.5, D = w + S * F * 0.5, H = v + C * F * 0.5, Z = z + S * F / 3 - C * W, N = E + C * F / 3 + S * W, V = z + S * 2 * F / 3 - C * T, le = E + C * 2 * F / 3 + S * T;
|
|
123
|
+
for (let B = 0; B <= ge; B++) {
|
|
124
|
+
const L = B / ge, _ = 1 - L, J = _ * _ * _, ee = 3 * _ * _ * L, te = 3 * _ * L * L, me = L * L * L;
|
|
125
|
+
n.pts[B * 2] = J * z + ee * Z + te * V + me * D, n.pts[B * 2 + 1] = J * E + ee * N + te * le + me * H;
|
|
126
|
+
}
|
|
127
|
+
return n.dark = y < c.darkRatio, n.halfWidth = c.width * (0.6 + 0.8 * p) * 0.5, n.alpha = c.opacity * (0.4 + 0.6 * m), !0;
|
|
128
|
+
}
|
|
129
|
+
function gt(r, o, i) {
|
|
130
|
+
let t = 1 / 0;
|
|
131
|
+
const e = r.pts;
|
|
132
|
+
for (let a = 0; a < ge; a++) {
|
|
133
|
+
const n = e[a * 2], c = e[a * 2 + 1], s = e[a * 2 + 2], l = e[a * 2 + 3], u = s - n, d = l - c, g = o - n, h = i - c, f = Math.min(1, Math.max(0, (g * u + h * d) / (u * u + d * d + 1e-9))), y = g - u * f, p = h - d * f, m = y * y + p * p;
|
|
134
|
+
m < t && (t = m);
|
|
135
|
+
}
|
|
136
|
+
return Math.min(1, Math.max(0, r.halfWidth + 0.5 - Math.sqrt(t)));
|
|
137
|
+
}
|
|
138
|
+
function mt(r, o, i, t, e, a, n) {
|
|
139
|
+
const c = r.specks;
|
|
140
|
+
let s = Je(o, i, c.seed, a);
|
|
141
|
+
if (k(s) >= Math.min(1, Math.max(0, c.count - a))) return !1;
|
|
142
|
+
s = M(s);
|
|
143
|
+
const l = k(s);
|
|
144
|
+
s = M(s);
|
|
145
|
+
const u = k(s);
|
|
146
|
+
s = M(s);
|
|
147
|
+
const d = k(s);
|
|
148
|
+
s = M(s);
|
|
149
|
+
const g = k(s);
|
|
150
|
+
s = M(s);
|
|
151
|
+
const h = k(s);
|
|
152
|
+
s = M(s);
|
|
153
|
+
const f = k(s);
|
|
154
|
+
s = M(s);
|
|
155
|
+
const y = k(s);
|
|
156
|
+
s = M(s);
|
|
157
|
+
const p = k(s);
|
|
158
|
+
s = M(s);
|
|
159
|
+
const m = k(s);
|
|
160
|
+
n.cx = (t + l) * c.cell[0], n.cy = (e + u) * c.cell[1];
|
|
161
|
+
const w = d * ke;
|
|
162
|
+
n.cos = Math.cos(w), n.sin = Math.sin(w);
|
|
163
|
+
const v = c.sizeMin + (c.sizeMax - c.sizeMin) * g * g * g;
|
|
164
|
+
return n.rb = v, n.ra = v * (1 + c.elongation * h), n.color = Math.min(2, Math.floor(f * 3)), n.alpha = c.opacity * (0.5 + 0.5 * y), n.ph1 = p * ke, n.ph2 = m * ke, !0;
|
|
165
|
+
}
|
|
166
|
+
function yt(r, o, i) {
|
|
167
|
+
const t = o - r.cx, e = i - r.cy, a = t * r.cos + e * r.sin, n = -t * r.sin + e * r.cos, c = a / r.ra, s = n / r.rb, l = Math.atan2(s, c), u = 1 + 0.12 * Math.sin(3 * l + r.ph1) + 0.1 * Math.sin(5 * l + r.ph2), d = Math.sqrt(c * c + s * s) / u;
|
|
168
|
+
return Math.min(1, Math.max(0, (1 - d) * r.rb + 0.5));
|
|
169
|
+
}
|
|
170
|
+
function vt() {
|
|
171
|
+
return { pts: new Float64Array((ge + 1) * 2), halfWidth: 0, alpha: 0, dark: !1 };
|
|
172
|
+
}
|
|
173
|
+
function bt() {
|
|
174
|
+
return { cx: 0, cy: 0, cos: 1, sin: 0, ra: 1, rb: 1, ph1: 0, ph2: 0, color: 0, alpha: 0 };
|
|
175
|
+
}
|
|
176
|
+
const fe = (r) => r < 0 ? 0 : r > 1 ? 1 : r;
|
|
177
|
+
function wt(r, o, i, t, e, a, n, c, s) {
|
|
178
|
+
const l = r.light.depth;
|
|
179
|
+
let u = -n * l, d = -c * l, g = 1;
|
|
180
|
+
const h = Math.sqrt(u * u + d * d + g * g);
|
|
181
|
+
u /= h, d /= h, g /= h;
|
|
182
|
+
const f = r.output;
|
|
183
|
+
if (o === "normal") {
|
|
184
|
+
s[0] = u * 0.5 + 0.5, s[1] = (f.flipY ? d : -d) * 0.5 + 0.5, s[2] = g * 0.5 + 0.5;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (o === "height") {
|
|
188
|
+
const S = fe(0.5 + 0.5 * a * r.heightNorm);
|
|
189
|
+
s[0] = s[1] = s[2] = S;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const y = r.light.dir;
|
|
193
|
+
let p = (u * y[0] + d * y[1] + g * y[2]) / y[2];
|
|
194
|
+
p = p < 0 ? 0 : p > 3 ? 3 : p;
|
|
195
|
+
const m = o !== "albedo";
|
|
196
|
+
let w = m ? i * p : i, v = m ? t * p : t, x = m ? e * p : e;
|
|
197
|
+
if (o === "overlay") {
|
|
198
|
+
const S = 0.2126 * w + 0.7152 * v + 0.0722 * x, C = fe((S - r.baseLum) * 0.5 * f.contrast + 0.5 + f.brightness);
|
|
199
|
+
s[0] = s[1] = s[2] = C;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
s[0] = fe((w - 0.5) * f.contrast + 0.5 + f.brightness), s[1] = fe((v - 0.5) * f.contrast + 0.5 + f.brightness), s[2] = fe((x - 0.5) * f.contrast + 0.5 + f.brightness);
|
|
203
|
+
}
|
|
204
|
+
const Te = Math.PI * 2, Le = (r) => r < 0 ? 0 : r > 1 ? 1 : r, xt = (r, o, i) => {
|
|
205
|
+
const t = Le((i - r) / (o - r));
|
|
206
|
+
return t * t * (3 - 2 * t);
|
|
207
|
+
}, ie = new Float64Array(9), ne = new Float64Array(9), ae = new Float64Array(9);
|
|
208
|
+
function St(r, o, i, t, e, a) {
|
|
209
|
+
let n = I(R(r, i), R(o, t), e);
|
|
210
|
+
const c = k(n);
|
|
211
|
+
n = M(n);
|
|
212
|
+
const s = k(n);
|
|
213
|
+
n = M(n), ie[a] = r + 0.5 + (c - 0.5) * 0.7, ne[a] = o + 0.5 + (s - 0.5) * 0.7, ae[a] = k(n) * 2 - 1;
|
|
214
|
+
}
|
|
215
|
+
function be(r, o, i, t, e) {
|
|
216
|
+
const a = ie[t] - ie[i], n = ne[t] - ne[i], c = ie[e] - ie[i], s = ne[e] - ne[i], l = r - ie[i], u = o - ne[i], d = a * s - c * n, g = (l * s - c * u) / d, h = (a * u - l * n) / d;
|
|
217
|
+
return g >= -1e-5 && h >= -1e-5 && g + h <= 1 + 1e-5 ? ae[i] + g * (ae[t] - ae[i]) + h * (ae[e] - ae[i]) : NaN;
|
|
218
|
+
}
|
|
219
|
+
function ze(r, o, i, t, e) {
|
|
220
|
+
const a = Math.floor(r), n = Math.floor(o);
|
|
221
|
+
for (let c = 0; c < 3; c++) for (let s = 0; s < 3; s++) St(a - 1 + s, n - 1 + c, i, t, e, c * 3 + s);
|
|
222
|
+
for (let c = 0; c < 2; c++)
|
|
223
|
+
for (let s = 0; s < 2; s++) {
|
|
224
|
+
const l = c * 3 + s, u = l + 1, d = l + 3, g = l + 4, h = I(R(a - 1 + s, i), R(n - 1 + c, t), e + 7 >>> 0) & 1;
|
|
225
|
+
let f;
|
|
226
|
+
if (h === 0) {
|
|
227
|
+
if (f = be(r, o, l, u, g), f === f || (f = be(r, o, l, g, d), f === f)) return f;
|
|
228
|
+
} else if (f = be(r, o, l, u, d), f === f || (f = be(r, o, u, g, d), f === f)) return f;
|
|
229
|
+
}
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
function Ne(r, o, i, t, e, a, n, c) {
|
|
233
|
+
const s = o / i, l = r / s - t, u = Math.floor(l), d = l - u, g = R(u, i), h = R(u + 1, i), f = k(I(g, 0, e)) * 2 - 1, y = k(I(h, 0, e)) * 2 - 1, p = f + (y - f) * d, m = Math.min(d, 1 - d) * s, w = d < 0.5 ? g : h, v = k(M(I(w, 0, e))) < 0.5 ? -1 : 1, x = Math.max(0, 1 - m / n);
|
|
234
|
+
return c[0] = m, a * (p * s * 0.12 + v * x * x * n * 0.3);
|
|
235
|
+
}
|
|
236
|
+
const re = new Float64Array(1);
|
|
237
|
+
function kt(r, o, i, t) {
|
|
238
|
+
const e = o / r.width, a = i / r.height;
|
|
239
|
+
t.dh = 0, t.mr = 1, t.mg = 1, t.mb = 1;
|
|
240
|
+
const n = r.crumples;
|
|
241
|
+
if (n.amp > 0 || n.wAmp > 0) {
|
|
242
|
+
let l = e, u = a;
|
|
243
|
+
if (n.warp > 0) {
|
|
244
|
+
const d = n.warp / ((n.per[0] + n.per[1]) * 0.5);
|
|
245
|
+
l += d * Ce(e * n.per[0], a * n.per[1], n.per[0], n.per[1], n.warpSeed), u += d * Ce(e * n.per[0] + 5.2, a * n.per[1] + 1.3, n.per[0], n.per[1], n.warpSeed);
|
|
246
|
+
}
|
|
247
|
+
if (n.amp > 0 && (t.dh += n.amp * ze(l * n.per[0], u * n.per[1], n.per[0], n.per[1], n.seed)), n.wAmp > 0) {
|
|
248
|
+
const [d, g] = n.wPer;
|
|
249
|
+
t.dh += n.wAmp * (ze(l * d, u * g, d, g, n.seed + 1 >>> 0) + 0.5 * ze(l * d * 2, u * g * 2, d * 2, g * 2, n.seed + 2 >>> 0));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const c = r.folds;
|
|
253
|
+
if (c.strength > 0 || c.wear > 0) {
|
|
254
|
+
let l = 0;
|
|
255
|
+
c.count[0] > 0 && (t.dh += Ne(o, r.width, c.count[0], c.offset, c.seed, c.strength, c.width, re), l = Math.max(l, Math.exp(-(re[0] / 1.3) * (re[0] / 1.3)))), c.count[1] > 0 && (t.dh += Ne(i, r.height, c.count[1], c.offset, c.seed + 1 >>> 0, c.strength, c.width, re), l = Math.max(l, Math.exp(-(re[0] / 1.3) * (re[0] / 1.3))));
|
|
256
|
+
const u = 1 - c.wear * 0.22 * l;
|
|
257
|
+
t.mr *= u, t.mg *= u, t.mb *= u;
|
|
258
|
+
}
|
|
259
|
+
const s = r.stains;
|
|
260
|
+
if (s.density > 0 && s.strength > 0) {
|
|
261
|
+
const l = Math.floor(o / s.cell[0]), u = Math.floor(i / s.cell[1]);
|
|
262
|
+
let d = 1;
|
|
263
|
+
for (let h = -1; h <= 1; h++)
|
|
264
|
+
for (let f = -1; f <= 1; f++) {
|
|
265
|
+
const y = l + f, p = u + h;
|
|
266
|
+
let m = I(R(y, s.per[0]), R(p, s.per[1]), s.seed);
|
|
267
|
+
if (k(m) >= s.density) continue;
|
|
268
|
+
m = M(m);
|
|
269
|
+
const w = k(m);
|
|
270
|
+
m = M(m);
|
|
271
|
+
const v = k(m);
|
|
272
|
+
m = M(m);
|
|
273
|
+
const x = k(m);
|
|
274
|
+
m = M(m);
|
|
275
|
+
const S = k(m);
|
|
276
|
+
m = M(m);
|
|
277
|
+
const C = k(m);
|
|
278
|
+
m = M(m);
|
|
279
|
+
const F = k(m), W = (y + 0.2 + 0.6 * w) * s.cell[0], T = (p + 0.2 + 0.6 * v) * s.cell[1], z = s.size * (0.55 + 0.55 * x), E = o - W, D = i - T, H = Math.sqrt(E * E + D * D);
|
|
280
|
+
if (H > z * 1.3) continue;
|
|
281
|
+
const Z = Math.atan2(D, E), N = 1 + 0.035 * Math.sin(3 * Z + S * Te) + 0.02 * Math.sin(7 * Z + C * Te), V = H / (z * N), le = Le((1 - V) * z * N + 0.5), B = (V - 0.985) / 0.03, L = Math.exp(-B * B) * (0.35 + 0.65 * xt(-0.4, 0.6, Math.sin(Z + F * Te))), _ = Le(le * (0.1 + 0.14 * V * V) + L * s.ring) * s.strength;
|
|
282
|
+
d *= 1 - _, t.dh += 0.15 * L * s.strength;
|
|
283
|
+
}
|
|
284
|
+
const g = 1 - d;
|
|
285
|
+
t.mr *= 1 + (s.color[0] - 1) * g, t.mg *= 1 + (s.color[1] - 1) * g, t.mb *= 1 + (s.color[2] - 1) * g;
|
|
286
|
+
}
|
|
287
|
+
return t;
|
|
288
|
+
}
|
|
289
|
+
function Mt(r) {
|
|
290
|
+
const o = r.width, i = r.height, t = o * i, e = new Float32Array(t * 3), a = new Float32Array(t), n = { r: 0, g: 0, b: 0, height: 0 }, c = { dh: 0, mr: 1, mg: 1, mb: 1 }, l = r.crumples.amp > 0 || r.crumples.wAmp > 0 || r.folds.strength > 0 || r.folds.wear > 0 || r.stains.density > 0 ? new Float32Array(t * 3) : null;
|
|
291
|
+
for (let g = 0; g < i; g++)
|
|
292
|
+
for (let h = 0; h < o; h++) {
|
|
293
|
+
dt(r, h + 0.5, g + 0.5, n);
|
|
294
|
+
const f = g * o + h;
|
|
295
|
+
e[f * 3] = n.r, e[f * 3 + 1] = n.g, e[f * 3 + 2] = n.b, a[f] = n.height, l && (kt(r, h + 0.5, g + 0.5, c), a[f] += c.dh, l[f * 3] = c.mr, l[f * 3 + 1] = c.mg, l[f * 3 + 2] = c.mb);
|
|
296
|
+
}
|
|
297
|
+
const u = r.fibers;
|
|
298
|
+
if (u.count > 0 && u.opacity > 0) {
|
|
299
|
+
const g = new Float32Array(t).fill(1), h = new Float32Array(t).fill(1), f = vt(), y = Math.ceil(u.count);
|
|
300
|
+
for (let p = 0; p < u.per[1]; p++)
|
|
301
|
+
for (let m = 0; m < u.per[0]; m++)
|
|
302
|
+
for (let w = 0; w < y; w++) {
|
|
303
|
+
if (!pt(r, m, p, m, p, w, f)) continue;
|
|
304
|
+
let v = 1 / 0, x = 1 / 0, S = -1 / 0, C = -1 / 0;
|
|
305
|
+
for (let T = 0; T <= ge; T++) {
|
|
306
|
+
const z = f.pts[T * 2], E = f.pts[T * 2 + 1];
|
|
307
|
+
z < v && (v = z), z > S && (S = z), E < x && (x = E), E > C && (C = E);
|
|
308
|
+
}
|
|
309
|
+
const F = f.halfWidth + 1, W = f.dark ? g : h;
|
|
310
|
+
for (let T = Math.floor(x - F); T <= Math.ceil(C + F); T++) {
|
|
311
|
+
const z = R(T, i);
|
|
312
|
+
for (let E = Math.floor(v - F); E <= Math.ceil(S + F); E++) {
|
|
313
|
+
const D = gt(f, E + 0.5, T + 0.5);
|
|
314
|
+
if (D <= 0) continue;
|
|
315
|
+
const H = z * o + R(E, o);
|
|
316
|
+
W[H] *= 1 - D * f.alpha;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (let p = 0; p < t; p++) {
|
|
321
|
+
const m = 1 - g[p], w = 1 - h[p];
|
|
322
|
+
if (!(m === 0 && w === 0)) {
|
|
323
|
+
for (let v = 0; v < 3; v++) {
|
|
324
|
+
let x = e[p * 3 + v];
|
|
325
|
+
x += (u.dark[v] - x) * m, x += (u.light[v] - x) * w, e[p * 3 + v] = x;
|
|
326
|
+
}
|
|
327
|
+
a[p] += u.relief * (1 - g[p] * h[p]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const d = r.specks;
|
|
332
|
+
if (d.count > 0 && d.opacity > 0) {
|
|
333
|
+
const g = new Float32Array(t).fill(1), h = new Float32Array(t * 4), f = bt(), y = Math.ceil(d.count);
|
|
334
|
+
for (let p = 0; p < d.per[1]; p++)
|
|
335
|
+
for (let m = 0; m < d.per[0]; m++)
|
|
336
|
+
for (let w = 0; w < y; w++) {
|
|
337
|
+
if (!mt(r, m, p, m, p, w, f)) continue;
|
|
338
|
+
const v = 1.32 * f.ra + 0.66 * f.ra / f.rb + 1, x = d.colors[f.color];
|
|
339
|
+
for (let S = Math.floor(f.cy - v); S <= Math.ceil(f.cy + v); S++) {
|
|
340
|
+
const C = R(S, i);
|
|
341
|
+
for (let F = Math.floor(f.cx - v); F <= Math.ceil(f.cx + v); F++) {
|
|
342
|
+
const W = yt(f, F + 0.5, S + 0.5);
|
|
343
|
+
if (W <= 0) continue;
|
|
344
|
+
const T = W * f.alpha, z = C * o + R(F, o);
|
|
345
|
+
g[z] *= 1 - T, h[z * 4] += x[0] * T, h[z * 4 + 1] += x[1] * T, h[z * 4 + 2] += x[2] * T, h[z * 4 + 3] += T;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
for (let p = 0; p < t; p++) {
|
|
350
|
+
const m = h[p * 4 + 3];
|
|
351
|
+
if (m <= 0) continue;
|
|
352
|
+
const w = 1 - g[p];
|
|
353
|
+
for (let v = 0; v < 3; v++) {
|
|
354
|
+
const x = e[p * 3 + v];
|
|
355
|
+
e[p * 3 + v] = x + (h[p * 4 + v] / m - x) * w;
|
|
356
|
+
}
|
|
357
|
+
a[p] += d.relief * w;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (l) for (let g = 0; g < t * 3; g++) e[g] *= l[g];
|
|
361
|
+
return { width: o, height: i, albedo: e, height_: a };
|
|
362
|
+
}
|
|
363
|
+
function Ct(r, o) {
|
|
364
|
+
const i = Mt(r), t = i.width, e = i.height, a = {}, n = new Float64Array(4);
|
|
365
|
+
for (const c of o) {
|
|
366
|
+
const s = new Uint8ClampedArray(t * e * 4);
|
|
367
|
+
for (let l = 0; l < e; l++) {
|
|
368
|
+
const u = R(l - 1, e) * t, d = R(l + 1, e) * t, g = l * t;
|
|
369
|
+
for (let h = 0; h < t; h++) {
|
|
370
|
+
const f = R(h - 1, t), y = R(h + 1, t), p = g + h, m = (i.height_[g + y] - i.height_[g + f]) * 0.5, w = (i.height_[d + h] - i.height_[u + h]) * 0.5;
|
|
371
|
+
wt(r, c, i.albedo[p * 3], i.albedo[p * 3 + 1], i.albedo[p * 3 + 2], i.height_[p], m, w, n), s[p * 4] = Math.round(n[0] * 255), s[p * 4 + 1] = Math.round(n[1] * 255), s[p * 4 + 2] = Math.round(n[2] * 255), s[p * 4 + 3] = 255;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
a[c] = s;
|
|
375
|
+
}
|
|
376
|
+
return a;
|
|
377
|
+
}
|
|
378
|
+
const Ft = (
|
|
379
|
+
/* glsl */
|
|
380
|
+
`#version 300 es
|
|
381
|
+
in vec2 aPos;
|
|
382
|
+
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
|
|
383
|
+
`
|
|
384
|
+
), et = (
|
|
385
|
+
/* glsl */
|
|
386
|
+
`
|
|
387
|
+
precision highp float;
|
|
388
|
+
precision highp int;
|
|
389
|
+
const float TAU = 6.283185307179586;
|
|
390
|
+
|
|
391
|
+
uint pcg(uint v) {
|
|
392
|
+
uint state = v * 747796405u + 2891336453u;
|
|
393
|
+
uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
|
|
394
|
+
return (word >> 22u) ^ word;
|
|
395
|
+
}
|
|
396
|
+
uint hash2(int x, int y, uint seed) { return pcg(uint(x) + pcg(uint(y) + pcg(seed))); }
|
|
397
|
+
float u01(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }
|
|
398
|
+
int imod(int a, int b) { return a - b * int(floor(float(a) / float(b))); }
|
|
399
|
+
ivec2 imod2(ivec2 a, ivec2 b) { return ivec2(imod(a.x, b.x), imod(a.y, b.y)); }
|
|
400
|
+
|
|
401
|
+
float corner(ivec2 c, ivec2 per, uint seed, vec2 d) {
|
|
402
|
+
ivec2 w = imod2(c, per);
|
|
403
|
+
uint h = hash2(w.x, w.y, seed) & 31u;
|
|
404
|
+
float a = float(h) * (TAU / 32.0);
|
|
405
|
+
return cos(a) * d.x + sin(a) * d.y;
|
|
406
|
+
}
|
|
407
|
+
float fade(float t) { return t * t * t * (t * (t * 6.0 - 15.0) + 10.0); }
|
|
408
|
+
|
|
409
|
+
float gnoise(vec2 p, ivec2 per, uint seed) {
|
|
410
|
+
vec2 i = floor(p);
|
|
411
|
+
vec2 f = p - i;
|
|
412
|
+
ivec2 c = ivec2(i);
|
|
413
|
+
float a = corner(c, per, seed, f);
|
|
414
|
+
float b = corner(c + ivec2(1, 0), per, seed, f - vec2(1.0, 0.0));
|
|
415
|
+
float cc = corner(c + ivec2(0, 1), per, seed, f - vec2(0.0, 1.0));
|
|
416
|
+
float d = corner(c + ivec2(1, 1), per, seed, f - vec2(1.0, 1.0));
|
|
417
|
+
vec2 u = vec2(fade(f.x), fade(f.y));
|
|
418
|
+
float ab = mix(a, b, u.x);
|
|
419
|
+
float cd = mix(cc, d, u.x);
|
|
420
|
+
return mix(ab, cd, u.y) * 1.4142;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
float fbm(vec2 p, ivec2 per, int octaves, float persistence, uint seed) {
|
|
424
|
+
float sum = 0.0, amp = 1.0, norm = 0.0, f = 1.0;
|
|
425
|
+
for (int o = 0; o < 12; o++) {
|
|
426
|
+
if (o >= octaves) break;
|
|
427
|
+
int fi = int(f);
|
|
428
|
+
sum += amp * gnoise(p * f, per * fi, seed + uint(o));
|
|
429
|
+
norm += amp;
|
|
430
|
+
amp *= persistence;
|
|
431
|
+
f *= 2.0;
|
|
432
|
+
}
|
|
433
|
+
return sum / norm;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
vec2 worley(vec2 p, ivec2 per, uint seed) {
|
|
437
|
+
ivec2 c = ivec2(floor(p));
|
|
438
|
+
float f1 = 9.0, f2 = 9.0, acc = 0.0;
|
|
439
|
+
for (int j = -1; j <= 1; j++) {
|
|
440
|
+
for (int i = -1; i <= 1; i++) {
|
|
441
|
+
ivec2 n = c + ivec2(i, j);
|
|
442
|
+
ivec2 w = imod2(n, per);
|
|
443
|
+
uint h = hash2(w.x, w.y, seed);
|
|
444
|
+
vec2 pt = vec2(n) + vec2(u01(h), u01(pcg(h)));
|
|
445
|
+
float d = length(pt - p);
|
|
446
|
+
acc += exp(-10.0 * d);
|
|
447
|
+
if (d < f1) { f2 = f1; f1 = d; } else if (d < f2) { f2 = d; }
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return vec2(max(0.0, -log(acc) / 10.0), f2);
|
|
451
|
+
}
|
|
452
|
+
`
|
|
453
|
+
), tt = (
|
|
454
|
+
/* glsl */
|
|
455
|
+
`
|
|
456
|
+
vec3 crV[9];
|
|
457
|
+
void crVertex(ivec2 n, ivec2 per, uint seed, int k) {
|
|
458
|
+
ivec2 w = imod2(n, per);
|
|
459
|
+
uint h = hash2(w.x, w.y, seed);
|
|
460
|
+
float jx = u01(h); h = pcg(h);
|
|
461
|
+
float jy = u01(h); h = pcg(h);
|
|
462
|
+
crV[k] = vec3(vec2(n) + 0.5 + (vec2(jx, jy) - 0.5) * 0.7, u01(h) * 2.0 - 1.0);
|
|
463
|
+
}
|
|
464
|
+
bool crTri(vec2 p, int a, int b, int c, out float h) {
|
|
465
|
+
vec2 v0 = crV[b].xy - crV[a].xy, v1 = crV[c].xy - crV[a].xy, v2 = p - crV[a].xy;
|
|
466
|
+
float d = v0.x * v1.y - v1.x * v0.y;
|
|
467
|
+
float u = (v2.x * v1.y - v1.x * v2.y) / d;
|
|
468
|
+
float v = (v0.x * v2.y - v2.x * v0.y) / d;
|
|
469
|
+
h = crV[a].z + u * (crV[b].z - crV[a].z) + v * (crV[c].z - crV[a].z);
|
|
470
|
+
return u >= -1e-5 && v >= -1e-5 && u + v <= 1.0 + 1e-5;
|
|
471
|
+
}
|
|
472
|
+
// periodic faceted height in [-1, 1]; p in lattice units
|
|
473
|
+
float crumple(vec2 p, ivec2 per, uint seed) {
|
|
474
|
+
ivec2 c = ivec2(floor(p));
|
|
475
|
+
for (int j = 0; j < 3; j++) for (int i = 0; i < 3; i++) crVertex(c + ivec2(i - 1, j - 1), per, seed, j * 3 + i);
|
|
476
|
+
float h;
|
|
477
|
+
for (int qy = 0; qy < 2; qy++) for (int qx = 0; qx < 2; qx++) {
|
|
478
|
+
int a = qy * 3 + qx, b = a + 1, cc = a + 3, d = a + 4;
|
|
479
|
+
ivec2 qw = imod2(c + ivec2(qx - 1, qy - 1), per);
|
|
480
|
+
uint diag = hash2(qw.x, qw.y, seed + 7u) & 1u;
|
|
481
|
+
if (diag == 0u) {
|
|
482
|
+
if (crTri(p, a, b, d, h)) return h;
|
|
483
|
+
if (crTri(p, a, d, cc, h)) return h;
|
|
484
|
+
} else {
|
|
485
|
+
if (crTri(p, a, b, cc, h)) return h;
|
|
486
|
+
if (crTri(p, b, d, cc, h)) return h;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return 0.0;
|
|
490
|
+
}
|
|
491
|
+
float foldAxis(float x, float L, int count, float offset, uint seed, float strength, float width, out float dist) {
|
|
492
|
+
float s = L / float(count);
|
|
493
|
+
float t = x / s - offset;
|
|
494
|
+
float k = floor(t);
|
|
495
|
+
float f = t - k;
|
|
496
|
+
int k0 = imod(int(k), count);
|
|
497
|
+
int k1 = imod(int(k) + 1, count);
|
|
498
|
+
float h0 = u01(hash2(k0, 0, seed)) * 2.0 - 1.0;
|
|
499
|
+
float h1 = u01(hash2(k1, 0, seed)) * 2.0 - 1.0;
|
|
500
|
+
float panel = h0 + (h1 - h0) * f;
|
|
501
|
+
float dn = min(f, 1.0 - f) * s;
|
|
502
|
+
int kn = f < 0.5 ? k0 : k1;
|
|
503
|
+
float sgn = u01(pcg(hash2(kn, 0, seed))) < 0.5 ? -1.0 : 1.0;
|
|
504
|
+
float rr = max(0.0, 1.0 - dn / width);
|
|
505
|
+
dist = dn;
|
|
506
|
+
return strength * (panel * s * 0.12 + sgn * rr * rr * width * 0.3);
|
|
507
|
+
}
|
|
508
|
+
`
|
|
509
|
+
), At = (
|
|
510
|
+
/* glsl */
|
|
511
|
+
`#version 300 es
|
|
512
|
+
${et}
|
|
513
|
+
${tt}
|
|
514
|
+
uniform ivec2 uSize; // tile size
|
|
515
|
+
uniform ivec2 uOrigin; // absolute pixel of this target's (0,0)
|
|
516
|
+
|
|
517
|
+
uniform vec3 uBase, uTint;
|
|
518
|
+
uniform float uTintAmount, uVariation, uGrainTone;
|
|
519
|
+
|
|
520
|
+
uniform uint uMoSeed, uMoTintSeed, uMoWarpSeed;
|
|
521
|
+
uniform ivec2 uMoPer; uniform int uMoOct; uniform float uMoWarp, uMoRelief;
|
|
522
|
+
|
|
523
|
+
uniform uint uGrSeed; uniform ivec2 uGrPer; uniform int uGrOct; uniform float uGrRough, uGrStrength;
|
|
524
|
+
|
|
525
|
+
uniform uint uCeSeed, uCeWarpSeed; uniform ivec2 uCePer; uniform float uCeStrength, uCeRidge, uCeWarp;
|
|
526
|
+
|
|
527
|
+
uniform uint uSkSeed; uniform ivec2 uSkPer; uniform int uSkOct; uniform float uSkStrength;
|
|
528
|
+
|
|
529
|
+
uniform int uStType; uniform uint uStSeed; uniform ivec2 uStPer;
|
|
530
|
+
uniform float uStStrength, uStSharp, uStWarp; uniform bool uStVertical;
|
|
531
|
+
|
|
532
|
+
uniform uint uFbSeed; uniform ivec2 uFbPer; uniform vec2 uFbCell; uniform float uFbCount;
|
|
533
|
+
uniform float uFbLength, uFbWidth, uFbCurl, uFbDarkRatio, uFbOpacity, uFbRelief;
|
|
534
|
+
uniform vec3 uFbDark, uFbLight;
|
|
535
|
+
|
|
536
|
+
uniform uint uSpSeed; uniform ivec2 uSpPer; uniform vec2 uSpCell; uniform float uSpCount;
|
|
537
|
+
uniform float uSpMin, uSpMax, uSpElong, uSpOpacity, uSpRelief;
|
|
538
|
+
uniform vec3 uSpC0, uSpC1, uSpC2;
|
|
539
|
+
|
|
540
|
+
uniform uint uCrSeed, uCrWarpSeed; uniform ivec2 uCrPer, uCrWPer; uniform float uCrAmp, uCrWAmp, uCrWarp;
|
|
541
|
+
uniform uint uFoSeed; uniform ivec2 uFoCount; uniform float uFoOffset, uFoStrength, uFoWidth, uFoWear;
|
|
542
|
+
uniform uint uSnSeed; uniform ivec2 uSnPer; uniform vec2 uSnCell; uniform float uSnDensity, uSnSize, uSnStrength, uSnRing; uniform vec3 uSnColor;
|
|
543
|
+
|
|
544
|
+
out vec4 outField;
|
|
545
|
+
|
|
546
|
+
// returns colour multiplier; adds relief to dh
|
|
547
|
+
vec3 overlays(vec2 p, float u, float v, inout float dh) {
|
|
548
|
+
vec3 mul = vec3(1.0);
|
|
549
|
+
if (uCrAmp > 0.0 || uCrWAmp > 0.0) {
|
|
550
|
+
float wu = u, wv = v;
|
|
551
|
+
if (uCrWarp > 0.0) {
|
|
552
|
+
float k = uCrWarp / (float(uCrPer.x + uCrPer.y) * 0.5);
|
|
553
|
+
wu += k * gnoise(vec2(u, v) * vec2(uCrPer), uCrPer, uCrWarpSeed);
|
|
554
|
+
wv += k * gnoise(vec2(u, v) * vec2(uCrPer) + vec2(5.2, 1.3), uCrPer, uCrWarpSeed);
|
|
555
|
+
}
|
|
556
|
+
if (uCrAmp > 0.0) dh += uCrAmp * crumple(vec2(wu, wv) * vec2(uCrPer), uCrPer, uCrSeed);
|
|
557
|
+
if (uCrWAmp > 0.0) {
|
|
558
|
+
dh += uCrWAmp * (crumple(vec2(wu, wv) * vec2(uCrWPer), uCrWPer, uCrSeed + 1u)
|
|
559
|
+
+ 0.5 * crumple(vec2(wu, wv) * vec2(uCrWPer * 2), uCrWPer * 2, uCrSeed + 2u));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (uFoStrength > 0.0 || uFoWear > 0.0) {
|
|
563
|
+
float wear = 0.0, d;
|
|
564
|
+
if (uFoCount.x > 0) {
|
|
565
|
+
dh += foldAxis(p.x, float(uSize.x), uFoCount.x, uFoOffset, uFoSeed, uFoStrength, uFoWidth, d);
|
|
566
|
+
wear = max(wear, exp(-(d / 1.3) * (d / 1.3)));
|
|
567
|
+
}
|
|
568
|
+
if (uFoCount.y > 0) {
|
|
569
|
+
dh += foldAxis(p.y, float(uSize.y), uFoCount.y, uFoOffset, uFoSeed + 1u, uFoStrength, uFoWidth, d);
|
|
570
|
+
wear = max(wear, exp(-(d / 1.3) * (d / 1.3)));
|
|
571
|
+
}
|
|
572
|
+
mul *= 1.0 - uFoWear * 0.22 * wear;
|
|
573
|
+
}
|
|
574
|
+
if (uSnDensity > 0.0 && uSnStrength > 0.0) {
|
|
575
|
+
ivec2 c = ivec2(floor(p / uSnCell));
|
|
576
|
+
float keep = 1.0;
|
|
577
|
+
for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {
|
|
578
|
+
ivec2 n = c + ivec2(i, j);
|
|
579
|
+
ivec2 w = imod2(n, uSnPer);
|
|
580
|
+
uint h = hash2(w.x, w.y, uSnSeed);
|
|
581
|
+
if (u01(h) >= uSnDensity) continue;
|
|
582
|
+
h = pcg(h); float r1 = u01(h);
|
|
583
|
+
h = pcg(h); float r2 = u01(h);
|
|
584
|
+
h = pcg(h); float r3 = u01(h);
|
|
585
|
+
h = pcg(h); float r4 = u01(h);
|
|
586
|
+
h = pcg(h); float r5 = u01(h);
|
|
587
|
+
h = pcg(h); float r6 = u01(h);
|
|
588
|
+
vec2 cen = (vec2(n) + 0.2 + 0.6 * vec2(r1, r2)) * uSnCell;
|
|
589
|
+
float R = uSnSize * (0.55 + 0.55 * r3);
|
|
590
|
+
vec2 dd = p - cen;
|
|
591
|
+
float L = length(dd);
|
|
592
|
+
if (L > R * 1.3) continue;
|
|
593
|
+
float a = atan(dd.y, dd.x);
|
|
594
|
+
float e = 1.0 + 0.035 * sin(3.0 * a + r4 * TAU) + 0.02 * sin(7.0 * a + r5 * TAU);
|
|
595
|
+
float q = L / (R * e);
|
|
596
|
+
float inside = clamp((1.0 - q) * R * e + 0.5, 0.0, 1.0);
|
|
597
|
+
float t = (q - 0.985) / 0.03;
|
|
598
|
+
float ring = exp(-t * t) * (0.35 + 0.65 * smoothstep(-0.4, 0.6, sin(a + r6 * TAU)));
|
|
599
|
+
float alpha = clamp(inside * (0.1 + 0.14 * q * q) + ring * uSnRing, 0.0, 1.0) * uSnStrength;
|
|
600
|
+
keep *= 1.0 - alpha;
|
|
601
|
+
dh += 0.15 * ring * uSnStrength;
|
|
602
|
+
}
|
|
603
|
+
mul *= 1.0 + (uSnColor - 1.0) * (1.0 - keep);
|
|
604
|
+
}
|
|
605
|
+
return mul;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
float structureHeight(float u, float v) {
|
|
609
|
+
float a = uStVertical ? u : v;
|
|
610
|
+
float b = uStVertical ? v : u;
|
|
611
|
+
float mainLen = float(uStVertical ? uSize.x : uSize.y);
|
|
612
|
+
float crossLen = float(uStVertical ? uSize.y : uSize.x);
|
|
613
|
+
int wpa = max(1, int(round(float(uStPer.x) / 4.0)));
|
|
614
|
+
int wpb = max(1, int(round(float(uStPer.y) / 4.0)));
|
|
615
|
+
float A = a * float(uStPer.x) + uStWarp * 0.6 * gnoise(vec2(a * float(wpa), b * float(wpb)), ivec2(wpa, wpb), uStSeed);
|
|
616
|
+
float B = b * float(uStPer.y);
|
|
617
|
+
float sharp = uStSharp;
|
|
618
|
+
if (uStType == 1) {
|
|
619
|
+
float s = 0.5 + 0.5 * cos(TAU * A);
|
|
620
|
+
return pow(s, 1.0 + 5.0 * sharp) * 2.0 - 1.0;
|
|
621
|
+
} else if (uStType == 2) {
|
|
622
|
+
float chain = pow(0.5 + 0.5 * cos(TAU * B), 8.0 + 60.0 * sharp);
|
|
623
|
+
return 0.6 * cos(TAU * A) + 1.2 * chain - 0.1;
|
|
624
|
+
} else if (uStType == 3) {
|
|
625
|
+
float cellA = mainLen / float(uStPer.x);
|
|
626
|
+
float cellB = crossLen / float(uStPer.y);
|
|
627
|
+
float cm = min(cellA, cellB);
|
|
628
|
+
int row = int(floor(A));
|
|
629
|
+
float dmin = 9.0;
|
|
630
|
+
for (int dr = -1; dr <= 1; dr++) {
|
|
631
|
+
int rr = row + dr;
|
|
632
|
+
float off = imod(rr, 2) == 1 ? 0.5 : 0.0;
|
|
633
|
+
float col = floor(B - off);
|
|
634
|
+
for (int dc = -1; dc <= 1; dc++) {
|
|
635
|
+
float dy = (A - (float(rr) + 0.5)) * cellA;
|
|
636
|
+
float dx = (B - (col + float(dc) + off + 0.5)) * cellB;
|
|
637
|
+
dmin = min(dmin, sqrt(dx * dx + dy * dy) / cm);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
float edge = mix(0.45, 0.08, sharp);
|
|
641
|
+
return smoothstep(0.35 - edge, 0.35 + edge, dmin) * 2.0 - 1.0;
|
|
642
|
+
} else if (uStType == 4) {
|
|
643
|
+
float x = cos(TAU * A) * cos(TAU * B);
|
|
644
|
+
return sign(x) * pow(abs(x), 1.0 - 0.7 * sharp);
|
|
645
|
+
}
|
|
646
|
+
return 0.0;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
uint slotHash(ivec2 w, uint seed, int k) { return pcg(hash2(w.x, w.y, seed) + uint(k) * 0x9e3779b9u); }
|
|
650
|
+
|
|
651
|
+
float segDist2(vec2 p, vec2 a, vec2 b) {
|
|
652
|
+
vec2 e = b - a, w = p - a;
|
|
653
|
+
float t = clamp(dot(w, e) / (dot(e, e) + 1e-9), 0.0, 1.0);
|
|
654
|
+
vec2 q = w - e * t;
|
|
655
|
+
return dot(q, q);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// returns (darkT, lightT)
|
|
659
|
+
vec2 fibers(vec2 p) {
|
|
660
|
+
float darkT = 1.0, lightT = 1.0;
|
|
661
|
+
if (uFbCount <= 0.0 || uFbOpacity <= 0.0) return vec2(1.0);
|
|
662
|
+
ivec2 c = ivec2(floor(p / uFbCell));
|
|
663
|
+
int slots = int(ceil(uFbCount));
|
|
664
|
+
float reach = uFbLength * (0.5 + 0.75 * uFbCurl) + uFbWidth * 0.7 + 1.0;
|
|
665
|
+
for (int j = -1; j <= 1; j++)
|
|
666
|
+
for (int i = -1; i <= 1; i++) {
|
|
667
|
+
ivec2 n = c + ivec2(i, j);
|
|
668
|
+
ivec2 w = imod2(n, uFbPer);
|
|
669
|
+
for (int k = 0; k < 32; k++) {
|
|
670
|
+
if (k >= slots) break;
|
|
671
|
+
uint h = slotHash(w, uFbSeed, k);
|
|
672
|
+
if (u01(h) >= clamp(uFbCount - float(k), 0.0, 1.0)) continue;
|
|
673
|
+
h = pcg(h); float r1 = u01(h);
|
|
674
|
+
h = pcg(h); float r2 = u01(h);
|
|
675
|
+
vec2 cen = (vec2(n) + vec2(r1, r2)) * uFbCell;
|
|
676
|
+
if (length(p - cen) > reach) continue;
|
|
677
|
+
h = pcg(h); float r3 = u01(h);
|
|
678
|
+
h = pcg(h); float r4 = u01(h);
|
|
679
|
+
h = pcg(h); float r5 = u01(h);
|
|
680
|
+
h = pcg(h); float r6 = u01(h);
|
|
681
|
+
h = pcg(h); float r7 = u01(h);
|
|
682
|
+
h = pcg(h); float r8 = u01(h);
|
|
683
|
+
h = pcg(h); float r9 = u01(h);
|
|
684
|
+
float ang = r3 * TAU;
|
|
685
|
+
vec2 d = vec2(cos(ang), sin(ang));
|
|
686
|
+
vec2 nrm = vec2(-d.y, d.x);
|
|
687
|
+
float L = uFbLength * (0.4 + 0.6 * r4);
|
|
688
|
+
float c1 = (r5 * 2.0 - 1.0) * uFbCurl * L;
|
|
689
|
+
float c2 = (r6 * 2.0 - 1.0) * uFbCurl * L;
|
|
690
|
+
vec2 p0 = cen - d * L * 0.5;
|
|
691
|
+
vec2 p3 = cen + d * L * 0.5;
|
|
692
|
+
vec2 p1 = p0 + d * L / 3.0 + nrm * c1;
|
|
693
|
+
vec2 p2 = p0 + d * 2.0 * L / 3.0 + nrm * c2;
|
|
694
|
+
float d2 = 1e20;
|
|
695
|
+
vec2 prev = p0;
|
|
696
|
+
for (int s = 1; s <= 6; s++) {
|
|
697
|
+
float t = float(s) / 6.0;
|
|
698
|
+
float q = 1.0 - t;
|
|
699
|
+
vec2 cur = q * q * q * p0 + 3.0 * q * q * t * p1 + 3.0 * q * t * t * p2 + t * t * t * p3;
|
|
700
|
+
d2 = min(d2, segDist2(p, prev, cur));
|
|
701
|
+
prev = cur;
|
|
702
|
+
}
|
|
703
|
+
float hw = uFbWidth * (0.6 + 0.8 * r8) * 0.5;
|
|
704
|
+
float cov = clamp(hw + 0.5 - sqrt(d2), 0.0, 1.0);
|
|
705
|
+
if (cov <= 0.0) continue;
|
|
706
|
+
float alpha = uFbOpacity * (0.4 + 0.6 * r9);
|
|
707
|
+
if (r7 < uFbDarkRatio) darkT *= 1.0 - cov * alpha; else lightT *= 1.0 - cov * alpha;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return vec2(darkT, lightT);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// returns accumulated (rgb * a, a) and transmittance in .w of second
|
|
714
|
+
void specks(vec2 p, out vec4 acc, out float T) {
|
|
715
|
+
acc = vec4(0.0); T = 1.0;
|
|
716
|
+
if (uSpCount <= 0.0 || uSpOpacity <= 0.0) return;
|
|
717
|
+
ivec2 c = ivec2(floor(p / uSpCell));
|
|
718
|
+
int slots = int(ceil(uSpCount));
|
|
719
|
+
for (int j = -1; j <= 1; j++)
|
|
720
|
+
for (int i = -1; i <= 1; i++) {
|
|
721
|
+
ivec2 n = c + ivec2(i, j);
|
|
722
|
+
ivec2 w = imod2(n, uSpPer);
|
|
723
|
+
for (int k = 0; k < 32; k++) {
|
|
724
|
+
if (k >= slots) break;
|
|
725
|
+
uint h = slotHash(w, uSpSeed, k);
|
|
726
|
+
if (u01(h) >= clamp(uSpCount - float(k), 0.0, 1.0)) continue;
|
|
727
|
+
h = pcg(h); float r1 = u01(h);
|
|
728
|
+
h = pcg(h); float r2 = u01(h);
|
|
729
|
+
h = pcg(h); float r3 = u01(h);
|
|
730
|
+
h = pcg(h); float r4 = u01(h);
|
|
731
|
+
h = pcg(h); float r5 = u01(h);
|
|
732
|
+
vec2 cen = (vec2(n) + vec2(r1, r2)) * uSpCell;
|
|
733
|
+
float rad = uSpMin + (uSpMax - uSpMin) * r4 * r4 * r4;
|
|
734
|
+
float rb = rad;
|
|
735
|
+
float ra = rad * (1.0 + uSpElong * r5);
|
|
736
|
+
vec2 dd = p - cen;
|
|
737
|
+
if (length(dd) > 1.32 * ra + 0.66 * ra / rb + 1.0) continue;
|
|
738
|
+
h = pcg(h); float r6 = u01(h);
|
|
739
|
+
h = pcg(h); float r7 = u01(h);
|
|
740
|
+
h = pcg(h); float r8 = u01(h);
|
|
741
|
+
h = pcg(h); float r9 = u01(h);
|
|
742
|
+
float ang = r3 * TAU;
|
|
743
|
+
float cs = cos(ang), sn = sin(ang);
|
|
744
|
+
vec2 q = vec2(dd.x * cs + dd.y * sn, -dd.x * sn + dd.y * cs);
|
|
745
|
+
vec2 e = vec2(q.x / ra, q.y / rb);
|
|
746
|
+
float a2 = atan(e.y, e.x);
|
|
747
|
+
float irr = 1.0 + 0.12 * sin(3.0 * a2 + r8 * TAU) + 0.1 * sin(5.0 * a2 + r9 * TAU);
|
|
748
|
+
float dn = length(e) / irr;
|
|
749
|
+
float cov = clamp((1.0 - dn) * rb + 0.5, 0.0, 1.0);
|
|
750
|
+
if (cov <= 0.0) continue;
|
|
751
|
+
int ci = min(2, int(floor(r6 * 3.0)));
|
|
752
|
+
vec3 col = ci == 0 ? uSpC0 : (ci == 1 ? uSpC1 : uSpC2);
|
|
753
|
+
float a = cov * uSpOpacity * (0.5 + 0.5 * r7);
|
|
754
|
+
T *= 1.0 - a;
|
|
755
|
+
acc += vec4(col * a, a);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
void main() {
|
|
761
|
+
ivec2 ip = imod2(uOrigin + ivec2(gl_FragCoord.xy), uSize);
|
|
762
|
+
vec2 p = vec2(ip) + 0.5;
|
|
763
|
+
float u = p.x / float(uSize.x);
|
|
764
|
+
float v = p.y / float(uSize.y);
|
|
765
|
+
|
|
766
|
+
// mottle
|
|
767
|
+
vec2 mp = vec2(u, v) * vec2(uMoPer);
|
|
768
|
+
if (uMoWarp > 0.0) {
|
|
769
|
+
float wx = fbm(mp, uMoPer, 3, 0.5, uMoWarpSeed);
|
|
770
|
+
float wy = fbm(mp + vec2(5.2, 1.3), uMoPer, 3, 0.5, uMoWarpSeed);
|
|
771
|
+
mp += uMoWarp * vec2(wx, wy);
|
|
772
|
+
}
|
|
773
|
+
float m = fbm(mp, uMoPer, uMoOct, 0.5, uMoSeed);
|
|
774
|
+
float t = uTintAmount > 0.0 ? fbm(vec2(u, v) * vec2(uMoPer), uMoPer, uMoOct, 0.5, uMoTintSeed) : 0.0;
|
|
775
|
+
|
|
776
|
+
float g = uGrStrength > 0.0 ? fbm(vec2(u, v) * vec2(uGrPer), uGrPer, uGrOct, uGrRough, uGrSeed) : 0.0;
|
|
777
|
+
|
|
778
|
+
float hc = 0.0;
|
|
779
|
+
if (uCeStrength > 0.0) {
|
|
780
|
+
vec2 cp = vec2(u, v) * vec2(uCePer);
|
|
781
|
+
if (uCeWarp > 0.0) {
|
|
782
|
+
cp.x += uCeWarp * fbm(cp, uCePer, 2, 0.5, uCeWarpSeed);
|
|
783
|
+
cp.y += uCeWarp * fbm(cp + vec2(3.7, 8.1), uCePer, 2, 0.5, uCeWarpSeed);
|
|
784
|
+
}
|
|
785
|
+
vec2 F = worley(cp, uCePer, uCeSeed);
|
|
786
|
+
float dome = 0.5 - F.x;
|
|
787
|
+
float ridge = F.y - F.x - 0.4;
|
|
788
|
+
hc = mix(dome, ridge, uCeRidge) * 2.0;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
float st = uSkStrength > 0.0 ? fbm(vec2(u, v) * vec2(uSkPer), uSkPer, uSkOct, 0.5, uSkSeed) : 0.0;
|
|
792
|
+
float hs = uStStrength > 0.0 ? structureHeight(u, v) : 0.0;
|
|
793
|
+
|
|
794
|
+
float surface = uGrStrength * g + uCeStrength * hc + uSkStrength * st + uStStrength * hs;
|
|
795
|
+
float height = uMoRelief * m + surface;
|
|
796
|
+
|
|
797
|
+
float ta = uTintAmount * clamp(0.5 + t, 0.0, 1.0);
|
|
798
|
+
float tone = 1.0 + uVariation * 2.0 * m + uGrainTone * surface;
|
|
799
|
+
vec3 col = mix(uBase, uTint, ta) * tone;
|
|
800
|
+
|
|
801
|
+
vec2 fT = fibers(p);
|
|
802
|
+
col = mix(col, uFbDark, 1.0 - fT.x);
|
|
803
|
+
col = mix(col, uFbLight, 1.0 - fT.y);
|
|
804
|
+
height += uFbRelief * (1.0 - fT.x * fT.y);
|
|
805
|
+
|
|
806
|
+
vec4 acc; float T;
|
|
807
|
+
specks(p, acc, T);
|
|
808
|
+
if (acc.w > 0.0) {
|
|
809
|
+
col = mix(col, acc.rgb / acc.w, 1.0 - T);
|
|
810
|
+
height += uSpRelief * (1.0 - T);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
vec3 mul = overlays(p, u, v, height);
|
|
814
|
+
outField = vec4(col * mul, height);
|
|
815
|
+
}
|
|
816
|
+
`
|
|
817
|
+
), Tt = (
|
|
818
|
+
/* glsl */
|
|
819
|
+
`#version 300 es
|
|
820
|
+
precision highp float;
|
|
821
|
+
precision highp int;
|
|
822
|
+
uniform highp sampler2D uField; // padded by 1px on every side
|
|
823
|
+
uniform int uMode; // 0 color, 1 albedo, 2 overlay, 3 height, 4 normal
|
|
824
|
+
uniform vec3 uLight;
|
|
825
|
+
uniform float uDepth, uBaseLum, uHeightNorm, uBrightness, uContrast;
|
|
826
|
+
uniform bool uFlipY;
|
|
827
|
+
uniform bool uFlipOut; // flip vertically when drawing to the default framebuffer
|
|
828
|
+
uniform int uOutHeight;
|
|
829
|
+
out vec4 outColor;
|
|
830
|
+
|
|
831
|
+
void main() {
|
|
832
|
+
ivec2 ij = ivec2(gl_FragCoord.xy);
|
|
833
|
+
if (uFlipOut) ij.y = uOutHeight - 1 - ij.y;
|
|
834
|
+
ivec2 q = ij + 1;
|
|
835
|
+
vec4 f = texelFetch(uField, q, 0);
|
|
836
|
+
float hx = (texelFetch(uField, q + ivec2(1, 0), 0).a - texelFetch(uField, q - ivec2(1, 0), 0).a) * 0.5;
|
|
837
|
+
float hy = (texelFetch(uField, q + ivec2(0, 1), 0).a - texelFetch(uField, q - ivec2(0, 1), 0).a) * 0.5;
|
|
838
|
+
vec3 n = normalize(vec3(-hx * uDepth, -hy * uDepth, 1.0));
|
|
839
|
+
|
|
840
|
+
if (uMode == 4) {
|
|
841
|
+
outColor = vec4(n.x * 0.5 + 0.5, (uFlipY ? n.y : -n.y) * 0.5 + 0.5, n.z * 0.5 + 0.5, 1.0);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (uMode == 3) {
|
|
845
|
+
outColor = vec4(vec3(clamp(0.5 + 0.5 * f.a * uHeightNorm, 0.0, 1.0)), 1.0);
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
float shade = clamp(dot(n, uLight) / uLight.z, 0.0, 3.0);
|
|
849
|
+
vec3 c = uMode == 1 ? f.rgb : f.rgb * shade;
|
|
850
|
+
if (uMode == 2) {
|
|
851
|
+
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
852
|
+
outColor = vec4(vec3(clamp((lum - uBaseLum) * 0.5 * uContrast + 0.5 + uBrightness, 0.0, 1.0)), 1.0);
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
outColor = vec4(clamp((c - 0.5) * uContrast + 0.5 + uBrightness, 0.0, 1.0), 1.0);
|
|
856
|
+
}
|
|
857
|
+
`
|
|
858
|
+
);
|
|
859
|
+
function G(r) {
|
|
860
|
+
const o = r.trim();
|
|
861
|
+
if (o.startsWith("#")) {
|
|
862
|
+
let t = o.slice(1);
|
|
863
|
+
(t.length === 3 || t.length === 4) && (t = [...t.slice(0, 3)].map((a) => a + a).join(""));
|
|
864
|
+
const e = parseInt(t.slice(0, 6), 16);
|
|
865
|
+
return Number.isNaN(e) ? [0, 0, 0] : [(e >> 16 & 255) / 255, (e >> 8 & 255) / 255, (e & 255) / 255];
|
|
866
|
+
}
|
|
867
|
+
const i = o.match(/rgba?\(\s*([\d.]+)[ ,]+([\d.]+)[ ,]+([\d.]+)/i);
|
|
868
|
+
return i ? [+i[1] / 255, +i[2] / 255, +i[3] / 255] : [0, 0, 0];
|
|
869
|
+
}
|
|
870
|
+
function zt([r, o, i]) {
|
|
871
|
+
const t = (e) => Math.round(Math.min(1, Math.max(0, e)) * 255).toString(16).padStart(2, "0");
|
|
872
|
+
return `#${t(r)}${t(o)}${t(i)}`;
|
|
873
|
+
}
|
|
874
|
+
function rt([r, o, i]) {
|
|
875
|
+
return 0.2126 * r + 0.7152 * o + 0.0722 * i;
|
|
876
|
+
}
|
|
877
|
+
const Oe = 12, Me = 4, Pt = ["straight", "torn", "deckle", "zigzag", "cut", "wavy"], Rt = {
|
|
878
|
+
straight: [0, 1],
|
|
879
|
+
torn: [5, 26],
|
|
880
|
+
deckle: [3, 14],
|
|
881
|
+
zigzag: [4, 9],
|
|
882
|
+
cut: [1.4, 40],
|
|
883
|
+
wavy: [2, 30]
|
|
884
|
+
}, Et = ["none", "stripes", "dots", "grid", "checker"], Wt = { tl: 1, tr: 2, br: 4, bl: 8 }, qt = { top: 1, right: 2, bottom: 4, left: 8 };
|
|
885
|
+
function Lt(r) {
|
|
886
|
+
const o = r.pixelRatio ?? 1, i = r.shape ?? {}, t = r.relief ?? {}, e = r.finish ?? {}, a = ["top", "right", "bottom", "left"], n = [0, 0, 0, 0], c = [0, 0, 0, 0], s = [1, 1, 1, 1];
|
|
887
|
+
a.forEach((v, x) => {
|
|
888
|
+
const S = i.edges?.[v];
|
|
889
|
+
if (!S) return;
|
|
890
|
+
const C = typeof S == "string" ? { kind: S } : S, [F, W] = Rt[C.kind];
|
|
891
|
+
n[x] = Math.max(0, Pt.indexOf(C.kind)), c[x] = (C.amount ?? F) * o, s[x] = Math.max(1, (C.scale ?? W) * o);
|
|
892
|
+
});
|
|
893
|
+
const l = r.shadow === !1 ? null : { strength: 1, softness: 5, offsetX: 1.5, offsetY: 4, lift: 0.1, ...r.shadow }, u = t.curl, d = (u?.amount ?? 0) + Math.abs(t.bend ?? 0) + (t.crumples ?? 0) * (t.crumpleSize ?? 120) * 0.25, g = l ? Math.ceil(l.softness * 2.2 + Math.max(Math.abs(l.offsetX), Math.abs(l.offsetY)) * (1 + l.lift * d) + 4) : 2, h = Math.ceil((r.margin ?? g) * o), f = (i.holes ?? []).slice(0, Oe).map((v) => [v.x * o, v.y * o, v.r * o, v.rough ?? 0]), y = (i.holeRows ?? []).slice(0, Me), p = e.pattern, m = t.folds ?? {}, w = (m.strength ?? 1) > 0 && ((m.x ?? 0) > 0 || (m.y ?? 0) > 0);
|
|
894
|
+
return {
|
|
895
|
+
width: Math.max(1, Math.round(r.width * o)),
|
|
896
|
+
height: Math.max(1, Math.round(r.height * o)),
|
|
897
|
+
margin: h,
|
|
898
|
+
pixelRatio: o,
|
|
899
|
+
seed: M((r.seed ?? 1) >>> 0),
|
|
900
|
+
radius: (i.radius ?? 0) * o,
|
|
901
|
+
chamfer: (i.chamfer ?? 0) * o,
|
|
902
|
+
edgeKind: n,
|
|
903
|
+
edgeAmt: c,
|
|
904
|
+
edgeScale: s,
|
|
905
|
+
rim: (i.rim ?? 2.4) * o,
|
|
906
|
+
holes: f,
|
|
907
|
+
rowA: y.map((v) => [v.x * o, v.y * o, v.dx * o, v.dy * o]),
|
|
908
|
+
rowB: y.map((v) => [v.count, v.r * o, v.tear ?? 0, v.rough ?? 0]),
|
|
909
|
+
crumples: [(t.crumples ?? 0) * (t.crumpleSize ?? 120) * 0.25 * o, Math.max(4, (t.crumpleSize ?? 120) * o)],
|
|
910
|
+
wrinkles: [(t.wrinkles ?? 0) * (t.wrinkleSize ?? 24) * 0.25 * o, Math.max(2, (t.wrinkleSize ?? 24) * o)],
|
|
911
|
+
folds: {
|
|
912
|
+
count: w ? [Math.round(m.x ?? 0), Math.round(m.y ?? 0)] : [0, 0],
|
|
913
|
+
strength: w ? (m.strength ?? 1) * 0.5 : 0,
|
|
914
|
+
offset: m.offset ?? 0,
|
|
915
|
+
width: Math.max(1, (m.width ?? 3) * o),
|
|
916
|
+
wear: w ? m.wear ?? 0.4 : 0
|
|
917
|
+
},
|
|
918
|
+
curl: u ? [
|
|
919
|
+
u.amount * o,
|
|
920
|
+
Math.max(1, (u.radius ?? 60) * o),
|
|
921
|
+
(u.corners ?? []).reduce((v, x) => v | Wt[x], 0),
|
|
922
|
+
(u.sides ?? []).reduce((v, x) => v | qt[x], 0)
|
|
923
|
+
] : [0, 1, 0, 0],
|
|
924
|
+
cockle: [(t.cockle ?? 0) * o * 6, Math.max(4, (t.cockleSize ?? 90) * o)],
|
|
925
|
+
bend: [(t.bend ?? 0) * o, (t.bendAngle ?? 0) * Math.PI / 180],
|
|
926
|
+
opacity: e.opacity ?? 1,
|
|
927
|
+
gloss: e.gloss ?? 0,
|
|
928
|
+
edgeWear: e.edgeWear ?? 0,
|
|
929
|
+
aging: e.aging ?? 0,
|
|
930
|
+
agingColor: G(e.agingColor ?? "#c9a66b"),
|
|
931
|
+
pattern: {
|
|
932
|
+
kind: p ? Math.max(0, Et.indexOf(p.kind)) : 0,
|
|
933
|
+
color: G(p?.color ?? "#000000"),
|
|
934
|
+
params: [Math.max(1, (p?.scale ?? 10) * o), (p?.angle ?? 0) * Math.PI / 180, p?.width ?? 0.5, p?.opacity ?? 1]
|
|
935
|
+
},
|
|
936
|
+
shadow: l ? [l.strength, Math.max(0.5, l.softness * o), l.offsetX * o, l.offsetY * o] : [0, 1, 0, 0],
|
|
937
|
+
shadowLift: l ? l.lift : 0
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
function Ot(r, o) {
|
|
941
|
+
return {
|
|
942
|
+
...r,
|
|
943
|
+
scale: r.scale * o,
|
|
944
|
+
fibers: { ...r.fibers, density: r.fibers.density / (o * o) },
|
|
945
|
+
specks: { ...r.specks, density: r.specks.density / (o * o) }
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
const Dt = (
|
|
949
|
+
/* glsl */
|
|
950
|
+
`#version 300 es
|
|
951
|
+
${et}
|
|
952
|
+
${tt}
|
|
953
|
+
uniform highp sampler2D uField; // paper field, 1px apron
|
|
954
|
+
uniform ivec2 uFieldSize;
|
|
955
|
+
uniform vec2 uSheet;
|
|
956
|
+
uniform float uMargin;
|
|
957
|
+
uniform int uMode; // 0 color, 1 base, 2 shade, 3 shadow only
|
|
958
|
+
uniform int uSeparateShadow; // 1: color/base omit the cast shadow (it is requested as its own map)
|
|
959
|
+
uniform vec3 uLight;
|
|
960
|
+
uniform float uDepth;
|
|
961
|
+
uniform uint uSeed;
|
|
962
|
+
|
|
963
|
+
uniform float uRadius, uChamfer, uRim;
|
|
964
|
+
uniform ivec4 uEdgeKind;
|
|
965
|
+
uniform vec4 uEdgeAmt, uEdgeScale;
|
|
966
|
+
uniform int uHoleCount;
|
|
967
|
+
uniform vec4 uHoles[${Oe}];
|
|
968
|
+
uniform int uRowCount;
|
|
969
|
+
uniform vec4 uRowA[${Me}], uRowB[${Me}];
|
|
970
|
+
|
|
971
|
+
uniform vec2 uCrumples, uWrinkles; // amp, size
|
|
972
|
+
uniform ivec2 uFoCount;
|
|
973
|
+
uniform float uFoStrength, uFoOffset, uFoWidth, uFoWear;
|
|
974
|
+
uniform vec4 uCurl; // amount, radius, corner bits, side bits
|
|
975
|
+
uniform vec2 uCockle, uBend;
|
|
976
|
+
|
|
977
|
+
uniform float uOpacity, uGloss, uEdgeWear, uAging;
|
|
978
|
+
uniform vec3 uAgeColor;
|
|
979
|
+
uniform int uPattern;
|
|
980
|
+
uniform vec3 uPatColor;
|
|
981
|
+
uniform vec4 uPatParam; // scale, angle, width, opacity
|
|
982
|
+
|
|
983
|
+
uniform vec4 uShadow; // strength, softness, offset x, offset y
|
|
984
|
+
uniform float uShadowLift;
|
|
985
|
+
|
|
986
|
+
out vec4 outColor;
|
|
987
|
+
|
|
988
|
+
const ivec2 BIG = ivec2(8192);
|
|
989
|
+
|
|
990
|
+
float n1(float x, uint s) { return gnoise(vec2(x, 0.37), BIG, s); }
|
|
991
|
+
float fbm1(float x, uint s, int oct) {
|
|
992
|
+
float sum = 0.0, amp = 1.0, norm = 0.0, f = 1.0;
|
|
993
|
+
for (int o = 0; o < 6; o++) {
|
|
994
|
+
if (o >= oct) break;
|
|
995
|
+
sum += amp * n1(x * f, s + uint(o));
|
|
996
|
+
norm += amp;
|
|
997
|
+
amp *= 0.55;
|
|
998
|
+
f *= 2.0;
|
|
999
|
+
}
|
|
1000
|
+
return sum / norm;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// how far the edge bites in at position t along it; rim = width of the fibrous zone beyond it
|
|
1004
|
+
float edgeProfile(int kind, float t, float amt, float scale, uint s, out float rim) {
|
|
1005
|
+
rim = 0.0;
|
|
1006
|
+
if (kind == 1) {
|
|
1007
|
+
float n = fbm1(t / scale, s, 5);
|
|
1008
|
+
rim = uRim * (0.3 + 0.7 * clamp(0.5 + 0.9 * fbm1(t / (scale * 0.3), s + 9u, 3), 0.0, 1.0));
|
|
1009
|
+
return amt * clamp(0.5 + 0.7 * n, 0.0, 1.0);
|
|
1010
|
+
}
|
|
1011
|
+
if (kind == 2) {
|
|
1012
|
+
float n = fbm1(t / scale, s, 5);
|
|
1013
|
+
rim = uRim * 1.6 * (0.4 + 0.6 * clamp(0.5 + fbm1(t / (scale * 0.25), s + 5u, 3), 0.0, 1.0));
|
|
1014
|
+
return amt * clamp(0.5 + 0.7 * n, 0.0, 1.0);
|
|
1015
|
+
}
|
|
1016
|
+
if (kind == 3) return amt * abs(fract(t / scale) * 2.0 - 1.0);
|
|
1017
|
+
if (kind == 4) {
|
|
1018
|
+
float seg = floor(t / scale);
|
|
1019
|
+
float j = u01(pcg(uint(int(seg) + 4096) ^ s));
|
|
1020
|
+
return amt * (0.25 + 0.35 * j + 0.4 * clamp(0.5 + 0.5 * fbm1(t / (scale * 4.0), s, 2), 0.0, 1.0));
|
|
1021
|
+
}
|
|
1022
|
+
if (kind == 5) return amt * (0.5 + 0.5 * sin(TAU * t / scale));
|
|
1023
|
+
return 0.0;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
float gHole; // distance to the nearest punched hole (px), set by shape()
|
|
1027
|
+
|
|
1028
|
+
// (core, rim) signed distances in px, positive inside the paper
|
|
1029
|
+
vec2 shape(vec2 q) {
|
|
1030
|
+
vec2 S = uSheet;
|
|
1031
|
+
float core = 1e5, rim = 1e5;
|
|
1032
|
+
vec4 d = vec4(q.y, S.x - q.x, S.y - q.y, q.x);
|
|
1033
|
+
vec4 along = vec4(q.x, q.y, S.x - q.x, S.y - q.y);
|
|
1034
|
+
for (int i = 0; i < 4; i++) {
|
|
1035
|
+
float r;
|
|
1036
|
+
float e = edgeProfile(uEdgeKind[i], along[i], uEdgeAmt[i], uEdgeScale[i], uSeed + uint(i) * 101u, r);
|
|
1037
|
+
core = min(core, d[i] - e);
|
|
1038
|
+
rim = min(rim, d[i] - e + r);
|
|
1039
|
+
}
|
|
1040
|
+
if (uRadius > 0.0) {
|
|
1041
|
+
vec2 h = S * 0.5;
|
|
1042
|
+
vec2 qq = abs(q - h) - (h - uRadius);
|
|
1043
|
+
float dr = uRadius - (length(max(qq, 0.0)) + min(max(qq.x, qq.y), 0.0));
|
|
1044
|
+
core = min(core, dr);
|
|
1045
|
+
rim = min(rim, dr);
|
|
1046
|
+
}
|
|
1047
|
+
if (uChamfer > 0.0) {
|
|
1048
|
+
float dc = min(q.x + q.y - uChamfer, S.x - q.x + q.y - uChamfer) * 0.70710678;
|
|
1049
|
+
core = min(core, dc);
|
|
1050
|
+
rim = min(rim, dc);
|
|
1051
|
+
}
|
|
1052
|
+
gHole = 1e5;
|
|
1053
|
+
for (int i = 0; i < ${Oe}; i++) {
|
|
1054
|
+
if (i >= uHoleCount) break;
|
|
1055
|
+
vec4 h = uHoles[i];
|
|
1056
|
+
vec2 dd = q - h.xy;
|
|
1057
|
+
float a = atan(dd.y, dd.x);
|
|
1058
|
+
float dh = length(dd) - h.z * (1.0 + h.w * 0.12 * gnoise(vec2(a * 3.0, float(i) * 7.1), BIG, uSeed + 61u));
|
|
1059
|
+
gHole = min(gHole, dh);
|
|
1060
|
+
}
|
|
1061
|
+
for (int i = 0; i < ${Me}; i++) {
|
|
1062
|
+
if (i >= uRowCount) break;
|
|
1063
|
+
vec4 A = uRowA[i], B = uRowB[i];
|
|
1064
|
+
vec2 stp = A.zw;
|
|
1065
|
+
float k = clamp(floor(dot(q - A.xy, stp) / max(dot(stp, stp), 1e-6) + 0.5), 0.0, B.x - 1.0);
|
|
1066
|
+
vec2 c = A.xy + stp * k;
|
|
1067
|
+
vec2 dd = q - c;
|
|
1068
|
+
float a = atan(dd.y, dd.x);
|
|
1069
|
+
uint hs = pcg(uint(int(k) + 17 * i) ^ uSeed);
|
|
1070
|
+
float dh = length(dd) - B.y * (1.0 + B.w * 0.12 * gnoise(vec2(a * 3.0, k * 3.1), BIG, hs));
|
|
1071
|
+
gHole = min(gHole, dh);
|
|
1072
|
+
// torn out towards the nearest sheet side
|
|
1073
|
+
if (u01(pcg(hs)) < B.z) {
|
|
1074
|
+
vec4 sd = vec4(c.y, S.x - c.x, S.y - c.y, c.x);
|
|
1075
|
+
vec2 dir = vec2(0.0, -1.0); float L = sd.x;
|
|
1076
|
+
if (sd.y < L) { dir = vec2(1.0, 0.0); L = sd.y; }
|
|
1077
|
+
if (sd.z < L) { dir = vec2(0.0, 1.0); L = sd.z; }
|
|
1078
|
+
if (sd.w < L) { dir = vec2(-1.0, 0.0); L = sd.w; }
|
|
1079
|
+
float along2 = dot(dd, dir);
|
|
1080
|
+
float perp = dot(dd, vec2(-dir.y, dir.x));
|
|
1081
|
+
float w = B.y * (0.55 + 0.35 * clamp(0.5 + fbm1(along2 * 0.25 + k * 13.0, hs, 3), 0.0, 1.0));
|
|
1082
|
+
float slot = min(w - abs(perp), along2 + B.y);
|
|
1083
|
+
if (along2 <= L + 2.0) {
|
|
1084
|
+
core = min(core, -slot);
|
|
1085
|
+
rim = min(rim, -slot + uRim * 0.8);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
core = min(core, gHole);
|
|
1090
|
+
rim = min(rim, gHole);
|
|
1091
|
+
return vec2(core, rim);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
float macroH(vec2 q) {
|
|
1095
|
+
float h = 0.0;
|
|
1096
|
+
if (uCrumples.x > 0.0) h += uCrumples.x * crumple(q / uCrumples.y + 7.3, BIG, uSeed + 31u);
|
|
1097
|
+
if (uWrinkles.x > 0.0) {
|
|
1098
|
+
h += uWrinkles.x * (crumple(q / uWrinkles.y + 3.1, BIG, uSeed + 32u) + 0.5 * crumple(q / (uWrinkles.y * 0.5), BIG, uSeed + 33u));
|
|
1099
|
+
}
|
|
1100
|
+
if (uFoStrength > 0.0) {
|
|
1101
|
+
float dd;
|
|
1102
|
+
if (uFoCount.x > 0) h += foldAxis(q.x, uSheet.x, uFoCount.x, uFoOffset, uSeed + 41u, uFoStrength, uFoWidth, dd);
|
|
1103
|
+
if (uFoCount.y > 0) h += foldAxis(q.y, uSheet.y, uFoCount.y, uFoOffset, uSeed + 42u, uFoStrength, uFoWidth, dd);
|
|
1104
|
+
}
|
|
1105
|
+
if (uCurl.x > 0.0) {
|
|
1106
|
+
int cb = int(uCurl.z), sb = int(uCurl.w);
|
|
1107
|
+
vec2 corners[4] = vec2[4](vec2(0.0), vec2(uSheet.x, 0.0), uSheet, vec2(0.0, uSheet.y));
|
|
1108
|
+
for (int i = 0; i < 4; i++) {
|
|
1109
|
+
if ((cb & (1 << i)) == 0) continue;
|
|
1110
|
+
float s = max(0.0, 1.0 - length(q - corners[i]) / uCurl.y);
|
|
1111
|
+
h += uCurl.x * s * s;
|
|
1112
|
+
}
|
|
1113
|
+
vec4 sd = vec4(q.y, uSheet.x - q.x, uSheet.y - q.y, q.x);
|
|
1114
|
+
for (int i = 0; i < 4; i++) {
|
|
1115
|
+
if ((sb & (1 << i)) == 0) continue;
|
|
1116
|
+
float s = max(0.0, 1.0 - sd[i] / uCurl.y);
|
|
1117
|
+
h += uCurl.x * s * s;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (uCockle.x > 0.0) h += uCockle.x * fbm(q / uCockle.y, BIG, 3, 0.5, uSeed + 51u);
|
|
1121
|
+
if (uBend.x != 0.0) {
|
|
1122
|
+
vec2 dir = vec2(cos(uBend.y), sin(uBend.y));
|
|
1123
|
+
float t = dot(q - uSheet * 0.5, dir) / (0.5 * length(uSheet));
|
|
1124
|
+
h += uBend.x * t * t;
|
|
1125
|
+
}
|
|
1126
|
+
return h;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
float softShape(vec2 q, float blur) {
|
|
1130
|
+
vec2 s = shape(q);
|
|
1131
|
+
return smoothstep(-blur, blur, s.x);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
float pattern(vec2 q) {
|
|
1135
|
+
float c = cos(uPatParam.y), s = sin(uPatParam.y);
|
|
1136
|
+
vec2 r = vec2(c * q.x + s * q.y, -s * q.x + c * q.y) / uPatParam.x;
|
|
1137
|
+
float w = uPatParam.z;
|
|
1138
|
+
if (uPattern == 1) return smoothstep(w + 0.03, w - 0.03, fract(r.x));
|
|
1139
|
+
if (uPattern == 2) return smoothstep(w * 0.5 + 0.04, w * 0.5 - 0.04, length(fract(r) - 0.5));
|
|
1140
|
+
if (uPattern == 3) {
|
|
1141
|
+
vec2 g = abs(fract(r) - 0.5);
|
|
1142
|
+
return smoothstep(0.5 - w * 0.2, 0.5 - w * 0.2 + 0.05, max(g.x, g.y));
|
|
1143
|
+
}
|
|
1144
|
+
if (uPattern == 4) return mod(floor(r.x) + floor(r.y), 2.0);
|
|
1145
|
+
return 0.0;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
void main() {
|
|
1149
|
+
vec2 q = gl_FragCoord.xy - uMargin;
|
|
1150
|
+
vec2 sd = shape(q);
|
|
1151
|
+
float holeD = gHole;
|
|
1152
|
+
float aCore = clamp(sd.x + 0.5, 0.0, 1.0);
|
|
1153
|
+
float aRim = 0.0;
|
|
1154
|
+
if (sd.y > sd.x + 0.01 && sd.x < 1.0) {
|
|
1155
|
+
float fuzz = 0.45 + 0.55 * clamp(0.5 + 0.8 * gnoise(q * 0.8, BIG, uSeed + 71u), 0.0, 1.0);
|
|
1156
|
+
aRim = clamp(sd.y + 0.5, 0.0, 1.0) * fuzz;
|
|
1157
|
+
// stray fibres just past the rim
|
|
1158
|
+
if (sd.y < 0.0 && sd.y > -5.0) {
|
|
1159
|
+
float hair = smoothstep(0.55, 0.8, gnoise(q * vec2(0.45, 0.45), BIG, uSeed + 72u) + 0.5 * gnoise(q * 1.7, BIG, uSeed + 73u));
|
|
1160
|
+
aRim = max(aRim, hair * exp(sd.y / 1.6) * 0.8);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
float A = max(aCore, aRim) * uOpacity;
|
|
1164
|
+
|
|
1165
|
+
vec3 col = vec3(0.0);
|
|
1166
|
+
if (A > 0.0 && uMode != 3) {
|
|
1167
|
+
ivec2 fi = imod2(ivec2(floor(q)), uFieldSize) + 1;
|
|
1168
|
+
vec4 f = texelFetch(uField, fi, 0);
|
|
1169
|
+
float hx = (texelFetch(uField, fi + ivec2(1, 0), 0).a - texelFetch(uField, fi - ivec2(1, 0), 0).a) * 0.5;
|
|
1170
|
+
float hy = (texelFetch(uField, fi + ivec2(0, 1), 0).a - texelFetch(uField, fi - ivec2(0, 1), 0).a) * 0.5;
|
|
1171
|
+
float Hx = (macroH(q + vec2(1.0, 0.0)) - macroH(q - vec2(1.0, 0.0))) * 0.5;
|
|
1172
|
+
float Hy = (macroH(q + vec2(0.0, 1.0)) - macroH(q - vec2(0.0, 1.0))) * 0.5;
|
|
1173
|
+
vec3 nm = normalize(vec3(-hx * uDepth, -hy * uDepth, 1.0));
|
|
1174
|
+
vec3 nf = normalize(vec3(-hx * uDepth - Hx, -hy * uDepth - Hy, 1.0));
|
|
1175
|
+
float sm = clamp(dot(nm, uLight) / uLight.z, 0.0, 3.0);
|
|
1176
|
+
float sf = clamp(dot(nf, uLight) / uLight.z, 0.0, 3.0);
|
|
1177
|
+
|
|
1178
|
+
vec3 alb = f.rgb;
|
|
1179
|
+
if (uPattern > 0) alb = mix(alb, alb * uPatColor, pattern(q) * uPatParam.w);
|
|
1180
|
+
float inner = max(sd.x, 0.0);
|
|
1181
|
+
if (uAging > 0.0) alb *= mix(vec3(1.0), uAgeColor, uAging * exp(-inner / (0.18 * min(uSheet.x, uSheet.y))));
|
|
1182
|
+
if (uEdgeWear > 0.0) alb *= 1.0 - uEdgeWear * 0.2 * exp(-inner / 3.0);
|
|
1183
|
+
if (uFoWear > 0.0) {
|
|
1184
|
+
float wear = 0.0, dd;
|
|
1185
|
+
if (uFoCount.x > 0) { foldAxis(q.x, uSheet.x, uFoCount.x, uFoOffset, uSeed + 41u, uFoStrength, uFoWidth, dd); wear = max(wear, exp(-(dd / 1.3) * (dd / 1.3))); }
|
|
1186
|
+
if (uFoCount.y > 0) { foldAxis(q.y, uSheet.y, uFoCount.y, uFoOffset, uSeed + 42u, uFoStrength, uFoWidth, dd); wear = max(wear, exp(-(dd / 1.3) * (dd / 1.3))); }
|
|
1187
|
+
alb *= 1.0 - uFoWear * 0.22 * wear;
|
|
1188
|
+
}
|
|
1189
|
+
if (holeD < 4.0) alb *= 1.0 - 0.16 * exp(-max(holeD, 0.0) / 1.2);
|
|
1190
|
+
// torn fibres expose the paler core of the sheet
|
|
1191
|
+
vec3 rimCol = mix(alb, vec3(0.975, 0.97, 0.955), 0.55);
|
|
1192
|
+
alb = mix(rimCol, alb, aCore / max(max(aCore, aRim), 1e-4));
|
|
1193
|
+
|
|
1194
|
+
vec3 refl = reflect(-uLight, nf);
|
|
1195
|
+
float spec = uGloss * pow(max(refl.z, 0.0), 24.0);
|
|
1196
|
+
|
|
1197
|
+
if (uMode == 2) {
|
|
1198
|
+
float R = sf / max(sm, 1e-3);
|
|
1199
|
+
float lum = dot(alb, vec3(0.2126, 0.7152, 0.0722));
|
|
1200
|
+
// shadows: exact multiply; highlights: screen, capped so ink on top never washes out
|
|
1201
|
+
float g = R <= 1.0 ? 0.5 * R : 0.5 + 0.5 * min(0.3, (R - 1.0) * lum / max(1.0 - lum, 0.06));
|
|
1202
|
+
g = min(1.0, g + 0.5 * spec);
|
|
1203
|
+
outColor = vec4(vec3(g), A);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
col = alb * (uMode == 1 ? sm : sf) + (uMode == 1 ? 0.0 : spec);
|
|
1207
|
+
} else if (uMode == 2) {
|
|
1208
|
+
outColor = vec4(0.5, 0.5, 0.5, 0.0);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
float sh = 0.0;
|
|
1213
|
+
if (uShadow.x > 0.0 && (uMode == 3 || uSeparateShadow == 0)) {
|
|
1214
|
+
float lift = uShadowLift * max(macroH(q), 0.0);
|
|
1215
|
+
float s1 = softShape(q - uShadow.zw * 0.3, 1.0 + 0.3 * lift);
|
|
1216
|
+
float s2 = softShape(q - uShadow.zw * (1.0 + lift), uShadow.y * (1.0 + 0.4 * lift));
|
|
1217
|
+
sh = 1.0 - (1.0 - 0.38 * s1) * (1.0 - 0.3 * s2);
|
|
1218
|
+
sh *= uShadow.x * mix(1.0, uOpacity, 0.6);
|
|
1219
|
+
}
|
|
1220
|
+
if (uMode == 3) {
|
|
1221
|
+
outColor = vec4(0.0, 0.0, 0.0, sh);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
float outA = A + sh * (1.0 - A);
|
|
1225
|
+
outColor = vec4(outA > 0.0 ? clamp(col, 0.0, 1.0) * A / outA : vec3(0.0), outA);
|
|
1226
|
+
}
|
|
1227
|
+
`
|
|
1228
|
+
), Bt = { color: 0, albedo: 1, overlay: 2, height: 3, normal: 4 }, _t = (
|
|
1229
|
+
/* glsl */
|
|
1230
|
+
`#version 300 es
|
|
1231
|
+
precision highp float;
|
|
1232
|
+
uniform sampler2D uTex;
|
|
1233
|
+
uniform vec2 uTexSize;
|
|
1234
|
+
uniform vec2 uView; // canvas size in px
|
|
1235
|
+
uniform vec2 uOffset; // pan in texture px
|
|
1236
|
+
uniform float uZoom; // screen px per texture px
|
|
1237
|
+
uniform bool uSeams;
|
|
1238
|
+
out vec4 outColor;
|
|
1239
|
+
void main() {
|
|
1240
|
+
vec2 s = vec2(gl_FragCoord.x, uView.y - gl_FragCoord.y);
|
|
1241
|
+
vec2 t = (s - uView * 0.5) / uZoom + uOffset;
|
|
1242
|
+
vec2 w = mod(t, uTexSize);
|
|
1243
|
+
vec4 c = texelFetch(uTex, ivec2(w), 0);
|
|
1244
|
+
if (uSeams) {
|
|
1245
|
+
vec2 e = min(w, uTexSize - w) * uZoom;
|
|
1246
|
+
if (min(e.x, e.y) < 2.0) c.rgb = mix(c.rgb, vec3(1.0, 0.1, 0.4), 0.6);
|
|
1247
|
+
}
|
|
1248
|
+
outColor = c;
|
|
1249
|
+
}
|
|
1250
|
+
`
|
|
1251
|
+
);
|
|
1252
|
+
class Ut {
|
|
1253
|
+
canvas;
|
|
1254
|
+
gl;
|
|
1255
|
+
maxSize;
|
|
1256
|
+
fieldProg;
|
|
1257
|
+
composeProg;
|
|
1258
|
+
displayProg;
|
|
1259
|
+
sheetProg = null;
|
|
1260
|
+
vao;
|
|
1261
|
+
fieldFormat;
|
|
1262
|
+
fieldTex = null;
|
|
1263
|
+
fieldSize = [0, 0];
|
|
1264
|
+
outTex = null;
|
|
1265
|
+
outSize = [0, 0];
|
|
1266
|
+
fbo;
|
|
1267
|
+
/** Size of the texture produced by the last renderToTexture(). */
|
|
1268
|
+
lastSize = [0, 0];
|
|
1269
|
+
static isSupported() {
|
|
1270
|
+
try {
|
|
1271
|
+
const i = (typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1) : document.createElement("canvas")).getContext("webgl2");
|
|
1272
|
+
return !!i && !!(i.getExtension("EXT_color_buffer_float") || i.getExtension("EXT_color_buffer_half_float"));
|
|
1273
|
+
} catch {
|
|
1274
|
+
return !1;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
constructor(o) {
|
|
1278
|
+
this.canvas = o ?? (typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1) : document.createElement("canvas"));
|
|
1279
|
+
const i = this.canvas.getContext("webgl2", {
|
|
1280
|
+
antialias: !1,
|
|
1281
|
+
premultipliedAlpha: !1,
|
|
1282
|
+
preserveDrawingBuffer: !0
|
|
1283
|
+
});
|
|
1284
|
+
if (!i) throw new Error("procedural-paper: WebGL2 is not available");
|
|
1285
|
+
if (this.gl = i, i.getExtension("EXT_color_buffer_float"))
|
|
1286
|
+
this.fieldFormat = { internal: i.RGBA32F, type: i.FLOAT };
|
|
1287
|
+
else if (i.getExtension("EXT_color_buffer_half_float"))
|
|
1288
|
+
this.fieldFormat = { internal: i.RGBA16F, type: i.HALF_FLOAT };
|
|
1289
|
+
else
|
|
1290
|
+
throw new Error("procedural-paper: float render targets are not supported");
|
|
1291
|
+
this.maxSize = Math.min(i.getParameter(i.MAX_TEXTURE_SIZE), i.getParameter(i.MAX_RENDERBUFFER_SIZE)), this.fieldProg = this.program(At), this.composeProg = this.program(Tt), this.displayProg = this.program(_t), this.vao = i.createVertexArray(), i.bindVertexArray(this.vao);
|
|
1292
|
+
const t = i.createBuffer();
|
|
1293
|
+
i.bindBuffer(i.ARRAY_BUFFER, t), i.bufferData(i.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), i.STATIC_DRAW);
|
|
1294
|
+
for (const e of [this.fieldProg, this.composeProg, this.displayProg]) {
|
|
1295
|
+
const a = i.getAttribLocation(e.prog, "aPos");
|
|
1296
|
+
a >= 0 && (i.enableVertexAttribArray(a), i.vertexAttribPointer(a, 2, i.FLOAT, !1, 0, 0));
|
|
1297
|
+
}
|
|
1298
|
+
this.fbo = i.createFramebuffer();
|
|
1299
|
+
}
|
|
1300
|
+
program(o) {
|
|
1301
|
+
const i = this.gl, t = (a, n) => {
|
|
1302
|
+
const c = i.createShader(a);
|
|
1303
|
+
if (i.shaderSource(c, n), i.compileShader(c), !i.getShaderParameter(c, i.COMPILE_STATUS))
|
|
1304
|
+
throw new Error("procedural-paper shader error: " + i.getShaderInfoLog(c));
|
|
1305
|
+
return c;
|
|
1306
|
+
}, e = i.createProgram();
|
|
1307
|
+
if (i.attachShader(e, t(i.VERTEX_SHADER, Ft)), i.attachShader(e, t(i.FRAGMENT_SHADER, o)), i.bindAttribLocation(e, 0, "aPos"), i.linkProgram(e), !i.getProgramParameter(e, i.LINK_STATUS))
|
|
1308
|
+
throw new Error("procedural-paper link error: " + i.getProgramInfoLog(e));
|
|
1309
|
+
return { prog: e, loc: /* @__PURE__ */ new Map() };
|
|
1310
|
+
}
|
|
1311
|
+
u(o, i) {
|
|
1312
|
+
let t = o.loc.get(i);
|
|
1313
|
+
return t === void 0 && (t = this.gl.getUniformLocation(o.prog, i), o.loc.set(i, t)), t;
|
|
1314
|
+
}
|
|
1315
|
+
ensureTex(o, i, t) {
|
|
1316
|
+
const e = this.gl, a = o === "field" ? this.fieldTex : this.outTex, n = o === "field" ? this.fieldSize : this.outSize;
|
|
1317
|
+
if (a && n[0] === i && n[1] === t) return a;
|
|
1318
|
+
a && e.deleteTexture(a);
|
|
1319
|
+
const c = e.createTexture();
|
|
1320
|
+
return e.bindTexture(e.TEXTURE_2D, c), o === "field" ? e.texStorage2D(e.TEXTURE_2D, 1, this.fieldFormat.internal, i, t) : e.texStorage2D(e.TEXTURE_2D, 1, e.RGBA8, i, t), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.NEAREST), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.NEAREST), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), o === "field" ? (this.fieldTex = c, this.fieldSize = [i, t]) : (this.outTex = c, this.outSize = [i, t]), c;
|
|
1321
|
+
}
|
|
1322
|
+
setFieldUniforms(o) {
|
|
1323
|
+
const i = this.gl, t = this.fieldProg, e = (y, p) => i.uniform1f(this.u(t, y), p), a = (y, p) => i.uniform1i(this.u(t, y), p), n = (y, p) => i.uniform1ui(this.u(t, y), p >>> 0), c = (y, p) => i.uniform2i(this.u(t, y), p[0], p[1]), s = (y, p) => i.uniform2f(this.u(t, y), p[0], p[1]), l = (y, p) => i.uniform3f(this.u(t, y), p[0], p[1], p[2]);
|
|
1324
|
+
c("uSize", [o.width, o.height]), l("uBase", o.base), l("uTint", o.tint), e("uTintAmount", o.tintAmount), e("uVariation", o.variation), e("uGrainTone", o.grainTone), n("uMoSeed", o.mottle.seed), n("uMoTintSeed", o.mottle.tintSeed), n("uMoWarpSeed", o.mottle.warpSeed), c("uMoPer", o.mottle.per), a("uMoOct", o.mottle.octaves), e("uMoWarp", o.mottle.warp), e("uMoRelief", o.mottle.relief), n("uGrSeed", o.grain.seed), c("uGrPer", o.grain.per), a("uGrOct", o.grain.octaves), e("uGrRough", o.grain.roughness), e("uGrStrength", o.grain.strength), n("uCeSeed", o.cells.seed), n("uCeWarpSeed", o.cells.warpSeed), c("uCePer", o.cells.per), e("uCeStrength", o.cells.strength), e("uCeRidge", o.cells.ridge), e("uCeWarp", o.cells.warp), n("uSkSeed", o.streaks.seed), c("uSkPer", o.streaks.per), a("uSkOct", o.streaks.octaves), e("uSkStrength", o.streaks.strength), a("uStType", o.structure.type), n("uStSeed", o.structure.seed), c("uStPer", o.structure.per), e("uStStrength", o.structure.strength), e("uStSharp", o.structure.sharpness), e("uStWarp", o.structure.warp), a("uStVertical", o.structure.vertical ? 1 : 0);
|
|
1325
|
+
const u = o.fibers;
|
|
1326
|
+
n("uFbSeed", u.seed), c("uFbPer", u.per), s("uFbCell", u.cell), e("uFbCount", u.count), e("uFbLength", u.length), e("uFbWidth", u.width), e("uFbCurl", u.curl), e("uFbDarkRatio", u.darkRatio), e("uFbOpacity", u.opacity), e("uFbRelief", u.relief), l("uFbDark", u.dark), l("uFbLight", u.light);
|
|
1327
|
+
const d = o.specks;
|
|
1328
|
+
n("uSpSeed", d.seed), c("uSpPer", d.per), s("uSpCell", d.cell), e("uSpCount", d.count), e("uSpMin", d.sizeMin), e("uSpMax", d.sizeMax), e("uSpElong", d.elongation), e("uSpOpacity", d.opacity), e("uSpRelief", d.relief), l("uSpC0", d.colors[0]), l("uSpC1", d.colors[1]), l("uSpC2", d.colors[2]);
|
|
1329
|
+
const g = o.crumples;
|
|
1330
|
+
n("uCrSeed", g.seed), n("uCrWarpSeed", g.warpSeed), c("uCrPer", g.per), c("uCrWPer", g.wPer), e("uCrAmp", g.amp), e("uCrWAmp", g.wAmp), e("uCrWarp", g.warp);
|
|
1331
|
+
const h = o.folds;
|
|
1332
|
+
n("uFoSeed", h.seed), c("uFoCount", h.count), e("uFoOffset", h.offset), e("uFoStrength", h.strength), e("uFoWidth", h.width), e("uFoWear", h.wear);
|
|
1333
|
+
const f = o.stains;
|
|
1334
|
+
n("uSnSeed", f.seed), c("uSnPer", f.per), s("uSnCell", f.cell), e("uSnDensity", f.density), e("uSnSize", f.size), e("uSnStrength", f.strength), e("uSnRing", f.ring), l("uSnColor", f.color);
|
|
1335
|
+
}
|
|
1336
|
+
setComposeUniforms(o, i) {
|
|
1337
|
+
const t = this.gl, e = this.composeProg;
|
|
1338
|
+
t.uniform1i(this.u(e, "uField"), 0), t.uniform1i(this.u(e, "uMode"), Bt[i]), t.uniform3f(this.u(e, "uLight"), o.light.dir[0], o.light.dir[1], o.light.dir[2]), t.uniform1f(this.u(e, "uDepth"), o.light.depth), t.uniform1f(this.u(e, "uBaseLum"), o.baseLum), t.uniform1f(this.u(e, "uHeightNorm"), o.heightNorm), t.uniform1f(this.u(e, "uBrightness"), o.output.brightness), t.uniform1f(this.u(e, "uContrast"), o.output.contrast), t.uniform1i(this.u(e, "uFlipY"), o.output.flipY ? 1 : 0), t.uniform1i(this.u(e, "uFlipOut"), 0);
|
|
1339
|
+
}
|
|
1340
|
+
/** Render the 1px-padded field for the chunk at (ox, oy) of size (w, h). */
|
|
1341
|
+
renderField(o, i, t, e, a) {
|
|
1342
|
+
const n = this.gl, c = this.ensureTex("field", e + 2, a + 2);
|
|
1343
|
+
n.bindFramebuffer(n.FRAMEBUFFER, this.fbo), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, c, 0), n.viewport(0, 0, e + 2, a + 2), n.useProgram(this.fieldProg.prog), this.setFieldUniforms(o), n.uniform2i(this.u(this.fieldProg, "uOrigin"), i - 1, t - 1), n.bindVertexArray(this.vao), n.drawArrays(n.TRIANGLES, 0, 3);
|
|
1344
|
+
}
|
|
1345
|
+
composeInto(o, i, t, e) {
|
|
1346
|
+
const a = this.gl;
|
|
1347
|
+
a.useProgram(this.composeProg.prog), this.setComposeUniforms(o, i), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, this.fieldTex), a.viewport(0, 0, t, e), a.bindVertexArray(this.vao), a.drawArrays(a.TRIANGLES, 0, 3);
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Render the requested maps to RGBA8 pixel buffers (rows top to bottom).
|
|
1351
|
+
* Large tiles are rendered in chunks, so sizes beyond MAX_TEXTURE_SIZE work.
|
|
1352
|
+
*/
|
|
1353
|
+
render(o, i, t = 1024) {
|
|
1354
|
+
const e = this.gl, a = o.width, n = o.height, c = Math.max(64, Math.min(t, this.maxSize - 2)), s = {};
|
|
1355
|
+
for (const u of i) s[u] = new Uint8ClampedArray(a * n * 4);
|
|
1356
|
+
const l = new Uint8Array(c * c * 4);
|
|
1357
|
+
for (let u = 0; u < n; u += c)
|
|
1358
|
+
for (let d = 0; d < a; d += c) {
|
|
1359
|
+
const g = Math.min(c, a - d), h = Math.min(c, n - u);
|
|
1360
|
+
this.renderField(o, d, u, g, h);
|
|
1361
|
+
const f = this.ensureTex("out", c, c);
|
|
1362
|
+
for (const y of i) {
|
|
1363
|
+
e.bindFramebuffer(e.FRAMEBUFFER, this.fbo), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, f, 0), this.composeInto(o, y, g, h), e.readPixels(0, 0, g, h, e.RGBA, e.UNSIGNED_BYTE, l);
|
|
1364
|
+
const p = s[y];
|
|
1365
|
+
for (let m = 0; m < h; m++)
|
|
1366
|
+
p.set(l.subarray(m * g * 4, (m + 1) * g * 4), ((u + m) * a + d) * 4);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return e.bindFramebuffer(e.FRAMEBUFFER, null), s;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Render one map into an internal GPU texture (no readback). Used for live
|
|
1373
|
+
* previews together with drawPreview(). Size must fit MAX_TEXTURE_SIZE.
|
|
1374
|
+
*/
|
|
1375
|
+
renderToTexture(o, i) {
|
|
1376
|
+
const t = this.gl, e = Math.min(o.width, this.maxSize - 2), a = Math.min(o.height, this.maxSize - 2);
|
|
1377
|
+
this.renderField(o, 0, 0, e, a);
|
|
1378
|
+
const n = this.ensureTex("out", e, a);
|
|
1379
|
+
return t.bindFramebuffer(t.FRAMEBUFFER, this.fbo), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, n, 0), this.composeInto(o, i, e, a), t.bindFramebuffer(t.FRAMEBUFFER, null), this.lastSize = [e, a], n;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Render a finite sheet (see sheet.ts): the paper field at the sheet's size,
|
|
1383
|
+
* then the outline / relief / shadow pass. Returns RGBA8 buffers (straight
|
|
1384
|
+
* alpha, rows top to bottom) of size (width + 2 margin) x (height + 2 margin).
|
|
1385
|
+
*/
|
|
1386
|
+
renderSheet(o, i, t) {
|
|
1387
|
+
const e = this.gl, a = i.width + 2 * i.margin, n = i.height + 2 * i.margin;
|
|
1388
|
+
if (a > this.maxSize || n > this.maxSize) throw new Error("procedural-paper: sheet larger than MAX_TEXTURE_SIZE");
|
|
1389
|
+
if (this.renderField(o, 0, 0, o.width, o.height), !this.sheetProg) {
|
|
1390
|
+
this.sheetProg = this.program(Dt);
|
|
1391
|
+
const g = e.getAttribLocation(this.sheetProg.prog, "aPos");
|
|
1392
|
+
e.bindVertexArray(this.vao), g >= 0 && (e.enableVertexAttribArray(g), e.vertexAttribPointer(g, 2, e.FLOAT, !1, 0, 0));
|
|
1393
|
+
}
|
|
1394
|
+
const c = this.sheetProg, s = this.ensureTex("out", a, n);
|
|
1395
|
+
e.bindFramebuffer(e.FRAMEBUFFER, this.fbo), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, s, 0), e.viewport(0, 0, a, n), e.useProgram(c.prog), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.fieldTex);
|
|
1396
|
+
const l = (g) => this.u(c, g);
|
|
1397
|
+
e.uniform1i(l("uField"), 0), e.uniform2i(l("uFieldSize"), o.width, o.height), e.uniform2f(l("uSheet"), i.width, i.height), e.uniform1f(l("uMargin"), i.margin), e.uniform3f(l("uLight"), o.light.dir[0], o.light.dir[1], o.light.dir[2]), e.uniform1f(l("uDepth"), o.light.depth), e.uniform1ui(l("uSeed"), i.seed >>> 0), e.uniform1f(l("uRadius"), i.radius), e.uniform1f(l("uChamfer"), i.chamfer), e.uniform1f(l("uRim"), i.rim), e.uniform4i(l("uEdgeKind"), ...i.edgeKind), e.uniform4f(l("uEdgeAmt"), ...i.edgeAmt), e.uniform4f(l("uEdgeScale"), ...i.edgeScale), e.uniform1i(l("uHoleCount"), i.holes.length), i.holes.length && e.uniform4fv(l("uHoles"), i.holes.flat()), e.uniform1i(l("uRowCount"), i.rowA.length), i.rowA.length && (e.uniform4fv(l("uRowA"), i.rowA.flat()), e.uniform4fv(l("uRowB"), i.rowB.flat())), e.uniform2f(l("uCrumples"), ...i.crumples), e.uniform2f(l("uWrinkles"), ...i.wrinkles), e.uniform2i(l("uFoCount"), ...i.folds.count), e.uniform1f(l("uFoStrength"), i.folds.strength), e.uniform1f(l("uFoOffset"), i.folds.offset), e.uniform1f(l("uFoWidth"), i.folds.width), e.uniform1f(l("uFoWear"), i.folds.wear), e.uniform4f(l("uCurl"), ...i.curl), e.uniform2f(l("uCockle"), ...i.cockle), e.uniform2f(l("uBend"), ...i.bend), e.uniform1f(l("uOpacity"), i.opacity), e.uniform1f(l("uGloss"), i.gloss), e.uniform1f(l("uEdgeWear"), i.edgeWear), e.uniform1f(l("uAging"), i.aging), e.uniform3f(l("uAgeColor"), ...i.agingColor), e.uniform1i(l("uPattern"), i.pattern.kind), e.uniform3f(l("uPatColor"), ...i.pattern.color), e.uniform4f(l("uPatParam"), ...i.pattern.params), e.uniform4f(l("uShadow"), ...i.shadow), e.uniform1f(l("uShadowLift"), i.shadowLift), e.bindVertexArray(this.vao);
|
|
1398
|
+
const u = {}, d = { color: 0, base: 1, shade: 2, shadow: 3 };
|
|
1399
|
+
e.uniform1i(l("uSeparateShadow"), t.includes("shadow") ? 1 : 0);
|
|
1400
|
+
for (const g of t) {
|
|
1401
|
+
e.uniform1i(l("uMode"), d[g]), e.drawArrays(e.TRIANGLES, 0, 3);
|
|
1402
|
+
const h = new Uint8ClampedArray(a * n * 4);
|
|
1403
|
+
e.readPixels(0, 0, a, n, e.RGBA, e.UNSIGNED_BYTE, h), u[g] = h;
|
|
1404
|
+
}
|
|
1405
|
+
return e.bindFramebuffer(e.FRAMEBUFFER, null), u;
|
|
1406
|
+
}
|
|
1407
|
+
/** Draw the last renderToTexture() result to the canvas, tiled infinitely. */
|
|
1408
|
+
drawPreview(o = {}) {
|
|
1409
|
+
const i = this.gl;
|
|
1410
|
+
if (!this.outTex) return;
|
|
1411
|
+
const t = this.canvas.width, e = this.canvas.height;
|
|
1412
|
+
i.bindFramebuffer(i.FRAMEBUFFER, null), i.viewport(0, 0, t, e);
|
|
1413
|
+
const a = this.displayProg;
|
|
1414
|
+
i.useProgram(a.prog), i.activeTexture(i.TEXTURE0), i.bindTexture(i.TEXTURE_2D, this.outTex), i.uniform1i(this.u(a, "uTex"), 0), i.uniform2f(this.u(a, "uTexSize"), this.lastSize[0], this.lastSize[1]), i.uniform2f(this.u(a, "uView"), t, e), i.uniform2f(this.u(a, "uOffset"), o.offsetX ?? this.lastSize[0] / 2, o.offsetY ?? this.lastSize[1] / 2), i.uniform1f(this.u(a, "uZoom"), o.zoom ?? 1), i.uniform1i(this.u(a, "uSeams"), o.seams ? 1 : 0), i.bindVertexArray(this.vao), i.drawArrays(i.TRIANGLES, 0, 3);
|
|
1415
|
+
}
|
|
1416
|
+
dispose() {
|
|
1417
|
+
const o = this.gl;
|
|
1418
|
+
this.fieldTex && o.deleteTexture(this.fieldTex), this.outTex && o.deleteTexture(this.outTex), o.deleteFramebuffer(this.fbo);
|
|
1419
|
+
for (const i of [this.fieldProg, this.composeProg, this.displayProg, this.sheetProg]) i && o.deleteProgram(i.prog);
|
|
1420
|
+
o.getExtension("WEBGL_lose_context")?.loseContext();
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
const de = {
|
|
1424
|
+
seed: 1,
|
|
1425
|
+
scale: 1,
|
|
1426
|
+
color: { base: "#f2efe8", tint: "#e8dcc4", tintAmount: 0.15, variation: 0.04, grainTone: 0.04 },
|
|
1427
|
+
mottle: { size: 320, octaves: 4, warp: 0.4, relief: 0.1 },
|
|
1428
|
+
grain: { size: 6, strength: 0.4, roughness: 0.55, octaves: 4 },
|
|
1429
|
+
cells: { size: 14, strength: 0, ridge: 0, warp: 0.3 },
|
|
1430
|
+
streaks: { length: 60, width: 3, strength: 0, direction: "horizontal" },
|
|
1431
|
+
fibers: {
|
|
1432
|
+
density: 4,
|
|
1433
|
+
length: 18,
|
|
1434
|
+
width: 1,
|
|
1435
|
+
curl: 0.3,
|
|
1436
|
+
darkRatio: 0.5,
|
|
1437
|
+
darkColor: "#8a8070",
|
|
1438
|
+
lightColor: "#ffffff",
|
|
1439
|
+
opacity: 0.25,
|
|
1440
|
+
relief: 0.2
|
|
1441
|
+
},
|
|
1442
|
+
specks: {
|
|
1443
|
+
density: 6,
|
|
1444
|
+
sizeMin: 0.6,
|
|
1445
|
+
sizeMax: 2.2,
|
|
1446
|
+
elongation: 0.3,
|
|
1447
|
+
colors: ["#3a3430", "#8a6a50", "#b89878"],
|
|
1448
|
+
opacity: 0.7,
|
|
1449
|
+
relief: 0.2
|
|
1450
|
+
},
|
|
1451
|
+
structure: { type: "none", spacing: 24, strength: 0, sharpness: 0.5, direction: "horizontal", warp: 0.2 },
|
|
1452
|
+
crumples: { strength: 0, size: 140, wrinkles: 0, wrinkleSize: 26, warp: 0.12 },
|
|
1453
|
+
folds: { strength: 0, countX: 2, countY: 2, offset: 0, width: 3, wear: 0.4 },
|
|
1454
|
+
stains: { density: 0, size: 60, strength: 0.5, ring: 0.6, color: "#9a6a3a" },
|
|
1455
|
+
lighting: { depth: 1, azimuth: 225, elevation: 45 },
|
|
1456
|
+
output: { brightness: 0, contrast: 1, normalFlipY: !1 }
|
|
1457
|
+
}, b = (r, o, i, t, e) => ({
|
|
1458
|
+
key: r,
|
|
1459
|
+
label: o,
|
|
1460
|
+
type: "number",
|
|
1461
|
+
min: i,
|
|
1462
|
+
max: t,
|
|
1463
|
+
step: e
|
|
1464
|
+
}), X = (r, o) => ({ key: r, label: o, type: "color" }), ir = [
|
|
1465
|
+
{ key: "", label: "General", fields: [b("seed", "Seed", 0, 9999, 1), b("scale", "Scale", 0.25, 4, 0.05)] },
|
|
1466
|
+
{
|
|
1467
|
+
key: "color",
|
|
1468
|
+
label: "Color",
|
|
1469
|
+
fields: [
|
|
1470
|
+
X("base", "Base"),
|
|
1471
|
+
X("tint", "Tint"),
|
|
1472
|
+
b("tintAmount", "Tint amount", 0, 1, 0.01),
|
|
1473
|
+
b("variation", "Mottle tone", 0, 0.3, 5e-3),
|
|
1474
|
+
b("grainTone", "Grain tone", 0, 0.3, 5e-3)
|
|
1475
|
+
]
|
|
1476
|
+
},
|
|
1477
|
+
{
|
|
1478
|
+
key: "mottle",
|
|
1479
|
+
label: "Mottle (clouds)",
|
|
1480
|
+
fields: [
|
|
1481
|
+
b("size", "Size", 20, 2e3, 1),
|
|
1482
|
+
b("octaves", "Octaves", 1, 8, 1),
|
|
1483
|
+
b("warp", "Warp", 0, 2, 0.01),
|
|
1484
|
+
b("relief", "Relief", 0, 1, 0.01)
|
|
1485
|
+
]
|
|
1486
|
+
},
|
|
1487
|
+
{
|
|
1488
|
+
key: "grain",
|
|
1489
|
+
label: "Grain (tooth)",
|
|
1490
|
+
fields: [
|
|
1491
|
+
b("size", "Size", 1, 64, 0.5),
|
|
1492
|
+
b("strength", "Strength", 0, 2, 0.01),
|
|
1493
|
+
b("roughness", "Roughness", 0.2, 0.9, 0.01),
|
|
1494
|
+
b("octaves", "Octaves", 1, 8, 1)
|
|
1495
|
+
]
|
|
1496
|
+
},
|
|
1497
|
+
{
|
|
1498
|
+
key: "cells",
|
|
1499
|
+
label: "Cells (cold press)",
|
|
1500
|
+
fields: [
|
|
1501
|
+
b("size", "Size", 3, 120, 0.5),
|
|
1502
|
+
b("strength", "Strength", 0, 2, 0.01),
|
|
1503
|
+
b("ridge", "Ridge", 0, 1, 0.01),
|
|
1504
|
+
b("warp", "Warp", 0, 1.5, 0.01)
|
|
1505
|
+
]
|
|
1506
|
+
},
|
|
1507
|
+
{
|
|
1508
|
+
key: "streaks",
|
|
1509
|
+
label: "Streaks (drag)",
|
|
1510
|
+
fields: [
|
|
1511
|
+
b("length", "Length", 4, 400, 1),
|
|
1512
|
+
b("width", "Width", 1, 40, 0.5),
|
|
1513
|
+
b("strength", "Strength", 0, 2, 0.01),
|
|
1514
|
+
{ key: "direction", label: "Direction", type: "select", options: ["horizontal", "vertical"] }
|
|
1515
|
+
]
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
key: "fibers",
|
|
1519
|
+
label: "Fibers",
|
|
1520
|
+
fields: [
|
|
1521
|
+
b("density", "Density", 0, 120, 0.5),
|
|
1522
|
+
b("length", "Length", 2, 120, 0.5),
|
|
1523
|
+
b("width", "Width", 0.3, 6, 0.05),
|
|
1524
|
+
b("curl", "Curl", 0, 1.5, 0.01),
|
|
1525
|
+
b("darkRatio", "Dark ratio", 0, 1, 0.01),
|
|
1526
|
+
X("darkColor", "Dark color"),
|
|
1527
|
+
X("lightColor", "Light color"),
|
|
1528
|
+
b("opacity", "Opacity", 0, 1, 0.01),
|
|
1529
|
+
b("relief", "Relief", 0, 2, 0.01)
|
|
1530
|
+
]
|
|
1531
|
+
},
|
|
1532
|
+
{
|
|
1533
|
+
key: "specks",
|
|
1534
|
+
label: "Specks & inclusions",
|
|
1535
|
+
fields: [
|
|
1536
|
+
b("density", "Density", 0, 300, 0.5),
|
|
1537
|
+
b("sizeMin", "Size min", 0.3, 10, 0.05),
|
|
1538
|
+
b("sizeMax", "Size max", 0.3, 24, 0.05),
|
|
1539
|
+
b("elongation", "Elongation", 0, 6, 0.05),
|
|
1540
|
+
X("colors.0", "Color 1"),
|
|
1541
|
+
X("colors.1", "Color 2"),
|
|
1542
|
+
X("colors.2", "Color 3"),
|
|
1543
|
+
b("opacity", "Opacity", 0, 1, 0.01),
|
|
1544
|
+
b("relief", "Relief", 0, 2, 0.01)
|
|
1545
|
+
]
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
key: "structure",
|
|
1549
|
+
label: "Structure",
|
|
1550
|
+
fields: [
|
|
1551
|
+
{ key: "type", label: "Type", type: "select", options: ["none", "corrugated", "laid", "honeycomb", "canvas"] },
|
|
1552
|
+
b("spacing", "Spacing", 2, 200, 0.5),
|
|
1553
|
+
b("strength", "Strength", 0, 2, 0.01),
|
|
1554
|
+
b("sharpness", "Sharpness", 0, 1, 0.01),
|
|
1555
|
+
{ key: "direction", label: "Direction", type: "select", options: ["horizontal", "vertical"] },
|
|
1556
|
+
b("warp", "Warp", 0, 1, 0.01)
|
|
1557
|
+
]
|
|
1558
|
+
},
|
|
1559
|
+
{
|
|
1560
|
+
key: "crumples",
|
|
1561
|
+
label: "Crumples & wrinkles",
|
|
1562
|
+
fields: [
|
|
1563
|
+
b("strength", "Crumples", 0, 2, 0.01),
|
|
1564
|
+
b("size", "Facet size", 20, 1e3, 1),
|
|
1565
|
+
b("wrinkles", "Wrinkles", 0, 2, 0.01),
|
|
1566
|
+
b("wrinkleSize", "Wrinkle size", 4, 200, 0.5),
|
|
1567
|
+
b("warp", "Warp", 0, 1, 0.01)
|
|
1568
|
+
]
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
key: "folds",
|
|
1572
|
+
label: "Folds",
|
|
1573
|
+
fields: [
|
|
1574
|
+
b("strength", "Strength", 0, 2, 0.01),
|
|
1575
|
+
b("countX", "Vertical", 0, 16, 1),
|
|
1576
|
+
b("countY", "Horizontal", 0, 16, 1),
|
|
1577
|
+
b("offset", "Offset", 0, 1, 0.01),
|
|
1578
|
+
b("width", "Ridge width", 1, 60, 0.5),
|
|
1579
|
+
b("wear", "Wear", 0, 1, 0.01)
|
|
1580
|
+
]
|
|
1581
|
+
},
|
|
1582
|
+
{
|
|
1583
|
+
key: "stains",
|
|
1584
|
+
label: "Stains",
|
|
1585
|
+
fields: [
|
|
1586
|
+
b("density", "Density", 0, 1, 0.01),
|
|
1587
|
+
b("size", "Size", 4, 400, 1),
|
|
1588
|
+
b("strength", "Strength", 0, 1, 0.01),
|
|
1589
|
+
b("ring", "Tide line", 0, 1, 0.01),
|
|
1590
|
+
X("color", "Color")
|
|
1591
|
+
]
|
|
1592
|
+
},
|
|
1593
|
+
{
|
|
1594
|
+
key: "lighting",
|
|
1595
|
+
label: "Lighting",
|
|
1596
|
+
fields: [b("depth", "Depth", 0, 6, 0.01), b("azimuth", "Azimuth", 0, 360, 1), b("elevation", "Elevation", 5, 90, 1)]
|
|
1597
|
+
},
|
|
1598
|
+
{
|
|
1599
|
+
key: "output",
|
|
1600
|
+
label: "Output",
|
|
1601
|
+
fields: [
|
|
1602
|
+
b("brightness", "Brightness", -0.5, 0.5, 5e-3),
|
|
1603
|
+
b("contrast", "Contrast", 0, 3, 0.01),
|
|
1604
|
+
{ key: "normalFlipY", label: "Normal: flip Y (DirectX)", type: "boolean" }
|
|
1605
|
+
]
|
|
1606
|
+
}
|
|
1607
|
+
];
|
|
1608
|
+
function De(r) {
|
|
1609
|
+
return {
|
|
1610
|
+
...r,
|
|
1611
|
+
color: { ...r.color },
|
|
1612
|
+
mottle: { ...r.mottle },
|
|
1613
|
+
grain: { ...r.grain },
|
|
1614
|
+
cells: { ...r.cells },
|
|
1615
|
+
streaks: { ...r.streaks },
|
|
1616
|
+
fibers: { ...r.fibers },
|
|
1617
|
+
specks: { ...r.specks, colors: [...r.specks.colors] },
|
|
1618
|
+
structure: { ...r.structure },
|
|
1619
|
+
// overlay groups were added later; fill them in for older param objects
|
|
1620
|
+
crumples: { ...de.crumples, ...r.crumples },
|
|
1621
|
+
folds: { ...de.folds, ...r.folds },
|
|
1622
|
+
stains: { ...de.stains, ...r.stains },
|
|
1623
|
+
lighting: { ...r.lighting },
|
|
1624
|
+
output: { ...r.output }
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
function Be(r, ...o) {
|
|
1628
|
+
const i = De(r);
|
|
1629
|
+
for (const t of o)
|
|
1630
|
+
if (t) {
|
|
1631
|
+
for (const [e, a] of Object.entries(t))
|
|
1632
|
+
if (a !== void 0)
|
|
1633
|
+
if (a && typeof a == "object" && !Array.isArray(a)) {
|
|
1634
|
+
i[e] = { ...i[e] };
|
|
1635
|
+
for (const [n, c] of Object.entries(a))
|
|
1636
|
+
c !== void 0 && (i[e][n] = Array.isArray(c) ? [...c] : c);
|
|
1637
|
+
} else
|
|
1638
|
+
i[e] = a;
|
|
1639
|
+
}
|
|
1640
|
+
return i;
|
|
1641
|
+
}
|
|
1642
|
+
function nr(r, o) {
|
|
1643
|
+
return o.split(".").reduce((i, t) => i?.[t], r);
|
|
1644
|
+
}
|
|
1645
|
+
function ar(r, o, i) {
|
|
1646
|
+
const t = De(r), e = o.split(".");
|
|
1647
|
+
let a = t;
|
|
1648
|
+
for (let n = 0; n < e.length - 1; n++) a = a[e[n]];
|
|
1649
|
+
return a[e[e.length - 1]] = i, t;
|
|
1650
|
+
}
|
|
1651
|
+
const q = (r, o, i, t = 0) => {
|
|
1652
|
+
const e = G(r), a = i ? G(i) : e;
|
|
1653
|
+
return zt(e.map((n, c) => (n + (a[c] - n) * t) * o));
|
|
1654
|
+
}, ce = {
|
|
1655
|
+
cells: { strength: 0 },
|
|
1656
|
+
streaks: { strength: 0 },
|
|
1657
|
+
structure: { type: "none", strength: 0 }
|
|
1658
|
+
}, oe = {
|
|
1659
|
+
...ce,
|
|
1660
|
+
color: { base: "#f8f8f5", tint: "#efece2", tintAmount: 0.15, variation: 0.012, grainTone: 0.066 },
|
|
1661
|
+
mottle: { size: 280, octaves: 4, warp: 0.5, relief: 0.05 },
|
|
1662
|
+
grain: { size: 3, strength: 0.3, roughness: 0.6, octaves: 3 },
|
|
1663
|
+
fibers: { density: 1.2, length: 14, width: 0.8, curl: 0.4, darkRatio: 0.3, darkColor: "#c8c4bb", lightColor: "#ffffff", opacity: 0.3, relief: 0.3 },
|
|
1664
|
+
specks: { density: 4.5, sizeMin: 0.4, sizeMax: 1.1, elongation: 0.4, colors: ["#9a958c", "#b8b0a2", "#c9c2b5"], opacity: 0.5, relief: 0 },
|
|
1665
|
+
lighting: { depth: 0.36, azimuth: 225, elevation: 45 }
|
|
1666
|
+
}, Pe = (r) => ({
|
|
1667
|
+
...ce,
|
|
1668
|
+
color: { base: r, tint: q(r, 0.92), tintAmount: 0.4, variation: 0.02, grainTone: 0.11 },
|
|
1669
|
+
mottle: { size: 220, octaves: 5, warp: 0.6, relief: 0.08 },
|
|
1670
|
+
grain: { size: 3.5, strength: 0.4, roughness: 0.6, octaves: 4 },
|
|
1671
|
+
fibers: {
|
|
1672
|
+
density: 14,
|
|
1673
|
+
length: 16,
|
|
1674
|
+
width: 0.8,
|
|
1675
|
+
curl: 0.45,
|
|
1676
|
+
darkRatio: 0.7,
|
|
1677
|
+
darkColor: q(r, 0.72),
|
|
1678
|
+
lightColor: q(r, 1.12, "#ffffff", 0.25),
|
|
1679
|
+
opacity: 0.55,
|
|
1680
|
+
relief: 0.25
|
|
1681
|
+
},
|
|
1682
|
+
specks: { density: 9, sizeMin: 0.4, sizeMax: 1.2, elongation: 0.3, colors: [q(r, 0.6), q(r, 1.2, "#ffffff", 0.4), "#e8e2d0"], opacity: 0.6, relief: 0.2 },
|
|
1683
|
+
lighting: { depth: 0.44, azimuth: 225, elevation: 45 }
|
|
1684
|
+
}), we = (r) => ({
|
|
1685
|
+
...ce,
|
|
1686
|
+
color: { base: r, tint: q(r, 0.95), tintAmount: 0.3, variation: 0.012, grainTone: 0.11 },
|
|
1687
|
+
mottle: { size: 260, octaves: 4, warp: 0.4, relief: 0.04 },
|
|
1688
|
+
grain: { size: 2.5, strength: 0.45, roughness: 0.6, octaves: 3 },
|
|
1689
|
+
fibers: {
|
|
1690
|
+
density: 80,
|
|
1691
|
+
length: 15,
|
|
1692
|
+
width: 0.75,
|
|
1693
|
+
curl: 1,
|
|
1694
|
+
darkRatio: 0.92,
|
|
1695
|
+
darkColor: q(r, 0.68, "#484850", 0.3),
|
|
1696
|
+
lightColor: q(r, 1.1, "#ffffff", 0.3),
|
|
1697
|
+
opacity: 0.5,
|
|
1698
|
+
relief: 0.15
|
|
1699
|
+
},
|
|
1700
|
+
specks: { density: 2.4, sizeMin: 0.6, sizeMax: 1.6, elongation: 0.2, colors: [q(r, 0.4), q(r, 0.6), q(r, 0.8)], opacity: 0.8, relief: 0 },
|
|
1701
|
+
lighting: { depth: 0.48, azimuth: 225, elevation: 45 }
|
|
1702
|
+
}), Y = (r) => ({
|
|
1703
|
+
...ce,
|
|
1704
|
+
color: { base: r, tint: q(r, 0.9, "#c8a070", 0.15), tintAmount: 0.5, variation: 0.035, grainTone: 0.132 },
|
|
1705
|
+
mottle: { size: 360, octaves: 5, warp: 0.8, relief: 0.25 },
|
|
1706
|
+
grain: { size: 4, strength: 0.45, roughness: 0.62, octaves: 4 },
|
|
1707
|
+
cells: { size: 22, strength: 0.25, ridge: 0.2, warp: 0.8 },
|
|
1708
|
+
fibers: {
|
|
1709
|
+
density: 3,
|
|
1710
|
+
length: 46,
|
|
1711
|
+
width: 0.9,
|
|
1712
|
+
curl: 0.7,
|
|
1713
|
+
darkRatio: 0.55,
|
|
1714
|
+
darkColor: q(r, 0.62, "#6b4a30", 0.3),
|
|
1715
|
+
lightColor: q(r, 1.08, "#ffffff", 0.4),
|
|
1716
|
+
opacity: 0.35,
|
|
1717
|
+
relief: 0.35
|
|
1718
|
+
},
|
|
1719
|
+
specks: { density: 150, sizeMin: 0.4, sizeMax: 2.6, elongation: 0.8, colors: ["#3a302a", "#9a6c48", "#c8a27c"], opacity: 0.75, relief: 0.3 },
|
|
1720
|
+
lighting: { depth: 0.64, azimuth: 225, elevation: 45 }
|
|
1721
|
+
}), Q = (r) => ({
|
|
1722
|
+
...ce,
|
|
1723
|
+
color: { base: r, tint: q(r, 0.92, "#806048", 0.2), tintAmount: 0.4, variation: 0.025, grainTone: 0.132 },
|
|
1724
|
+
mottle: { size: 240, octaves: 5, warp: 0.6, relief: 0.08 },
|
|
1725
|
+
grain: { size: 3, strength: 0.45, roughness: 0.62, octaves: 4 },
|
|
1726
|
+
fibers: {
|
|
1727
|
+
density: 70,
|
|
1728
|
+
length: 12,
|
|
1729
|
+
width: 0.75,
|
|
1730
|
+
curl: 0.5,
|
|
1731
|
+
darkRatio: 0.45,
|
|
1732
|
+
darkColor: q(r, 0.72, "#5a3a28", 0.2),
|
|
1733
|
+
lightColor: q(r, 1.14, "#f0dcc0", 0.25),
|
|
1734
|
+
opacity: 0.45,
|
|
1735
|
+
relief: 0.25
|
|
1736
|
+
},
|
|
1737
|
+
specks: { density: 42, sizeMin: 0.5, sizeMax: 2.2, elongation: 0.7, colors: ["#3c2a22", "#7a4e38", "#e8dcc8"], opacity: 0.7, relief: 0.25 },
|
|
1738
|
+
lighting: { depth: 0.44, azimuth: 225, elevation: 45 }
|
|
1739
|
+
}), Re = (r) => ({
|
|
1740
|
+
...ce,
|
|
1741
|
+
color: { base: r, tint: q(r, 0.97, "#e8dcc8", 0.3), tintAmount: 0.25, variation: 0.012, grainTone: 0.12 },
|
|
1742
|
+
mottle: { size: 300, octaves: 4, warp: 0.5, relief: 0.1 },
|
|
1743
|
+
grain: { size: 3, strength: 0.5, roughness: 0.6, octaves: 3 },
|
|
1744
|
+
cells: { size: 8, strength: 0.7, ridge: 0.1, warp: 0.45 },
|
|
1745
|
+
fibers: { density: 1, length: 12, width: 0.7, curl: 0.5, darkRatio: 0.5, darkColor: "#b8b4a8", lightColor: "#ffffff", opacity: 0.2, relief: 0.2 },
|
|
1746
|
+
specks: { density: 7.5, sizeMin: 0.4, sizeMax: 1.2, elongation: 0.6, colors: ["#3a3836", "#8a3a48", "#7a6a50"], opacity: 0.7, relief: 0 },
|
|
1747
|
+
lighting: { depth: 0.4, azimuth: 225, elevation: 50 }
|
|
1748
|
+
}), Gt = [
|
|
1749
|
+
// drawing
|
|
1750
|
+
{ id: "printer", name: "Printer Paper", family: "drawing", layers: [oe, { color: { base: "#f6f7f6" }, grain: { size: 2.5, strength: 0.25 }, lighting: { depth: 0.24 } }] },
|
|
1751
|
+
{ id: "drawing-pad", name: "Drawing Pad", family: "drawing", layers: [oe, { color: { base: "#fafaf7" }, streaks: { length: 30, width: 2, strength: 0.3, direction: "horizontal" }, lighting: { depth: 0.52 } }] },
|
|
1752
|
+
{ id: "sketchbook", name: "Sketchbook", family: "drawing", layers: [oe, { color: { base: "#f8f8f4" }, streaks: { length: 22, width: 2.5, strength: 0.35 }, grain: { strength: 0.4 }, lighting: { depth: 0.48 } }] },
|
|
1753
|
+
{ id: "sketchbook-cream", name: "Sketchbook Cream", family: "drawing", layers: [oe, { color: { base: "#fcf9e9", tint: "#f3ead0" }, streaks: { length: 22, width: 2.5, strength: 0.3 }, grain: { strength: 0.4 }, lighting: { depth: 0.44 } }] },
|
|
1754
|
+
{
|
|
1755
|
+
id: "newsprint",
|
|
1756
|
+
name: "Newsprint",
|
|
1757
|
+
family: "drawing",
|
|
1758
|
+
layers: [
|
|
1759
|
+
oe,
|
|
1760
|
+
{
|
|
1761
|
+
color: { base: "#dcd2ca", tint: "#d0c0b0", tintAmount: 0.35, variation: 0.03 },
|
|
1762
|
+
grain: { size: 3, strength: 0.35 },
|
|
1763
|
+
fibers: { density: 9, length: 12, darkRatio: 0.7, darkColor: "#a89888", lightColor: "#ece6de", opacity: 0.35 },
|
|
1764
|
+
specks: { density: 24, colors: ["#5a5048", "#8a7868", "#a89080"] }
|
|
1765
|
+
}
|
|
1766
|
+
]
|
|
1767
|
+
},
|
|
1768
|
+
{
|
|
1769
|
+
id: "newsprint-old",
|
|
1770
|
+
name: "Newsprint Old",
|
|
1771
|
+
family: "drawing",
|
|
1772
|
+
layers: [
|
|
1773
|
+
oe,
|
|
1774
|
+
{
|
|
1775
|
+
color: { base: "#e0cbb3", tint: "#cfae8c", tintAmount: 0.5, variation: 0.045 },
|
|
1776
|
+
mottle: { size: 200, warp: 0.9 },
|
|
1777
|
+
grain: { size: 3, strength: 0.35 },
|
|
1778
|
+
streaks: { length: 120, width: 3, strength: 0.12, direction: "vertical" },
|
|
1779
|
+
fibers: { density: 7, length: 18, darkRatio: 0.8, darkColor: "#b08a78", lightColor: "#efe0cc", opacity: 0.3 },
|
|
1780
|
+
specks: { density: 18, colors: ["#504860", "#9a7058", "#b89070"] }
|
|
1781
|
+
}
|
|
1782
|
+
]
|
|
1783
|
+
},
|
|
1784
|
+
{ id: "construction-white", name: "Construction White", family: "drawing", layers: [Pe("#f6fafb"), { fibers: { darkColor: "#d6dde2", density: 4 } }] },
|
|
1785
|
+
// construction
|
|
1786
|
+
...[
|
|
1787
|
+
["red", "Red", "#c93e55"],
|
|
1788
|
+
["orange", "Orange", "#f66c53"],
|
|
1789
|
+
["yellow", "Yellow", "#f6ba66"],
|
|
1790
|
+
["green", "Green", "#6fbb84"],
|
|
1791
|
+
["blue", "Blue", "#698bd3"],
|
|
1792
|
+
["sky", "Sky", "#9ac1d4"],
|
|
1793
|
+
["purple", "Purple", "#775390"],
|
|
1794
|
+
["brown", "Brown", "#9c6b5d"],
|
|
1795
|
+
["black", "Black", "#433f40"]
|
|
1796
|
+
].map(([r, o, i]) => ({
|
|
1797
|
+
id: `construction-${r}`,
|
|
1798
|
+
name: `Construction ${o}`,
|
|
1799
|
+
family: "construction",
|
|
1800
|
+
layers: [Pe(i), r === "black" ? { fibers: { darkColor: "#2a2627", lightColor: "#6a6466" } } : {}]
|
|
1801
|
+
})),
|
|
1802
|
+
{ id: "construction-overlay", name: "Construction Overlay", family: "construction", layers: [Pe("#808080")] },
|
|
1803
|
+
// pastel (Mi-Teintes-like)
|
|
1804
|
+
...[
|
|
1805
|
+
["white", "White", "#f0f0f0"],
|
|
1806
|
+
["light-cream", "Light Cream", "#f2eee3"],
|
|
1807
|
+
["light-yellow", "Light Yellow", "#e3dbbe"],
|
|
1808
|
+
["light-gray", "Light Gray", "#dcdbdc"],
|
|
1809
|
+
["light-gray-warm", "Light Gray Warm", "#d6d0c9"],
|
|
1810
|
+
["light-cool", "Light Cool", "#e8eae9"],
|
|
1811
|
+
["mid-rose", "Mid Rose", "#beada9"],
|
|
1812
|
+
["mid-green", "Mid Green", "#b0b9b3"],
|
|
1813
|
+
["mid-gray", "Mid Gray", "#b0aaa6"],
|
|
1814
|
+
["mid-gray-cool", "Mid Gray Cool", "#c4c5ca"],
|
|
1815
|
+
["mid-cool", "Mid Cool", "#adb3b2"],
|
|
1816
|
+
["mid-warm", "Mid Warm", "#a7a09a"],
|
|
1817
|
+
["dark-gray", "Dark Gray", "#838383"],
|
|
1818
|
+
["dark-gray-warm", "Dark Gray Warm", "#918a85"],
|
|
1819
|
+
["dark-cool", "Dark Cool", "#83878c"],
|
|
1820
|
+
["dark-green", "Dark Green", "#858b87"],
|
|
1821
|
+
["dark-rose", "Dark Rose", "#9e8e8e"],
|
|
1822
|
+
["dark-warm", "Dark Warm", "#908b87"],
|
|
1823
|
+
["dark-blue", "Dark Blue", "#61657b"],
|
|
1824
|
+
["black", "Black", "#3b3739"]
|
|
1825
|
+
].map(([r, o, i]) => ({
|
|
1826
|
+
id: `pastel-${r}`,
|
|
1827
|
+
name: `Pastel ${o}`,
|
|
1828
|
+
family: "pastel",
|
|
1829
|
+
layers: [we(i), r === "black" ? { fibers: { darkRatio: 0.3, lightColor: "#6a6668", darkColor: "#262224" } } : {}]
|
|
1830
|
+
})),
|
|
1831
|
+
{
|
|
1832
|
+
id: "pastel-black-patterned",
|
|
1833
|
+
name: "Pastel Black Patterned",
|
|
1834
|
+
family: "pastel",
|
|
1835
|
+
layers: [
|
|
1836
|
+
we("#333133"),
|
|
1837
|
+
{
|
|
1838
|
+
structure: { type: "honeycomb", spacing: 5, strength: 0.55, sharpness: 0.3, direction: "horizontal", warp: 0.5 },
|
|
1839
|
+
fibers: { darkRatio: 0.2, lightColor: "#5a5458", darkColor: "#1e1c1e", density: 14, opacity: 0.35 },
|
|
1840
|
+
lighting: { depth: 0.8 }
|
|
1841
|
+
}
|
|
1842
|
+
]
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
id: "parchment",
|
|
1846
|
+
name: "Parchment",
|
|
1847
|
+
family: "pastel",
|
|
1848
|
+
layers: [we("#f3dbc3"), { fibers: { density: 8, darkRatio: 0.4, opacity: 0.2 }, mottle: { size: 160, warp: 1 }, color: { variation: 0.03, tint: "#ead0b4", tintAmount: 0.5 } }]
|
|
1849
|
+
},
|
|
1850
|
+
{ id: "pastel-overlay", name: "Pastel Overlay", family: "pastel", layers: [we("#808080")] },
|
|
1851
|
+
// handmade
|
|
1852
|
+
{ id: "handmade-ivory", name: "Handmade Ivory", family: "handmade", layers: [Y("#efe7d6")] },
|
|
1853
|
+
{ id: "oatmeal", name: "Oatmeal", family: "handmade", layers: [Y("#f2efdd"), { specks: { density: 180, sizeMax: 3.6, colors: ["#5a4a38", "#a08868", "#c8b898"] } }] },
|
|
1854
|
+
{ id: "handmade-green", name: "Handmade Green", family: "handmade", layers: [Y("#8d9078")] },
|
|
1855
|
+
{ id: "handmade-yellow", name: "Handmade Yellow", family: "handmade", layers: [Y("#c99355")] },
|
|
1856
|
+
{ id: "handmade-navy", name: "Handmade Navy", family: "handmade", layers: [Y("#544e5d"), { specks: { colors: ["#2a2630", "#8a8090", "#b0a8b8"] } }] },
|
|
1857
|
+
{ id: "handmade-sky", name: "Handmade Sky", family: "handmade", layers: [Y("#959dad")] },
|
|
1858
|
+
{ id: "handmade-rust", name: "Handmade Rust", family: "handmade", layers: [Y("#92534a")] },
|
|
1859
|
+
{ id: "handmade-overlay", name: "Handmade Overlay", family: "handmade", layers: [Y("#808080"), { specks: { colors: ["#404040", "#606060", "#a0a0a0"] } }] },
|
|
1860
|
+
// watercolor
|
|
1861
|
+
{ id: "watercolor-cold-press", name: "Watercolor Cold Press", family: "watercolor", layers: [Re("#f2f2ea")] },
|
|
1862
|
+
{ id: "watercolor-hot-press", name: "Watercolor Hot Press", family: "watercolor", layers: [Re("#f5f1ee"), { cells: { size: 12, strength: 0.25 }, grain: { strength: 0.35 }, lighting: { depth: 0.44 } }] },
|
|
1863
|
+
{ id: "watercolor-rough", name: "Watercolor Rough", family: "watercolor", layers: [Re("#f3f1e8"), { cells: { size: 20, strength: 1.3, warp: 0.7 }, mottle: { relief: 0.2 }, lighting: { depth: 0.88 } }] },
|
|
1864
|
+
// craft & cardboard
|
|
1865
|
+
{ id: "kraft", name: "Kraft Paper", family: "craft", layers: [Q("#a8856f")] },
|
|
1866
|
+
{ id: "kraft-rough", name: "Kraft Rough", family: "craft", layers: [Q("#a7836e"), { grain: { strength: 0.6, size: 3.5 }, fibers: { density: 20 }, lighting: { depth: 0.56 } }] },
|
|
1867
|
+
{ id: "kraft-light", name: "Kraft Light", family: "craft", layers: [Q("#d3bca5")] },
|
|
1868
|
+
{ id: "kraft-gray", name: "Kraft Gray", family: "craft", layers: [Q("#b3a599"), { color: { tint: "#a89080" } }] },
|
|
1869
|
+
{
|
|
1870
|
+
id: "chipboard",
|
|
1871
|
+
name: "Chipboard",
|
|
1872
|
+
family: "craft",
|
|
1873
|
+
layers: [Q("#9d8a7b"), { fibers: { density: 10, length: 22, curl: 0.25, darkRatio: 0.25, lightColor: "#d8ccb8", opacity: 0.4 }, specks: { density: 72, colors: ["#3a302a", "#8a3a30", "#e0d8c8"] } }]
|
|
1874
|
+
},
|
|
1875
|
+
{ id: "cardboard", name: "Cardboard", family: "craft", layers: [Q("#a6866f"), { mottle: { size: 160 }, color: { variation: 0.035 } }] },
|
|
1876
|
+
{
|
|
1877
|
+
id: "cardboard-corrugated",
|
|
1878
|
+
name: "Cardboard Corrugated",
|
|
1879
|
+
family: "craft",
|
|
1880
|
+
layers: [Q("#a5856e"), { structure: { type: "corrugated", spacing: 90, strength: 0.25, sharpness: 0.2, direction: "horizontal", warp: 0.1 }, color: { grainTone: 0.176 } }]
|
|
1881
|
+
}
|
|
1882
|
+
], Ht = Gt.map((r) => ({
|
|
1883
|
+
id: r.id,
|
|
1884
|
+
name: r.name,
|
|
1885
|
+
family: r.family,
|
|
1886
|
+
params: Be(de, ...r.layers)
|
|
1887
|
+
})), It = Object.fromEntries(Ht.map((r) => [r.id, r]));
|
|
1888
|
+
function Nt(r) {
|
|
1889
|
+
const o = It[r];
|
|
1890
|
+
if (!o) throw new Error(`procedural-paper: unknown preset "${r}"`);
|
|
1891
|
+
return o;
|
|
1892
|
+
}
|
|
1893
|
+
const Ve = 32, Vt = ["none", "corrugated", "laid", "honeycomb", "canvas"], $ = (r, o, i, t = i) => [
|
|
1894
|
+
Math.max(1, Math.round(r / Math.max(i, 1e-3))),
|
|
1895
|
+
Math.max(1, Math.round(o / Math.max(t, 1e-3)))
|
|
1896
|
+
], Ee = (r, o, i, t) => {
|
|
1897
|
+
let e = Math.max(1, Math.round(r));
|
|
1898
|
+
for (; e > 1 && (o[0] * 2 ** (e - 1) > i / 1.5 || o[1] * 2 ** (e - 1) > t / 1.5); ) e--;
|
|
1899
|
+
return e;
|
|
1900
|
+
};
|
|
1901
|
+
function We(r, o, i) {
|
|
1902
|
+
const t = De(r), e = Math.max(1, Math.round(o)), a = Math.max(1, Math.round(i)), n = Math.max(0.01, t.scale), c = Math.round(t.seed) >>> 0, s = G(t.color.base), l = $(e, a, t.mottle.size * n), u = $(e, a, t.grain.size * n), d = $(e, a, t.cells.size * n), g = t.streaks.direction !== "vertical", h = t.streaks.length * n, f = t.streaks.width * n, y = g ? $(e, a, h, f) : $(e, a, f, h), p = Math.min(t.fibers.length * n, Math.min(e, a) * 0.45), m = t.fibers.width * n, w = Math.max(0, t.fibers.curl), v = p * (0.5 + 0.75 * w) + m * 0.7 + 1, x = [
|
|
1903
|
+
Math.max(1, Math.floor(e / (2 * v))),
|
|
1904
|
+
Math.max(1, Math.floor(a / (2 * v)))
|
|
1905
|
+
], S = [e / x[0], a / x[1]], C = Math.min(Ve, t.fibers.density * S[0] * S[1] / 1e4), F = Math.max(0.2, t.specks.sizeMin * n), W = Math.max(F, t.specks.sizeMax * n), T = 1 + Math.max(0, t.specks.elongation), z = Math.min(1.32 * W * T + 0.66 * T + 1, Math.min(e, a) * 0.45), E = Math.max(2 * z, 48 * n), D = [
|
|
1906
|
+
Math.max(1, Math.floor(e / E)),
|
|
1907
|
+
Math.max(1, Math.floor(a / E))
|
|
1908
|
+
], H = [e / D[0], a / D[1]], Z = Math.min(Ve, t.specks.density * H[0] * H[1] / 262144), N = t.structure.direction === "vertical", V = N ? e : a, le = N ? a : e, B = Math.max(1, t.structure.spacing * n), L = [
|
|
1909
|
+
Math.max(1, Math.round(V / B)),
|
|
1910
|
+
Math.max(1, Math.round(le / (t.structure.type === "laid" ? B * 12 : B)))
|
|
1911
|
+
];
|
|
1912
|
+
t.structure.type === "honeycomb" && L[0] % 2 === 1 && (L[0] += 1);
|
|
1913
|
+
const _ = t.lighting.azimuth * Math.PI / 180, J = Math.min(89.5, Math.max(1, t.lighting.elevation)) * Math.PI / 180, ee = 0.5 / Math.max(0.05, t.lighting.depth), te = $(e, a, t.crumples.size * n), me = (e / te[0] + a / te[1]) / 2, Fe = $(e, a, t.crumples.wrinkleSize * n), at = (e / Fe[0] + a / Fe[1]) / 2, _e = Math.max(0, t.crumples.strength) * me * 0.25 * ee, Ue = Math.max(0, t.crumples.wrinkles) * at * 0.25 * ee, U = t.folds.strength > 0 ? [Math.max(0, Math.round(t.folds.countX)), Math.max(0, Math.round(t.folds.countY))] : [0, 0], Ge = Math.max(0, t.folds.strength) * ee, He = Math.max(1, t.folds.width * n), st = Ge * (0.2 * Math.max(U[0] ? e / U[0] : 0, U[1] ? a / U[1] : 0) + 0.5 * He), Ae = $(e, a, 2.6 * Math.max(2, t.stains.size * n)), ct = [e / Ae[0], a / Ae[1]], lt = t.mottle.relief + t.grain.strength + t.cells.strength + t.streaks.strength + t.structure.strength + t.fibers.relief * Math.min(1, t.fibers.opacity * 2) + t.specks.relief * Math.min(1, t.specks.opacity) + _e + 1.5 * Ue + (U[0] || U[1] ? st : 0);
|
|
1914
|
+
return {
|
|
1915
|
+
width: e,
|
|
1916
|
+
height: a,
|
|
1917
|
+
base: s,
|
|
1918
|
+
baseLum: rt(s),
|
|
1919
|
+
tint: G(t.color.tint),
|
|
1920
|
+
tintAmount: t.color.tintAmount,
|
|
1921
|
+
variation: t.color.variation,
|
|
1922
|
+
grainTone: t.color.grainTone,
|
|
1923
|
+
mottle: {
|
|
1924
|
+
seed: O(c, 1),
|
|
1925
|
+
tintSeed: O(c, 2),
|
|
1926
|
+
warpSeed: O(c, 3),
|
|
1927
|
+
per: l,
|
|
1928
|
+
octaves: Ee(t.mottle.octaves, l, e, a),
|
|
1929
|
+
warp: t.mottle.warp,
|
|
1930
|
+
relief: t.mottle.relief
|
|
1931
|
+
},
|
|
1932
|
+
grain: {
|
|
1933
|
+
seed: O(c, 4),
|
|
1934
|
+
per: u,
|
|
1935
|
+
octaves: Ee(t.grain.octaves, u, e, a),
|
|
1936
|
+
roughness: t.grain.roughness,
|
|
1937
|
+
strength: t.grain.strength
|
|
1938
|
+
},
|
|
1939
|
+
cells: {
|
|
1940
|
+
seed: O(c, 5),
|
|
1941
|
+
warpSeed: O(c, 6),
|
|
1942
|
+
per: d,
|
|
1943
|
+
strength: t.cells.strength,
|
|
1944
|
+
ridge: t.cells.ridge,
|
|
1945
|
+
warp: t.cells.warp
|
|
1946
|
+
},
|
|
1947
|
+
streaks: { seed: O(c, 7), per: y, octaves: Ee(3, y, e, a), strength: t.streaks.strength },
|
|
1948
|
+
fibers: {
|
|
1949
|
+
seed: O(c, 8),
|
|
1950
|
+
per: x,
|
|
1951
|
+
cell: S,
|
|
1952
|
+
count: C,
|
|
1953
|
+
length: p,
|
|
1954
|
+
width: m,
|
|
1955
|
+
curl: w,
|
|
1956
|
+
darkRatio: t.fibers.darkRatio,
|
|
1957
|
+
dark: G(t.fibers.darkColor),
|
|
1958
|
+
light: G(t.fibers.lightColor),
|
|
1959
|
+
opacity: t.fibers.opacity,
|
|
1960
|
+
relief: t.fibers.relief
|
|
1961
|
+
},
|
|
1962
|
+
specks: {
|
|
1963
|
+
seed: O(c, 9),
|
|
1964
|
+
per: D,
|
|
1965
|
+
cell: H,
|
|
1966
|
+
count: Z,
|
|
1967
|
+
sizeMin: F,
|
|
1968
|
+
sizeMax: W,
|
|
1969
|
+
elongation: Math.max(0, t.specks.elongation),
|
|
1970
|
+
colors: t.specks.colors.map(G),
|
|
1971
|
+
opacity: t.specks.opacity,
|
|
1972
|
+
relief: t.specks.relief
|
|
1973
|
+
},
|
|
1974
|
+
structure: {
|
|
1975
|
+
type: Math.max(0, Vt.indexOf(t.structure.type)),
|
|
1976
|
+
seed: O(c, 10),
|
|
1977
|
+
per: L,
|
|
1978
|
+
strength: t.structure.type === "none" ? 0 : t.structure.strength,
|
|
1979
|
+
sharpness: t.structure.sharpness,
|
|
1980
|
+
vertical: N,
|
|
1981
|
+
warp: t.structure.warp
|
|
1982
|
+
},
|
|
1983
|
+
crumples: {
|
|
1984
|
+
seed: O(c, 11),
|
|
1985
|
+
warpSeed: O(c, 12),
|
|
1986
|
+
per: te,
|
|
1987
|
+
wPer: Fe,
|
|
1988
|
+
amp: _e,
|
|
1989
|
+
wAmp: Ue,
|
|
1990
|
+
warp: Math.max(0, t.crumples.warp)
|
|
1991
|
+
},
|
|
1992
|
+
folds: {
|
|
1993
|
+
seed: O(c, 13),
|
|
1994
|
+
count: U,
|
|
1995
|
+
offset: t.folds.offset,
|
|
1996
|
+
strength: U[0] || U[1] ? Ge : 0,
|
|
1997
|
+
width: He,
|
|
1998
|
+
wear: U[0] || U[1] ? t.folds.wear : 0
|
|
1999
|
+
},
|
|
2000
|
+
stains: {
|
|
2001
|
+
seed: O(c, 14),
|
|
2002
|
+
per: Ae,
|
|
2003
|
+
cell: ct,
|
|
2004
|
+
density: Math.min(1, Math.max(0, t.stains.density)),
|
|
2005
|
+
size: Math.max(2, t.stains.size * n),
|
|
2006
|
+
strength: t.stains.strength,
|
|
2007
|
+
ring: t.stains.ring,
|
|
2008
|
+
color: G(t.stains.color)
|
|
2009
|
+
},
|
|
2010
|
+
light: {
|
|
2011
|
+
dir: [Math.cos(J) * Math.cos(_), Math.cos(J) * Math.sin(_), Math.sin(J)],
|
|
2012
|
+
depth: t.lighting.depth
|
|
2013
|
+
},
|
|
2014
|
+
heightNorm: 1 / Math.max(0.05, lt),
|
|
2015
|
+
output: { brightness: t.output.brightness, contrast: t.output.contrast, flipY: t.output.normalFlipY }
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
let xe = null;
|
|
2019
|
+
function jt(r, o, i) {
|
|
2020
|
+
if (!xe) {
|
|
2021
|
+
xe = new Uint32Array(256);
|
|
2022
|
+
for (let e = 0; e < 256; e++) {
|
|
2023
|
+
let a = e;
|
|
2024
|
+
for (let n = 0; n < 8; n++) a = a & 1 ? 3988292384 ^ a >>> 1 : a >>> 1;
|
|
2025
|
+
xe[e] = a >>> 0;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
let t = 4294967295;
|
|
2029
|
+
for (let e = o; e < i; e++) t = xe[(t ^ r[e]) & 255] ^ t >>> 8;
|
|
2030
|
+
return (t ^ 4294967295) >>> 0;
|
|
2031
|
+
}
|
|
2032
|
+
async function Xt(r) {
|
|
2033
|
+
const o = new CompressionStream("deflate"), i = new Blob([r]).stream().pipeThrough(o);
|
|
2034
|
+
return new Uint8Array(await new Response(i).arrayBuffer());
|
|
2035
|
+
}
|
|
2036
|
+
async function ot(r, o = {}) {
|
|
2037
|
+
const { width: i, height: t, data: e } = r, a = o.grayscale ?? $t(e), n = a ? 1 : 3, c = i * n + 1, s = new Uint8Array(c * t);
|
|
2038
|
+
for (let y = 0; y < t; y++) {
|
|
2039
|
+
const p = y * c;
|
|
2040
|
+
s[p] = 1;
|
|
2041
|
+
let m = 0;
|
|
2042
|
+
for (let w = 0; w < i; w++) {
|
|
2043
|
+
const v = (y * i + w) * 4;
|
|
2044
|
+
for (let x = 0; x < n; x++) {
|
|
2045
|
+
const S = e[v + x], C = w > 0 ? e[v - 4 + x] : 0;
|
|
2046
|
+
s[p + 1 + m++] = S - C & 255;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
const l = await Xt(s), u = [
|
|
2051
|
+
["IHDR", Yt(i, t, a ? 0 : 2)],
|
|
2052
|
+
["IDAT", l],
|
|
2053
|
+
["IEND", new Uint8Array(0)]
|
|
2054
|
+
];
|
|
2055
|
+
let d = 8;
|
|
2056
|
+
for (const [, y] of u) d += 12 + y.length;
|
|
2057
|
+
const g = new Uint8Array(d);
|
|
2058
|
+
g.set([137, 80, 78, 71, 13, 10, 26, 10], 0);
|
|
2059
|
+
const h = new DataView(g.buffer);
|
|
2060
|
+
let f = 8;
|
|
2061
|
+
for (const [y, p] of u) {
|
|
2062
|
+
h.setUint32(f, p.length);
|
|
2063
|
+
for (let m = 0; m < 4; m++) g[f + 4 + m] = y.charCodeAt(m);
|
|
2064
|
+
g.set(p, f + 8), h.setUint32(f + 8 + p.length, jt(g, f + 4, f + 8 + p.length)), f += 12 + p.length;
|
|
2065
|
+
}
|
|
2066
|
+
return g;
|
|
2067
|
+
}
|
|
2068
|
+
function Yt(r, o, i) {
|
|
2069
|
+
const t = new Uint8Array(13), e = new DataView(t.buffer);
|
|
2070
|
+
return e.setUint32(0, r), e.setUint32(4, o), t[8] = 8, t[9] = i, t;
|
|
2071
|
+
}
|
|
2072
|
+
function $t(r) {
|
|
2073
|
+
for (let o = 0; o < r.length; o += 388) if (r[o] !== r[o + 1] || r[o] !== r[o + 2]) return !1;
|
|
2074
|
+
return !0;
|
|
2075
|
+
}
|
|
2076
|
+
async function Kt(r) {
|
|
2077
|
+
return new Blob([await ot(r)], { type: "image/png" });
|
|
2078
|
+
}
|
|
2079
|
+
async function sr(r) {
|
|
2080
|
+
const o = await ot(r);
|
|
2081
|
+
let i = "";
|
|
2082
|
+
for (let t = 0; t < o.length; t += 32768) i += String.fromCharCode(...o.subarray(t, t + 32768));
|
|
2083
|
+
return "data:image/png;base64," + btoa(i);
|
|
2084
|
+
}
|
|
2085
|
+
function Zt(r) {
|
|
2086
|
+
return new ImageData(r.data, r.width, r.height);
|
|
2087
|
+
}
|
|
2088
|
+
function cr(r, o) {
|
|
2089
|
+
const i = o ?? document.createElement("canvas");
|
|
2090
|
+
return i.width = r.width, i.height = r.height, i.getContext("2d").putImageData(Zt(r), 0, 0), i;
|
|
2091
|
+
}
|
|
2092
|
+
async function lr(r, o = 1) {
|
|
2093
|
+
return `url(${URL.createObjectURL(await Kt(r))}) repeat 0 0 / ${r.width / o}px ${r.height / o}px`;
|
|
2094
|
+
}
|
|
2095
|
+
const je = (r) => ({
|
|
2096
|
+
preset: "printer",
|
|
2097
|
+
params: { color: { base: r, tint: r, variation: 0.03 }, grain: { strength: 0.18 }, fibers: { density: 1.5, opacity: 0.15 }, lighting: { depth: 0.2 } }
|
|
2098
|
+
}), Qt = {
|
|
2099
|
+
// stock presets
|
|
2100
|
+
printer: { preset: "printer" },
|
|
2101
|
+
"drawing-pad": { preset: "drawing-pad" },
|
|
2102
|
+
sketchbook: { preset: "sketchbook" },
|
|
2103
|
+
"sketchbook-cream": { preset: "sketchbook-cream" },
|
|
2104
|
+
newsprint: { preset: "newsprint" },
|
|
2105
|
+
"newsprint-old": { preset: "newsprint-old" },
|
|
2106
|
+
parchment: { preset: "parchment" },
|
|
2107
|
+
"construction-white": { preset: "construction-white" },
|
|
2108
|
+
"handmade-ivory": { preset: "handmade-ivory" },
|
|
2109
|
+
oatmeal: { preset: "oatmeal" },
|
|
2110
|
+
"handmade-green": { preset: "handmade-green" },
|
|
2111
|
+
"handmade-yellow": { preset: "handmade-yellow" },
|
|
2112
|
+
"handmade-navy": { preset: "handmade-navy" },
|
|
2113
|
+
"handmade-sky": { preset: "handmade-sky" },
|
|
2114
|
+
"handmade-rust": { preset: "handmade-rust" },
|
|
2115
|
+
// finer tooth than the presets: these are seen at desk scale, not as a full-page scan
|
|
2116
|
+
"watercolor-cold-press": { preset: "watercolor-cold-press", params: { cells: { size: 9, strength: 0.55 }, lighting: { depth: 0.3 } } },
|
|
2117
|
+
"watercolor-hot-press": { preset: "watercolor-hot-press", params: { cells: { size: 8, strength: 0.2 }, lighting: { depth: 0.3 } } },
|
|
2118
|
+
"watercolor-rough": { preset: "watercolor-rough", params: { cells: { size: 12, strength: 0.8 }, lighting: { depth: 0.45 } } },
|
|
2119
|
+
kraft: { preset: "kraft" },
|
|
2120
|
+
"kraft-light": { preset: "kraft-light" },
|
|
2121
|
+
"kraft-rough": { preset: "kraft-rough" },
|
|
2122
|
+
"kraft-gray": { preset: "kraft-gray" },
|
|
2123
|
+
chipboard: { preset: "chipboard" },
|
|
2124
|
+
cardboard: { preset: "cardboard" },
|
|
2125
|
+
"cardboard-corrugated": { preset: "cardboard-corrugated" },
|
|
2126
|
+
"construction-red": { preset: "construction-red" },
|
|
2127
|
+
"construction-orange": { preset: "construction-orange" },
|
|
2128
|
+
"construction-yellow": { preset: "construction-yellow" },
|
|
2129
|
+
"construction-green": { preset: "construction-green" },
|
|
2130
|
+
"construction-blue": { preset: "construction-blue" },
|
|
2131
|
+
"construction-sky": { preset: "construction-sky" },
|
|
2132
|
+
"construction-purple": { preset: "construction-purple" },
|
|
2133
|
+
"construction-black": { preset: "construction-black" },
|
|
2134
|
+
"pastel-light-cream": { preset: "pastel-light-cream" },
|
|
2135
|
+
"pastel-light-yellow": { preset: "pastel-light-yellow" },
|
|
2136
|
+
"pastel-mid-rose": { preset: "pastel-mid-rose" },
|
|
2137
|
+
"pastel-mid-green": { preset: "pastel-mid-green" },
|
|
2138
|
+
"pastel-mid-cool": { preset: "pastel-mid-cool" },
|
|
2139
|
+
"pastel-dark-blue": { preset: "pastel-dark-blue" },
|
|
2140
|
+
"pastel-dark-rose": { preset: "pastel-dark-rose" },
|
|
2141
|
+
"pastel-black": { preset: "pastel-black" },
|
|
2142
|
+
"pastel-black-patterned": { preset: "pastel-black-patterned" },
|
|
2143
|
+
// custom recipes
|
|
2144
|
+
// sticky notes get their colour per card (params.color)
|
|
2145
|
+
sticky: je("#f8e47e"),
|
|
2146
|
+
tracing: {
|
|
2147
|
+
preset: "printer",
|
|
2148
|
+
params: { color: { base: "#f7f8f6", tint: "#f1f3f1", variation: 0.02 }, grain: { strength: 0.1 }, fibers: { density: 0 }, specks: { density: 0 }, lighting: { depth: 0.15 } }
|
|
2149
|
+
},
|
|
2150
|
+
washi: {
|
|
2151
|
+
preset: "printer",
|
|
2152
|
+
params: { color: { base: "#e98b9a", variation: 0.03 }, grain: { strength: 0.2, size: 2 }, fibers: { density: 30, length: 8, width: 0.6, opacity: 0.25, lightColor: "#ffffff", darkRatio: 0 }, lighting: { depth: 0.25 } }
|
|
2153
|
+
},
|
|
2154
|
+
"clear-tape": {
|
|
2155
|
+
preset: "printer",
|
|
2156
|
+
params: { color: { base: "#ffffff", tint: "#ffffff", variation: 0 }, grain: { strength: 0 }, mottle: { relief: 0 }, fibers: { density: 0 }, specks: { density: 0 }, lighting: { depth: 0.1 } }
|
|
2157
|
+
},
|
|
2158
|
+
napkin: {
|
|
2159
|
+
preset: "printer",
|
|
2160
|
+
params: {
|
|
2161
|
+
color: { base: "#fbfbf8", variation: 0.02 },
|
|
2162
|
+
grain: { size: 2, strength: 0.5, roughness: 0.6 },
|
|
2163
|
+
structure: { type: "canvas", spacing: 7, strength: 0.35, sharpness: 0.2, warp: 0.5 },
|
|
2164
|
+
fibers: { density: 3, opacity: 0.12 },
|
|
2165
|
+
lighting: { depth: 0.55, elevation: 40 }
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2168
|
+
thermal: {
|
|
2169
|
+
preset: "printer",
|
|
2170
|
+
params: { color: { base: "#f3f2ee", tint: "#ece9e0", tintAmount: 0.4 }, grain: { strength: 0.12 }, fibers: { density: 0 }, lighting: { depth: 0.12 } }
|
|
2171
|
+
},
|
|
2172
|
+
// photo stock: resin-coated prints, instant-film frames, film base
|
|
2173
|
+
"photo-gloss": je("#f7f6f2"),
|
|
2174
|
+
"photo-matte": {
|
|
2175
|
+
preset: "printer",
|
|
2176
|
+
params: { color: { base: "#f2efe7", tint: "#ece7da", variation: 0.03 }, grain: { strength: 0.3 }, fibers: { density: 1, opacity: 0.12 }, specks: { density: 0 }, lighting: { depth: 0.18 } }
|
|
2177
|
+
},
|
|
2178
|
+
polaroid: {
|
|
2179
|
+
preset: "printer",
|
|
2180
|
+
params: { color: { base: "#f4f2ec", tint: "#eeebe2", variation: 0.02 }, grain: { strength: 0.38, size: 1.5 }, fibers: { density: 0 }, specks: { density: 0 }, lighting: { depth: 0.2 } }
|
|
2181
|
+
},
|
|
2182
|
+
film: {
|
|
2183
|
+
preset: "printer",
|
|
2184
|
+
params: { color: { base: "#211a15", tint: "#2a1d14", variation: 0.04 }, grain: { strength: 0.12 }, fibers: { density: 0 }, specks: { density: 0 }, lighting: { depth: 0.12 } }
|
|
2185
|
+
},
|
|
2186
|
+
masking: {
|
|
2187
|
+
preset: "kraft-light",
|
|
2188
|
+
params: {
|
|
2189
|
+
color: { base: "#e9dcbd", tint: "#e2d2ae", variation: 0.04 },
|
|
2190
|
+
// crepe: fine creases across the tape
|
|
2191
|
+
streaks: { length: 3, width: 40, strength: 0.55, direction: "vertical" },
|
|
2192
|
+
fibers: { density: 4, opacity: 0.2 },
|
|
2193
|
+
specks: { density: 6 },
|
|
2194
|
+
grain: { strength: 0.25 },
|
|
2195
|
+
lighting: { depth: 0.45 }
|
|
2196
|
+
}
|
|
2197
|
+
},
|
|
2198
|
+
// desk surfaces
|
|
2199
|
+
cork: {
|
|
2200
|
+
preset: "kraft",
|
|
2201
|
+
params: {
|
|
2202
|
+
color: { base: "#bf9468", tint: "#a97b52", tintAmount: 0.5, variation: 0.08, grainTone: 0.4 },
|
|
2203
|
+
grain: { size: 3, strength: 0.7, roughness: 0.65 },
|
|
2204
|
+
cells: { size: 6, strength: 0.6, ridge: 0.3, warp: 0.6 },
|
|
2205
|
+
fibers: { density: 0 },
|
|
2206
|
+
specks: { density: 900, sizeMin: 0.8, sizeMax: 3.2, elongation: 0.6, colors: ["#6b4426", "#8e6238", "#dcbd8f"], opacity: 0.75, relief: 0.4 },
|
|
2207
|
+
lighting: { depth: 0.8 }
|
|
2208
|
+
}
|
|
2209
|
+
},
|
|
2210
|
+
"cutting-mat": {
|
|
2211
|
+
preset: "construction-green",
|
|
2212
|
+
params: { color: { base: "#2f5a4b", tint: "#2a5245" }, fibers: { density: 0 }, grain: { strength: 0.25 }, lighting: { depth: 0.2 } }
|
|
2213
|
+
},
|
|
2214
|
+
oak: qe("#b98b5b", "#9a6c40"),
|
|
2215
|
+
walnut: qe("#6a4630", "#4f3221"),
|
|
2216
|
+
plywood: qe("#d8b98d", "#c9a676", 0.15),
|
|
2217
|
+
steel: {
|
|
2218
|
+
preset: "printer",
|
|
2219
|
+
params: {
|
|
2220
|
+
color: { base: "#c9cdd1", tint: "#b9bec4", tintAmount: 0.4, variation: 0.05, grainTone: 0.35 },
|
|
2221
|
+
grain: { strength: 0.12 },
|
|
2222
|
+
streaks: { length: 500, width: 1.2, strength: 0.7, direction: "horizontal" },
|
|
2223
|
+
fibers: { density: 0 },
|
|
2224
|
+
specks: { density: 8, colors: ["#8a8f94", "#a0a4a8", "#e8eaec"], opacity: 0.4 },
|
|
2225
|
+
lighting: { depth: 0.25 }
|
|
2226
|
+
}
|
|
2227
|
+
},
|
|
2228
|
+
pegboard: {
|
|
2229
|
+
preset: "kraft",
|
|
2230
|
+
params: { color: { base: "#c79f72", tint: "#b88d61", variation: 0.04 }, fibers: { density: 2 }, grain: { strength: 0.3 }, specks: { density: 30 }, lighting: { depth: 0.3 } }
|
|
2231
|
+
},
|
|
2232
|
+
concrete: {
|
|
2233
|
+
preset: "printer",
|
|
2234
|
+
params: {
|
|
2235
|
+
color: { base: "#a3a19c", tint: "#8f8c86", tintAmount: 0.5, variation: 0.09, grainTone: 0.3 },
|
|
2236
|
+
mottle: { size: 260, relief: 0.2 },
|
|
2237
|
+
grain: { size: 3, strength: 0.7, roughness: 0.7 },
|
|
2238
|
+
fibers: { density: 0 },
|
|
2239
|
+
specks: { density: 700, sizeMin: 0.5, sizeMax: 2.2, elongation: 0.2, colors: ["#5d5b57", "#c8c6c0", "#7a7772"], opacity: 0.6, relief: -0.3 },
|
|
2240
|
+
lighting: { depth: 0.5 }
|
|
2241
|
+
}
|
|
2242
|
+
},
|
|
2243
|
+
felt: {
|
|
2244
|
+
preset: "pastel-black",
|
|
2245
|
+
params: { color: { base: "#2c2b2e" }, fibers: { density: 40, length: 10, opacity: 0.35 }, lighting: { depth: 0.5 } }
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
function qe(r, o, i = 0.14) {
|
|
2249
|
+
return {
|
|
2250
|
+
preset: "printer",
|
|
2251
|
+
params: {
|
|
2252
|
+
color: { base: r, tint: o, tintAmount: 0.7, variation: 0.06, grainTone: 0.32 },
|
|
2253
|
+
mottle: { size: 700, warp: 0.6, relief: 0.04 },
|
|
2254
|
+
grain: { size: 2, strength: 0.1 },
|
|
2255
|
+
streaks: { length: 600, width: 2, strength: 1, direction: "horizontal" },
|
|
2256
|
+
structure: { type: "corrugated", spacing: 34, strength: i, sharpness: 0.9, direction: "horizontal", warp: 0.45 },
|
|
2257
|
+
fibers: { density: 0 },
|
|
2258
|
+
specks: { density: 260, sizeMin: 0.4, sizeMax: 1.1, elongation: 5, colors: [o, o, r], opacity: 0.7, relief: -0.25 },
|
|
2259
|
+
lighting: { depth: 0.3 }
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
const Xe = /* @__PURE__ */ new Map();
|
|
2264
|
+
function it(r) {
|
|
2265
|
+
let o = Xe.get(r);
|
|
2266
|
+
if (!o) {
|
|
2267
|
+
const i = Qt[r];
|
|
2268
|
+
o = nt(i.preset, i.params), Xe.set(r, o);
|
|
2269
|
+
}
|
|
2270
|
+
return o;
|
|
2271
|
+
}
|
|
2272
|
+
const Jt = (r) => it(r).color.base, ur = (r) => rt(G(Jt(r))) < 0.45, fr = ["sticky", "index", "notebook", "napkin", "scrap", "graph", "biz", "quote", "tag", "receipt", "ticket", "memo", "watercolor", "clipping", "stamp", "tracing", "tapelabel", "polaroid", "photonote", "print", "vintage", "tear", "album", "booth", "film"], se = (r, o, i) => ({ kind: r, amount: o, scale: i }), he = (r) => ({ top: r, right: r, bottom: r, left: r }), K = se("torn", 5, 18), er = se("deckle", 3, 12), Ye = se("zigzag", 3, 6), A = (r, o, i, t) => ({ x: r, y: o, width: i, height: t }), P = (r, o, i, t, e, a = {}, n = {}) => ({
|
|
2273
|
+
id: r,
|
|
2274
|
+
label: o,
|
|
2275
|
+
stock: i,
|
|
2276
|
+
width: t,
|
|
2277
|
+
height: e,
|
|
2278
|
+
sheet: a,
|
|
2279
|
+
regions: { content: A(16, 16, t - 32, e - 32) },
|
|
2280
|
+
...n
|
|
2281
|
+
}), tr = [
|
|
2282
|
+
P("sticky", "Sticky note", "sticky", 196, 196, { relief: { curl: { amount: 8, radius: 75, corners: ["br"] } }, shadow: { lift: 0.22 } }),
|
|
2283
|
+
P("index", "Index card", "construction-white", 310, 190, { shape: { radius: 1 }, relief: { bend: 2 } }, { ruling: "index", regions: { content: A(22, 41, 266, 137), title: A(18, 4, 274, 30) } }),
|
|
2284
|
+
P("notebook", "Notebook page", "drawing-pad", 255, 335, { shape: { edges: { left: K }, holeRows: [{ x: 13, y: 11, dx: 0, dy: 22, count: 15, r: 4.6, tear: 0.3, rough: 0.5 }] }, relief: { curl: { amount: 4, corners: ["br"] } } }, { ruling: "notebook", regions: { content: A(46, 33, 193, 288) } }),
|
|
2285
|
+
P("napkin", "Napkin", "napkin", 250, 250, { shape: { edges: he(se("deckle", 1.4, 8)), rim: 1.2 }, relief: { folds: { x: 2, y: 2, strength: 1, wear: 0.15 }, crumples: 0.12, wrinkles: 0.08 } }),
|
|
2286
|
+
P("scrap", "Torn scrap", "kraft-light", 190, 145, { shape: { edges: he(K), rim: 2.6 }, relief: { crumples: 0.12, wrinkles: 0.06 } }),
|
|
2287
|
+
P("graph", "Graph paper", "printer", 260, 280, { shape: { edges: { bottom: K } } }, { ruling: "grid" }),
|
|
2288
|
+
P("biz", "Business card", "handmade-ivory", 260, 150, { shape: { radius: 2 }, relief: { bend: 1 } }),
|
|
2289
|
+
P("quote", "Quote card", "handmade-navy", 250, 165, { relief: { bend: 2 }, shadow: { softness: 4.5 } }),
|
|
2290
|
+
P("tag", "Shipping tag", "kraft", 140, 255, { shape: { chamfer: 24, holes: [{ x: 70, y: 28, r: 6 }] }, relief: { bend: 2, bendAngle: 90 }, finish: { edgeWear: 0.4 } }, { regions: { content: A(12, 58, 116, 173) } }),
|
|
2291
|
+
P("receipt", "Receipt", "thermal", 192, 300, { shape: { edges: { top: Ye, bottom: Ye } }, relief: { bend: 6, crumples: 0.1, crumpleSize: 90, wrinkles: 0.05 }, finish: { gloss: 0.06 } }),
|
|
2292
|
+
P("ticket", "Ticket stub", "construction-yellow", 265, 108, { shape: { holes: [{ x: 0, y: 54, r: 9 }, { x: 265, y: 54, r: 9 }], holeRows: [{ x: 191, y: 5, dx: 0, dy: 6.5, count: 16, r: 1.3 }] }, relief: { bend: 2 } }, { regions: { content: A(18, 14, 161, 80), stub: A(199, 14, 50, 80) } }),
|
|
2293
|
+
P("memo", "Typed letter", "sketchbook-cream", 285, 360, { relief: { folds: { y: 3, strength: 1, wear: 0.35 } }, finish: { aging: 0.2 } }, { regions: { content: A(26, 26, 233, 250), signature: A(40, 294, 205, 40) } }),
|
|
2294
|
+
P("watercolor", "Watercolor swatch", "watercolor-cold-press", 220, 250, { shape: { edges: he(er) }, relief: { cockle: 0.4 } }),
|
|
2295
|
+
P("clipping", "Newspaper clipping", "newsprint-old", 235, 295, { shape: { edges: he(se("cut", 2, 40)) }, relief: { folds: { x: 2, strength: 0.6 }, curl: { amount: 3, sides: ["right"] } }, finish: { aging: 0.4, edgeWear: 0.4 } }),
|
|
2296
|
+
P("stamp", "Postage stamp", "printer", 80, 96, { shape: { holeRows: [{ x: 0, y: 0, dx: 8, dy: 0, count: 11, r: 2 }, { x: 0, y: 96, dx: 8, dy: 0, count: 11, r: 2 }, { x: 0, y: 0, dx: 0, dy: 8, count: 13, r: 2 }, { x: 80, y: 0, dx: 0, dy: 8, count: 13, r: 2 }] } }, { regions: { content: A(8, 8, 64, 80) } }),
|
|
2297
|
+
P("tracing", "Tracing paper", "tracing", 250, 280, { finish: { opacity: 0.65 }, relief: { wrinkles: 0.08 } }),
|
|
2298
|
+
P("tapelabel", "Tape label", "masking", 220, 64, { shape: { edges: { left: K, right: K } }, finish: { opacity: 0.94 }, shadow: { softness: 1, offsetY: 1 } }, { regions: { content: A(12, 8, 196, 48) } }),
|
|
2299
|
+
P("polaroid", "Instant photo", "polaroid", 220, 270, { shape: { radius: 2 }, relief: { bend: 2 }, finish: { gloss: 0.12 } }, { regions: { photo: A(14, 14, 192, 192), content: A(14, 214, 192, 42) } }),
|
|
2300
|
+
P("photonote", "Photo note", "sketchbook-cream", 260, 320, { relief: { bend: 2 } }, { regions: { photo: A(18, 18, 224, 180), content: A(18, 214, 224, 88) } }),
|
|
2301
|
+
P("print", "Rounded print", "photo-gloss", 240, 180, { shape: { radius: 11 }, relief: { bend: 2 }, finish: { gloss: 0.45 } }, { regions: { content: A(0, 0, 240, 180) } }),
|
|
2302
|
+
P("vintage", "Vintage print", "photo-matte", 220, 240, { shape: { edges: he(se("wavy", 1.3, 5.5)), rim: 0 }, relief: { cockle: 0.2 }, finish: { aging: 0.4, edgeWear: 0.5, gloss: 0.05 } }, { regions: { photo: A(12, 12, 196, 184), content: A(12, 206, 196, 22) } }),
|
|
2303
|
+
P("tear", "Magazine tear", "photo-gloss", 230, 260, { shape: { edges: { top: K, right: K, bottom: K }, rim: 2.8 }, relief: { cockle: 0.4 }, finish: { gloss: 0.15 } }, { regions: { photo: A(0, 0, 230, 194), content: A(16, 202, 198, 42) } }),
|
|
2304
|
+
P("album", "Album page", "construction-black", 300, 370, { shape: { radius: 1 }, relief: { bend: 2, bendAngle: 90 } }, { regions: { photo1: A(20, 20, 150, 145), photo2: A(20, 200, 150, 145), content: A(182, 20, 98, 145), caption2: A(182, 200, 98, 145) } }),
|
|
2305
|
+
P("booth", "Photo-booth strip", "photo-matte", 100, 310, { shape: { radius: 0.8 }, relief: { bend: 4, bendAngle: 90 }, finish: { gloss: 0.15 } }, { regions: { photo1: A(8, 8, 84, 64), photo2: A(8, 78, 84, 64), photo3: A(8, 148, 84, 64), photo4: A(8, 218, 84, 64), content: A(8, 286, 84, 16) } }),
|
|
2306
|
+
P("film", "Film strip", "film", 348, 112, { shape: { holeRows: [{ x: 7, y: 7, dx: 14, dy: 0, count: 25, r: 2.8 }, { x: 7, y: 105, dx: 14, dy: 0, count: 25, r: 2.8 }] }, relief: { bend: 2 }, finish: { opacity: 0.95, gloss: 0.55 } }, { regions: { photo1: A(10, 21, 104, 70), photo2: A(122, 21, 104, 70), photo3: A(234, 21, 104, 70), content: A(10, 93, 328, 12) } })
|
|
2307
|
+
];
|
|
2308
|
+
function rr(r) {
|
|
2309
|
+
const o = tr.find((i) => i.id === r);
|
|
2310
|
+
if (!o) throw new Error(`procedural-paper: unknown card preset "${r}"`);
|
|
2311
|
+
return structuredClone(o);
|
|
2312
|
+
}
|
|
2313
|
+
function hr(r) {
|
|
2314
|
+
const o = rr(r.preset), i = r.width ?? o.width, t = r.height ?? o.height;
|
|
2315
|
+
if (![i, t].every((s) => Number.isFinite(s) && s > 0)) throw new RangeError("Paper dimensions must be positive finite numbers");
|
|
2316
|
+
const e = i / o.width, a = t / o.height, n = o.sheet.shape;
|
|
2317
|
+
n && (n.chamfer && (n.chamfer *= Math.min(e, a)), n.holes?.forEach((s) => {
|
|
2318
|
+
s.x *= e, s.y *= a;
|
|
2319
|
+
}), n.holeRows?.forEach((s) => {
|
|
2320
|
+
s.x *= e, s.y *= a, s.dx *= e, s.dy *= a;
|
|
2321
|
+
}));
|
|
2322
|
+
const c = Object.fromEntries(Object.entries(o.regions).map(([s, l]) => [s, A(l.x * e, l.y * a, l.width * e, l.height * a)]));
|
|
2323
|
+
return { preset: o, regions: c, params: Be(it(o.stock), r.params, r.seed === void 0 ? void 0 : { seed: r.seed }), sheet: { ...o.sheet, seed: r.seed ?? 1, ...r.sheet, width: i, height: t } };
|
|
2324
|
+
}
|
|
2325
|
+
function nt(r, o, i) {
|
|
2326
|
+
const t = r ? Nt(r).params : de;
|
|
2327
|
+
return Be(t, o, i !== void 0 ? { seed: i } : void 0);
|
|
2328
|
+
}
|
|
2329
|
+
class $e {
|
|
2330
|
+
backend;
|
|
2331
|
+
gl;
|
|
2332
|
+
constructor(o = {}) {
|
|
2333
|
+
const i = o.backend ?? "auto";
|
|
2334
|
+
let t = null;
|
|
2335
|
+
if (i !== "cpu")
|
|
2336
|
+
try {
|
|
2337
|
+
t = new Ut(o.canvas);
|
|
2338
|
+
} catch (e) {
|
|
2339
|
+
if (i === "webgl2") throw e;
|
|
2340
|
+
}
|
|
2341
|
+
this.gl = t, this.backend = t ? "webgl2" : "cpu";
|
|
2342
|
+
}
|
|
2343
|
+
renderResolved(o, i) {
|
|
2344
|
+
return this.gl ? this.gl.render(o, i) : Ct(o, i);
|
|
2345
|
+
}
|
|
2346
|
+
render(o, i, t = i, e = ["color"]) {
|
|
2347
|
+
const a = We(o, i, t), n = this.renderResolved(a, e), c = {};
|
|
2348
|
+
for (const s of e) c[s] = { width: a.width, height: a.height, data: n[s] };
|
|
2349
|
+
return { width: a.width, height: a.height, params: o, backend: this.backend, maps: c };
|
|
2350
|
+
}
|
|
2351
|
+
/** WebGL only: render one map to the GPU and draw it tiled on the renderer's canvas. */
|
|
2352
|
+
preview(o, i, t, e, a) {
|
|
2353
|
+
if (!this.gl) throw new Error("procedural-paper: preview() needs the webgl2 backend");
|
|
2354
|
+
this.gl.renderToTexture(We(o, i, t), e), this.gl.drawPreview(a);
|
|
2355
|
+
}
|
|
2356
|
+
/**
|
|
2357
|
+
* Render a finite sheet of paper with an outline, holes, relief and shadow
|
|
2358
|
+
* (WebGL2 only). `params` describe the paper at 1 CSS px per px; the sheet's
|
|
2359
|
+
* `pixelRatio` scales them up for crisp output.
|
|
2360
|
+
*/
|
|
2361
|
+
renderSheet(o, i, t = ["color"]) {
|
|
2362
|
+
if (!this.gl) throw new Error("procedural-paper: renderSheet() needs the webgl2 backend");
|
|
2363
|
+
const e = Lt(i), a = We(Ot(o, e.pixelRatio), e.width, e.height), n = this.gl.renderSheet(a, e, t), c = e.width + 2 * e.margin, s = e.height + 2 * e.margin, l = {};
|
|
2364
|
+
for (const u of t) l[u] = { width: c, height: s, data: n[u] };
|
|
2365
|
+
return { width: c, height: s, margin: e.margin, pixelRatio: e.pixelRatio, maps: l };
|
|
2366
|
+
}
|
|
2367
|
+
dispose() {
|
|
2368
|
+
this.gl?.dispose();
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
let Se = null;
|
|
2372
|
+
async function dr(r) {
|
|
2373
|
+
const o = nt(r.preset, r.params, r.seed), i = r.backend ?? "auto";
|
|
2374
|
+
let t;
|
|
2375
|
+
return i === "cpu" ? t = new $e({ backend: "cpu" }) : ((!Se || i === "webgl2" && Se.backend !== "webgl2") && (Se = new $e({ backend: i })), t = Se), t.render(o, r.width, r.height ?? r.width, r.outputs ?? ["color"]);
|
|
2376
|
+
}
|
|
2377
|
+
export {
|
|
2378
|
+
Ut as GLPaperRenderer,
|
|
2379
|
+
Oe as MAX_HOLES,
|
|
2380
|
+
Me as MAX_HOLE_ROWS,
|
|
2381
|
+
$e as PaperRenderer,
|
|
2382
|
+
nt as buildParams,
|
|
2383
|
+
fr as cardPresetIds,
|
|
2384
|
+
tr as cardPresets,
|
|
2385
|
+
De as cloneParams,
|
|
2386
|
+
de as defaultParams,
|
|
2387
|
+
ot as encodePNG,
|
|
2388
|
+
dr as generatePaper,
|
|
2389
|
+
rr as getCardPreset,
|
|
2390
|
+
nr as getParam,
|
|
2391
|
+
Nt as getPreset,
|
|
2392
|
+
ur as isDark,
|
|
2393
|
+
rt as luminance,
|
|
2394
|
+
Be as mergeParams,
|
|
2395
|
+
Jt as paperBase,
|
|
2396
|
+
Qt as paperStocks,
|
|
2397
|
+
ir as paramSchema,
|
|
2398
|
+
G as parseColor,
|
|
2399
|
+
It as presetMap,
|
|
2400
|
+
Ht as presets,
|
|
2401
|
+
Ct as renderCPU,
|
|
2402
|
+
hr as resolveCard,
|
|
2403
|
+
We as resolveParams,
|
|
2404
|
+
Lt as resolveSheet,
|
|
2405
|
+
Ot as scaleParams,
|
|
2406
|
+
ar as setParam,
|
|
2407
|
+
it as stockParams,
|
|
2408
|
+
Kt as toBlob,
|
|
2409
|
+
lr as toCSSBackground,
|
|
2410
|
+
cr as toCanvas,
|
|
2411
|
+
sr as toDataURL,
|
|
2412
|
+
zt as toHex,
|
|
2413
|
+
Zt as toImageData
|
|
2414
|
+
};
|
|
2415
|
+
//# sourceMappingURL=index.js.map
|