top | item 41897933

(no title)

jasmcole | 1 year 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.

discuss

order

zorgmonkey|1 year ago

Annoyingly WebGL2 doesn't have compute shaders even though GLES3.x that it is based on does.

pjmlp|1 year ago

Thank Google for that, as they dropped Intel contribution to WebGL Compute, with the reasoning WebGPU would be good enough.

soheil|1 year ago

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);

vardump|1 year ago

That's no solver, it just displays a sine wave pattern.

dankwizard|1 year ago

Did ChatGPT write that for you because it has missed the mark by 500 metres.