GithubHelp home page GithubHelp logo

kishimisu / webgpu-fluid-simulation Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 5.0 31.08 MB

Implementation of Jos Stam's Real-Time Fluid Dynamics for Games paper using javascript as a playground for learning the WebGPU API.

HTML 2.68% JavaScript 97.32%

webgpu-fluid-simulation's Introduction

WebGPU Fluid Simulation

This is my attempt at implementing Jos Stam's Real-Time Fluid Dynamics for Games paper using javascript as a playground for learning the WebGPU API.

Demo

Live Demo

As WebGPU is still in development, it is not yet available in release builds of recent navigators. In order for this demo to run properly, you will have to enable WebGPU experimental features in your browser. I'll update this readme once it will be officially supported.

The simplest solution that worked for me was to download Google Chrome Canary, then navigate to chrome://flags and enable Unsafe WebGPU & WebGPU Developer Features (for better security, don't navigate the web with these features on). Other methods can be found here.

Once you have WebGPU enabled, you can start playing with the live demo !

Context

I've already tried to create a fluid simulation a few years ago using plain javascript and no GPU, but quickly came to the limitations of intense CPU computing on the web.

It's also been some time now since I've wanted to learn WebGPU and I thought it would be the perfect opportunity to tackle back on implementing fluid simulation using the power of this new API optimized for parallel computing and graphic rendering.

For this simulation, I'm making use of compute shaders to do the calculations instead of fragment shaders that can be found in usual OpenGL/WebGL implementations.

Project Structure

  • index.html : web page containing the demo
  • src/main.js : simulation setup & render loop
  • src/init.js : initialization functions (webgpu context, render size & gui)
  • src/utils.js : utility wrappers to handle WebGPU buffers, uniforms and programs
  • src/render.js : program used to render on the canvas
  • src/shaders.js : WGSL strings containing each program's compute shader code
  • libraries/ : contains the CCapture.js library for canvas recording and the dat.gui.js library for GUI elements

Symmetry Demo

References

Fluid Simulation References

WebGPU References

webgpu-fluid-simulation's People

Contributors

kishimisu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

webgpu-fluid-simulation's Issues

error: grid is not defined

tried to change 'rdx' or 'dyeRdx' parameter from GUI, but got the following error message:


init.js:136 Uncaught ReferenceError: grid is not defined
at t.__onChange (init.js:136:9)
at t.value (dat.gui.min.js:13:16995)
at t.value (dat.gui.min.js:13:23215)
at t.setValue (dat.gui.min.js:13:9877)
at HTMLInputElement. (dat.gui.min.js:13:24016)
at HTMLInputElement. (dat.gui.min.js:13:24270)

the code snippet at init.js 136 is:

grid.update(device.queue, [settings.grid_w, settings.grid_h, settings.dye_w, settings.dye_h, settings.dx, settings.rdx, settings.dyeRdx])

it seems that the grid instance needs to be recreated when changing rdx or dyeRdx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.