/ proof-of-concept / steelsim21
Sign in
proof-of-concept / steelsim21
steelsim21 / src / sim / shaders / common.wgsl
57 lines · 2.0 KBCodeBlameHistory
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)
bfde5e4High-frequency ringing: in-plane loss, band-limited listener sum, damping defaultsJeremy Magland 23 fs: f32, // audio sample rate [Hz]
10998acDrumstick strike excitation (Hertz contact with a free mass)Jeremy Magland 24 strikeX: f32, // drumstick contact point [m]
25 strikeY: f32,
26 strikeR2: f32, // squared contact radius [m^2]
27 patchMass: f32, // mass of the contact patch [kg]
28 strikeNode: u32, // node nearest the contact point
29 K: f32, // Hertz contact stiffness [N/m^alpha]
30 alpha: f32, // Hertz exponent
31 stickMass: f32, // [kg]
34// Per-step parameters, addressed with a dynamic uniform offset.
35struct StepParams {
36 step: u32,
10998acDrumstick strike excitation (Hertz contact with a free mass)Jeremy Magland 37 flags: u32, // bit 0: push constraint active; bit 1: record the constraint reaction; bit 2: apply the recorded reaction; bit 3: drumstick active
f8a8a6cNonlinear steel sheet gong simulator with WebGPUJeremy Magland 38 audioSlot: i32, // ring-buffer slot to record acceleration into (-1: none)
39 audioOut: i32, // output sample index within the batch
40 pushW: f32, // prescribed patch displacement [m]
41 pushV: f32, // prescribed patch velocity [m/s]
42 sigma0: f32,
43 sigma1: f32,
adc495dFinite finger release: ramp the recorded reaction force to zero over a release timeJeremy Magland 44 releaseGain: f32, // fraction of the recorded reaction still applied (finger letting go)
bfde5e4High-frequency ringing: in-plane loss, band-limited listener sum, damping defaultsJeremy Magland 45 sigmaIn: f32, // additional frequency-independent loss of the in-plane motion
10998acDrumstick strike excitation (Hertz contact with a free mass)Jeremy Magland 46 parity: u32, // which of the two stick-state slots holds the current state
50fn nodeX(i: i32) -> f32 { return (f32(i) - 0.5 * f32(P.nx - 1u)) * P.hx; }
51fn nodeY(j: i32) -> f32 { return (f32(j) - 0.5 * f32(P.ny - 1u)) * P.hy; }
52fn trapWeight(i: i32, j: i32) -> f32 {
53 var t = 1.0;
54 if (i == 0 || i == i32(P.nx) - 1) { t = t * 0.5; }
55 if (j == 0 || j == i32(P.ny) - 1) { t = t * 0.5; }
56 return t;
↑↓ move↵openescclose