to make liquidfun-wasm, I repurposed my existing box2d-wasm and pointed it at a different release of Box2D — a commit obtained by rebasing liquidfun over 7 years of upstream Box2D changes. the end result is that liquidfun is now distributed in WebAssembly and with TypeScript typings for the first time. The TypeScript typings are generated from WebIDL bindings via my webidl-to-ts compiler.
this demo in particular aims to bring to the Web the shaders from the liquidfun EyeCandy demo, and show how fast JS can run if you avoid incurring the garbage collector (the main loop tries not to allocate objects). the demo repurposes gravity and drag calculations that I'd used previously in my Lunar Survey experiment (a Mario Galaxy homage).
in fact, you've caught that it was using as many as 16 iterations (my intention was 3), so this change should make it substantially more performant and less stiff.
moreover, I found that some objects were being allocated by my perf-measurement code. ironically making it slower. fixed now.
if it needs to simulate large stretches of time: I now split that into multiple 1/60th-second world.Step() calls, instead of attempting to scale up the time and number of iterations.
as a result of these changes: Wave Machine now looks a bit more like the original liquidfun.js demo. Gravity looks a bit more stable now (doesn't bounce when the scheduler throttles us).
I've also added a safeguard to help underpowered devices. if we determine that we're not simulating fast enough to finish in a timely manner: we settle for simulating just 1/60th of a second (i.e. even if 1/20th of a second elapsed since we were last scheduled). this admittedly results in slow-mo, but is preferable to exacerbating the perf problem (and has a chance of getting us back-on-track).
their loop  is pretty simple; it's scheduled by `requestAnimationFrame`, advances time by 1/60th of a second, and runs their default of 3 particle iterations. it completes the physics simulation within 3.9–5.5ms, which is easily in time for the 16ms deadline. the rendering is WebGL, which I assume fits easily into that 16ms budget too.
my loop  is more complicated; I don't hardcode the timestep to 1/60 seconds, because requestAnimationFrame may be scheduled less frequently than that. so instead I advance time by the time elasped since I was last scheduled. hm, I think there's a mistake there — `lastMs = nowMs` is probably on the wrong side of the physics calculation.
there's an additional technique I use: I put a `Math.min()` over the simulation interval, so that I don't attempt to simulate more than 20ms (this can happen if you get scheduled infrequently due to hot CPU or backgrounding the app) — simulating too much time will make us fail our frame deadline anyway.
furthermore, if we are calculating more than 1/60th of a second, I employ more particle iterations (i.e. 3 particle iterations for every 1/60th of a second that passes). this gave me good results, but turns out it is based on incorrect assumptions (iterations are unrelated to timestep). moreover, I may be making mistakes in my decision of whether to round this fraction up/down.
if too few particle iterations for a timestep: the particles will bounce. if too many: the particles will look too incompressible. I think that's the "solid-like" structure you're describing.
the main reason I complicated this is because the last one I did made me feel motion-sick. I think if "every 1/60th, or 1/30th, or 1/20th of a second: you simulate a 1/60th of a second of time": the result (if you're not scheduled consistently) is that the world speed keeps changing. I think liquidfun.js's approach should be vulnerable to this, but for some reason it looks fine to me. maybe they get scheduled more consistently than me (even though by my measurements, my physics runs slightly faster, so should be able to achieve similar results).
I think I need to remind myself of what happens if I program the timestep in the simple way that liquidfun.js did. will try that out at some point.
liquidfun-wasm is a fork with additional algorithms for performantly simulating particles. I have not yet built a benchmark to measure the particle code, but do intend to. I am optimistic that liquidfun's particle code could auto-vectorize better than the general Box2D code.
the Google engineers considered how to take advantage of SIMD, to the extent that they even ship a NEON SIMD algorithm. I don't believe my compiler config will use that NEON algorithm (and will instead fallback to the general algorithm ). that's probably not a missed opportunity; many NEON features are not supported. but since the engineers were thinking about SIMD, hopefully the non-NEON algorithm will try to make good use of the CPU and memory layout too, and auto-vectorize well.
We built another open source example app called Voltair based on LiquidFun:
VoltAir was the game where we wanted to showcase a few new technologies: how to build a game using tech other than Unity (which still dominates mobile game dev), first party Android TV and controller support examples, and of course LiquidFun which also powered LiquidFun paint.
The longer term business vision was what you now know as Stadia which evolved from Chromecast and Android TV experiments like these.
Thanks for sharing and creating this.
Is the implementation of it related to real-world mechanisms, or is it all smoke-and-mirrors that happens to look like real-world liquids? (Or, is the distinction non-important?!)
Interesting. A kind of universal "Turing test" :)
Very nice! How does this relate to the Google official release of Liquidfun, and the mainline release of Box2D?
liquidfun-wasm  is my effort to rebase the liquidfun contributions onto latest Box2D, v2.4.1 (October 2020), and to distribute it in WebAssembly with TypeScript typings.
this work is detailed in liquidfun-wasm's first release notes. 
I've also enabled WASM SIMD acceleration (via LLVM's autovectorizer) on supported devices. Haven't yet measured what performance difference this makes.
the main assets of the library are:
- Box2D.simd.js (422kB)
- Box2D.simd.wasm (266 kB)
a minimal demo that uses the library can be created in just a few kB:
you can compare the performance of this demo's Wave Machine mode against the one used on the liquidfun.js frontpage: in my crude measurement just now, a `Step()` took liquidfun.js 3.9–5.52ms, whereas it took 3.6–3.7ms in liquidfun-wasm. take with a pinch of salt since I just sampled a few random frames of each experiment at random CPU temperatures.