top | item 37781982

(no title)

infixed | 2 years ago

This topic is about fluid simulation, but it also references shaders as a way to performantly implement fluid simulation.

I've played around with shaders in the past to build particle simulations with millions of points, and it's always really tickled my mind. You basically write functions that operate against a big 2d grid of colors. But because colors are represented by a 4x1 vector [r,g,b,a], you can repurpose this pattern to do general purpose computation (e.g. you can represent a point in a 3D coordinate space as a [r,g,b] color).

You can see this in the codepen in this post. It's literally creating "materials" and "render targets" that are actually just intermediate computation steps in the fluid simulation.

  class Fluid {
      constructor(context) {
          this.context = context;
          this.speed = 4;
          this.forceInitMaterial = this.createShaderMaterial(forceInitFrag);
          this.divergenceMaterial = this.createShaderMaterial(divergenceFrag);
          ...
          this.divergence = this.createRenderTarget();
          this.advection = this.createRenderTarget();
          ...

discuss

order

KeplerBoy|2 years ago

that's pretty much how CUDA was born 15 years ago. Crazy how a few guys playing with shaders to simulate clouds led to the AI craze we have today.

Look up Mark Harris PhD thesis "Real-Time Cloud Simulation and Rendering" for more details.

bl0b|2 years ago

I'm sure the origins of CUDA are very interesting in their own right, and it cannot be denied that the evolution of the GPU and GPU programming has had a huge impact on the growth of the field.. but, without the specific work of these specific people, at worst I think we'd only be a tiny bit behind where we are now.

The AI craze we have today is built on the continuous, sustained work of a huge amount of people over years and years.