by jasmcole · 2y ago · 0 comments
You absolutely could do this using WebGL2 compute shaders too, but I thought it would be fun to try this newer API.
Here is a very basic shader for what you want:
float freq1 = 2.0;
float freq2 = 3.0;
float amp = 0.5;
pos.z += sin(pos.x * freq1 + uTime) * amp;
pos.z += cos(pos.y * freq2 + uTime) * amp;
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0); let newEz = Ez0[me] + calcEzDiff(vec2u(id.x, id.y), dx, dy, aspect);
let newEzAbove = Ez0[above] + calcEzDiff(vec2u(id.x, id.y + 1), dx, dy, aspect);
let newEzRight = Ez0[right] + calcEzDiff(vec2u(id.x + 1, id.y), dx, dy, aspect);
Hx1[me] = Hx0[me] - (uniforms.dt/mu0)*(newEzAbove - newEz) / dy;
Hy1[me] = Hy0[me] + (uniforms.dt/mu0)*(newEzRight - newEz) / dx;
Ez1[me] = newEz;
let localDelta = delta[me];
let fac = 1 + uniforms.omega * uniforms.dt * (delta[me] / eps[me] / 2);
Ez1[me] = Ez1[me] / fac;
Hx1[me] = Hx1[me] / fac;
Hy1[me] = Hy1[me] / fac;
and then a bunch of other GPU code. You can find this with little effort from the bundle, if you care, by base64-decoding the Pt("xxx") parts.Though I do imagine it indeed could be implementable with WebGL shaders, but I also wouldn't start a new compute-based on it, unless I had a particular need to support older systems. And this I say as a Firefox user..