12 ms·
2D Liquid Simulator with Cellular Automaton (2017)
- trungdq88 4y agoI learned and implemented this in JS a while ago. It was a lot of fun! https://github.com/trungdq88/summer https://github.com/trungdq88/summer
- genpfault 4y agoSee also Tom Forsyth's "Cellular Automata for Physical Modelling" from 2006[1]: [1]: https://tomforsyth1000.github.io/papers/cellular_automata_for_physical_modelling.html https://tomforsyth1000.github.io/papers/cellular_automata_fo...
- csense 4y agoOxygen Not Included is a video game with some pretty good liquid and gas simulations along these lines.
- s1mplicissimus 4y agoi read the article and had exactly the same thought! especially the part where the falling cells are being rendered as full cells made me go "waaait a minute, this would look slightly weird in exactly the same way that ONI water does when it falls". Does anyone maybe with ONI modding experience insights on wether that's really how the game implemented liquids? The release date certainly wasn't too far off. Great writeup and a fun exercise to implement by oneself as a learning project.
- 6502nerdface 4y agoMy favorite 2D liquid simulator is this IOCCC2012 submission [1]... simply astonishing. That is the source file shown at the beginning of the video... it compiles without warnings, runs a full blown fluid dynamics sim with surface tension and everything, can take itself as its own input... truly a work of art. [1] https://youtu.be/QMYfkOtYYlg https://youtu.be/QMYfkOtYYlg
- dekhn 4y agohttps://www.ioccc.org/2012/endoh1/hint.html https://www.ioccc.org/2012/endoh1/hint.html for those who want a direct link.
- lukko 4y agoOh, that is cool! I love that the code itself can be used in the sim - reminds me a bit of 'quines' from GEB: http://www.madore.org/~david/computers/quine.html http://www.madore.org/~david/computers/quine.html
- jrootabega 4y agoPerhaps there is material for a game sequel titled 'Baba is Goo'
- diceduckmonk 4y agoIt's got to be this one for me: https://madebyevan.com/webgl-water/ https://madebyevan.com/webgl-water/
- lukko 4y agoThat one is brilliant - I just realised you can change the light direction. Another classic: http://david.li/fluid/ http://david.li/fluid/
- notmysql_ 4y agothis is probably the best form of user interaction with simulated fluid I have seen
- deleted 4y ago[deleted]
- floodle 4y agoThis one looks like a shallow water simulation, rather than a fluid simulation in the sense of handling pressure etc. Rendering is gorgeous though!
- convolvatron 4y agoif you want waves..check out huygens principle. you'll need alot more cells though.
- evrimoztamur 4y agoThis is quite close to Terraria's implementation, earlier versions having the same falling water rendering 'glitch.' It does not implement pressurised water flowing upward on the other hand.
- 9dev 4y agoThis has always annoyed me about Terraria a bit; it would have been so much cooler to have properly flowing water, with air pockets and all.
- diceduckmonk 4y agoSimple Hooke's Law for Springs worked pretty well [1], even when I generalized to 3D. There much less nodes you have to iterate over to achieve a water effect. https://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236 https://gamedevelopment.tutsplus.com/tutorials/make-a-splash...
- deleted 4y ago[deleted]
- choubli 4y agoLove this one, I've ported it to Godot Engine a while ago for fun : https://www.youtube.com/watch?v=nF7cdUVgvNc https://www.youtube.com/watch?v=nF7cdUVgvNc https://github.com/tterrasson/liquid-simulator-godot/ https://github.com/tterrasson/liquid-simulator-godot/
- deleted 4y ago[deleted]
- waynecochran 4y agoVery cool. I wonder if this, in some sense, is a numerical solution to the various differential equations that govern fluid flow (e.g. Navier–Stokes).
- kqr 4y agoKey phrase: "in some sense". I mean clearly, yes, it looks fluid-ish to a layman, so in some sense it does simulate a fluid. But as soon as you dive into a tiny bit of detail, no, this violates those equations at basically every iteration.
- alar44 4y agoNot at all. Maybe if your fluid was magnetic Legos.
- animaomnium 4y agoFor a more physically-accurate fluid sinulation using Cellular Automata, see Reintegration Tracking: https://michaelmoroz.github.io/Reintegration-Tracking/ https://michaelmoroz.github.io/Reintegration-Tracking/
- SeanAnderson 4y agoThis is great, thanks for sharing. I'm planning on using this, or something similar, in a game I'm developing. It'll be waves of fog, but act like a fluid, and will encroach on simulated ants :) I'm curious why the simulator never reaches a complete, steady state? It seems to settle mostly and then a few squares flicker rapidly. Is this just floating point math doing its thing, or ?
- ricardobeat 4y agoWhy are 'pressurized' cells needed, vs having water not flow downwards when the cell undermeath is full? Does this help to add a slosh effect?
- zmgsabst 4y agoA falling stream generates outward flow without piling up. Watch your faucet run into a partially full sink: there’s a small depression where the stream impacts it — while the pressurized region under the stream pushes the water out and away. This is in contrast to honey, which will form a mound when a stream hits, because of its higher viscosity.
- explaininjs 4y agoConsider a J-shaped tube, open on both ends. After you add some water to the taller end, the bottom loop fills up. When you add more water, what happens? The water flows downwards even though the cell underneath is full.
- ricardobeat 4y agoThat makes sense. The counterintuitive part for me was a cell causing the one underneath to become pressurized and then flowing back up. You don’t usually think of water as compressible.
- antegamisou 4y agoAlso check out wavelet-based water wave simulation for a very close approach to the real thing, by a pioneer in the field of physics simulation in Computer Graphics, Matthias Muller-Fischer: https://www.youtube.com/watch?v=6I6BV0-BVxI https://www.youtube.com/watch?v=6I6BV0-BVxI https://github.com/lecopivo/WaterSurfaceWavelets/ https://github.com/lecopivo/WaterSurfaceWavelets/
- ulrischa 4y agoSame idea: General framework for observer based cellular automata simulation. Invented years ago as a geospatial research. https://github.com/ulrischa/OCell https://github.com/ulrischa/OCell
- F-W-M 4y agoThis must be how dwarf fortress does it
- tehsauce 4y agoShamelessly sharing some research I worked on a few years ago- Using ML to learn cellular automata which simulate a given system (uses neural cellular automata). Code: https://github.com/PWhiddy/Growing-Neural-Cellular-Automata-Pytorch https://github.com/PWhiddy/Growing-Neural-Cellular-Automata-... Demo: https://transdimensional.xyz/projects/neural_ca/index.html https://transdimensional.xyz/projects/neural_ca/index.html
- theGnuMe 4y agoThis is neat. Can you explain neural cellular automata? I’m familiar with neural networks and cellular automata. I’ve been interested in DNNs to analyze CAs but is this the other way around?
- tantalor 4y agoDoesn't model air pressure, so no siphon :(
- taylorius 4y agoThis seems to be a version of a lattice gas fluid model. (Or, more precisely, lattice-boltzmann, since it allows for fractional values of fluid occupancy per cell.) I had a Santa Fe institute monograph on this back in the day, and I seem to recall that they ended up using a hexagonal grid, in order to achieve the required isotropy of fluid behaviour. Might be something to consider.
- lukko 4y agoQuick video of a viscoelastic fluid sim I made that runs on iPad GPU - https://vimeo.com/779004024 https://vimeo.com/779004024. You can get really interesting mixing behaviour by varying the density of the particles - https://en.wikipedia.org/wiki/Rayleigh–Taylor_instability https://en.wikipedia.org/wiki/Rayleigh–Taylor_instability
- can16358p 4y agoThe Vimeo link seems broken though.
- pohl 4y agoReminds me of how liquids behave in Starbound.
- bartwe 4y agoHa, yup, I enjoyed adding that to the game :) It was inspired by the system dwarf fortress used at the time extended with pressure to allow equalizing vessels.
- swayvil 4y agoSpeaking as a cellular automation enthusiast, this is hot. First questions on my mind : Can it do surface tension? Pressure?
- bodhiandphysics 4y agoYes actually... i'm using a similar model right now to model bubbles dynamics (though my model is somewhat more complicated, and oh yes... it's in 3d)
- elietoubi 4y agoremind me of a old cellular automaton I built to picture covid propagation: https://www.coronasimulator.com/ https://www.coronasimulator.com/
- deleted 4y ago[deleted]
- KRAKRISMOTT 4y agoDoes this use the Lattice-Boltzmann method?
- bodhiandphysics 4y agoNo... lattice-boltzmann discritizes the navier stokes equations. This is just a cellular automaton. It uses a small number of rules in order to determine the change of every cell. You can of course conceptualize an eulerian solver of navier stokes as a cellular automata... but this system simply uses a very small set of simple rules to get something that looks right.
- deleted 4y ago[deleted]
- tomxor 4y agoIf you limit the cell states to to 0 and 1 it behaves much like sand. Shameless plug, in 194 bytes: https://www.dwitter.net/d/19550 https://www.dwitter.net/d/19550
- isoprophlex 4y agoSeeing this wonderful simulation makes me wonder if a physics simulation using cellular automata could benefit from a HashLife-esque algo to speed up calculations. For GoL, the speedups are just insane. The linked wiki shows a simulation: The 6,366,548,773,467,669,985,195,496,000 (6 octillionth) generation of a Turing machine in Life computed in less than 30 seconds on an Intel Core Duo 2GHz CPU using Hashlife But then of course, Game of Life has loads of 'boring' repeating stuff and is much more discrete compared to physical fluid dynamics simulation. https://en.m.wikipedia.org/wiki/Hashlife https://en.m.wikipedia.org/wiki/Hashlife
- renox 4y agoI'm not an expert on this topic but: GoL cells have only a very limited number of states whereas realistic simulations have a big numbers of possible states for each cells so I doubt it's possible.
- taneq 4y agoCalling it a specific insanely high generation when it’s a repeating cycle just rubs me up the wrong way. Very cool algorithm though!
- addaon 4y agoIt's a turing machine -- it potentially never halts / repeats. Hashlife isn't just about exponential time-stepping, though that's a major part of it -- it's also about isolating periodic portions of the grid for memoization and speed-up, without requiring that the entire grid be periodic. All said, it really is a specific insanely high generation here.
- taneq 4y agoIt's deterministic, though, so once it detects a repeated global state it will cycle endlessly so you're not calculating generation N, you're calculating generation firstOccurrence+N*cycleLength for all N. At least, this line from the wiki reads to me like this is what's happening: > Computed by detecting a repeating cycle in the pattern, and skipping ahead to any requested generation.
- madamelic 4y agoEveryone in this thread is much smarter than me. If you are an idiot like me: make a 3x3 block, delete the middle, hold down the "spawn water" button for as long as you like while the mouse is on the empty block then remove the top block to create an explosion of water.
- 3vidence 4y ago+1 That was fun to try, keep your hacking mindset :D
- 6451937099 4y ago[dead]
- 6451937099 4y ago[dead]
- Bobaso 4y agoIt reminds me of the way Minecraft simulates flowing water
- luismedel 4y agoCool. Check the 1994 demo "Heartquake" from the spanish demogroup Iguana for an earlier realtime water simulation https://youtu.be/LLsRBbFOa3k?t=350 https://youtu.be/LLsRBbFOa3k?t=350
- amelius 4y agoWould these rules allow an object (boat) to float on the liquid?
- HyperSane 4y agoNoita is a computer game that takes this concept and runs with it. Every pixel of the world is simulated and destructible. Flammable materials will start on fire and be consumed. Your primary weapon are magic wands and hundreds of spells and you use the spells to make little programs that run every time the wand is fired.
- hypertele-Xii 4y agoThere was a selection of Finnish "cave flying" games decades ago with those features, that Noita is an extension of.
- 29athrowaway 4y agoIt does not seem to simulate pressure very well. If you create a closed container with zigzagging tubes, you would expect water to go fast through the tubes but it won't.
- sinuhe69 4y agoCool. Does anyone know a simulation (free accessible) simulation for air current? I want to see air currents in different building designs but have not found an accessible simulation yet.
- lapama 4y agoI am a CA researcher and I often ask myself a hard question: where is the boundary between CA and just spatially explicit optimisation?
- theGnuMe 4y agoWhat’s your answer?
- lapama 4y agoA blurred line, I was thinking after asking. When the function has outputs that connect with space with visible logic, more CA; when not, more just optimisation. But this thus limits CA with art... not a good answer. What would be yours?
- theGnuMe 4y agoI don’t know. I just find it fascinating that there are two ways of looking at a problem but CAs strike me as simple computational units that can evolve in time, genetically cross each other to gain new function and demonstrate emergent behavior.
- tomaskafka 4y agoThis seems very similar to what Minecraft does, at least in behavior (not sure about the implementation).