16 ms·
Simulating fluids, fire, and smoke in real-time
- andybak 3y agoI think I'm probably smart enough to follow this, but maths notation is so opaque that I get stuck the moment the greek letters come out.
- burjui 3y agoYoy may want to check out Sean Carroll's book "The Biggest Ideas in the Universe" vol. 1. He explains a bit of calculus, how to read and understand equations etc. Basically, this book contains a crash course in physics-related math smeared out across a few chapters. Perfect for noobs like us.
- jamestweb 3y agoLooks amazing!
- kragen 3y agoit blows my mind that cfd is a thing we can do in real time on a pc
- s-macke 3y agoYes, we can since a long time. They were already a thing 14 years ago on the PS3 in the game "Pixeljunk shooter" [0]. But real time simulations often use massive simplifications. They aim to look real, not to match exact solutions of the Navier-Stokes equations. [0] https://www.youtube.com/watch?v=qQkvlxLV6sI https://www.youtube.com/watch?v=qQkvlxLV6sI
- mcphage 3y agoHeck, the Wii had Fluidity around the same time period (2010), and that's a lot weaker than the PS3. Fluidity was pretty neat—you played as a volume of water, changing states as you moved through a level that looked like a classic science textbook:https://youtu.be/j7IooyXp3Pc?si=E79rCrq2mdyZSKoF&t=120 https://youtu.be/j7IooyXp3Pc?si=E79rCrq2mdyZSKoF&t=120
- s-macke 3y agoWell, technically yes. Both use the same technique: Smoothed Particle Hydrodynamics. But the PS3 was able to fill the whole screen with these particles. Hundreds of them. The game Fluidity seems to have approx. 20.
- mcphage 3y ago> The game Fluidity seems to have approx. 20. It had more than 20, but... not by much.
- kragen 3y agothanks, i had no idea about pixeljunk shooter! it looks like those fluids are 2-d tho. otoh it's apparently performing a multiphysics simulation including thermodynamics btw, almost unrelatedly, you have no idea how much i appreciate your exegesis of the voxelspace algorithm
- mhh__ 3y agoI remember reading about finite element tire models and how complicated they were, they can now run in real time give or take a bit.
- cherryteastain 3y agoAs a person who did a PhD in CFD, I must admit I never encountered the vorticity confinement method and curl-noise turbulence. I guess you learn something new every day! Also, in industrial CFD, where the Reynolds numbers are higher you'd never want something like counteracting artificial dissipation of the numerical method by trying to applying noise. In fact, quite often people want artificial dissipation to stabilize high Re simulations! Guess the requirements in computer graphics are more inclined towards making something that looks right instead of getting the physics right.
- ChuckMcM 3y ago> ... the requirements in computer graphics are more inclined towards making something that looks right instead of getting the physics right. That is exactly correct. That said, as something of a physics nerd (it was a big part of the EE curriculum in school) people often chuckled at me in the arcade pointing out things which were violating various principles of physics :-). And one of the fun things was listening to a translated interview with the physicist who worked on Mario World at Nintendo who stressed that while the physics of Mario's world were not the same as "real" physics, they were consistent and had rules just like real physics did, and how that was important for players to understand what they could and could not do in the game (and how they might solve a puzzle in the game).
- hyperthesis 3y agoYes, consistency. Similar in scifi/fantasy, where an absurd conceit is believable if internally consistent, i.e. self-consistent. (I also call it principled) Too much ad hoc prevents suspension of disbelief. Reactions are an important part of this, it's not just how good an actor is, but how other character react to them. If they are ignored, it's like that character doesn't exist, has no effect, is inconsequential, doesn't matter... is not real. In a fluid simulation, when water does not react to the shoreline, rocks in the water, columns supporting a pier etc, it is like the water (or the obstacles) don't exist. In this sense, the water (or the obstacles) "aren't real". For example, the water in Sea of Thieves looks magnificent... but because it doesn't interact (it's procedural), it doesn't feel real. It isn't real. A further problem here with water is that it's difficult to make a continuous fluid that is consistent and isn't realistic, because the basic principles of fluid are so very very simple: conservation of mass, conservation of momentum. [ Of course, you can still vary density, gravity. There are other effects beyond these: viscosity, surface tension. Also, compressible fluids, different reynolds numbers, adiabatic effects, behaviour at non-everyday temperatures, pressures, scales, velocities, accelerations etc. ] There are also simplifications, like depth-averaging (Shallow Water Equations aka St Venant), but again, it's hard to vary it and yet remain self-consistent. Cellular methods - similar to conway's game of life but for fluid - maybe are an exception, because thet are self-consistent - but pretty far from "water", because not lack momentum (and aren't continuous). The final issue is error: simulations are never perfectly self-consistent anyway, because they must discretize the continuous, which introduces error. In engineering, you can reduce this error with a finer grid, until it too small to matter for your specific application. For computer graphics, it only needs to be perceivably" self-consistent - and perhaps pixel size is one measure of this, for the appearance* of consistency, in area/volume, acceleration, velocity, displacement (...though, we can perceive sub-pixel displacement, e.g. an aliased line.)
- JaggerJo 3y agodoes not work on ios for me.
- bee_rider 3y agoIt works fine on iOS/safari for me, in the sense that the text is all readable, but the simulations don’t seem to all execute. Which… given that other folks are reporting that the site is slowed to a crawl, I guess because it is running the simulations, I’ll take the iOS experience.
- askonomm 3y agoInteresting. I have 64GB of RAM and yet this page managed to kill the tab entirely.
- deleted 3y ago[deleted]
- Fervicus 3y agoWeird. I only have 16GB but seems to run fine for me?
- ghawkescs 3y agoFWIW, works great and animates smoothly on a Surface Laptop 4 with 16 GB RAM (Firefox).
- xboxnolifes 3y agoDo you have hardware acceleration disabled in your browser?
- askonomm 3y agoI checked and I have it enabled. But, I don't have a dedicated GPU, just whatever is inside of i7-14700k. Maybe it's just not up for the task?
- xboxnolifes 3y agoThat may be it. The page runs a fire simulation, so it really struggles when my hardware acceleration is off.
- CaptainOfCoit 3y agoEmberGen is absolutely crazy software that does simulation of fire and smoke in real-time on consumer GPUs, and supports a node-based workflow which makes it so easy to create new effects. Seriously, my workflow probably went from spending hours on making something that now takes minutes to get right. https://jangafx.com/software/embergen/ https://jangafx.com/software/embergen/ I was sure that this submission would be about EmberGen and I'm gonna be honest, I'm a bit sad EmberGen never really got traction on HN (https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=%22embergen%22%20comments%3E0&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...) (Not affiliated with EmberGen/JangaFX, just a happy customer)
- PKop 3y agoWritten in Odin https://odin-lang.org/showcase/embergen/ https://odin-lang.org/showcase/embergen/
- imiric 3y agoOdin is such a neat language. I was equally impressed by Spall: https://odin-lang.org/showcase/spall/ https://odin-lang.org/showcase/spall/
- ilrwbwrkhv 3y agoYes this is fantastic. One of the best software currently available in the market.
- llm_nerd 3y agoPage is basically unusable on my Intel MBP, and still a beastly consumer on my AS Mac. I presume simulations are happening somewhere on the page, but it would be a good idea to make them toggled. Ideally via user interaction, but if one insists on auto-play when scrolled into the viewport.
- pdabbadabba 3y agoInterestingly, no noticeable performance issues on my M2 MacBook Air. Maybe he's already made some of the changes you recommended?
- whalesalad 3y agoTestament to the insane power and efficiency of Apple silicon
- kqr 3y agoSame thing on a modern flagship smartphone.
- andygeorge 3y agoPixel 8 Pro here, using DDG browser, smooth for me.
- chefandy 3y agoWhat I can use works great on FF on my S22 Ultra, but it's not interactive because the shader fields won't register taps as click events.
- aeyes 3y agoSeems to work only in Safari, using Chrome I can't scroll past the first quarter of the page and CPU is at 100%.
- pudquick 3y agoRuns buttery smooth on my M2 here in Safari on macOS 14.2.1 Tried them out in Chrome and they're mostly all the same though I do notice a slight jitter to the rendering in the smoke example.
- bee_rider 3y agoThey mention simulating fire and smoke for games, and doing fluid simulations on the GPU. Something I’ve never understood, if these effects are to run in a game, isn’t the GPU already busy? It seems like running a CFD problem and rendering at the same time is a lot. Can this stuff run on an iGPU while the dGPU is doing more rendering-related tasks? Or are iGPUs just too weak, better to fall all the way down to the CPU.
- photoGrant 3y agoWelp. It used to be PhysX math would run on a dedicated gpu of choice. I remember assigning or realising this during the Red Faction game with forever destructing walls. Almost Minecraft, but with rocket launchers on mars
- bee_rider 3y agoI remember PhysX, but my feeling at the time was “yeah I guess NVIDIA would love for me to buy two graphics cards.” On the other hand, processors without any iGPUs are pretty rare by now.
- jayGlow 3y agoI'm fairly certain red faction didn't use Nvidia physX at all.
- photoGrant 3y agoIt didn’t!
- dexwiz 3y agoYou don't have to be gaming to use a GPU. Plenty of rendering software have a GPU mode now. But writing GPU aglos are often different from a CPU simulation algo, because it is highly parallelized.
- Valgrim 3y agoNow that LLMs run on GPU too, future GPUs will need to juggle between the graphics, the physics and the AI for NPCs. Fun times trying to balance all that. My guess is that the load will become more and more shared between local and remote computing resources.
- pbowyer 3y agoI'm really impressed by the output of the distill.pub template and page building system used for this article. It's a shame it was abandoned in 2021 and is no longer maintained.
- jvans 3y agoDoes anyone have any recommendations for a former math major turned SWE to get into CFD simulations? I find this material fascinating but it's been a while since I've done any vector calculus or PDEs so my math is very rusty.
- chefandy 3y agoIf you're more interested in the physics simulation for research, I can't help ya. However, SideFX Houdini is tough to beat if you're going more for entertainment-focused simulations. https://www.youtube.com/watch?v=zxiqA8_CiC4 https://www.youtube.com/watch?v=zxiqA8_CiC4 Their free non-commercial "Apprentice" version is only limited in its rendering and collaboration capabilities. It's pretty... uh... deep though. Coming from software and moving into this industry, the workflow for learning these sorts of tools is totally different. Lots of people say Houdini is more like an IDE than a 3D modelling program, and I agree in many ways. Rather than using the visual tools like in, say, blender, it's almost entirely based on creating a network of nodes, and modifying attributes and parameters. You can do most stuff in Python more cleanly than others like 3ds Max, though it won't compile, so the performance is bad in big sims. Their own C-like language, vex, is competent, and there's even a more granular version of their node system for the finer work with more complex math and such. It's almost entirely a data-oriented workflow on the technical side. However, if you're a "learn by reading the docs" type, you're going to have to learn to love tutorials rather quickly. It's very, very different from any environment or paradigm I've worked with, and the community at large, while generally friendly, suffers from the curse of expertise big-time.
- physicsguy 3y agoApply for jobs at a place like StarCCM or similar
- araes 3y agoI used to work at NASA (contractor) doing this. One thing, get a job in the field. If you really want to, apply to Marshall Space Flight Center and / or Ames (Top500: Aitken [#85, 9.07 PFlops], Pleiades [#132, 5.95 PFlops], Electra [#143, 5.44 PFlops] systems) on either the Federal or Contractor side. GRC, LARC, and JSC also have some. At least a few years ago, the Contractor / Federal integration was actually quite good, and nearly transparent (except for allocating money). These groups are both fairly well known at NASA (MSFC, Propulsion Structural, Thermal & Fluid Analysis [2][3], and Ames, Entry Systems [4]) When I was there we were running ~100 million cell (vehicle) or (vehicle + pad) Hybrid RANS/LES sims with moving overset grids, maybe 10-20 species reactive combustion chemistry (SSMEs and SRBs lighting together), and Lagrangian evaporative particle dynamics (launch water suppression) using Overflow/LARC [5], or Loci/Mississippi State University [6]. Note: My info's a decade out of data, so no idea what the SOTA is these days. More than this. If you're interested in the field and what a lot of the industry is concerned about, then while old (2014), the CFD Vision 2030 Study is not a bad orientation. [7] Try to get a ticket to Supercomputing and go wander around. This year was in Denver. [8] Their focus tends to be on "large" though, so you'll mostly get massive weather simulations and stellar cloud dynamics. I like the conference, yet its difficult to get any notice unless you did #CPUs/#GPUs/#FPGAs++. GOV Outside NASA: NIST (Gaithersburg), DOE (Oak Ridge, Sandia, Los Alamos), Air Force (AF Research Lab), Huntington Beach. [1] NASA Advanced Supercomputing Division: https://en.wikipedia.org/wiki/NASA_Advanced_Supercomputing_Division https://en.wikipedia.org/wiki/NASA_Advanced_Supercomputing_D... [2] NASA, MSFC: https://www.nasa.gov/wp-content/uploads/2016/01/g-28367g_pstfa_er40.pdf https://www.nasa.gov/wp-content/uploads/2016/01/g-28367g_pst... [3] Somewhat old examples: https://ntrs.nasa.gov/api/citations/20140016892/downloads/20140016892.pdf https://ntrs.nasa.gov/api/citations/20140016892/downloads/20... [4] NASA Ames: https://www.nasa.gov/entry-systems-and-technology-division/ https://www.nasa.gov/entry-systems-and-technology-division/ [5] OVERFLOW/NASA/LARC: https://overflow.larc.nasa.gov/ https://overflow.larc.nasa.gov/ [6] Loci/MSU: https://simcenter.msstate.edu/ https://simcenter.msstate.edu/ [7] CFD Vision 2030 Study: https://ntrs.nasa.gov/api/citations/20140003093/downloads/20140003093.pdf https://ntrs.nasa.gov/api/citations/20140003093/downloads/20... [8] Supercomputing SC23: https://sc23.supercomputing.org/ https://sc23.supercomputing.org/
- jbverschoor 3y agoGood explanation why CG explosions suck: https://www.youtube.com/watch?v=fPb7yUPcKhk https://www.youtube.com/watch?v=fPb7yUPcKhk
- randyrand 3y agothis is so useful thank you!
- riidom 3y agoWhile not the main point of the article, the introductory premise is a bit off IMO. When you choose simulation, you trade artistic control for painful negotiation via an (often overwhelming) amount of controls. For a key scene like the balrog, you will probably never decide for simulation and go for full control on every frame instead. To stay in the tolkien fantasy example, a landscape scene with a nice river, doing a lot of bends, some rocks inside, the occasional happy fish jumping out of water - that would suit a simulation much better.
- johnnyanmac 3y agoNot impossible to do both, but very few tools are built where simulation comes for "free". At least not free and real-time as of now. Maybe one day. But I agree with you. You'd ideally reserve key moments for full control and leave simulation for the background polish (assuming your work isn't bound by a physically realistic world).
- holoduke 3y agoWhat will be quicker. Realtime raytraced volumetric super realistic particle effects or somekind of diffusion model shaderlike implementation.
- Phelinofist 3y agoI recently watched this video about implementing a simple fluid simulation and found it quite interesting: https://www.youtube.com/watch?v=rSKMYc1CQHE https://www.youtube.com/watch?v=rSKMYc1CQHE
- nox100 3y agoThis is very nice! Another person explaining this stuff is "10 Minute Physics" https://matthias-research.github.io/pages/tenMinutePhysics/index.html https://matthias-research.github.io/pages/tenMinutePhysics/i...
- pictureofabear 3y agoIf you need a refresher on diff eq... https://www.youtube.com/watch?v=ly4S0oi3Yz8 https://www.youtube.com/watch?v=ly4S0oi3Yz8
- berniedurfee 3y agoI wrote a super simple flame simulation a long time ago as a toy in C after reading an article somewhere. You just set each pixel’s brightness to be the average brightness of the immediately adjacent pixels. Calculate from bottom to top. Add a few “hot” pixels moving back and forth along the bottom and boom, instant fire. Looks very cool for a tiny amount of code and no calculus. :)
- shnock 3y agoCould you share the repo?
- berniedurfee 3y agoI will, but I need to dig it out of my archives. It was from a time before repos. :)
- fjkdlsjflkds 3y ago> no calculus "set each pixel’s brightness to be the average brightness of the immediately adjacent pixels" sounds like a convolution ;)
- Cthulhu_ 3y agoIt's a trick! Calculus puts me right off, but explain it in code and visualizable ways and I'm on board.
- hyperthesis 3y agoThis is the laplacian operator (in 1D, just the second derivative, or curvature). The sharper the crest, the more negative; the sharper the trough, the more positive. If you change the value there, by that much, the effect is averaging (and the discretized form is literally averaging). You've been doing calculus the whole time. There's a difference between knowing the path, and walking the path. Here's a 3Blue1Brown video with intuitive graphics on it https://youtube.com/watch?v=ToIXSwZ1pJU https://youtube.com/watch?v=ToIXSwZ1pJU
- danybittel 3y agoIt looks to me like you did not add gamma correction to the final color?
- sieste 3y agoIf you like this, you'll also enjoy Ten Minute Physics, especially chapter 17 "How to write an Eulerian Fluid Simulator with 200 lines of code." https://matthias-research.github.io/pages/tenMinutePhysics/index.html https://matthias-research.github.io/pages/tenMinutePhysics/i...
- deleted 3y ago[deleted]
- throw10920 3y agoI've never seen (x, t) anywhere other than the Schrödinger equation - seeing it used here for a dye density function was weird, but it makes sense!
- richardlblair 3y agoClicked hoping for interactive examples. Did not disappoint. Here's an internet point, friend. Thank you for your service.
- hyperthesis 3y agoBridson's course notes also cover most of this https://www.cs.ubc.ca/~rbridson/fluidsimulation/fluids_notes.pdf https://www.cs.ubc.ca/~rbridson/fluidsimulation/fluids_notes... There's a second part by Muller, who's also very active in the area: https://matthias-research.github.io/pages/tenMinutePhysics/index.html https://matthias-research.github.io/pages/tenMinutePhysics/i... It became a book, now in 2ed: Fluid Simulation for Computer Graphics