6 ms·
Good question! This is actually a numerical solver for a few coupled partial differential equations - the method in this context (electromagnetism) is called F
by jasmcole 2y ago
Good question! This is actually a numerical solver for a few coupled partial differential equations - the method in this context (electromagnetism) is called FDTD. It's implemented as a WebGPU compute shader.
You absolutely could do this using WebGL2 compute shaders too, but I thought it would be fun to try this newer API.
- zorgmonkey 2y agoAnnoyingly WebGL2 doesn't have compute shaders even though GLES3.x that it is based on does.
- deleted 2y ago[deleted]
- pjmlp 2y agoThank Google for that, as they dropped Intel contribution to WebGL Compute, with the reasoning WebGPU would be good enough.
- soheil 2y agoI don't understand what other type of solution is there to render on a gpu other than a numeric one? 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);
- vardump 2y agoThat's no solver, it just displays a sine wave pattern.
- dankwizard 2y agoDid ChatGPT write that for you because it has missed the mark by 500 metres.
- soheil 2y agoIt's a sin + cos function.. you need an AI for that?
- _flux 2y agoThe point was that the implementation of this tool is not a sin+cos function. It's more like 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..