1// Shared declarations, prepended to every kernel of the full simulation.
3struct Params {
4 nx: u32,
5 ny: u32,
6 n: u32,
7 histLen: u32,
8 hx: f32,
9 hy: f32,
10 dt: f32,
11 nu: f32,
12 Db: f32, // E / (12 (1 - nu^2)): bending stiffness per h^3 [Pa]
13 Cm: f32, // E / (1 - nu^2): membrane stiffness per h [Pa]
14 Gm: f32, // E / (2 (1 + nu)): membrane shear stiffness per h [Pa]
15 rho: f32, // density [kg/m^3]
16 mass: f32, // total mass [kg]
17 Ix: f32, // sum m y^2
18 Iy: f32, // sum m x^2
19 fs: f32, // audio sample rate [Hz]
20 strikeX: f32, // drumstick contact point [m]
21 strikeY: f32,
22 strikeR2: f32, // squared contact radius [m^2]
23 patchMass: f32, // mass of the contact patch [kg]
24 strikeNode: u32, // plate node nearest the contact point
25 K: f32, // Hertz contact stiffness [N/m^alpha]
26 alpha: f32, // Hertz exponent
27 stickMass: f32, // [kg]
28 patchI0: u32, // index box enclosing the contact patch (inclusive)
29 patchI1: u32,
30 patchJ0: u32,
31 patchJ1: u32,
32 patchCX: f32, // mass-weighted center of the contact patch [m]
33 patchCY: f32,
34 pad0: u32,
35 pad1: u32,
36 pad2: u32,
37 pad3: u32,
38 pad4: u32,
39 pad5: u32,
40 pad6: u32,
41 pad7: u32,
42 pad8: u32,
43 pad9: u32,
44};
46// Per-step parameters, addressed with a dynamic uniform offset.
47struct StepParams {
48 step: u32,
49 flags: u32, // bit 0: drumstick active
50 audioSlot: i32, // ring-buffer slot to record the velocity into (-1: none)
51 audioOut: i32, // index of this sample within the batch's output
52 sigma0: f32,
53 sigma1: f32,
54 sigmaIn: f32, // additional frequency-independent loss of the in-plane motion
55 parity: u32, // which of the two stick-state slots holds the current state
56 pad0: u32,
57 pad1: u32,
58 pad2: u32,
59 pad3: u32,
60};
62fn nodeX(i: i32) -> f32 { return (f32(i) - 0.5 * f32(P.nx - 1u)) * P.hx; }
63fn nodeY(j: i32) -> f32 { return (f32(j) - 0.5 * f32(P.ny - 1u)) * P.hy; }
65// Static per-node data, written once by the host: x = stress-free shape w0 [m],
66// y = quadrature and lumped-mass weight (the fraction of the node's four cells
67// that belong to the plate; zero outside), z = thickness [m], w unused.
68@group(0) @binding(8) var<storage, read> nd: array<vec4f>;
69fn nodeWeight(i: i32, j: i32) -> f32 {
70 if (i < 0 || i >= i32(P.nx) || j < 0 || j >= i32(P.ny)) { return 0.0; }
71 return nd[u32(j) * P.nx + u32(i)].y;
72}
73// Lumped mass of a node [kg].
74fn nodeMass(i: i32, j: i32) -> f32 {
75 if (i < 0 || i >= i32(P.nx) || j < 0 || j >= i32(P.ny)) { return 0.0; }
76 let k = u32(j) * P.nx + u32(i);
77 return P.rho * nd[k].z * P.hx * P.hy * nd[k].y;
78}