f8a8a6cNonlinear steel sheet gong simulator with WebGPUJeremy Magland 1// Shared declarations, prepended to every kernel.
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 D: f32, // bending stiffness [N m]
13 C: f32, // E h / (1 - nu^2) [N/m]
14 G: f32, // E h / (2 (1 + nu)) [N/m]
15 rhoh: f32, // mass per unit area [kg/m^2]
16 pushX: f32, // center of the pushed patch [m]
17 pushY: f32,
18 pushR2: f32, // squared patch radius [m^2]
19 mass: f32, // total mass [kg]
20 Ix: f32, // sum m y^2
21 Iy: f32, // sum m x^2
22 Iz: f32, // sum m (x^2 + y^2)
23 pad0: f32,
24};
26// Per-step parameters, addressed with a dynamic uniform offset.
27struct StepParams {
28 step: u32,
adc495dFinite finger release: ramp the recorded reaction force to zero over a release timeJeremy Magland 29 flags: u32, // bit 0: push constraint active; bit 1: record the constraint reaction; bit 2: apply the recorded reaction
f8a8a6cNonlinear steel sheet gong simulator with WebGPUJeremy Magland 30 audioSlot: i32, // ring-buffer slot to record acceleration into (-1: none)
31 audioOut: i32, // output sample index within the batch
32 pushW: f32, // prescribed patch displacement [m]
33 pushV: f32, // prescribed patch velocity [m/s]
34 sigma0: f32,
35 sigma1: f32,
adc495dFinite finger release: ramp the recorded reaction force to zero over a release timeJeremy Magland 36 releaseGain: f32, // fraction of the recorded reaction still applied (finger letting go)
37 pad0: f32,
38 pad1: f32,
39 pad2: f32,
42fn nodeX(i: i32) -> f32 { return (f32(i) - 0.5 * f32(P.nx - 1u)) * P.hx; }
43fn nodeY(j: i32) -> f32 { return (f32(j) - 0.5 * f32(P.ny - 1u)) * P.hy; }
44fn trapWeight(i: i32, j: i32) -> f32 {
45 var t = 1.0;
46 if (i == 0 || i == i32(P.nx) - 1) { t = t * 0.5; }
47 if (j == 0 || j == i32(P.ny) - 1) { t = t * 0.5; }
48 return t;
49}