@margoengine/vfx 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 +201 -0
- package/NOTICE +4 -0
- package/README.md +1642 -3
- package/dist/base-C9upJytz.js +658 -0
- package/dist/base.d.ts +767 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +229 -0
- package/dist/clouds.js +566 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +111 -0
- package/dist/debris.js +258 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +539 -0
- package/dist/fire-front.js +840 -0
- package/dist/fire.d.ts +119 -0
- package/dist/fire.js +173 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +260 -0
- package/dist/flame.js +605 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +696 -0
- package/dist/gunfire.js +1204 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +237 -0
- package/dist/lit.d.ts +11 -0
- package/dist/lit.js +105 -0
- package/dist/mesh.d.ts +14 -0
- package/dist/mesh.js +225 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +93 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +20 -0
- package/dist/ribbons.js +151 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +44 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +215 -0
- package/dist/smoke.js +280 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +192 -6
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
import { t as e } from "./view-RKprOPAy.js";
|
|
5
|
+
import { n as t, t as n } from "./view-rect-DkeiiUtw.js";
|
|
6
|
+
import { soft as r, softDepthWgsl as i } from "./soft.js";
|
|
7
|
+
import { t as a } from "./require-webgpu--tUXPsmA.js";
|
|
8
|
+
import { parseColor as o } from "@margoengine/math/color";
|
|
9
|
+
//#region ../shared/unit-light.js
|
|
10
|
+
function s(e, t, n) {
|
|
11
|
+
let r = Math.hypot(n[0], n[1], n[2]);
|
|
12
|
+
e[t] = n[0] / r, e[t + 1] = n[1] / r, e[t + 2] = n[2] / r, e[t + 3] = n[3];
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/blown-sand.ts
|
|
16
|
+
var c = 9.81, l = 1.225, u = .4;
|
|
17
|
+
function d(e = 25e-5, t = 10, n = 1e-4) {
|
|
18
|
+
if (!(e >= 6e-5 && e <= .002)) throw RangeError(`sandThreshold grainSize is ${e}; pass 0.00006 to 0.002 m`);
|
|
19
|
+
if (!(t >= .5 && t <= 100)) throw RangeError(`sandThreshold height is ${t}; pass 0.5 to 100 m`);
|
|
20
|
+
if (!(n > 0 && n < t)) throw RangeError(`sandThreshold roughness is ${n}; pass above 0 and below the height`);
|
|
21
|
+
return .1 * Math.sqrt(2648.775 / l * c * e) / u * Math.log(t / n);
|
|
22
|
+
}
|
|
23
|
+
var f = Object.freeze({
|
|
24
|
+
referenceMass: {
|
|
25
|
+
default: .02,
|
|
26
|
+
unit: "kg/m²",
|
|
27
|
+
about: "moving mass at half-strength opacity with live transport"
|
|
28
|
+
},
|
|
29
|
+
amount: {
|
|
30
|
+
default: 1,
|
|
31
|
+
range: [0, 1],
|
|
32
|
+
about: "density of the blowing sand (0 none)"
|
|
33
|
+
},
|
|
34
|
+
threshold: {
|
|
35
|
+
default: "sandThreshold(grainSize)",
|
|
36
|
+
range: [0, 60],
|
|
37
|
+
unit: "m/s",
|
|
38
|
+
about: "wind speed at windHeight at which sand starts to move"
|
|
39
|
+
},
|
|
40
|
+
grainSize: {
|
|
41
|
+
default: 25e-5,
|
|
42
|
+
range: [6e-5, .002],
|
|
43
|
+
unit: "m",
|
|
44
|
+
about: "grain diameter for the default threshold"
|
|
45
|
+
},
|
|
46
|
+
windHeight: {
|
|
47
|
+
default: 10,
|
|
48
|
+
range: [.5, 100],
|
|
49
|
+
unit: "m",
|
|
50
|
+
about: "height the wind speed is given at"
|
|
51
|
+
},
|
|
52
|
+
color: {
|
|
53
|
+
default: [
|
|
54
|
+
.5,
|
|
55
|
+
.42,
|
|
56
|
+
.29
|
|
57
|
+
],
|
|
58
|
+
about: "grain albedo, linear RGB (terrain dry sand)"
|
|
59
|
+
},
|
|
60
|
+
streak: {
|
|
61
|
+
default: .6,
|
|
62
|
+
range: [.05, 5],
|
|
63
|
+
unit: "m",
|
|
64
|
+
about: "length of a streak of moving sand"
|
|
65
|
+
},
|
|
66
|
+
height: {
|
|
67
|
+
default: .3,
|
|
68
|
+
range: [.02, 3],
|
|
69
|
+
unit: "m",
|
|
70
|
+
about: "height under which most sand moves; crest plumes rise about 4 times it"
|
|
71
|
+
},
|
|
72
|
+
opacity: {
|
|
73
|
+
default: .6,
|
|
74
|
+
range: [0, 1],
|
|
75
|
+
about: "opacity"
|
|
76
|
+
},
|
|
77
|
+
gustiness: {
|
|
78
|
+
default: .35,
|
|
79
|
+
range: [0, 1],
|
|
80
|
+
about: "how far gusts swing the wind (default the wind gust)"
|
|
81
|
+
},
|
|
82
|
+
seed: {
|
|
83
|
+
default: 1,
|
|
84
|
+
about: "the same seed and time draw the same sand"
|
|
85
|
+
},
|
|
86
|
+
limit: {
|
|
87
|
+
default: 32768,
|
|
88
|
+
range: [1, 1048576],
|
|
89
|
+
about: "most particles drawn"
|
|
90
|
+
},
|
|
91
|
+
range: {
|
|
92
|
+
default: 250,
|
|
93
|
+
range: [10, 2e3],
|
|
94
|
+
unit: "m",
|
|
95
|
+
about: "radius around the camera with blowing sand"
|
|
96
|
+
},
|
|
97
|
+
fog: {
|
|
98
|
+
default: 0,
|
|
99
|
+
range: [0, 1],
|
|
100
|
+
unit: "1/m",
|
|
101
|
+
about: "fog density the sand fades by with distance"
|
|
102
|
+
},
|
|
103
|
+
softness: {
|
|
104
|
+
default: 0,
|
|
105
|
+
range: [0, 100],
|
|
106
|
+
unit: "m",
|
|
107
|
+
about: "fade in front of the surface behind (needs depth)"
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
function p(e) {
|
|
111
|
+
let t = Math.imul(e >>> 0, 747796405) + 2891336453 >>> 0, n = Math.imul((t >>> (t >>> 28) + 4 ^ t) >>> 0, 277803737) >>> 0;
|
|
112
|
+
return (n >>> 22 ^ n) >>> 0;
|
|
113
|
+
}
|
|
114
|
+
var m = (e, t) => p((e ^ p(t)) >>> 0) / 4294967296, h = (e, t, n, r) => p((Math.imul(e | 0, 73856093) ^ Math.imul(t | 0, 19349663) ^ Math.imul(n | 0, 83492791) ^ r) >>> 0) / 4294967296 * 2 - 1, g = (e) => e * e * (3 - 2 * e);
|
|
115
|
+
function _(e, t, n, r) {
|
|
116
|
+
let i = Math.floor(e), a = Math.floor(t), o = Math.floor(n), s = g(e - i), c = g(t - a), l = g(n - o), u = (e, t, n) => h(i + e, a + t, o + n, r), d = (e) => (u(0, 0, e) + (u(1, 0, e) - u(0, 0, e)) * s) * (1 - c) + (u(0, 1, e) + (u(1, 1, e) - u(0, 1, e)) * s) * c;
|
|
117
|
+
return d(0) + (d(1) - d(0)) * l;
|
|
118
|
+
}
|
|
119
|
+
var v = (e, t, n) => g(Math.min(1, Math.max(0, (n - e) / (t - e))));
|
|
120
|
+
function y(e) {
|
|
121
|
+
return e > 1 ? 1 - Math.exp(-1.5 * (e * e * e - e) / 6) : 0;
|
|
122
|
+
}
|
|
123
|
+
var b = 2, x = 6, S = 16, C = 8, w = 96;
|
|
124
|
+
function T(e, t, n, r) {
|
|
125
|
+
let i = t * e.dx + n * e.dz - e.speed * r, a = n * e.dx - t * e.dz, o = Math.max(4, .6 * e.speed * e.period);
|
|
126
|
+
return 1 + e.gust * (.7 * _(i / o, a / (o * .5), r / e.period, e.seed) + .3 * _(i / (o * .3), a / (o * .2), 3.1 * r / e.period, e.seed ^ 23505));
|
|
127
|
+
}
|
|
128
|
+
function E(e, t, n) {
|
|
129
|
+
let r = [
|
|
130
|
+
0,
|
|
131
|
+
e[t + 4],
|
|
132
|
+
e[t + 5],
|
|
133
|
+
e[t + 6],
|
|
134
|
+
e[t + 7]
|
|
135
|
+
], i = Math.max(0, n) / b, a = Math.min(3, Math.floor(i));
|
|
136
|
+
return r[a] + (r[a + 1] - r[a]) * (i - a);
|
|
137
|
+
}
|
|
138
|
+
function D(e, t, n, r) {
|
|
139
|
+
if (n.physical) {
|
|
140
|
+
let r = e[t + 14], i = e[t + 15], a = Math.hypot(r, i);
|
|
141
|
+
n = {
|
|
142
|
+
...n,
|
|
143
|
+
dx: r / a,
|
|
144
|
+
dz: i / a,
|
|
145
|
+
speed: a
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
let i = e[t + 9], a = e[t + 10] >>> 0, o = e[t + 11], s = m(a, 1), c = m(a, 2), l = n.physical ? n.speed : (i === 1 ? .6 : i === 2 ? .45 : .5) * n.speed * (.8 + .4 * c), u = Math.min(6, Math.max(.4, x * (.6 + .4 * s) / Math.max(l, .5))), d = n.time / u + e[t + 3], f = Math.floor(d), p = (d - f) * u, h = n.time - p, g = f + 40503 >>> 0, b = m(a ^ g, 3), S = m(a ^ g, 4), C = m(a ^ g, 5), w = b * .8, D = (S - .5) * .8, O = e[t] + n.dx * w - n.dz * D, k = e[t + 2] + n.dz * w + n.dx * D, A = n.physical ? 1 : T(n, O, k, h), j = l * Math.max(A, 0) * p, M = p / u, N = .12 * Math.sin(p * 2.7 + c * 6.283) * Math.min(1, j), P = O + n.dx * j - n.dz * N, F = k + n.dz * j + n.dx * N, I = e[t + 1] + E(e, t, j + w) + (e[t + 12] * -n.dz + e[t + 13] * n.dx) * D, L = n.physical ? e[t + 8] : y(n.ratio * e[t + 8] * A), R, z, B;
|
|
149
|
+
if (i === 1) {
|
|
150
|
+
let r = n.height * (.25 + 3.2 * Math.sqrt(Math.min(j, 8) / 8)) * (.5 + C);
|
|
151
|
+
R = Math.max(e[t + 1] + r, I + n.height * .3), B = [n.streak * (.6 + j / 6) * o, (.08 + .18 * j) * o], z = L * v(0, .12, M) * (1 - v(.45, 1, M)) * .55 / (1 + j / 3);
|
|
152
|
+
} else if (i === 2) {
|
|
153
|
+
let r = n.height * 1.4 * (.7 + .6 * C), i = n.physical ? L : y(n.ratio * e[t + 8] * T(n, P, F, n.time));
|
|
154
|
+
R = I + r * .4, B = [(1.4 + 1.4 * c) * o, r * .6], z = i * v(0, .25, M) * (1 - v(.7, 1, M)) * .22;
|
|
155
|
+
} else {
|
|
156
|
+
let e = n.height * .33 * -Math.log(1 - .95 * C), t = .05 + .2 * s, r = P * n.dx + F * n.dz - .5 * n.speed * n.time, i = F * n.dx - P * n.dz, a = n.physical ? 1 : v(-.15, .45, _(r / 2.5, i / .45, n.time / 1.3, n.seed ^ 11291));
|
|
157
|
+
B = [n.streak * (.35 + .3 * c) * o, t * .5 * o], R = I + Math.max(e * v(0, .15, M), B[1] * .8), z = L * a * v(0, .1, M) * (1 - v(.75, 1, M)) * .5;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
position: [
|
|
161
|
+
P,
|
|
162
|
+
R,
|
|
163
|
+
F
|
|
164
|
+
],
|
|
165
|
+
kind: i,
|
|
166
|
+
size: B,
|
|
167
|
+
alpha: z * r
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function O(e, t, n, r, i, a, o = !1) {
|
|
171
|
+
let s = (t) => e(n + i * t, r + a * t), c = e(n, r), l = (s(1) - s(-1)) / 2, u = 0;
|
|
172
|
+
if (!o) for (let e of [
|
|
173
|
+
3,
|
|
174
|
+
9,
|
|
175
|
+
27
|
|
176
|
+
]) {
|
|
177
|
+
let t = (s(-e + 1) - s(-e - 1)) / 2, n = (s(e + 1) - s(e - 1)) / 2;
|
|
178
|
+
u += Math.log(3) * (t - n) / Math.PI;
|
|
179
|
+
}
|
|
180
|
+
let d = Math.min(3, Math.max(0, 1 + 3 * (u + .3 * l))), f = v(-.36, -.2, l), p = [
|
|
181
|
+
s(2) - c,
|
|
182
|
+
s(4) - c,
|
|
183
|
+
s(6) - c,
|
|
184
|
+
s(8) - c
|
|
185
|
+
], m = (e(n + .5, r) - e(n - .5, r)) / 1, h = (e(n, r + .5) - e(n, r - .5)) / 1, g = t ? Math.min(1, Math.max(0, t(n, r))) : 1;
|
|
186
|
+
return {
|
|
187
|
+
speedUp: o ? g : Math.sqrt(d) * f * g,
|
|
188
|
+
profile: p,
|
|
189
|
+
gradient: [m, h],
|
|
190
|
+
brink: p[3] < -1 && Math.max(...p) < .3 && f > .5,
|
|
191
|
+
height: c
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function k(e) {
|
|
195
|
+
if (typeof e == "function") return e;
|
|
196
|
+
if (!e || typeof e != "object") throw TypeError("BlownSand ground must be a height function (x, z) => y or {samples, width, depth, cellSize, origin}");
|
|
197
|
+
let { samples: t, width: n, depth: r } = e, i = e.cellSize ?? 1, [a, o] = e.origin ?? [0, 0];
|
|
198
|
+
if (!Number.isInteger(n) || !Number.isInteger(r) || n < 2 || r < 2 || t.length !== n * r) throw RangeError("BlownSand ground grid needs width and depth of 2 or more and width * depth samples");
|
|
199
|
+
if (!(i > 0)) throw RangeError("BlownSand ground cellSize must be above 0");
|
|
200
|
+
return (e, s) => {
|
|
201
|
+
let c = Math.min(n - 1, Math.max(0, (e - a) / i)), l = Math.min(r - 1, Math.max(0, (s - o) / i)), u = Math.min(n - 2, Math.floor(c)), d = Math.min(r - 2, Math.floor(l)), f = c - u, p = l - d, m = t[d * n + u], h = t[d * n + u + 1], g = t[(d + 1) * n + u], _ = t[(d + 1) * n + u + 1];
|
|
202
|
+
return (m + (h - m) * f) * (1 - p) + (g + (_ - g) * f) * p;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function A(e, t, n) {
|
|
206
|
+
let r = M(e.wind), i = N(e), a = O(k(e.ground), e.mask ?? null, t, n, Math.sin(r.direction), Math.cos(r.direction));
|
|
207
|
+
return {
|
|
208
|
+
speedUp: a.speedUp,
|
|
209
|
+
flux: y(r.speed / i * a.speedUp),
|
|
210
|
+
brink: a.brink
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
var j = (e, t, n, r, i) => {
|
|
214
|
+
let a = e === void 0 ? t : e;
|
|
215
|
+
if (typeof a != "number" || !Number.isFinite(a) || a < r || a > i) throw RangeError(`BlownSand ${n} is ${String(a)}; pass a finite number from ${r} to ${i}`);
|
|
216
|
+
return a;
|
|
217
|
+
};
|
|
218
|
+
function M(e) {
|
|
219
|
+
let t = e && typeof e == "object" && "options" in e ? e.options : e;
|
|
220
|
+
if (!t || typeof t != "object") throw TypeError("BlownSand wind must be {speed, direction} or a WindField");
|
|
221
|
+
return {
|
|
222
|
+
speed: j(t.speed, NaN, "wind speed", 0, 60),
|
|
223
|
+
direction: j(t.direction, 0, "wind direction", -1e3, 1e3),
|
|
224
|
+
gust: j(t.gust, .35, "wind gust", 0, 1),
|
|
225
|
+
gustPeriod: j(t.gustPeriod, 8, "wind gustPeriod", .5, 600)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function N(e) {
|
|
229
|
+
let t = j(e.grainSize, 25e-5, "grainSize", 6e-5, .002), n = j(e.windHeight, 10, "windHeight", .5, 100);
|
|
230
|
+
return e.threshold === void 0 ? d(t, n) : j(e.threshold, 0, "threshold", 1e-6, 60);
|
|
231
|
+
}
|
|
232
|
+
var P = (e, t, n) => `
|
|
233
|
+
struct Frame {camera:mat4x4f,eye:vec4f,wind:vec4f,gust:vec4f,shape:vec4f,color:vec4f,light:vec4f,radiance:vec4f,ambient:vec4f,extra:vec4f}
|
|
234
|
+
@group(0) @binding(0) var<uniform> frame:Frame;
|
|
235
|
+
${e ? i(e) : ""}${n}
|
|
236
|
+
struct Out {@builtin(position) clip:vec4f,@location(0) uv:vec2f,@location(1) color:vec4f,@location(2) viewDepth:f32,@location(3) kind:f32}
|
|
237
|
+
fn pcg(v:u32)->u32 {let s=v*747796405u+2891336453u;let w=((s>>((s>>28u)+4u))^s)*277803737u;return (w>>22u)^w;}
|
|
238
|
+
fn rnd(a:u32,b:u32)->f32 {return f32(pcg(a^pcg(b)))/4294967296.0;}
|
|
239
|
+
fn lattice(i:i32,j:i32,k:i32,s:u32)->f32 {return f32(pcg((bitcast<u32>(i)*73856093u)^(bitcast<u32>(j)*19349663u)^(bitcast<u32>(k)*83492791u)^s))/4294967296.0*2.0-1.0;}
|
|
240
|
+
fn fade3(t:vec3f)->vec3f {return t*t*(3.0-2.0*t);}
|
|
241
|
+
fn noise(p:vec3f,s:u32)->f32 {
|
|
242
|
+
let c=floor(p);let f=fade3(p-c);let i=vec3i(c);
|
|
243
|
+
let a=mix(mix(lattice(i.x,i.y,i.z,s),lattice(i.x+1,i.y,i.z,s),f.x),mix(lattice(i.x,i.y+1,i.z,s),lattice(i.x+1,i.y+1,i.z,s),f.x),f.y);
|
|
244
|
+
let b=mix(mix(lattice(i.x,i.y,i.z+1,s),lattice(i.x+1,i.y,i.z+1,s),f.x),mix(lattice(i.x,i.y+1,i.z+1,s),lattice(i.x+1,i.y+1,i.z+1,s),f.x),f.y);
|
|
245
|
+
return mix(a,b,f.z);
|
|
246
|
+
}
|
|
247
|
+
fn flux(r:f32)->f32 {return select(0.0,1.0-exp(-1.5*(r*r*r-r)/6.0),r>1.0);}
|
|
248
|
+
fn gustAt(x:f32,z:f32,t:f32)->f32 {
|
|
249
|
+
let d=frame.wind.xy;let along=x*d.x+z*d.y-frame.wind.z*t;let across=z*d.x-x*d.y;let scale=max(4.0,0.6*frame.wind.z*frame.gust.y);let s=u32(frame.gust.w);
|
|
250
|
+
return 1.0+frame.gust.x*(0.7*noise(vec3f(along/scale,across/(scale*0.5),t/frame.gust.y),s)+0.3*noise(vec3f(along/(scale*0.3),across/(scale*0.2),3.1*t/frame.gust.y),s^0x5bd1u));
|
|
251
|
+
}
|
|
252
|
+
fn profileAt(p:vec4f,s:f32)->f32 {
|
|
253
|
+
let u=max(s,0.0)/${b.toFixed(1)};let i=min(3.0,floor(u));let f=u-i;
|
|
254
|
+
let a=select(select(select(p.z,p.y,i<2.5),p.x,i<1.5),0.0,i<0.5);
|
|
255
|
+
let b=select(select(select(p.w,p.z,i<2.5),p.y,i<1.5),p.x,i<0.5);
|
|
256
|
+
return a+(b-a)*f;
|
|
257
|
+
}
|
|
258
|
+
@vertex fn vertex(@builtin(vertex_index) vi:u32,@location(0) a0:vec4f,@location(1) a1:vec4f,@location(2) a2:vec4f,@location(3) a3:vec4f)->Out {
|
|
259
|
+
var o:Out;o.clip=vec4f(2.0,2.0,2.0,1.0);o.uv=vec2f(0.0);o.color=vec4f(0.0);o.viewDepth=0.0;o.kind=a2.y;
|
|
260
|
+
let physical=frame.extra.z>0.0;let localSpeed=length(a3.zw);
|
|
261
|
+
let d=select(frame.wind.xy,a3.zw/max(localSpeed,1e-10),physical);
|
|
262
|
+
let t=frame.eye.w;let kind=a2.y;let id=u32(a2.z);let lod=a2.w;
|
|
263
|
+
let r1=rnd(id,1u);let r2=rnd(id,2u);
|
|
264
|
+
let v0=select(select(select(0.5,0.45,kind==2.0),0.6,kind==1.0)*frame.wind.z*(0.8+0.4*r2),localSpeed,physical);
|
|
265
|
+
let life=min(6.0,max(0.4,${x.toFixed(1)}*(0.6+0.4*r1)/max(v0,0.5)));
|
|
266
|
+
let c=t/life+a0.w;let n=floor(c);let age=(c-n)*life;let born=t-age;
|
|
267
|
+
let cycle=u32(i32(n)+0x9e37);
|
|
268
|
+
let j1=rnd(id^cycle,3u);let j2=rnd(id^cycle,4u);let h1=rnd(id^cycle,5u);
|
|
269
|
+
let jx=j1*0.8;let jz=(j2-0.5)*0.8;
|
|
270
|
+
let bx=a0.x+d.x*jx-d.y*jz;let bz=a0.z+d.y*jx+d.x*jz;
|
|
271
|
+
let g=select(gustAt(bx,bz,born),1.0,physical);let v=v0*max(g,0.0);let s=v*age;let t01=age/life;
|
|
272
|
+
let wander=0.12*sin(age*2.7+r2*6.283)*min(1.0,s);
|
|
273
|
+
let x=bx+d.x*s-d.y*wander;let z=bz+d.y*s+d.x*wander;
|
|
274
|
+
let ground=a0.y+profileAt(a1,s+jx)+(a3.x*-d.y+a3.y*d.x)*jz;
|
|
275
|
+
let fl=select(flux(frame.wind.w*a2.x*g),a2.x,physical);
|
|
276
|
+
let H=frame.shape.y;let streak=frame.shape.x;
|
|
277
|
+
var y:f32;var alpha:f32;var half:vec2f;
|
|
278
|
+
if(kind==1.0){
|
|
279
|
+
let rise=H*(0.25+3.2*sqrt(min(s,8.0)/8.0))*(0.5+h1);
|
|
280
|
+
y=max(a0.y+rise,ground+H*0.3);
|
|
281
|
+
half=vec2f(streak*(0.6+s/6.0)*lod,(0.08+0.18*s)*lod);
|
|
282
|
+
alpha=fl*smoothstep(0.0,0.12,t01)*(1.0-smoothstep(0.45,1.0,t01))*0.55/(1.0+s/3.0);
|
|
283
|
+
}else if(kind==2.0){
|
|
284
|
+
let top=H*1.4*(0.7+0.6*h1);let here=gustAt(x,z,t);
|
|
285
|
+
y=ground+top*0.4;
|
|
286
|
+
half=vec2f((1.4+1.4*r2)*lod,top*0.6);
|
|
287
|
+
alpha=select(flux(frame.wind.w*a2.x*here),fl,physical)*smoothstep(0.0,0.25,t01)*(1.0-smoothstep(0.7,1.0,t01))*0.22;
|
|
288
|
+
}else{
|
|
289
|
+
let hop=-(H*0.33)*log(1.0-0.95*h1);let width=0.05+0.2*r1;
|
|
290
|
+
let along=x*d.x+z*d.y-0.5*frame.wind.z*t;let across=z*d.x-x*d.y;
|
|
291
|
+
let streamer=select(smoothstep(-0.15,0.45,noise(vec3f(along/2.5,across/0.45,t/1.3),u32(frame.gust.w)^0x2c1bu)),1.0,physical);
|
|
292
|
+
half=vec2f(streak*(0.35+0.3*r2)*lod,width*0.5*lod);
|
|
293
|
+
y=ground+max(hop*smoothstep(0.0,0.15,t01),half.y*0.8);
|
|
294
|
+
alpha=fl*streamer*smoothstep(0.0,0.1,t01)*(1.0-smoothstep(0.75,1.0,t01))*0.5;
|
|
295
|
+
}
|
|
296
|
+
alpha*=frame.gust.z;
|
|
297
|
+
let centre=vec3f(x,y,z);let toEye=frame.eye.xyz-centre;let dist=length(toEye);
|
|
298
|
+
alpha*=exp(-frame.extra.y*dist)*(1.0-smoothstep(0.8*frame.extra.x,frame.extra.x,dist));
|
|
299
|
+
if(alpha<=0.0005){return o;}
|
|
300
|
+
|
|
301
|
+
let slope=(profileAt(a1,s+jx+0.5)-profileAt(a1,s+jx-0.5));
|
|
302
|
+
var axis=normalize(vec3f(d.x,select(slope,0.0,kind==1.0),d.y));
|
|
303
|
+
var side=cross(axis,toEye/max(dist,1e-4));
|
|
304
|
+
if(kind==2.0){let r=vec3f(frame.shape.w,0.0,frame.color.w);axis=select(vec3f(1.0,0.0,0.0),normalize(r),length(r)>1e-4);side=vec3f(0.0,1.0,0.0);}
|
|
305
|
+
side=select(vec3f(0.0,1.0,0.0),normalize(side),length(side)>1e-4);
|
|
306
|
+
|
|
307
|
+
let pixels=2.0*half.y*frame.shape.z/max(dist,1e-4);
|
|
308
|
+
if(pixels<1.5){let k=1.5/max(pixels,1e-6);half.y*=k;alpha/=k;}
|
|
309
|
+
let corner=vec2f(f32(vi&1u),f32(vi>>1u))*2.0-1.0;
|
|
310
|
+
let world=centre+axis*corner.x*half.x+side*corner.y*half.y;
|
|
311
|
+
o.clip=frame.camera*vec4f(world,1.0);
|
|
312
|
+
o.uv=corner;
|
|
313
|
+
${e ? "o.viewDepth=dot(soft.plane.xyz,world)+soft.plane.w;" : ""}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
let L=frame.light.xyz;let view=-toEye/max(dist,1e-4);let ct=dot(view,L);
|
|
318
|
+
let hg=(1.0-0.64)/(12.566*pow(1.0+0.64-1.6*ct,1.5));
|
|
319
|
+
let ph=acos(clamp(-ct,-1.0,1.0));let lambert=(2.0/(3.0*9.8696))*(sin(ph)+(3.14159-ph)*cos(ph));
|
|
320
|
+
let beam=frame.radiance.rgb*frame.light.w;
|
|
321
|
+
${n ? "\n\n\n let mean=(skyIrradiance(vec3f(1.0,0.0,0.0))+skyIrradiance(vec3f(-1.0,0.0,0.0))+skyIrradiance(vec3f(0.0,1.0,0.0))+skyIrradiance(vec3f(0.0,-1.0,0.0))+skyIrradiance(vec3f(0.0,0.0,1.0))+skyIrradiance(vec3f(0.0,0.0,-1.0)))/6.0;\n let back=textureSampleLevel(skyLightMap,skyLightSampler,vec2f(atan2(view.z,view.x)/6.2831853+0.5,acos(clamp(view.y,-1.0,1.0))/3.14159265),2.0).rgb*skyLight[9].w;\n let ambient=mean;" : "let ambient=frame.radiance.w*frame.ambient.rgb;let back=ambient;"}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
let gamma=(1.0-frame.color.rgb)/(1.0+frame.color.rgb);let albedo=1.0-gamma*gamma;
|
|
325
|
+
o.color=vec4f(0.5*albedo*(beam*lambert+ambient)+0.5*(beam*hg+back),min(alpha,1.0));
|
|
326
|
+
return o;
|
|
327
|
+
}
|
|
328
|
+
fn encodeSrgb(c:vec3f)->vec3f {return select(1.055*pow(c,vec3f(1.0/2.4))-0.055,c*12.92,c<=vec3f(0.0031308));}
|
|
329
|
+
@fragment fn fragment(i:Out)->@location(0) vec4f {
|
|
330
|
+
let u=i.uv;
|
|
331
|
+
|
|
332
|
+
let streak=pow(max(1.0-u.x*u.x,0.0),1.5)*exp(-4.0*u.y*u.y)*(1.0-smoothstep(0.7,1.0,abs(u.y)));
|
|
333
|
+
let up=u.y*0.5+0.5;
|
|
334
|
+
let haze=pow(max(1.0-u.x*u.x,0.0),2.0)*smoothstep(0.0,0.2,up)*pow(1.0-up,2.0)*1.6;
|
|
335
|
+
var a=i.color.a*select(streak,haze,i.kind==2.0);
|
|
336
|
+
${e ? "a*=clamp(softGap(i.clip,i.viewDepth),0.0,1.0);" : ""}
|
|
337
|
+
var rgb=i.color.rgb;
|
|
338
|
+
${t ? "rgb=encodeSrgb(max(rgb,vec3f(0.0)));" : ""}
|
|
339
|
+
return vec4f(rgb*a,a);
|
|
340
|
+
}
|
|
341
|
+
`, F = 56, I = 0, L = class i {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
342
|
+
constructor(e) {
|
|
343
|
+
this.name = "blown-sand:" + I++, this.stats = {
|
|
344
|
+
tiles: 0,
|
|
345
|
+
particles: 0,
|
|
346
|
+
dropped: 0
|
|
347
|
+
}, this.seconds = 0, this.capacity = 0, this.owned = [], this.pipelines = /* @__PURE__ */ new Map(), this.groups = /* @__PURE__ */ new Map(), this.values = new Float32Array(F), this.view = /* @__PURE__ */ new Float32Array(16), this.data = /* @__PURE__ */ new Float32Array(), this.count = 0, this.uploaded = "", this.layoutKey = "", this.tiles = /* @__PURE__ */ new Map(), this.height = () => 0, this.groundSource = null, this.maskSource = null, this.disposed = !1, this.attachment = {
|
|
348
|
+
view: void 0,
|
|
349
|
+
loadOp: "load",
|
|
350
|
+
storeOp: "store"
|
|
351
|
+
}, this.depthAttachment = {
|
|
352
|
+
view: void 0,
|
|
353
|
+
depthReadOnly: !0
|
|
354
|
+
}, this.options = e, this.validate();
|
|
355
|
+
}
|
|
356
|
+
static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
357
|
+
let n = new i(t);
|
|
358
|
+
return e.use(n), n;
|
|
359
|
+
}
|
|
360
|
+
get time() {
|
|
361
|
+
return this.seconds;
|
|
362
|
+
}
|
|
363
|
+
set time(e) {
|
|
364
|
+
this.seconds = j(e, 0, "time", 0, Number.MAX_VALUE);
|
|
365
|
+
}
|
|
366
|
+
advanceTime(e) {
|
|
367
|
+
e > 0 && (this.seconds += e);
|
|
368
|
+
}
|
|
369
|
+
onPreUpdate(e) {
|
|
370
|
+
this.advanceTime(e);
|
|
371
|
+
}
|
|
372
|
+
resetTime() {
|
|
373
|
+
this.seconds = 0;
|
|
374
|
+
}
|
|
375
|
+
validate() {
|
|
376
|
+
let e = this.options;
|
|
377
|
+
if (!e || typeof e != "object") throw TypeError("BlownSand needs options {ground, wind}");
|
|
378
|
+
if (k(e.ground), e.mask != null && typeof e.mask != "function") throw TypeError("BlownSand mask must be a function (x, z) => 0..1 or null");
|
|
379
|
+
if (e.sky != null && (typeof e.sky.pbr != "function" || typeof e.sky.bindings != "function")) throw TypeError("BlownSand sky must have pbr(group) and bindings(), as a Sky from @margoengine/sky does");
|
|
380
|
+
let t = e.transport;
|
|
381
|
+
if (t && typeof t.sample != "function") throw TypeError("BlownSand transport needs a sampler; pass an attached AeolianTransport or provide sample(x, z).");
|
|
382
|
+
let n = M(e.wind ?? (t ? { speed: 0 } : void 0)), r = N(e), i = j(e.softness, 0, "softness", 0, 100);
|
|
383
|
+
if (i > 0 && typeof e.depth != "function") throw TypeError("BlownSand softness needs the scene depth; pass depth: () => depthTexture.texture (DepthTexture from @margoengine/post/depth)");
|
|
384
|
+
let a = j(e.limit, 32768, "limit", 1, 1 << 20);
|
|
385
|
+
if (!Number.isInteger(a)) throw RangeError(`BlownSand limit is ${a}; pass a whole number`);
|
|
386
|
+
return {
|
|
387
|
+
wind: n,
|
|
388
|
+
transport: t,
|
|
389
|
+
referenceMass: j(e.referenceMass, .02, "referenceMass", Number.MIN_VALUE, Number.MAX_VALUE),
|
|
390
|
+
threshold: r,
|
|
391
|
+
softness: i,
|
|
392
|
+
limit: a,
|
|
393
|
+
amount: j(e.amount, 1, "amount", 0, 1),
|
|
394
|
+
streak: j(e.streak, .6, "streak", .05, 5),
|
|
395
|
+
height: j(e.height, .3, "height", .02, 3),
|
|
396
|
+
opacity: j(e.opacity, .6, "opacity", 0, 1),
|
|
397
|
+
gustiness: j(e.gustiness, n.gust, "gustiness", 0, 1),
|
|
398
|
+
seed: j(e.seed, 1, "seed", -2147483648, 4294967295),
|
|
399
|
+
range: j(e.range, 250, "range", 10, 2e3),
|
|
400
|
+
fog: j(e.fog, 0, "fog", 0, 1),
|
|
401
|
+
color: o(e.color ?? [
|
|
402
|
+
.5,
|
|
403
|
+
.42,
|
|
404
|
+
.29
|
|
405
|
+
])
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
frameValues(e) {
|
|
409
|
+
return {
|
|
410
|
+
time: this.seconds,
|
|
411
|
+
dx: Math.sin(e.wind.direction),
|
|
412
|
+
dz: Math.cos(e.wind.direction),
|
|
413
|
+
speed: e.wind.speed,
|
|
414
|
+
ratio: e.wind.speed / e.threshold,
|
|
415
|
+
gust: e.gustiness,
|
|
416
|
+
period: e.wind.gustPeriod,
|
|
417
|
+
seed: e.seed >>> 0 & 16777215,
|
|
418
|
+
height: e.height,
|
|
419
|
+
streak: e.streak,
|
|
420
|
+
physical: !!e.transport
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
tile(e, t, n, r, i) {
|
|
424
|
+
let a = `${e},${t},${n}`, o = this.tiles.get(a);
|
|
425
|
+
if (o) return o;
|
|
426
|
+
let s = Math.round(w * r.amount), c = Math.max(+!!s, Math.ceil(s / 2 ** n)), l = Math.min(8, Math.sqrt(s / Math.max(c, 1))), u = new Float32Array(c * S), d = p((p(Math.imul(e, 668265261) ^ Math.imul(t, 374761393) ^ 20973) ^ i.seed) >>> 0), f = 0;
|
|
427
|
+
for (let n = 0; n < c; n++) {
|
|
428
|
+
let a = p((d ^ Math.imul(n + 1, 2654435761)) >>> 0) & 16777215, o = (e + m(a, 11)) * C, s = (t + m(a, 12)) * C, c = r.transport?.sample(o, s), [h, g] = c?.velocity ?? [0, 0], _ = Math.hypot(h, g);
|
|
429
|
+
if (r.transport && !(c && c.mass > 0 && _ >= 1e-10 && Number.isFinite(_))) continue;
|
|
430
|
+
let v = this.options.mask ?? null, y = O(this.height, v, o, s, c ? h / _ : i.dx, c ? g / _ : i.dz, i.physical), b = c ? y.speedUp / (1 + r.referenceMass / c.mass) : y.speedUp;
|
|
431
|
+
if (!(b > 0)) continue;
|
|
432
|
+
let x = n % 24 == 0 ? 2 : y.brink && m(a, 13) < .7 ? 1 : 0;
|
|
433
|
+
u.set([
|
|
434
|
+
o,
|
|
435
|
+
y.height,
|
|
436
|
+
s,
|
|
437
|
+
m(a, 14),
|
|
438
|
+
...y.profile,
|
|
439
|
+
b,
|
|
440
|
+
x,
|
|
441
|
+
a,
|
|
442
|
+
l,
|
|
443
|
+
...y.gradient,
|
|
444
|
+
h,
|
|
445
|
+
g
|
|
446
|
+
], f++ * S);
|
|
447
|
+
}
|
|
448
|
+
let h = {
|
|
449
|
+
data: u,
|
|
450
|
+
count: f
|
|
451
|
+
};
|
|
452
|
+
return this.tiles.size > 2e4 && this.tiles.clear(), this.tiles.set(a, h), h;
|
|
453
|
+
}
|
|
454
|
+
collect(e, t, n, r) {
|
|
455
|
+
let i = this.options, a = [
|
|
456
|
+
n.seed,
|
|
457
|
+
n.amount,
|
|
458
|
+
r.dx.toFixed(4),
|
|
459
|
+
r.dz.toFixed(4),
|
|
460
|
+
n.transport?.revision,
|
|
461
|
+
n.referenceMass
|
|
462
|
+
].join("|");
|
|
463
|
+
(a !== this.layoutKey || i.ground !== this.groundSource || (i.mask ?? null) !== this.maskSource || n.transport !== this.transportSource) && (this.tiles.clear(), this.uploaded = ""), this.layoutKey = a, this.groundSource = i.ground, this.maskSource = i.mask ?? null, this.transportSource = n.transport;
|
|
464
|
+
let o = n.range, s = Math.floor(e[0] / C), c = Math.floor(e[2] / C), l = Math.ceil(o / C) + 1, u = [], d = n.transport?.bounds;
|
|
465
|
+
for (let n = c - l; n <= c + l; n++) for (let r = s - l; r <= s + l; r++) {
|
|
466
|
+
if (d && ((r + 1) * C < d[0] || (n + 1) * C < d[1] || r * C > d[2] || n * C > d[3])) continue;
|
|
467
|
+
let i = (r + .5) * C, a = (n + .5) * C, s = Math.hypot(i - e[0], a - e[2]);
|
|
468
|
+
if (s > o + C) continue;
|
|
469
|
+
let c = this.height(i, a);
|
|
470
|
+
if (t) {
|
|
471
|
+
let e = [
|
|
472
|
+
r * C,
|
|
473
|
+
c - 6,
|
|
474
|
+
n * C
|
|
475
|
+
], i = [
|
|
476
|
+
(r + 1) * C,
|
|
477
|
+
c + 8,
|
|
478
|
+
(n + 1) * C
|
|
479
|
+
];
|
|
480
|
+
if (t.some((t) => t[0] * (t[0] > 0 ? i[0] : e[0]) + t[1] * (t[1] > 0 ? i[1] : e[1]) + t[2] * (t[2] > 0 ? i[2] : e[2]) + t[3] < 0)) continue;
|
|
481
|
+
}
|
|
482
|
+
let l = Math.hypot(s, c - e[1]), f = Math.max(0, Math.min(10, Math.round(2 * Math.log2(Math.max(l, 1) / 30))));
|
|
483
|
+
u.push({
|
|
484
|
+
tx: r,
|
|
485
|
+
tz: n,
|
|
486
|
+
distance: l,
|
|
487
|
+
level: f
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
u.sort((e, t) => e.distance - t.distance || e.tz - t.tz || e.tx - t.tx);
|
|
491
|
+
let f = [], p = [], m = 0, h = 0;
|
|
492
|
+
for (let e of u) {
|
|
493
|
+
let t = this.tile(e.tx, e.tz, e.level, n, r);
|
|
494
|
+
m + t.count > n.limit ? h += t.count : (m += t.count, f.push(t), p.push(`${e.tx},${e.tz},${e.level}`));
|
|
495
|
+
}
|
|
496
|
+
this.stats.tiles = f.length, this.stats.particles = m, this.stats.dropped = h, this.data.length < m * S && (this.data = new Float32Array(Math.max(m, 1024) * S));
|
|
497
|
+
let g = 0;
|
|
498
|
+
for (let e = f.length - 1; e >= 0; e--) this.data.set(f[e].data.subarray(0, f[e].count * S), g), g += f[e].count * S;
|
|
499
|
+
return this.count = m, a + ":" + p.join(";");
|
|
500
|
+
}
|
|
501
|
+
grains(e) {
|
|
502
|
+
let t = this.validate();
|
|
503
|
+
this.height = k(this.options.ground);
|
|
504
|
+
let n = this.frameValues(t);
|
|
505
|
+
this.collect(e, null, t, n);
|
|
506
|
+
let r = [];
|
|
507
|
+
for (let e = 0; e < this.count; e++) r.push(D(this.data, e * S, n, t.opacity));
|
|
508
|
+
return r;
|
|
509
|
+
}
|
|
510
|
+
setup(e) {
|
|
511
|
+
a(e, "BlownSand"), this.engine = e;
|
|
512
|
+
}
|
|
513
|
+
registerPasses(e) {
|
|
514
|
+
e.add({
|
|
515
|
+
name: this.name + ":draw",
|
|
516
|
+
order: 6,
|
|
517
|
+
execute: (e) => {
|
|
518
|
+
e.backend === "webgpu" && this.draw(e);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
draw(i) {
|
|
523
|
+
if (this.disposed) return;
|
|
524
|
+
let a = this.validate();
|
|
525
|
+
this.height = k(this.options.ground);
|
|
526
|
+
let o = this.frameValues(a), c = i.camera.matrix, l = [];
|
|
527
|
+
for (let [e, t] of [
|
|
528
|
+
[1, 0],
|
|
529
|
+
[-1, 0],
|
|
530
|
+
[1, 1],
|
|
531
|
+
[-1, 1],
|
|
532
|
+
[-1, 2]
|
|
533
|
+
]) {
|
|
534
|
+
let n = [
|
|
535
|
+
0,
|
|
536
|
+
1,
|
|
537
|
+
2,
|
|
538
|
+
3
|
|
539
|
+
].map((n) => c[n * 4 + 3] + e * c[n * 4 + t]), r = Math.hypot(n[0], n[1], n[2]);
|
|
540
|
+
r > 0 && l.push(n.map((e) => e / r));
|
|
541
|
+
}
|
|
542
|
+
let u = this.collect(i.camera.position, l, a, o), d = this.count;
|
|
543
|
+
if (!d || !(a.amount > 0)) return;
|
|
544
|
+
let f = i.device;
|
|
545
|
+
(!this.instances || this.capacity < d) && (this.instances?.destroy(), this.capacity = Math.max(d, Math.min(a.limit, 4096)), this.instances = f.createBuffer({
|
|
546
|
+
size: this.capacity * S * 4,
|
|
547
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
548
|
+
}), this.uploaded = ""), u !== this.uploaded && (f.queue.writeBuffer(this.instances, 0, this.data, 0, d * S), this.uploaded = u);
|
|
549
|
+
let p = e(this.view, i.camera), m = this.values, h = this.engine?.lighting, g = (t(i)?.[3] ?? i.height) * Math.hypot(c[1], c[5], c[9]) / 2;
|
|
550
|
+
m.set(c), m.set([
|
|
551
|
+
i.camera.position[0],
|
|
552
|
+
i.camera.position[1],
|
|
553
|
+
i.camera.position[2],
|
|
554
|
+
o.time
|
|
555
|
+
], 16), m.set([
|
|
556
|
+
o.dx,
|
|
557
|
+
o.dz,
|
|
558
|
+
o.speed,
|
|
559
|
+
o.ratio
|
|
560
|
+
], 20), m.set([
|
|
561
|
+
o.gust,
|
|
562
|
+
o.period,
|
|
563
|
+
a.opacity,
|
|
564
|
+
o.seed
|
|
565
|
+
], 24), m.set([
|
|
566
|
+
o.streak,
|
|
567
|
+
o.height,
|
|
568
|
+
g,
|
|
569
|
+
p[0]
|
|
570
|
+
], 28), m.set([
|
|
571
|
+
a.color[0],
|
|
572
|
+
a.color[1],
|
|
573
|
+
a.color[2],
|
|
574
|
+
p[8]
|
|
575
|
+
], 32), h ? (s(m, 36, h.direction), m.set(h.radiance, 40), m.set([
|
|
576
|
+
h.ambient[0],
|
|
577
|
+
h.ambient[1],
|
|
578
|
+
h.ambient[2],
|
|
579
|
+
0
|
|
580
|
+
], 44)) : (m.set([
|
|
581
|
+
3,
|
|
582
|
+
5,
|
|
583
|
+
4,
|
|
584
|
+
3
|
|
585
|
+
], 36), m.set([
|
|
586
|
+
1,
|
|
587
|
+
1,
|
|
588
|
+
1,
|
|
589
|
+
.15
|
|
590
|
+
], 40), m.set([
|
|
591
|
+
1,
|
|
592
|
+
1,
|
|
593
|
+
1,
|
|
594
|
+
0
|
|
595
|
+
], 44)), m.set([
|
|
596
|
+
a.range,
|
|
597
|
+
a.fog,
|
|
598
|
+
+!!o.physical,
|
|
599
|
+
0
|
|
600
|
+
], 48), this.uniform ??= f.createBuffer({
|
|
601
|
+
size: 224,
|
|
602
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
603
|
+
}), f.queue.writeBuffer(this.uniform, 0, m);
|
|
604
|
+
let _ = !i.format.includes("float") && !i.format.endsWith("-srgb"), v = 0;
|
|
605
|
+
a.softness > 0 && (this.softRuntime ??= r.create(f, this.owned), v = this.softRuntime.write(i, this.options.depth(), p, a.softness), this.softRuntime.changed && this.groups.clear());
|
|
606
|
+
let y = i.descriptor.multisample?.count ?? 1, b = i.descriptor.depthStencil.format, x = this.options.sky?.pbr(1), C = x ? this.options.sky.bindings() : [], w = [
|
|
607
|
+
i.format,
|
|
608
|
+
b,
|
|
609
|
+
y,
|
|
610
|
+
v,
|
|
611
|
+
_,
|
|
612
|
+
x?.declarations ?? ""
|
|
613
|
+
].join(":"), T = this.pipelines.get(w);
|
|
614
|
+
if (!T) {
|
|
615
|
+
let e = f.createShaderModule({ code: P(v, _, x?.declarations ?? "") });
|
|
616
|
+
T = f.createRenderPipeline({
|
|
617
|
+
layout: "auto",
|
|
618
|
+
vertex: {
|
|
619
|
+
module: e,
|
|
620
|
+
entryPoint: "vertex",
|
|
621
|
+
buffers: [{
|
|
622
|
+
arrayStride: 64,
|
|
623
|
+
stepMode: "instance",
|
|
624
|
+
attributes: [
|
|
625
|
+
0,
|
|
626
|
+
1,
|
|
627
|
+
2,
|
|
628
|
+
3
|
|
629
|
+
].map((e) => ({
|
|
630
|
+
shaderLocation: e,
|
|
631
|
+
offset: e * 16,
|
|
632
|
+
format: "float32x4"
|
|
633
|
+
}))
|
|
634
|
+
}]
|
|
635
|
+
},
|
|
636
|
+
fragment: {
|
|
637
|
+
module: e,
|
|
638
|
+
entryPoint: "fragment",
|
|
639
|
+
targets: [{
|
|
640
|
+
format: i.format,
|
|
641
|
+
blend: {
|
|
642
|
+
color: {
|
|
643
|
+
srcFactor: "one",
|
|
644
|
+
dstFactor: "one-minus-src-alpha"
|
|
645
|
+
},
|
|
646
|
+
alpha: {
|
|
647
|
+
srcFactor: "one",
|
|
648
|
+
dstFactor: "one-minus-src-alpha"
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}]
|
|
652
|
+
},
|
|
653
|
+
primitive: { topology: "triangle-strip" },
|
|
654
|
+
multisample: i.descriptor.multisample,
|
|
655
|
+
depthStencil: {
|
|
656
|
+
format: b,
|
|
657
|
+
depthWriteEnabled: !1,
|
|
658
|
+
depthCompare: "greater-equal"
|
|
659
|
+
}
|
|
660
|
+
}), this.pipelines.set(w, T);
|
|
661
|
+
}
|
|
662
|
+
let E = this.groups.get(T);
|
|
663
|
+
E || (E = f.createBindGroup({
|
|
664
|
+
layout: T.getBindGroupLayout(0),
|
|
665
|
+
entries: [{
|
|
666
|
+
binding: 0,
|
|
667
|
+
resource: { buffer: this.uniform }
|
|
668
|
+
}, ...v ? this.softRuntime.entries : []]
|
|
669
|
+
}), this.groups.set(T, E));
|
|
670
|
+
let D;
|
|
671
|
+
x && ((this.skyEntries !== C || this.skyPipeline !== T) && (this.skyEntries = C, this.skyPipeline = T, this.skyGroup = f.createBindGroup({
|
|
672
|
+
layout: T.getBindGroupLayout(1),
|
|
673
|
+
entries: C
|
|
674
|
+
})), D = this.skyGroup), this.attachment.view = i.color, this.depthAttachment.view = i.depth, this.depthAttachment.stencilReadOnly = b.includes("stencil") ? !0 : void 0;
|
|
675
|
+
let O = i.encoder.beginRenderPass({
|
|
676
|
+
colorAttachments: [this.attachment],
|
|
677
|
+
depthStencilAttachment: this.depthAttachment
|
|
678
|
+
});
|
|
679
|
+
n(O, i), O.setPipeline(T), O.setBindGroup(0, E), D && O.setBindGroup(1, D), O.setVertexBuffer(0, this.instances), O.draw(4, d), O.end(), this.engine && this.engine.stats.drawCalls++;
|
|
680
|
+
}
|
|
681
|
+
release() {
|
|
682
|
+
for (let e of [
|
|
683
|
+
this.instances,
|
|
684
|
+
this.uniform,
|
|
685
|
+
...this.owned
|
|
686
|
+
]) e?.destroy();
|
|
687
|
+
this.instances = this.uniform = this.softRuntime = void 0, this.capacity = 0, this.uploaded = "", this.owned = [], this.pipelines.clear(), this.groups.clear(), this.skyEntries = this.skyPipeline = this.skyGroup = void 0;
|
|
688
|
+
}
|
|
689
|
+
onDeviceRestored(e) {
|
|
690
|
+
this.release(), this.setup(e);
|
|
691
|
+
}
|
|
692
|
+
dispose() {
|
|
693
|
+
this.disposed || (this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.release(), this.tiles.clear(), this.engine = void 0);
|
|
694
|
+
}
|
|
695
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
696
|
+
this.dispose();
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
//#endregion
|
|
700
|
+
export { f as BLOWN_SAND_SETTINGS, L as BlownSand, A as sandEmission, y as sandFlux, d as sandThreshold };
|