r/howdidtheycodeit • u/pyahmeowpyah • Jul 28 '23
How did they code the fluid mechanics?
https://www.yuichiroharai.com/experiments/fluid/ . I want to implement something very similar to the fluid mechanics in this website for a digital art installation.
Basically this:
- a camera capturing a live scene
- compute opticalflow on it
- use the output of the opticalflow to generate similar effects to the one in the website
- apply those effects to art displayed on a large smd screen as close to real time as possible.
I was thinking of doing all this in opencv but im looking at this website and seems like it could be done in p5.js or three.js as well which i think would be simpler. I would love if someone could give me some pointers in the right direction of how i should go about implementing this
sorry if this is the wrong community to ask this
17
Upvotes
7
u/metal_mastery Jul 28 '23
Look for fluid simulations on shadertoy. The only way to do it in realtime is a shader
6
u/nulldiver Jul 28 '23
I can’t load the link in my phone, but most of the time when you see these fluid simulations, they are implementing Jos Stam’s solver first published in 2003: http://graphics.cs.cmu.edu/nsp/course/15-464/Fall09/papers/StamFluidforGames.pdf There are other approaches but I think that one is popular because it is pretty fast, pretty simple, and “good enough” for visual effects.
I’d treat this as two problems first - a gpu fluid solver and the optical flow from camera and then join the two using the flow vectors as an input to the solver.
4
u/LiverLipsMcGrowll Jul 29 '23 edited Aug 06 '24
scale advise merciful terrific cooing dam fuel scarce encourage yam
This post was mass deleted and anonymized with Redact
2
u/DrunkMc Jul 29 '23
https://youtu.be/alhpH6ECFvQ
Coding train did a video on fluid simulations. He does it fairly low res, but taking this code and putting it on a GPU will allow for much higher res.