←back to thread

WebGPU-Based WiFi Simulator

(wifi-solver.com)
325 points jasmcole | 10 comments | | HN request time: 0.002s | source | bottom
Show context
noahbp ◴[] No.41897720[source]
It's so frustrating that WebGPU support was released 1.5 years ago on Chrome, and yet is still unavailable on all other browsers.

This is a real killer feature that will dramatically slow adoption of non-Chromium browsers, even with Google defanging ad blockers.

replies(9): >>41897739 #>>41897797 #>>41897800 #>>41897830 #>>41897856 #>>41897860 #>>41897886 #>>41897974 #>>41898014 #
1. soheil ◴[] No.41897886[source]
Why do you need webgpu? It's unfortunate that people use technology that is "state-of-the-art techniques to run simulations at interactive speeds" without fully understanding what it's for. General compute on GPU is what webgpu is for.. To simulate basic waves like in this demo you absolutely do not need that, in fact it's an indication the author implemented the solution in a non-optimal way. WebGL is fully supported by all browsers fully supported by well-maintained libs like 3js, yet here we are people writing a sin function with basic interference patterns, one of the most elementary 3D primitives, in webgpu and argue that's using the "state-of-the-art" techniques.
replies(1): >>41897933 #
2. jasmcole ◴[] No.41897933[source]
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.

replies(2): >>41898010 #>>41898082 #
3. zorgmonkey ◴[] No.41898010[source]
Annoyingly WebGL2 doesn't have compute shaders even though GLES3.x that it is based on does.
replies(2): >>41898026 #>>41898296 #
4. ◴[] No.41898026{3}[source]
5. soheil ◴[] No.41898082[source]
I 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);
replies(2): >>41898209 #>>41899281 #
6. vardump ◴[] No.41898209{3}[source]
That's no solver, it just displays a sine wave pattern.
7. pjmlp ◴[] No.41898296{3}[source]
Thank Google for that, as they dropped Intel contribution to WebGL Compute, with the reasoning WebGPU would be good enough.
8. dankwizard ◴[] No.41899281{3}[source]
Did ChatGPT write that for you because it has missed the mark by 500 metres.
replies(1): >>41900112 #
9. soheil ◴[] No.41900112{4}[source]
It's a sin + cos function.. you need an AI for that?
replies(1): >>41901098 #
10. _flux ◴[] No.41901098{5}[source]
The 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..