Coding Adventure: Simulating Fluids

2024 ж. 1 Мам.
1 575 188 Рет қаралды

Let's try to convince a bunch of particles to behave (at least somewhat) like water.
Written in C# and HLSL, and running inside the Unity engine.
Source code:
github.com/SebLague/Fluid-Sim
If you'd like to support me in creating more videos like this, you can do so here:
/ sebastianlague
ko-fi.com/sebastianlague
Resources:
matthias-research.github.io/p...
www.ligum.umontreal.ca/Clavet-...
sph-tutorial.physics-simulati...
web.archive.org/web/201407250...
Music:
github.com/SebLague/Misc-Proj...
Chapters:
0:00 Intro
0:27 Gravity and Collisions
2:31 Smoothed Particles
3:55 Calculating Density
7:53 The Interpolation Equation
11:58 Gradient Calculations
15:38 The Pressure Force
19:19 Trying to Make it Work...
22:05 Optimizing Particle Lookups
26:31 Spatial Grid Code
27:48 Position Predictions
30:32 Mouse Force
33:22 Artificial Viscosity
36:46 Pressure Problems
39:51 Bugs
41:06 Parallel Sorting
43:22 Some Tests and Experiments
44:47 The Third Dimension
47:23 Outro

Пікірлер
  • Hi everyone, I hope you enjoy the video! This is a topic I’ve been wanting to tackle for ages, but have always found a bit intimidating to get started with. So I’m happy to have finally dived in! Let me know if you have any suggestions for improving it, or ideas for future projects. In other news, I’ve recently created a Ko-Fi page where it’s possible to support my work with a one-off contribution (as opposed to the monthly pledges on Patreon). No pressure of course, but if that’s something you’d like and are able to do, you can find the page here ko-fi.com/sebastianlague

    @SebastianLague@SebastianLague6 ай бұрын
    • ​@@sfsasteroid1 Yes, I definitely want to get back to that project. Hopefully soon!

      @SebastianLague@SebastianLague6 ай бұрын
    • I liked the video overall, but the first half was a slog to watch through. I like how acerolla approaches writing a script for that, maybe you could do something similar if there's lots of math involved.

      @ivanalantiev2397@ivanalantiev23976 ай бұрын
    • Could you also create more videos about shaders and how beautiful and realistic they make the “world”?

      @xu_fengxuan@xu_fengxuan6 ай бұрын
    • I wrote a reply before but I think it was removed because I included links. Anyway, I highly suggest you look into a fluid simulation method called FLIP (Fluid Implicit Particle), it's also primarily a Lagrangian or particle based method, like SPH, but it achieves improved conservation of quantities like density, and better divergence, by incorporating aspects of finite volume simulations, so it should address many of the issues you've noticed so far with pure SPH being more gas like. Considering you already have the particle code working, building an implementation of FLIP should be fairly easy as most of the changes it requires are calculating some quantities like velocity on a fixed grid rather than at particle locations. FLIP also happens to be one of the default fluid simulation methods used by commercial software such as Houdini, and is available as a very popular Blender addon too, so there's boatloads of work that's gone into optimising, much of which is available for free online. The paper I linked before was titled Flip: A low-dissipation, particle-in-cell method for fluid flow, if you want to learn more.

      @dominicmcg2368@dominicmcg23686 ай бұрын
    • I'd love for you to make a truly incompressable simulation, since this might also allow you to simulate stuff like sand or wheat

      @stonefreak5763@stonefreak57636 ай бұрын
  • The near-density trick was something I came up with for my master's thesis 18 years ago, and nobody mentioned that they were using it before today. It took a long time, but it was worth it in the end because I got my name in one of best videos on youtube. Thank you Sebastian.

    @clavetsi@clavetsi6 ай бұрын
    • Thank you for the super-helpful paper, and I’m so happy you liked the video!

      @SebastianLague@SebastianLague6 ай бұрын
    • I'd say that deserves at least a like

      @Ben-rz9cf@Ben-rz9cf6 ай бұрын
    • Damn. Masters of tech! Thanks for everything!

      @Dr.Kay_R@Dr.Kay_R6 ай бұрын
    • Maybe the same behaviour can be obtained by including a local minimum to the "interaction" function, so that particles tend to keep a certain distance to their neighbours, not more not less. The constant density would be an emergent property.

      @JavSusLar@JavSusLar6 ай бұрын
    • A local minimum in the interaction function would also provide a "boiling point": if the energy of the particles is higher than the well depth, the particules break their "bond" and fly with more freedom.

      @JavSusLar@JavSusLar6 ай бұрын
  • The worst part about Sebastian Lague videos is that they end.

    @fxzn@fxzn6 ай бұрын
    • Absolutely HATE when that happens :(

      @VivaanTheCraft3r@VivaanTheCraft3r6 ай бұрын
    • Ong😭

      @stickguy9109@stickguy91096 ай бұрын
    • The best part is that my memory isn't infallible, which means I can rewatch old videos

      @Vextrove@Vextrove6 ай бұрын
    • Wisdom to put on a bathroom tile and hang in your kitchen.

      @lucbloom@lucbloom6 ай бұрын
    • He is my favorite tumblr scrimblo

      @TheMagicat@TheMagicat6 ай бұрын
  • I love how one of the bugs you try to fix is just emergent surface tension.

    @jucom756@jucom7566 ай бұрын
    • That's what even I thought

      @MasterofTheDucks@MasterofTheDucks6 ай бұрын
    • Yes, I thought the same. That's likely exactly what it's supposed to do. There's no pressure from the other side, and that affects the distribution of particles.

      @KipIngram@KipIngram6 ай бұрын
    • It is sort of like surface tension but not really. Because of the function he picked, his water is compressible. And it shouldn't be.

      @Rothron@Rothron6 ай бұрын
    • @@RothronThat can be mostly fixed by turning up the pressure multiplier.

      @Owen_loves_Butters@Owen_loves_Butters6 ай бұрын
    • @@Rothron Only weakly compressible, right?

      @rileywheb4444@rileywheb44446 ай бұрын
  • He is the Bob Ross of Coding. He is like: „Lets put a happy little rekursive non-linear differencial equation of sixt order here.“ I love it!

    @michellinzer4881@michellinzer48816 ай бұрын
    • absolutely spot on!

      @ragingram2@ragingram26 ай бұрын
    • "This bug is a happy accident if you look at it this way"

      @0.Andi.0@0.Andi.04 ай бұрын
  • The real insane part of these videos isn’t the coding is the visualisation of the coding at the same time to make it so that non coders can understand clearly, I love these videos

    @OddlySpecificGaming@OddlySpecificGaming6 ай бұрын
    • Even people who do code benefit from the beautiful visualizations! It's just an all around great thing to include Kind of like how accessibility features benefit everyone I like this channel a lot 😊

      @MayaPapaya497@MayaPapaya4976 ай бұрын
    • It's insane how much time he invests for visually explaining clips that end up being 10 seconds, while they can easily sometimes take hours to create

      @adrianstarfinger5721@adrianstarfinger57216 ай бұрын
    • @@MayaPapaya497 Honestly, yeah I wish programming tools had those sorts of visualizations right out of the box. It would make debugging so much easer and less mentally abstract if you could see what was happening.

      @MightyBOBcnc@MightyBOBcnc6 ай бұрын
    • Honestly making everything as interactive and visualizable as he does is probably as much or more work then just getting the actual equations to work. Though I guess Unity helps a lot with that.

      @ryanmccampbell7@ryanmccampbell75 ай бұрын
    • unity ❤

      @muradm7748@muradm77484 ай бұрын
  • Sebastian Lague never disappoints. I am astonished by how much a single man can accomplish, and at the same time, how much he can teach others. The 48 minutes that this video lasted felt more like 10 because of how enjoyable and informative it was. I can't wait to see how the finished product will look like. Amazing work!

    @batimius@batimius6 ай бұрын
    • My problem is that these videos are often a bit too complicated to wrap my mind around, and therefore I have to watch them twice to understand. But that's probably also because I'm not a native speaker. Despite that, this channel is one of the best in explaining.

      @murmeldin@murmeldin6 ай бұрын
    • ​@@murmeldinAlthough I really like his videos, I do not believe that he codes these projects alone.

      @hypertizer@hypertizer6 ай бұрын
    • @@hypertizerWhy? Most of the time his projects are based on well documented techniques. He consistently mentions using papers and reference material - that’s really all you need to implement this stuff.

      @TheStolenBattenberg@TheStolenBattenberg6 ай бұрын
    • Its very much possible to do all this coding alone. Just takes patience, skill and persistence. Remember the research was already done in the papers. Not saying it's easy but any decent software engineer should be able to figure out a implementation.

      @Rick104547@Rick1045476 ай бұрын
    • @@hypertizer if someones gonna take like months to upload videos I'm sure he's doing it by his own

      @nullzishere@nullzishere6 ай бұрын
  • This is probably the only channel where I can watch an almost hour long video and not get bored for a tiny second

    @user-rb7vs5bx6b@user-rb7vs5bx6b6 ай бұрын
    • fr bro

      @MrSquares@MrSquares6 ай бұрын
    • While not understanding half of the stuff happening lol

      @playbird9009@playbird90095 ай бұрын
    • i didnt even realize it was almost an hour long

      @daffa_fm4583@daffa_fm45834 ай бұрын
    • the visualization here is better than marvel sgi

      @Basuliic@Basuliic4 ай бұрын
    • You do realize that all of NY city was cgi. so I wouldn't go that far, but his visualizations are very impressive none the less.@@Basuliic

      @MrSquares@MrSquares4 ай бұрын
  • Good throwback to my old times as a molecular dynamics scientist :) Heating up of your simulation: This is normal and happens for different reasons, the biggest contribution is certainly that your forces are cut off and discretized. There is a difference for incoming and outgoing particles (whenever particles bounce, they heat up a little bit, because not everything is perfectly symmetrical over time). The only way to solve this with 100% correct physics is to go via action integral solutions, which is absolutely not feasible for a simulation of that size, that is why even physicists don't use that for molecular dynamics (MD). The easy and cheap way here to go is to introduce a thermostat, which for example every 100 or 10k frames readjusts the temperature, by shifting the speed of each particle a bit more in the direction of the desired speed. In your case you don't need to care about real temperature, just pick an average speed that you are aiming for, which means you still set the temperature but don't know the value in terms of K or °C. Incompressibility: Be happy you don't have it. You don't want it. It is not a good thing for discrete particle simulations. This is something for totally different methods like finite volume/element simulations, density functional and such things. If you have discrete particles exchanging forces, don't try incompressibility. It is unphysical and it only works in more abstract and less close to real physics. Even in these fields it ends up with singularities and problems everywhere, ask people who try to model turbulence ;-) Behavior at the boundaries: This is no surprise. You have this behavior because the particles at the edges do not have any force pulling on them from the other side. They only have forces pulling on them from the inside and along the boundary but not from outside. This increases their local density there. In MD simulations there are several solutions for this. Often simulations have periodic boundary conditions, then this problem is mostly gone. In your case this is not a solution. You can have a background field that is outside of the box, which is calculated from what is happening inside the box, fast fourier transform is used to calculate that cheaply, this basically means that you copy your box abstractly into each direction, so the particles feel long distance forces from all sides. This is really important for MD simulation to get proper bulk behavior of materials, but in your case this is absolutely not necessary as you do not care if your fluid has a realistic volume viscosity, density, temperature / pressure relation etc. pp. You don't care about physical correctness, so you don't need to go that costly route (especially coding it from scratch). Another solution is to not have "neutral" walls. Your walls can have forces too, which results in the walls being sticky or repulsive, changing the behavior. The easiest solution would be to put ghost particles on the walls, which just emit the same forces as your other particles, but do not receive anything and do not move ever. This is often used in simulation of pores and confined materials. The ghost particles will certainly imprint a structure on the wall (and pull real particles into that structure), which you might not desire. In that case a homogenous wall force might be more what you are looking for, that is basically the same thing, but smooth, so that particles do not stick to certain points on the wall, but just still glide, without higher local density.

    @lordesfairgenug@lordesfairgenug6 ай бұрын
  • Super cool video! We need part 2 👁👄👁

    @Danidev@Danidev6 ай бұрын
    • yoo! danis here (im a big fan

      @nkkls@nkkls6 ай бұрын
    • you need a part 1 to literally anything first bro 😭

      @lowpolygons8562@lowpolygons85626 ай бұрын
    • Duuude, where you been?

      @davidemmanuel9418@davidemmanuel94186 ай бұрын
    • He isn't dead! :)

      @Gapi505@Gapi5056 ай бұрын
    • Yo, its the milk man! His milk is delicious

      @5x9x@5x9x6 ай бұрын
  • This is extremely cool! There's something about the combination of particle-based systems and fluid simulations that is fascinating. I ran into a lot of the same problems while trying to implement a particle-based fluid visualization where the underlying simulation is not actually particle based. A lot of the techniques you showed would definitely be applicable to this problem and I'll look into them a bit more. My solution was just giving up on trying to match the density with the particles and instead make the particles act more like dust that is pulled and pushed by the fluid's motion. It works alright but suffers from its own set of issues... Anyway, great video as always!

    @AngeTheGreat@AngeTheGreat6 ай бұрын
    • Thank you! I don't know if I've said before, but your simulations are super impressive and always really fascinating to watch. I'm excited to catch up on the latest videos (now that I've finally finished editing this)!

      @SebastianLague@SebastianLague6 ай бұрын
    • Omg its the engine simulator guy. Huge fan

      @arthurblack-petersen4213@arthurblack-petersen42136 ай бұрын
    • woah it's the trumpet simulator person

      @1e1001@1e10016 ай бұрын
    • Please do a collaboration, you two!

      @AaronStatic@AaronStatic6 ай бұрын
    • ​@AaronStatic I do think if two or three of these GOAT coders worked together they would fix humanities problems. Genius

      @SuperFireMatt@SuperFireMatt6 ай бұрын
  • I personally would love to see a "deep dive walkthrough" on you porting this to the GPU. It seems like a great vehicle for introducing a lot of people to GPU programming. You mostly did that part "off screen" here - those details would be hugely interesting, I think.

    @KipIngram@KipIngram6 ай бұрын
    • I think he made a video on compute shaders where he goes over a lot of the techniques.

      @casperkant@casperkant4 ай бұрын
    • ditto this request! And please do it in taichi!

      @bluevisor@bluevisor3 ай бұрын
    • I found that analysing and modifying his marching cubes terrain source code was really informative.

      @Yewtewba@YewtewbaАй бұрын
  • It's so fun to watch these as a physicist! On the one hand, if feels like you get just enough of the physics to follow along with your project, and I, on the other hand, get just enough of the programming to follow along with your video. It's also so cool to see you implementing these ideas. One of my favorite youtube series for sure.

    @felipea.barretto7503@felipea.barretto75036 ай бұрын
    • Hello Fellow Physicist! Can you tell me what kind of engine does real life use to simulate Millions and billions of particles (Atoms) and make them interact with each other seamlessly? I mean.. is there even an engine? or is there something else at play here? I've been wondering that for the longest time 😭

      @ashlysherief3850@ashlysherief38504 ай бұрын
    • @@ashlysherief3850 oh yeah real life uses a very complicated engine it is called physics and it has no documentation

      @user-gi7vi9gm4t@user-gi7vi9gm4t4 ай бұрын
    • @@ashlysherief3850 Gromacs, NAMD, Amber, OpenMM are the most used ones if we're talking about fairly accurate, atomistic, classical simulations. And yes, with multi-gpu or even better, multinode clusters they can simulate even tens or hundreds of million of atoms. They get nowhere near "real time" speed though. Usually it takes months to accurately model big biomolecular systems for just a few tens of microseconds, or a few milliseconds. The problem is that atoms are really really fast, so your simulation step must be about a few femtoseconds. The faster you allow your particles to go, the slower will be the simulation, and with realistic atomist systems you really don't have a choice. BTW they mostly use the leapfrog (Verlet) method for the integration of the equations of motions, which Sebastian mentions, but then they also add stochastic terms in order to sample from the correct distribution of temperatures and pressures.

      @FabioMazza@FabioMazza3 ай бұрын
    • @@user-gi7vi9gm4t yeah the coder who came up with it doesnt seem to be answering any emails and apparently left the project as it is a long time ago

      @kstxevolution9642@kstxevolution96423 ай бұрын
  • Sebastian comes back every once in a while like a Santa to bless us with heavenly vibe

    @HeisenbergFam@HeisenbergFam6 ай бұрын
    • fr

      @catguy265@catguy2656 ай бұрын
    • you have great taste in the videos you comment on

      @penewoldahh@penewoldahh6 ай бұрын
    • This is number 91

      @wChris_@wChris_6 ай бұрын
    • stop appearing everywhere PLEASE

      @sussy-coder@sussy-coder6 ай бұрын
    • @@penewoldahh You think they have great taste because they comment on literally every popular video, so the ones you watch you will see their comment.

      @Nae_Ayy@Nae_Ayy6 ай бұрын
  • Developing these prototypes requires a lot of work. The fact you go the extra mile to create visual graphs on what is currently taking place using the Editor itself and no editing tricks is ridiculous, you take a great deal of pride in your work! You are a very smart man!

    @LHInstrumentals@LHInstrumentals6 ай бұрын
    • I think at his level, trying to learn editing tricks would be slower.

      @hurktang@hurktang6 ай бұрын
  • The way you timed up the music with the waves at 45:58 was so clean 🤌 love the production quality you put into these videos

    @alexbroaddus2380@alexbroaddus23806 ай бұрын
    • I think he uses DaVinci Resolve

      @trinitrotolueneRBLX@trinitrotolueneRBLX2 ай бұрын
  • Very impressive. I also like the fact that you don't hide your mistakes.

    @user-pc2rz9xv2g@user-pc2rz9xv2g6 ай бұрын
  • Sebastian didn’t end his video with “cheers”. My conclusion is that he’s been kidnapped and had to send a secret message that only we’d understand something was weird about. The chessbots must have finally got him.

    @thecakecraft7724@thecakecraft77246 ай бұрын
    • Read this before I've finished the video, son's crying now... Cheers.

      @Harry-kt3lk@Harry-kt3lk6 ай бұрын
    • I feel like he's smiling through his teeth the entire video.

      @robrobusa@robrobusa6 ай бұрын
    • I'm pretty sure his cat made this one. The cat was covering the keyboard in almost every shot.

      @ChrisD__@ChrisD__6 ай бұрын
  • An absolutely classic Lague video

    @Oziji@Oziji6 ай бұрын
    • It's been 8 minutes (I agree) Edit: nvm patron

      @zaidlacksalastname4905@zaidlacksalastname49056 ай бұрын
    • hi oziji

      @aspectreishauntingeurope@aspectreishauntingeurope6 ай бұрын
    • hi zorby

      @Oziji@Oziji6 ай бұрын
    • That's how you spell it? Always thought it was league lol

      @zaidlacksalastname4905@zaidlacksalastname49056 ай бұрын
    • a certified hood classic

      @ahegaoweeb9453@ahegaoweeb94536 ай бұрын
  • I did a compsci degree at a decent university many years back... this video is astounding quality and right up there in terms of lecturer quality... and it's free!

    @chimpana@chimpana6 ай бұрын
  • I love how the water particles simulate adhesion and cohesion naturally… so cool… (33:05)

    @Maxy.waxyyy@Maxy.waxyyy6 ай бұрын
  • Have been waiting for a fluid simulation video for 10 years, thank you Sebastian.

    @RealLukeLudicrous@RealLukeLudicrous6 ай бұрын
    • I'm not sure it can live up to 10 years of anticipation, but I hope you enjoy it nonetheless :) Definitely a topic I'll be exploring more in the future too.

      @SebastianLague@SebastianLague6 ай бұрын
    • @@SebastianLague any ideas for future experiments involving AI-related algorithms? I would love watching a revisit to Ecosystem Simulation (probably one of my favourites) with Q-Learning, perhaps

      @MrTitaniumCreeper@MrTitaniumCreeper6 ай бұрын
    • Gonkee has a similar video, but he doesn't explain how it works

      @ChuckSploder@ChuckSploder6 ай бұрын
    • Great video dude@@SebastianLague

      @account9949@account99496 ай бұрын
  • This is truly inspiring and the production quality is amazing as well, thank you! I also picked up a few notes for spatial search optimisations I'm excited to try out in my little evolution sandbox simulator

    @NeverSink@NeverSink6 ай бұрын
    • Thanks! And that's awesome, I'm happy to hear it!

      @SebastianLague@SebastianLague6 ай бұрын
    • Excited to see fluid sims in my poe filters 👌

      @kalledk21@kalledk216 ай бұрын
    • Truly amazing how this comment is reading as created 21 hours ago when the video was uploaded an hour ago

      @xu_fengxuan@xu_fengxuan6 ай бұрын
    • @@kalledk21 Haha, that's one way to liquify your currency in Path of Exile I suppose :)

      @NeverSink@NeverSink6 ай бұрын
    • ​@@xu_fengxuanim pretty sure members get early access

      @strelnagaming@strelnagaming6 ай бұрын
  • Absolutely wonderful video! I really like that you kept many of the fumbles and mistakes in the video and showed the thought process exactly the way an experienced programmer might or should, instead of just showing us the complex end result. Really looking forward to seeing how you turn the particles into a rendered result. Great video!

    @adaloveless3904@adaloveless39045 ай бұрын
  • I barely understand anything about how coding works, but your videos are not only relaxing, but somehow make it so easy to understand whats actually happening. Always are great day when a new Coding Adventure releases! Also, cute cat.

    @birb4415@birb44156 ай бұрын
  • Not only did he learn these concepts and teach them, he built an interactive tool to use as a presentation aid.

    @LevTheDev@LevTheDev6 ай бұрын
    • Not to take from his amazing work but I'm pretty sure he is using Unity. It's free if you want to try and experiment a bit yourself :)

      @alpani6805@alpani68056 ай бұрын
    • @@alpani6805 Yes, we are all well aware of that. But what LevTheDev is referring to is that Sebastian goes out of his way to code interactive simulations for things like the smoothing curves and whatnot as a means to help explain things. It's a lot of work for little progress on the project itself, but helps the audience a lot.

      @avananana@avananana6 ай бұрын
    • Better use Godot and dont support those Unity poopheads @@alpani6805

      @schnitzelhannes6431@schnitzelhannes64316 ай бұрын
  • It would be cool to see how different particles dispersed in the fluid. Like, start with 50% red particles and 50% blue and just watch them mix and diffuse.

    @CriticalMonkey623@CriticalMonkey6236 ай бұрын
    • you can kind of already see that, red just means fast and blue slow. When the waves crash you are effectively seeing that

      @ZombieChicken-X@ZombieChicken-X6 ай бұрын
    • @@ZombieChicken-X Except that color is just velocity. He wants discrete red and discrete blue particles mixing, with no velocity shading. But just mixing 50-50 red and blue particles won't do us any good unless the particles are smaller than a pixel and there are at least two particles per pixel. Obviously, this massively increases the simulation time, even with the cell-based simulation method, so unless we actually use the GPU to calculate all of this, it's computationally unviable at the moment. However, I'm certain one could emulate this by creating a smoothed color gradient using the smoothing circle and gradually shifting each and every particles' color towards this average at their location., performing this shift on the HSV color system.

      @Operational117@Operational1176 ай бұрын
    • @@Operational117 I dont understand, so like mixing two cups of water? Or mixing water and milk

      @ZombieChicken-X@ZombieChicken-X6 ай бұрын
    • @@ZombieChicken-X imagine a cup water but colored with red dye and one with blue dye and mixing them together watching the colors diffuse and disperse. he doesnt want to see the velocities, he wants to see diffusion of basically two different liquids

      @goldenbananas1389@goldenbananas13896 ай бұрын
    • gotcha@@goldenbananas1389

      @ZombieChicken-X@ZombieChicken-X6 ай бұрын
  • Something i think would be cool to see is a simulation with different liquids, different colors, viscosity, weight, ect, and have them collide together to see how they diffuse and mix together 😮

    @2pringles@2pringles6 ай бұрын
    • I'd love to see some sort of implementation of adding energy - as in heating the liquid. You could then not only plat with different kinds of liquids but watch how they behave if temp goes up. Something like that

      @jemakrol@jemakrol6 ай бұрын
  • Just came across your channel and as a fluid dynamics student who's starting his thesis using SPH and I'm super excited to see this and I love your approach! It's an awesome video and I'm definitely gonna stick around for more coding adventures! Thank you and have a lovely day

    @honza4471@honza44716 ай бұрын
  • You're like the Bob Ross of coding! Always a great day when you upload 😁

    @kallethoren@kallethoren6 ай бұрын
    • No bugs, only happy accidents lol

      @crakhaed@crakhaed6 ай бұрын
  • Here's a rogue idea for how the fluid sticks to the bounding box: Make the walls of the bounding box a little bit "elusive" by making it strongly repulse the particles instead of preventing the particles to go past it. This will prevent the particles from sticking to it and instead should bounce off of it. Hopefully.

    @mr.inconspicuous6395@mr.inconspicuous63956 ай бұрын
    • That would make sense since the wall is also made of particles in real life!

      @Josbird@Josbird6 ай бұрын
    • I think that's only the half story, but in its core it's the right idea. The particles accumulate because there is no force coming from the walls that tell the to go in the other direction. So particles must accumulate until a certain threshold is reached that roughly represent the force that would be introduced by the wall. Almost the same logic applies to the surface. Anyway I think you would need some kind of logic that flags particles in a way to determine if they contribute the the rendering of the surface or not, so you should be able to give them special treatment based on this flag. In the case of the walls simply apply the force they experience in opposite direction regarding the angle of the wall, aka dot product. If I'm not mistaken that should result in evenly spaced out points throughout the walls. The actual surface of the water is a little different there is a factor involved that is more closely related to surface tension.

      @siltax2814@siltax28146 ай бұрын
    • Just make the visual edge of the wall outset from the "physical" edge of the wall. It's a quick and dirty hack but it would look fine.

      @schwatoo@schwatoo6 ай бұрын
  • Thank you for the journey. It was great and satisfying to watch how you handle pretty complex problems of this project.

    @nurofen127@nurofen1276 ай бұрын
  • 0:38 Sebastian: "Let's keep track of the particle's position and velocity." Heisenberg: "Am I a Joke to you?"

    @cathalredmond4789@cathalredmond47896 ай бұрын
  • That 3blue1brown plush was so fitting with the math refresh, glad to see him also enjoy the obscure math problems and their explanation

    @DaveeeOnTop@DaveeeOnTop6 ай бұрын
  • As someone who works with SPH I am almost bursting of joy. Thank you so much @SebastianLague Consider using Artificial Viscosity (Monaghan et al.), diffusive density terms (Antuono et al.) and particle shifting technique (Sun et al.) to improve your simulation. Make sure your CFL conditions are correct. You can use kernel corrections to improve accuracy at the fluid boundary (Sheppard or CSPM (expensive)). For surface tension, use the CSF model (Morris is a simple enough model).

    @mlisic431@mlisic4316 ай бұрын
    • Not having any experience in the field i just assumed the boundary conditions arrise since he does not consider the density outside the bounding box or the pressure of the "air" obove, so his pressure gradients push particles outwards

      @user-wz8hj5fl4r@user-wz8hj5fl4r6 ай бұрын
    • Not quite. Allow me to make it a little more abstract: SPH is a way if interpolating a mathematical function (or continuous field in 3D), but it depends on particle distribution. If you want to approximate the constant number 1, you calculate = sum(1 * vol_j * W_j), with symbolizing SPH approximation, volume and kernel W. Ideally that would sum to 1, but at boundaries you don't have particles everywhere, so you get an error. Conseptually, a "missing particle is like interpolating 0. (0 * vol_j * W_j) That also arrises when particles move and have uneven distributions. For function interpolation (no derivate) that's pretty easy to fix: you just normalize = sum(f(x) * vol_j * W) / sum(vol_j * W) But for the gradient you have directionality (+/-) in 3 dimensions (x,y,z). Thus matrix calculation and getting their inverse is required. And this procedure is called corrected Corrective Smoothed Particle Method (CSPM). It is zeroth order consistent (constant gradients remain constant). There are higher order accurate schemes for gradient correction (e.g. Finite Particle Method (FPM), 1st order consistent), which are more taxing In summary: Because particles aren't evenly distributed everywhere, you need to correct your methods, which approximate the math of the governing physics that drive your simulation, in order the accurately approximate the physics. For gradiends, depending on accuracy use CSPM (0th) or FPM (1st)

      @mlisic431@mlisic4316 ай бұрын
    • Oh wow thats a lot for a non native speaker :D but if i get you right we correct the gradients based on the assumption that we have somewhat mundane situations (air pressure=water pressure at the surface etc) and dont look at situations like venting water into the vacuum of space or something which would lead to valid extreme changes in gradient direction?@@mlisic431

      @user-wz8hj5fl4r@user-wz8hj5fl4r6 ай бұрын
    • @mlisic431 Ahh that's awesome, thank you for all of the information! I have a question if you wouldn't mind taking a look at it! I implemented a realistic ideal gas SPH with an adiabatic equation of state. So I can simulate thermodynamic things like adiabatic expansion; also it's not too hard to add conduction (Monaghan has a good lecture where he discusses that as well, Introduction to SPH by Monash Astro here on youtube). But I'm wondering how one would go about modeling a classic irreversible thermodynamic process: free expansion. I guess that I'll start by looking at the literature on explosions with SPH, but if you have any recommendations that would be fantastic!

      @physbuzz@physbuzz4 ай бұрын
    • hey. I've worked with thermal expansion only in liquids and made bad experience in terms of stability of wcsph. I'm lacking hands on experience with gas phase. In my case i replicated a benchmark proposed by russell et al. "Numerical simulation of laser Fusion additive manufacturing processes using the SPH method." 2018. That is 2D free surface delta-SPH. I reckon Test1 fits your purposes. My intuition tells me that for big expansions, adaptive smoothing length might be worth looking into, to maintain stability (dont forget to average smoothing length upon particle interaction to maintain symmetry). I didn't implement that at the time. Be mindful of kernel correction at the free surface. Make sure your pressure term registers empty particles as a vacuum (i'd have to investigate, but assymmetric pressure term doesnt work, pressure can't be centered around 0 (like Russell)) I hope that helps as a starting point

      @mlisic431@mlisic4314 ай бұрын
  • You have genuinely changed my life, your videos have been a landmark for my development as a programmer and also reaffirming my interest in game development. I started game development at first just through loving games, but you have a way of presenting game development that made me love it as much as a love games themselves. Keep doing it❤️

    @yoyobro98@yoyobro986 ай бұрын
  • Sebastian Lague: new video \0/ All programmers while watching: “This part of my life, this little part, is called happiness” Thank you.

    @felippemiguel6751@felippemiguel67516 ай бұрын
    • Well said.

      @critical_always@critical_always6 ай бұрын
    • That's beautiful :')

      @crakhaed@crakhaed6 ай бұрын
    • This relates harrrd

      @silvertakana3932@silvertakana39326 ай бұрын
    • That perfectly describes my perception of those videos

      @valeriynefedov5629@valeriynefedov56296 ай бұрын
    • That made me smile, as did the video. Thank you! 🙂

      @jeroencommandeur@jeroencommandeur6 ай бұрын
  • this guy can make the most complicated concepts digestible and he has a calming voice and amazing editing

    @darkstar76@darkstar766 ай бұрын
  • Fantastic to see the simulation and hearing about how you made it! I can't wait to see where you take this.

    @Skeffles@Skeffles5 ай бұрын
  • amazing man; way to go; I can't wait to see the future video; more videos on fluids are always welcome!

    @lucasf.v.n.4197@lucasf.v.n.41976 ай бұрын
  • I love how humble and determined he is.

    @waffles6132@waffles61326 ай бұрын
  • I've done some fluid mechincs lately, and was utterly shocked (positively, of course) when I saw how fluid like you got it to behave sheerly through trying to enforce incompressibility. Very impressive!

    @YitzharVered@YitzharVered6 ай бұрын
  • I’d love a video on how these animations are made. Beautiful.

    @Pavel10017@Pavel100176 ай бұрын
  • My handsome fellow youtuber, I subscribed in your channel because of some cool Blender rigging tutorials and... here we are, 8 years later and you still amazes me with your videos. You make programing a lot more fun, thank you

    @netomtoloko01@netomtoloko016 ай бұрын
  • The production value, education, and accessibility of Sebastian Lague’s videos is astounding. Keep up the great work! ❤

    @charliezard64@charliezard646 ай бұрын
  • I feel like "on the brink of pandemonium" describes many of your projects 😂. This was both technically interesting and beautiful, like so many things you make.

    @cognisent_@cognisent_6 ай бұрын
  • Absolutely amazing. One of the fastest three quarters of an hour I’ve experienced. I’m loving the iteration: from idea, to concept, to good enough, a bit of polish, and on to the next idea. I can’t wait till the next one!

    @pindab0ter@pindab0ter6 ай бұрын
  • So cool. Love the project and seeing your thought process throughout! Great job!

    @WelcomeToTheGooniverse@WelcomeToTheGooniverse6 ай бұрын
  • It's always a good day when you post a new video. As always the effort you put in and the amazing simple explanation of a complex topic is much appreciated so thank you a lot for everything. What a legend

    @Tomsbax@Tomsbax6 ай бұрын
    • Thank you! :)

      @SebastianLague@SebastianLague6 ай бұрын
  • Awesome video! I've been reading a lot on fluid simulation, mainly focusing on gases. The reason using the predicted position works is because either way, you're incurring some O(dt^2) error, but using the predicted position has an error which tends to slow down the particles, while the initial position tends to speed them up. Consider a particle sliding in a bowl. If you use the position at the start of a timestep, it'll be higher up the bowl and see a larger speeding-up force when it's sliding downhill, and when it's sliding uphill, it'll be lower down and see a weaker slowing-down force. So you end up consistently speeding up the particle. The opposite happens when you use the predicted position. And that's also why the simulations at 30:00 diverge - the smaller the timestep, the more similar the predicted/initial positions become, and the closer you are to the exact value. The most physically realistic solution is to use a higher-order integrator (e.g. RK4) so your error becomes O(dt^5) and small enough to neglect. Then apply some viscosity to achieve the damping you were previously getting from your O(dt^2) error. (There are also other "symplectic" integrators which are designed around conserving energy, which you can also get higher-order versions of.)

    @Hailfire08@Hailfire086 ай бұрын
    • By the way, I've been mainly reading about finite-volume codes. Unlike SPH, which deals with particles of fixed shape which overlap with each other, finite-volume codes generally do not overlap, and deal with volumes which store conserved quantities (mass, energy, momentum). They immediately conserve these quantities (since you only ever deal with them getting transferred from one cell to its neighbour). Incompressibility is unfortunately hard, but you can do it using something like a potential-vorticity treatment (where you use an iterative solver to impose incompressibility).

      @Hailfire08@Hailfire086 ай бұрын
    • That makes sense, thanks for the explanation!

      @SebastianLague@SebastianLague6 ай бұрын
    • Yes! I was looking for this comment. The true physics should be conservative in the absence of viscosity, so as the time step size decreases, your simulation will be less and less viscous. Fixing the lookahead value to a constant will greatly limit the accuracy of the simulation. If you want to prevent the explosion caused by the high density initial condition, you can instead use gradient descent on the initial condition to minimize the potential energy!

      @davidvargas7651@davidvargas76516 ай бұрын
    • Interesting. Would using "pos + (predictedpos - pos)/2" remove any error in this case? I imagine not, but maybe it could at least _reduce_ it (as compared to picking either extreme)?

      @feha92@feha926 ай бұрын
  • God I love these videos! Love seeing you go through the steps and explain your thinking. This was a blast watching, can't wait to see what you do next

    @viktordominguez@viktordominguez6 ай бұрын
  • I keep recommending this video to people on reddit - and then usually end up watching it again myself, because it's just so damn good. Thanks for the videos Mr Lague.

    @dav1dsm1th@dav1dsm1th2 ай бұрын
  • Fluid simulation is probably one of the holy grails of indie gamedev. Great work!

    @OldShatterham@OldShatterham6 ай бұрын
    • Unless your entire game revolves around the fluid simulation, you're not gonna be looking to implement one

      @1234macro@1234macro6 ай бұрын
  • A cool project could be building a unity museum where you could walk through and see/interact with all of your different coding adventures projects

    @Jejkobbb@Jejkobbb6 ай бұрын
    • they could all be on their own planets, from the solar system video

      @koolkdny@koolkdny6 ай бұрын
    • Since it's Lague doing these things and not Unity, he would need an SL logo, coding adventure or something specific.

      @curhob@curhob6 ай бұрын
  • It is so beautiful to see how you transform really simple implementation into wonderfully complex models that are really rich in details

    @finnheinemann3682@finnheinemann36826 ай бұрын
  • This was awesome! It is so inspiring and I want to build something like this myself now. I am really excited to see what you do next with this project! I can't wait to see your updates!

    @lucaseastman1877@lucaseastman18776 ай бұрын
  • For the boundaries, you could try getting WolframAlpha to calculate int_{-1}^{x} W(x,y,z) dx, which would give you the density if there was a uniform sea of particles on the other side of the wall

    @Hailfire08@Hailfire086 ай бұрын
    • yes or extend the particles beyond the boundary and only render those within

      @Ra99y@Ra99y6 ай бұрын
    • @@Ra99y This would make particles suddenly dissapear. An interesting tradeoff though.

      @thecasualparry7797@thecasualparry77976 ай бұрын
    • Or maybe just damp the velocities along the normals of the boundary surface? This paper might be helpful: "PIC/FLIP Fluid simulation using a block-optimized grid data structure", 2.5.7 Boundary conditions

      @opitopit2105@opitopit21056 ай бұрын
  • 47 minute Sebastian Lague video? Heck yeah! Love seeing these very charming and interesting programming projects you do. It's a lot of fun!

    @SpringySpring04@SpringySpring046 ай бұрын
  • Love your videos, your style of making them is so good. Waiting for part 2 already!

    @adixx328@adixx3286 ай бұрын
  • So inspiring! I'm so happy to found your work and that you share it with us!

    @harmoniac.design@harmoniac.design6 ай бұрын
  • First I must say this was an awesome video, thanks for making it. Now that I've released my new game on steam I have some more free time to do experiments and your video motivated me greatly. Happy to be a patreon, your content is always amazing.

    @mariandev@mariandev6 ай бұрын
    • Thank you, and congrats on the release! What is your game called?

      @SebastianLague@SebastianLague6 ай бұрын
    • @@SebastianLague Monos: The Endless Tower

      @mariandev@mariandev6 ай бұрын
    • @@mariandev Looks really nice! That's a cool idea to have the game take place along the outside of the tower :)

      @SebastianLague@SebastianLague6 ай бұрын
  • I work doing Computational Fluid Dynamics and this is just awesome. I just wish you'd talked a bit more about conservation of momentum, cause I feel it's one of the most important things for fluid simulations, given that conservation of mass is already accomplished by using a SPH. Otherwise, great work!!! I pretty much look forward to the next episode on fluid dynamics

    @charliemw333@charliemw3336 ай бұрын
    • I think it's so cool that vorticity came about naturally, but only after he added the speculative velocity update! I'm not entirely sure but I think that line helped satisfy the constant density part of navier Stokes? I'm not exactly sure but that is so fascinating

      @MayaPapaya497@MayaPapaya4976 ай бұрын
  • I recently have come across to this channel after the fluid simulation being recommended multiple times but I'm simply amazed by how skilled you are. You go on to the depth to show every piece of code and your mathematical explanations are remarkable. I'm pretty sure you can create a black hole simulation as well. That'd be fantastic😂

    @ramazandurmaz3012@ramazandurmaz30126 ай бұрын
  • I am in complete awe at this. This might just be the most informative video ever created on fluid simulation. Thank you immensely for sharing this with us.

    @rastyisanerd3686@rastyisanerd36863 ай бұрын
  • I find your videos really soothing and engaging. You raise the bar for what's considered high quality educational, yet entertaining content. You explain complicated concepts in simple terms, and turned boring and complicated papers into entertaining work of art, and you're too humble about it. I also love how you explain your thought process, what you tried, what did not work, and how you are equally in love with the journey as you are with the end result. I was watching this with my wife, who has about over a year of programming experience. She commented on how clean, readable and pleasant your code is, even though she did not know the language you're using (she did not know it was C#). When I explained that not only the simulation work is done in C#, but also all the graphs and animations are also done in Unity, she was blown away. I'm a Unity employee btw, and I have shared this video with other colleagues on internal Slack. Good reactions, and a few are already fans and familiar with your work. Thank you for a great video!

    @BrahimHadriche@BrahimHadriche6 ай бұрын
  • I really love coding adventures. They have long been my favorite series on youtube. I feel like this community views the world with a healthy sense of curiosity and wonder. In many ways I feel at home watching these.

    @LinuxBacon@LinuxBacon6 ай бұрын
  • Man I'd love to see how far you can bring this one! It looks amazing! So soothing aswell. Thanks

    @Siebeng@Siebeng6 ай бұрын
  • Always such high quality videos from you. I am looking forward to part 2.

    @Vajtosan@Vajtosan6 ай бұрын
  • That was absolutely fascinating to watch. The evolved behaviour that comes from such relatively “simple” rules coupled to mass computation is amazing to watch. Excellent explanation of your journey and fantastic visuals made this a riveting watch whilst I waited for my bread to bake. Well done 😊

    @squirrel@squirrel6 ай бұрын
  • That “clumping up against the boundaries” you noticed was actually the surface tension of the fluid as-is! Surface tension is an emergent property of fluids being simulated as individual particles, and is the reason you didn’t have to implement any special math to get those droplets. The tendrils you saw in the high-particle-count simulation were a result of extreme capillary forces dragging the fluid up!

    @codeconduit1576@codeconduit15766 ай бұрын
    • Capillary action is the result of inter-molecular forces which were not being simulated. In capillary action the walls of the container literally attract the fluid a small amount. The "tendrils" in the simulation were spray caused by extreme pressure (not capillary forces) forcing the fluid against the sides of the container, the only direction available was up, so it got sprayed up, like how covering the nozzle of a hose or tap increases the pressure of the water coming out, or how lowering a glass from your face too fast can cause the water to splash against the bottom of the glass and spray your face.

      @EdepolFox@EdepolFox6 ай бұрын
  • DAMN, do you simplify such complex iterations of getting to the point on such an overwhelming subject! I have to date not been ever as happy as now for a KZhead suggestion. And I am embarrassed to have not noticed you sooner. I shall Sub and Bell to hopefully never miss out again. Thank you so much for your contribution!

    @BlackDidThis@BlackDidThis6 ай бұрын
  • This video is incredible. The attention to detail is fascinating. The first time it behaved like a fluid I was impressed and would have stopped there, but Sebastian kept going. Looking forward to the sequel.

    @pierresouloumiac8630@pierresouloumiac86304 ай бұрын
  • It's a good day when Sebastian uploads.

    @whwahhdsh@whwahhdsh6 ай бұрын
  • I made something very like this for my final project at university, using spheres to represent fluid particles with variable density, the posibility of multiple fluids mixed together and sliders for variable gravity. I loved setting the gravity to nothing and watching my fluids float like they were on the space station

    @mattwhelan13@mattwhelan136 ай бұрын
  • A partnership between Sebastian League and AngeTheGreat is all that we need. Amazing video!

    @Themegalegendo@Themegalegendo6 ай бұрын
  • Fascinating and fabulous, as ever, Sebastian - thankyou!

    @GainesSteve@GainesSteve6 ай бұрын
  • It's kind of magical to see it start to look like a real physical thing, when you've seen the math evolve to that point.

    @4.0.4@4.0.46 ай бұрын
  • You are the best thing about youtube! I love the witty, not-taking-yourself-too-seriously narration and your voice is - as always - heavenly. My wife is not interested in math/programming at all but has commented many times saying you should read audiobooks for a living :) cheers and thanks as always!

    @ivovelo@ivovelo6 ай бұрын
  • Nice job! This is amazing, your research, the video editing... beautiful, really

    @doblajesimberbe1966@doblajesimberbe19666 ай бұрын
  • Phenomenal new video. Wow. Those little waves emerging in the last part was such a testament to how accurate it's getting!

    @GameDevBits@GameDevBits6 ай бұрын
  • Wait until Sebastian Lague reveals that he used all of his coding adventures to make an actual game

    @lejoueurfreetoplay@lejoueurfreetoplay6 ай бұрын
  • New coding adventure: Time to binge watch the whole series again!

    @shadowcrafter01@shadowcrafter016 ай бұрын
  • Hi, Huge respect for your work. I am doing right now my thesis in fluid dynamics. I have written already about all math basics. In your video I have not only visualisation but also you share with everyone how to creat code for it. During my studies I was writing the code for movement of the buoy on the waves. I spend lots of time to do it with supervision of my porfesor. I felt like a child id the fog. After your video I have comprehend all knowlege from my Naval Architect studies. Huge respect and thank you thousand times.

    @FreshJerz@FreshJerz2 ай бұрын
  • I can't explain with words the emotion that runs through me when watching your videos. They are truly fascinating and beautiful

    @GearsDatapacks@GearsDatapacks6 ай бұрын
  • Idea for rendering: You could try to implement the marching cubes algorithm to generate a mesh for it. Since you can already calculate the density at any point in space, this might be pretty straightforward. Marching Cubes is essentially used to approximate a boundary of some sort of single value field, like a density field!

    @dampfwatze@dampfwatze6 ай бұрын
    • He actually did a video on the marching cubes algorithm once

      @samuelthecamel@samuelthecamel6 ай бұрын
    • 46:38

      @theangry0077@theangry00776 ай бұрын
    • @@samuelthecamel that's probably part of why it was brought up

      @1e1001@1e10016 ай бұрын
    • Hmm, the same stuff he did for clouds (taking a noise-field and march cubes over it to generate a mesh) could surely be used for the water-rendering, yeah?

      @feha92@feha926 ай бұрын
    • ​@@theangry0077Raymarching and marching cubes aren't the same thing

      @Hexcede@Hexcede6 ай бұрын
  • The editing on this video is on another level!!! Great job Sebastian 👏

    @Abstract_Code@Abstract_Code6 ай бұрын
  • great work! rally nice video. you explain it excellently, and make it all really fun and entertaining. i think that a really funky idea would be to connect motion control to it all, so you can shake the entire liquid tank like a water bottle and see it react accordingly on your screen. it would also probably help testing if the liquid motion feels right. thanks for the video!

    @urari4244@urari42446 ай бұрын
  • Thank you for this incredible video and explanation. The subject of simulating fluids seems to be beautiful and filled with challenges : how it reacts to different solicitations, external pressure, etc.

    @matze8824@matze88246 ай бұрын
  • you're a literal coding code, every upload is just another mind boggling adventure

    @OrganicCitrus@OrganicCitrus6 ай бұрын
  • even though im currently sick, i still wanna watch sebastian lague, don't wanna miss his greatness, do i?

    @DigitalHandle@DigitalHandle6 ай бұрын
    • Same here....

      @Alex-lp6bg@Alex-lp6bg6 ай бұрын
    • Feeling rubbish too! We’ll get through it!

      @jackthehacker05@jackthehacker056 ай бұрын
    • Get well soon guys! ❤

      @forgettd@forgettd6 ай бұрын
  • ppl in the comments acting like this video wasn't a "coding adventure" and not some master at work showing off his craft or whatever, he is trying a new thing ppl shouldn't expect him to be insanely good first try.

    @Mr_Tophatt@Mr_Tophatt15 күн бұрын
  • crazy how i can watch you do every single step, hear you explain everything so simply and yet the end result feels like magic like the world is really just made up of math isnt it

    @podoke@podoke5 ай бұрын
  • When the particles settle down you can see multiple different hexagonal lattices forming, and I think that is really cool, because you see those in real life, if you look at galvanised steel those different shades are each their own lattice arrangement that are reflecting light slightly differently and they come from when the zinc coating was still a liquid, and formed those arrangements on the steel surface.

    @rojnx9@rojnx96 ай бұрын
  • Hey, physicist with experience in numerics here. First of all, great stuff! A few comments: Pretty sure the "prediction" part of the code is only helpful since it effectively makes the particles repel from their own future versions, which in essence means they experience a global damping force - this both explains why it "calms" the dynamics, by being the only mechanism for the system energy to lower (apart from the more realistic damping you added later), and possibly why it depends on the prediction timestep. I'd recommend just getting rid of this and using only the more realistic damping, unless that doesn't work. Also, did you try using some other spatial partitions, such as KDTrees? They might be better, though honestly I doubt it. Another neat option would be to instead of calculating the actual average quantities per particle, calculate a rough scale approximation for the average quantities per cell, and use that for approximating the effects of any far away particles (say, those further that R/3 or so) - this is similar to the Fast multipole method, though for such local interactions which decay quickly it again might just be wasteful. Oh, and, maybe try some symplectic integration schemes, such as Verlet or even something better (note that even though you have damping forces, which make your system non-Hamiltonian, you could just plug the force directly instead of dV/dq and get nice results) - I didn't mess around with these much, but I've seen claims they greatly improve long term stability for integration (i.e. better conserve energy for the same amount of compute). Oh, and for the boundary, at least against walls you could treat each wall like a really long and flat particle, manually adding a set density from them to the local density estimate. I don't know how to treat the free boundary "collapsing" though, maybe messing around with the near-repulsion term a little?

    @Rotem_S@Rotem_S6 ай бұрын
    • on the KDTrees part, i believe he made a small footnote that he might experiment with them which means he likely didnt attempt it, i dunno though, might just be hallucinating

      @dylanherrera5395@dylanherrera53956 ай бұрын
    • The "prediction" part of the code is actually analogous to the backward Euler method, ie. a more stable numerical integration scheme with less truncation error per step. It would probably be even more stable to use the Heun method (use the average between the current and the extrapolated position), though that would increase the frame time... ((in the specific example in the video, the backward Euler method has the advantage of underestimating the total kinetic energy, while the normal Euler method overestimates it. So if starting off with particles under really high pressure, any kind of energy underestimation probably helps... Simply making the initial packing less dense would be the most elegant solution tho)) Dampening might mask the integration error, but for a realistic simulation it still shouldn't be ignored. I don't have any practical experience with symplectic integrators, but I'd assume them to be relatively costly computationally, and since we have a dissipative system, they might not actually be much better then Heun/RK4 integration in practice. The density interpretation doesn't really help my intuition, but I'd guess the reason for the isolated surface layer/tendrils is energetic - ie. surfaces are energetically favorable compared to bulk states at low pressure (or at least a local optimum reinforced by the gravity induced flatness of the surface). I'm really curious whether sufficiently low gravity would cause a 2nd isolated layer to form, or perhaps even dissolve the existing one? I'd also guess it would be the attractive term, not the near-repulsive one, which is the primary cause of tendril formation in this simulation. btw, 13:44 shows really nice surface formation in the middle while in zero-G. So getting the gas to form droplets instead of surfaces (minimize surface area, instead of maximizing it) by tweaking the terms definitely seems to be the way to go to prevent tendril formation.

      @sh4dow666@sh4dow6666 ай бұрын
    • Games aren't like engineering fluid dynamics so I disagree about the prediction part. The state of the art for real time fluids is actually to get rid of SPH, leaving only the density computation, and instead solve the particles via constraints via newton's method. Of course with newton's method you'll make an even more crude prediction and then adjust multiple times per time step, which leads to even worse global damping (solved via introducing aritifical constraints) Yes, this is nothing like what a physcists would do, but this is computer graphics, not physics. The position based constraints give nearly identical visuals but performs much better for a wider range of time steps, and is less susceptible to tensile instability.

      @Kuroten01@Kuroten016 ай бұрын
    • @@sh4dow666 I'm making my own video, but it will have all the steps: simulating, rendering, external object interaction, and control (turning water into the shape of meshes and animating them). The integrator isn't the issue here imo. The real issue is the way the simulation is being solved via SPH, when it's more efficient and stable to solve via density constraints alone. Which is pretty obvious during the video once he runs into incompressibility issues (common flaw of standard SPH).

      @Kuroten01@Kuroten016 ай бұрын
    • @@Kuroten01The question is whether this is primarily supposed to be a physical or graphical fluid simulation :)

      @sh4dow666@sh4dow6666 ай бұрын
  • I've been trying to figure this out for an app I am working on. I love that you released this and explained everything. Thank you!

    @melodicwuitartree@melodicwuitartree6 ай бұрын
  • Really enjoyed this video. As a senior artist in effects i understood most of it - but it was still very illuminating on the procedures and math you needed to implement. Thanks for sharing.

    @oblongowl@oblongowl6 ай бұрын
  • Yes!! Was waiting for this one after I had watched Acerola video about ocean simulation and wondered how this fluid simulation project of yours is doing (since you mentioned it back in the AI game challenge). Question answered

    @toara@toara6 ай бұрын
  • I'm a simple gal. I see a new Coding Adventure, I click. Love these.

    @OutbackCatgirl@OutbackCatgirl6 ай бұрын
  • This reminds me of a game I had on my phone years ago, where it was basically the same 2 dimensional fluid but you could only pick up the fluid. Great video

    @lukef8978@lukef89784 ай бұрын
  • My MSC project back in 1990 was simulating forces in a 3D surface using the Inmos Transputer chip (actually a set of five of them, one controller and four workers). It used a very trivial averaging formula (vertical velocity of cell in next generation is the average of the height differences to its neighbours). It ended up looking quite pretty. After handing the project in, I've barely done anything with computer graphics, sadly. The point of the project was to demonstrate the power of parallelism and message passing rather than accurately model reality. But your adventure is next level and has got me thinking about downloading a games library for Python and reimplementing my MSc project, then moving onto yours. Thanks for the inspiration.

    @robbybobbyhobbies@robbybobbyhobbies6 ай бұрын
KZhead