Realtime 2D Gravity Simulation

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ม.ค. 2025

ความคิดเห็น • 955

  • @dialog_box
    @dialog_box ปีที่แล้ว +452

    aw man, it's unfortunate how much the youtube compression seems to dislike these kinds of visuals. i bet it's absolutely gorgeous when viewed directly in-engine. still incredibly cool! i always love projects like these

    • @monx
      @monx ปีที่แล้ว +15

      it seems there might have been some issue in the export format (it looks interlaced). usually the HD transcode looks pretty good.

    • @shavoshaco2402
      @shavoshaco2402 11 หลายเดือนก่อน +3

      Probably cause its a very fast moving color gradient, so it has trouble comoressing it accurately due to being fast moving increasing the amount of pixels it has to change, and a color gradient which has a range of colors in which they change slowly making a large range of colors to compress too.
      What I mean to say its inaccurate due to the nsture of the video I guess, ir maybe its just a compression algorithm that favors performance over looks

    • @rocheuro
      @rocheuro 10 หลายเดือนก่อน +2

      upload 4k60fps yt compression should not be the issue than.

    • @Monkeymario.
      @Monkeymario. 5 หลายเดือนก่อน +2

      @@rocheuroOr in easier to understand terms: "If you upload a video in 4k then the compression won't be as bad".

  • @Polygarden
    @Polygarden 2 ปีที่แล้ว +1501

    It's fascinating how they form the exact same shapes as our galaxies... it's the stuff you would normally do in a super computer. Beautiful work!

    • @nullifier_
      @nullifier_ 2 ปีที่แล้ว +97

      I wouldn't say exact shape of actual galaxies, but it's fascinating to see the simulation nonetheless

    • @chocoatemilk9227
      @chocoatemilk9227 2 ปีที่แล้ว +77

      @@nullifier_ from a gravitational standpoint i would say it really behaves as a galaxy like at 11:15

    • @ldvrrn8269
      @ldvrrn8269 2 ปีที่แล้ว +8

      I could agree more

    • @EccentricTuber
      @EccentricTuber 2 ปีที่แล้ว +58

      @@chocoatemilk9227 Well, the thing with real galaxies, is that at a certain point the acceleration due to gravity starts dropping off at 1/r instead of 1/r^2. This means that gravity doesn't appear to weaken (in galaxies) as much as it should, making galaxies more stable and spin faster at outer orbits. It's actually not understood why this happens, and is one of the reasons why physicists conjecture dark matter or modifications to gravity! I'd recommend reading about Modified Newtonian Dynamics (MOND), because it's super fascinating.

    • @skinnymayo
      @skinnymayo 2 ปีที่แล้ว +1

      I agree

  • @ibrozdemir
    @ibrozdemir 3 ปีที่แล้ว +817

    feels so natural, i felt like a timeless being, wathcing universe in fastforward.. good job optimising it, its a hard work

    • @mrgoodpeople
      @mrgoodpeople 2 ปีที่แล้ว +5

      It's 2D. 2D it's not natural =). Don't exist super flat object in the Universe. Galaxy thickness is 5-10% of its diameter.

    • @pilchu7978
      @pilchu7978 2 ปีที่แล้ว +4

      But still when you look from the side there can be illusion of 2D, some people still think the planets are discs not spheres so for visualization it is an amazing simulation!

    • @tiagogamer2540
      @tiagogamer2540 2 ปีที่แล้ว +27

      @@mrgoodpeople Yes, but vision is pretty much 2D (The depth approx the brain uses does not count for an extra D in my book. Motive: 3D vision would see inside closed boxes, we cannot. If disagreement enumerate whys.)

    • @ege8240
      @ege8240 2 ปีที่แล้ว +3

      @@mrgoodpeople a timeless being would have organic body, that means their vision would be diffrent than anything we can imagine

    • @quistador7
      @quistador7 2 ปีที่แล้ว +1

      This really helped me make sense of elliptical galaxies. The smaller ones with structure are just so cool and my brain had a hard time understanding why a white blob is way bigger.

  • @kanerogers7717
    @kanerogers7717 3 ปีที่แล้ว +144

    This looks absolutely amazing, Brendan!

  • @anykeyh
    @anykeyh 2 ปีที่แล้ว +572

    If I may, you should instead use integral sum (I) of the weight of all particles at any given points into a Float32 buffer, then you can compute easily the total sum of any given area (x1, y1, x2, y2) which equals to I(x2, y2) - I(x1, y1).
    Less memory usage, and faster resolution, no "absolute borders" as described in your video. Still an approximation, but I think you would get better results and performance.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +195

      Great tip thanks!! I’ll give that a shot when I come back to this project

    • @_ramar
      @_ramar 2 ปีที่แล้ว +20

      i wonder how large simulations with noticeable floating point precision would look, that'd be super cool to look into how weird it'd be, i wonder if it'd look more structured or chaotic

    • @slimeball3209
      @slimeball3209 2 ปีที่แล้ว +15

      @@_ramar look at "far lands" in minecraft, or border box of universe in space engine.
      you can't really imagine this, it's too large to be noticeable in any way for 32 or 64 bit numbers
      but for smaller bits is like graphics in old playstation, like vertex of model is jumping from voxel to voxel, and all mesh of the model is jittering.

    • @WeShallBeFreeAtLast
      @WeShallBeFreeAtLast 2 ปีที่แล้ว +7

      Replying just so I can save a reference to this comment. Been working on a small project as of late and I'm looking for any methods to increase the size of the simulation I can run.

    • @dertyp3463
      @dertyp3463 ปีที่แล้ว +6

      so she lied, when she said "size doesn't matter"? :(

  • @masela01
    @masela01 2 ปีที่แล้ว +103

    I love the way they merge into bigger objects in a way

    • @memor22
      @memor22 ปีที่แล้ว +4

      Yep thats how… our world works

    • @masela01
      @masela01 ปีที่แล้ว +8

      @@memor22 yeah and it's pretty cool how this emulates that

  • @openroomxyz
    @openroomxyz 2 ปีที่แล้ว +93

    I must admit that this did even more inspire me to learn Vulkan and related things.

  • @mamadshonazaramonov3010
    @mamadshonazaramonov3010 2 ปีที่แล้ว +18

    I am almost feeling the gravitational waves from those massive clumps hitting each other! So cool!

  • @pikatheminecrafter
    @pikatheminecrafter ปีที่แล้ว +3

    This could be made more interesting with two additions. One, some particles are around ten times heavier and rarer than the other, and two, the heavier particles tend to stick together with an additional force, making them "solid". Gravity and collision forces could break "solid" objects, but they may eventually stick together again. In a cloud of particles that rotates sufficiently quickly, some of these particles of "solid" would eventually form "solid planets" as they fall towards the "star" and the "solid" accumulates, while the lighter "gas", not attracted as much by the "star" as the "solid", stays further out, eventually creating "gas planets".
    A further extension could be a proper implementation of the electromagnetic force. This causes particles to repel each other at a short range. This would mostly apply to "gas" particles. Though it would make it more difficult for "solid" particles to combine, "solid" particles still have this force that sticks them together (which is still the EM force in real life). Perhaps they could be combined somehow? Also, have it such that that "gas" (or any such particle), when sufficiently compressed that two particles overlap, merges the particles into a heavier one, which in turn exerts a force counteracting gravity on nearby particles. More massive particles require more force to combine. This would allow for "stellar fusion", making "stars" puff out. Additionally, it could be balanced such that once a single particle gets to sufficient mass, the gravitational influence it has on nearby particles by itself is enough to cause this "fusion", regardless of pressure, so it can collapse infinitely, creating a "black hole".

  • @tomfoolery5680
    @tomfoolery5680 8 หลายเดือนก่อน +9

    The 3 billion body problem.

  • @bottlekruiser
    @bottlekruiser 3 ปีที่แล้ว +50

    Gotta admit, i watched most of the vid with the corner of my eye, like i usually do... Until the shot at 7:30ish just *stunned* me. Amazingly beautiful. There's just that **something** captivating in it.

    • @DescendDab
      @DescendDab ปีที่แล้ว +1

      Thanks so much for the timestamp, this shot is incredible! Sure, it might not be 100% realistic (which probably is impossible at the moment anyways) but it felt like galaxies forming due to gravity. Love it!

    • @bottlekruiser
      @bottlekruiser ปีที่แล้ว

      >which is probably impossible at the moment anyway
      Depending on how strict your definition of "impossible" is, it's either never possible in simulation, or already routinely occasionally done in high end astrophysics sims.
      You're welcome! :D

  • @ldvrrn8269
    @ldvrrn8269 2 ปีที่แล้ว +7

    It’s beautiful to watch and it makes me feel very timeless like a timeless being witnessing something we are all supposed to see.

  • @kodirovsshik
    @kodirovsshik 3 ปีที่แล้ว +19

    I don't know when and how I found this channel, but what I know for sure is that I really like it

  • @DoubtX
    @DoubtX 2 ปีที่แล้ว +130

    It looked like a spiral galaxy wanted to form at a few points but it never lasted. I don't know why spiral galaxies form in the first place, but it would be really cool to see it occur in a simulation.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +67

      Ya I think one problem to this approach is due to the grid and how I’m calculating forces, energy is lost over time. So the spirals are losing energy too quickly and dissipate.

    • @almicc
      @almicc 2 ปีที่แล้ว +33

      if you want the scientific reasoning, it's that galaxies contain much more mass than the sum of the mass that's visible, allowing larger and more complex structures to form despite it not being possible with only what's visible. look up "dark matter"

    • @DFPercush
      @DFPercush 2 ปีที่แล้ว +6

      I think it has to do with the fact that the orbits of stars around the galactic center isn't perfectly circular. There's some eccentricity to the orbit. So when a star is at its apoapsis, the farthest point from the center, it's moving slower. So you get clumps of stars that slow down and get closer together, and those are the arms. Something like that anyway.

    • @tonywells6990
      @tonywells6990 2 ปีที่แล้ว +14

      @@almicc You can say that the particles in this simulation naturally act like dark matter already since they only interact through gravitation.

    • @20ZZ20
      @20ZZ20 2 ปีที่แล้ว +8

      @@tonywells6990 in which case spiral galaxies won't form, as dark matter forms halos rather than the visible spiral galaxies we see. which looks more like what can be seen at the end of the formation, or a massive eliptical galaxy at least.
      more than just gravity would be needed to simulate actual galaxy formations. in this simulation it is like the entire universe eventually devolves into one huge blob. that might happen if the universe were fixed like this simulation, but in reality the expansion of the universe would have a factor on large scales. something that i doubt could be easily simulated at home! this would allow separate clusters to form perhaps.
      some kind of physical interaction between particles rather than just gravity would also be needed for spiral galaxies to form in a realistic way.

  • @brandonver-non7573
    @brandonver-non7573 ปีที่แล้ว +3

    This was mathematically interesting, visually stunning, and one heck of a side project. Well done!

  • @storm14k
    @storm14k 2 ปีที่แล้ว +5

    Whenever I hear about the big physics simulations done on matter I think about doing something like this myself just to explore the difficulties involved with scale. This is very neat! Thank you.

  • @SMGJohn
    @SMGJohn 2 ปีที่แล้ว +3

    Even a super basic simulation like this you can see the laws of the universe working as expected.

  • @embergamedev
    @embergamedev 2 ปีที่แล้ว +1

    This was a wild watch. So beautiful and I can't imagine the satisfaction of being able to say you built it yourself. I love coding anything with simulations or large amounts of data and visualizing it. This was fun, thanks for sharing!

  • @sammchenry738
    @sammchenry738 2 ปีที่แล้ว +5

    Best video explaining how spiral galaxies form, and its not even about that. Amazing work!

  • @TheBourbonWrench
    @TheBourbonWrench 2 ปีที่แล้ว

    I didn’t understand a single word. Yet here I am, still having some sort of existential crisis seeing how your mathematics and thought process come to life into something I can visually grasp. Stunning video.
    Also super intriguing how many people in the comments seem to actually know exactly what you described in the beginning of the video, and it blows my mind to see people actually give you tips and critique you work. It just shows me how absolutely lame and boring my brain is.

  • @_general_error
    @_general_error 3 ปีที่แล้ว +61

    You could use a quadtree (or octree if you want to go 3-dimensional), which may increase precision and speed though hurt implementation simplicity. Not yet sure, what clustering method would work best, especially on GPU. Another optimization would be to use a different time step for each particle and simply not update each particle at each step. I am just looking into similar O(N log N) or better N-body simulations, but not quite on this level, only star system scale simulations, where you have up to a million small bodies and a handful of large bodies.

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +32

      Different time step per particle: That’s an interesting idea that I didn’t consider! I’ll keep that in mind when I come back to this. I also should probably do some performance testing to find out which steps are the bottle neck.

    • @avatharbehemoth
      @avatharbehemoth 3 ปีที่แล้ว +1

      @@BrendanGalea it could work out great, or turn into something really strange.
      Probably doing the lower level of detail comparison for all grids and then only checking if a particle is likely to go to another gridarea, and then doing the individual particles in groups/ timesteps if they are likely to leave the gridarea?

    • @PuzzledMonkey
      @PuzzledMonkey 2 ปีที่แล้ว +2

      A quadtree or Oct tree is a key component of the fast multiple method.
      Edit: fast multiPOLE method

    • @fishercawkey
      @fishercawkey ปีที่แล้ว

      @@PuzzledMonkey Did you mean "fast *multipole* method?" Just asking because I've been reading about fluid dynamics simulations and FMM has come up a number of times.

    • @PuzzledMonkey
      @PuzzledMonkey ปีที่แล้ว +1

      @@fishercawkey yes, my autocorrect isn't numerical analysis literate.

  • @Inderastein
    @Inderastein 2 ปีที่แล้ว +2

    I love how the more particles you add, the more it's outer rings gets pulled faster into the center
    as if the center has an absolutely strong gravity despite it being only a group of particles
    ngl it feels so accurate

  • @hubismal
    @hubismal 3 ปีที่แล้ว +56

    Janice, please cancel my 3:00 with the President of the United States... brendan galea just uploaded

  • @MacElMasMancoDeTodos
    @MacElMasMancoDeTodos 2 ปีที่แล้ว +1

    This is simply amazing. The simplest way to show how the complex Universe works.
    As explaining to the orbit problem, an orbit is the horizontal momentum needed to fall to the central gravity point passing always above the object's horizon, making a circle-like trajectory around it. If a particle weights, as example, 1, even a gravity center of 1000 is still way to less to make an stable easy orbit. If you make a larger obj, it should work better, but the orbiter will end ripping particles apart from the center. You could fix it with larger (and heavier) particles, both as center or to attach one to another and make big compact stuff. Great job anyway and please develop this further, it's incredible :D

  • @lukewellcash
    @lukewellcash 2 ปีที่แล้ว +16

    Instead of summing just the mass in each grid cell, average the position as well and store it in a 3 float texture. Expanding this in the same way done in this video would give a method that should be 100% accurate and one that grows in complexity at the same rate as the one you displayed. The only draw back is that it would be a bit slower (just because it is having to do more). Very nice project!! Well done.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +3

      Great suggestion, definitely going to attempt this for version 2!!

    • @busy_beaver
      @busy_beaver 2 ปีที่แล้ว +1

      This is a good improvement that I also thought of. But it won't be 100% accurate.

    • @dhowitzer
      @dhowitzer ปีที่แล้ว

      @@busy_beaver I thought the same thing, I agree that it may not be perfect. I remember learning in early physics that the earth's gravity can be "accurately" modeled as a point mass at the center of the earth but to the extent there are variances like mountains then the field 'fluctuates' a bit. i wonder how close of an approximation it would be at a distance. you'd certainly account for all the mass that way.

    • @andrewferguson6901
      @andrewferguson6901 ปีที่แล้ว

      ​@busy_beaver it's a digital system. That must be the case. It can only be accurate to an arbitrarily fine precision

    • @Sporkabyte
      @Sporkabyte ปีที่แล้ว

      ​@@dhowitzerThis is true if you take the center to be the average position of all of the point masses. If you use the center of mass instead, then it's not an approximation anymore, it's just true

  • @luizfabiano4334
    @luizfabiano4334 6 หลายเดือนก่อน +1

    Every few months I make sure to come here to rewatch this video

  • @tunneloflight
    @tunneloflight 2 ปีที่แล้ว +37

    By using a gridded version of space, you will always create artifacts. Your pseudo-random jitter is an interesting approach to overcoming this inherent limitation.

  • @bennomomsen5554
    @bennomomsen5554 2 ปีที่แล้ว +49

    You have a good understanding of the problems you are facing here for massive particle based simulations. Getting up to speed with methods developed in the last 50 years in this area would benefit you a lot. I'd recommend a book like Hockney/Eastwood - Computer Simulations using Particles. Also you can always check GPU implemented particle simulators like HOOMD - I guess you could actually do the same simulation with that open-source software and it'd be interesting to see the differences.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +2

      Looks like a good read, thanks for the suggestion! Kind of expensive book though 😅 but am considering getting it

    • @matthewzimmers1097
      @matthewzimmers1097 2 ปีที่แล้ว +2

      @@BrendanGalea trust the guy

    • @lordpengz16
      @lordpengz16 2 ปีที่แล้ว +1

      @@BrendanGalea Hello, I’d like to ask what software you used to simulate this and to program it. And what is Vulkan for exactly? Thanks in advance

  • @ChiaraWatson
    @ChiaraWatson 2 ปีที่แล้ว +3

    Please make a couple hour long relaxing video with this. I totally can myself going to sleep with it. So mesmerizing.

  • @piroDYMSUS
    @piroDYMSUS ปีที่แล้ว +1

    Man, youtube compression algorithms really don’t do justice for this beautiful images.

  • @danielquedenfeld2052
    @danielquedenfeld2052 2 ปีที่แล้ว +12

    You could probably get some emergent behavior if you added an additional force, like EM interactions, give each particle a random starting charge
    I picked EM because I feel like it’s the most applicable to this simulation, and it also counterbalances gravity with repulsive effects, plus the grid system would work really well for summing localized charges I think

    • @krccmsitp2884
      @krccmsitp2884 2 ปีที่แล้ว

      What does EM stand for?

    • @danielquedenfeld2052
      @danielquedenfeld2052 2 ปีที่แล้ว +2

      @@krccmsitp2884 electromagnetism
      So particles would attract repel based on their charges

  • @akiyamach
    @akiyamach 2 ปีที่แล้ว

    "So that's why there's black holes in the middle of galaxies" was my thought when seeing that accumulation in the middle of every simulation.

  • @briandel8446
    @briandel8446 3 ปีที่แล้ว +7

    this was an amazing video! you just inspired my to work on a new project and test expiriment with something similair.

  • @sessionvideomag
    @sessionvideomag 2 ปีที่แล้ว +1

    This caused an optical illusion, as soon as i turned the fullscreen off, my screen was deforming in a spiral shape
    Amazing job!!

  • @christianalejandro4963
    @christianalejandro4963 3 ปีที่แล้ว +5

    Great work! Beautiful and inspiring! Congrats!

  • @ddopson
    @ddopson ปีที่แล้ว +1

    I really enjoyed your description of the algorithms. It reminds me a little bit of K-Means clustering, which likes to be O(N^2) for approximately the same reasons, and is a problem that I've spent a fair bit of time working on at scale. Hope you get a chance to come back to these algorithms and push them even further. Your description of the work is excellent.

  • @GamingDemiurge
    @GamingDemiurge 2 ปีที่แล้ว +7

    Absolutely fantastic. Bravo.

  • @uncommonsense360
    @uncommonsense360 2 ปีที่แล้ว

    you know the sims gonna be good when the author has a lisp. Chefs kiss to those algs and Comp concepts.

  • @DavidStruveDesigns
    @DavidStruveDesigns 2 ปีที่แล้ว +10

    What I find the most amazing about this entire simulation - other than absolutely _everything_ about it lol - is the fact that, even though this simulation is happening on a completely 2d flat plane (at least I _think_ it is??), it somehow manages to _look_ three dimensional. Kind of lends creedence to the theory that our entire Universe _also_ exists on a flat plane, doesn't it? :) Amazing work I have to say!!

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +5

      Thanks! Ya I was surprised how nice the 2D version ended up looking. I still want to give a 3D version a shot though!

    • @gamertardguardian1299
      @gamertardguardian1299 2 ปีที่แล้ว +1

      Maybe we are just one big petri dish, or, a not so big petri dish for the aliens who are messing with their particles for science lol

  • @nathanfredette
    @nathanfredette 11 หลายเดือนก่อน

    I think adding a magnetism approximation and particles with differing interactability to the simulation would increase its similarity to stellar phenomenon even further, love it!

  • @vsevolodnedora7779
    @vsevolodnedora7779 2 ปีที่แล้ว +5

    Beautiful work. Very inspiring. Coming from the field of numerical relativity and finite volume hydrodynamics, I recommend using adaptive mesh refinement, i.e., the resolution of a given patch of space depends on the number of particles there.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +2

      Thanks for the tip! I'll definitely need to look into that

  • @kevnar
    @kevnar 2 ปีที่แล้ว +2

    Quadtree + Flowfield = bliss

  • @leroywalton4348
    @leroywalton4348 3 ปีที่แล้ว +7

    technically jaw dropping !

  • @Choiis
    @Choiis ปีที่แล้ว

    7:17, The most beautiful simulation i have ever seen on how single dust particles inevetebly clumps to larger bodys. (Even if the early forces aint depending on gravity the outcome is the same). I loved it!

  • @dr_j0nes
    @dr_j0nes 3 ปีที่แล้ว +8

    OMG this is just stunning!!!!!!!

  • @statelyelms
    @statelyelms ปีที่แล้ว +1

    There were many times watching this where I forgot it was 2d and thought I was watching 3d objects spin and rotate and warp. Incredible work

  • @user-es6wn6pz3e
    @user-es6wn6pz3e 5 หลายเดือนก่อน +3

    Dude, sick video! I watched it like a year ago, and since I've been getting into compute shaders and stuff for the past year, I was inspired to try myself. For the first one, I tried doing regular parallelized incrementing, which got me about 50 000 particles at 60 fps. Then, I tried with a version of what you did, where each particle compares itself to a lower resolution texture which represents densities in larger areas, and that got about 1 000 000 particles at 60 fps, but it was a bit inaccurate since I learned you can't reliably increment (texture[xy] += 1) on the GPU, which is obvious in hindsight. So then I did exactly the same method you did in this video, and I just gotta ask, why did you stop at 4 mill? On mine, I was able to get 200 million before even dropping below 60 fps. 4 mill got about 140 fps, and the only thing that prevents me from running more than 260 million is the CPU cache size. This was using a few compute shaders in unity. Still, great video and great execution of the simulation, I'm just genuinely curious why you didn't do more particles.

    • @BrendanGalea
      @BrendanGalea  5 หลายเดือนก่อน +1

      Oh wow that’s amazing!! Maybe my implementation was not as good as yours, or worse hardware, the computer I was running this on is only a gtx 970. I was very curious to know what it would run like on better hardware but even on something modern I don’t know if what I wrote would be capable of 200 million! Other reason is I implemented things in fragment shaders rather than compute shaders which probably isn’t as efficient

    • @user-es6wn6pz3e
      @user-es6wn6pz3e 5 หลายเดือนก่อน +1

      @@BrendanGalea Oh wow, in a fragment shader? I'm not even sure how you'd do that in a fragment shader, that's impressive. I'm probably doing quite a few things that were literally impossible to you then. One thing I think is saving a lot in time, is that I'm going through all the particles, and just putting their position directly on a 16K texture as a white dot, then to get the 2K texture, I just add together 8x8 chunks of the 16K texture, then for 0.5K texture, I do 4x4 chunks of the 2K, and so on. That way I can get the chunk data very quickly, only incrementing each particle once. Then, when I'm comparing the chunks, I just put the delta V directly into the g and b channels of the chunk textures, and go through the particles again to apply it, so it's only going through each particle twice to do everything it needs to do. I don't think stuff like this is possible at all in a fragment shader, but I think it saves a lot of time. I'm on a 3060 though, which is probably a pretty big factor too. If you haven't learned compute shaders yet, btw, I highly recommend. They're actually very intuitive, and feel much more modern than fragment/vertex shaders. They just sound scary.

  • @Monkeymario.
    @Monkeymario. 5 หลายเดือนก่อน +1

    1:07 THE BITRATE

  • @igorastral4816
    @igorastral4816 2 ปีที่แล้ว +5

    NASA, are you watching this??

  • @uumatter_0106
    @uumatter_0106 ปีที่แล้ว

    Not only does it form galaxy shapes, but the inward collapse in the beginning looks like a big bang

  • @user-du9ch3tn2v
    @user-du9ch3tn2v 3 ปีที่แล้ว +21

    I don't know a thing but what if you view this as a cheap algorithm and us the traditional or an other exact method for calculating check steps every minute or so. This could help to reduce errors if you use this guide data to reduce the errors in your simulation. And also thank you for this amazing videos. The showcase in this was like a scene from interstellar:]

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +4

      Glad you like it! Ya that’s pretty similar to an idea I had. You could do a more accurate simulation offline and use it to train this cheaper algorithm by optimizing the kernel weights and some other features!

  • @justaplayermsk
    @justaplayermsk 11 หลายเดือนก่อน

    can't wait to watch 3D version of this
    P.S.: i absolutely stunned by this, insane work!

  • @MartinMizner
    @MartinMizner 2 ปีที่แล้ว +14

    Nice project. I tried to simulate 2D gravity in Python, but it was inefficient and maximum was 200 particles before the frame rate dropped under 5 fps.
    I also tried to implement particle joining so they would create planets and stars.
    Good to know I wasn't the only one to have the same troubles.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +7

      Particle joining is a really cool idea!
      I've run into similar issues when I've done particle simulations in the past. Could never get enough particles before performance became an issue. One of the reasons I ended up learning c++ and vulkan, because it doesn't really get faster than that. But it can be a bit of a pain to program...

  • @WesleiMB
    @WesleiMB 2 ปีที่แล้ว +1

    this is the coolest thing I have saw today !

  • @jojodi
    @jojodi 3 ปีที่แล้ว +5

    Beautiful results and explanation :) The earlier suggestion to explore trees is a well-known approach called Barnes-Hut trees. Have you tried this?
    I have written simulations like this several times but have always been interested by the idea of simulating gravitational bodies without any particles, just as continuous mass and velocity on a grid. Haven't derived the equations yet though.

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +4

      Thank you!!
      Some viewers provided some great articles on that topic (for example observablehq.com/@rreusser/2d-n-body-gravity-with-poissons-equation?collection=@rreusser/writeups)
      but I've never tried something like that myself yet. I've some past experience working with cpu-based particle fluid solvers, and originally when I started on this that was more the direction I was going to try. But then I got side tracked a bit by this idea for gravity.
      The no particle method you mention kind of reminds me of something like Stam - stable fluids: d2f99xq7vri1nk.cloudfront.net/legacy_app_files/pdf/ns.pdf
      That method probably could be extended with a multi-LOD approach to do a particle-less gravity simulation. That sounds like it would be something really interesting :)

  • @pyroblasted
    @pyroblasted 2 ปีที่แล้ว +1

    I have no words... this is amazing!

  • @WaveofThought
    @WaveofThought 2 ปีที่แล้ว +4

    Cool simulation. I tried to do something similar once, albeit with fewer particles, and I came across something called the Barnes-Hut algorithm for n-body simulations. This seems similar to your LoD approach but might be more robust, although I don't know if you could still make effective use of the GPU. Anyway, something to look into if you ever return to this project. Cheers!

  • @MateHomolya
    @MateHomolya 2 ปีที่แล้ว +2

    Very impressive work! Excellent idea of using multiple LODs to account for local and global effects. Thanks for sharing. ❤

    • @MateHomolya
      @MateHomolya 2 ปีที่แล้ว

      It looks like a physics simulation of galaxy filament formation they run on supercomputers.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +1

      Thank you!!

  • @DaminGamerMC
    @DaminGamerMC 3 ปีที่แล้ว +6

    youtube decompressi kills it. Would you consider uploding the code or executable for us to look a this and hiow you did it?

    • @dr_j0nes
      @dr_j0nes 3 ปีที่แล้ว +2

      Source code would be amazing 😍

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +6

      ya, it really does unfortunately :(
      The code is a bit of a mess right now, so I don't really want to share it yet. I'm going to be cleaning it up and putting it in the tutorial series over the course of the next couple months.
      The raw/messy code I'm thinking of sharing as a possible patreon bonus if I end up making one of those.

    • @Sam-nt8nk
      @Sam-nt8nk 3 ปีที่แล้ว +2

      @@BrendanGalea I have never subscribed to a Patreon before, but if you made one, it would be the first.

  • @michaelc.4321
    @michaelc.4321 ปีที่แล้ว +1

    Here’s a suggestion from physics. Because of the similarity between the form of electromagnetism and gravity, you can pretty much directly turn this into a PDE with velocity fields and then just numerically integrate to get particle behavior. You can do this by acknowledging:
    del2(φ)= kρ
    g=-del(φ)
    dρ/dt=-div(v)
    Where φ is gravitational potential, ρ is mass density, v is the velocity, and g is the gravitational field strength.
    You can brute force calculate the initial conditions of the potential from the particles pretty easily which is the most computationally expensive part. Additionally, you can just outright solve the poisson equation given some boundary conditions to start the simulation. From there, it’s possible to approximately evaluate each step by adjusting the potential in accordance with the mass density and computing how the velocity field changes. There are a number of algorithms one can use to quickly approximate solutions to Poisson’s equation. This is also essentially a near identical outline for direct simulation of fluid flow as well, the main difference is the sign of the Laplacian.
    Finally, one thing you might consider is adding a repulsion effect at high densities to avoid the PDE from diverging to infinity as a result of the fact that higher density=higher attraction and the PDE has no way to avoid that

  • @_caracalla_
    @_caracalla_ 2 ปีที่แล้ว +5

    that "expanding" particles demo was awesome. great work! also can i ask how much time you have on programming?

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +3

      Thanks, and about 15 years now!

    • @kittinanpakboon8129
      @kittinanpakboon8129 ปีที่แล้ว

      Hmm
      thanks for the info!
      Might get to this level in 10 years alot less than i thought.

  • @perbojsen3433
    @perbojsen3433 ปีที่แล้ว

    Very nice work. The simulations are very beautiful and even with the approximations you're using you can see things that look like galaxies and how galaxy clusters and mergers form and occur.

  • @aSpyIntheHaus
    @aSpyIntheHaus 3 ปีที่แล้ว +6

    Wow. this is a tremendous effort. I can see why astrophysicists really want dark matter and dark energy to be a thing. That rotating model coalesces way to easily into a rather homogeneous disc doesn't it?

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +6

      Haha ya I can start to see why astrophysics is so difficult! It would be interesting to see how the simulation would change if more interaction types are added such as dark matter!

    • @DavidStruveDesigns
      @DavidStruveDesigns 2 ปีที่แล้ว

      Not only that, but a previous theory that "the black hole at the center is what causes the rotation of a galaxy and the patterns of said galaxy" just doesn't work - not only because the actual mass of a black hole, even a supermassive one, actually only makes up a tiny fraction of the total mass of a galaxy - so there's not enough mass or gravitational force at the center to have _that_ much influence over the direction or speed of a galaxy, nor how a galaxy looks, but _also_ because it was discovered in many galaxies - including our own - the black hole at the center is actually rotating _in the opposite direction_ to the rest of the galaxy! _AND_ it can also be rotating along a different axial tilt to the rest of the galaxy! So something else is causing galaxies to rotate, and cause the patterns we see within galaxies as well as the changes to those patterns over time (like the arms of our own, or the more uniform disk shape of older galaxies). And that's not even including smaller halo galaxies that orbit their larger cousins. So they came up with a halo of dark matter surrounding every galaxy that keeps it rotating in a certain direction, keeps the mass within contained instead of having the outer mass launch away from the galaxy into the cosmic voids between, and influences the halo galaxies behaviour and the appearance of galaxies in general.

    • @DavidStruveDesigns
      @DavidStruveDesigns 2 ปีที่แล้ว

      Although, _your_ simulation _seems_ to suggest the combined gravitational forces created by the combined mass being simulated actually _is_ enough to replicate the behaviours we see of real galaxies. It would be quite interesting to see what would happen if you could somehow also add a simulation of a black hole in the center of the largest mass - but rotating in the opposite direction to the rest of the mass in the simulation.

    • @aSpyIntheHaus
      @aSpyIntheHaus 2 ปีที่แล้ว +1

      @@DavidStruveDesigns Any of those centralised areas where you can see the bulk of masses accumulating in points can be considered analogous to a black hole already. As in the gravitational effect is the same however without a horizon or accretion effects.
      That said though it would still be cool to see, especially things like relativistic jets that would wobble as the black hole builds in mass

    • @aSpyIntheHaus
      @aSpyIntheHaus 10 หลายเดือนก่อน

      I came to post a comment only to see that I have already commented what I wanted to say. ☺️

  • @Kiriixer
    @Kiriixer 2 ปีที่แล้ว

    I love being able to recognize and understand code and not seeing it as an absolute other language, ty school

  • @suncrafterspielt9479
    @suncrafterspielt9479 3 ปีที่แล้ว +4

    What about using kd trees or other tree structures to more efficiently process particle to particle interaction?

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว +1

      Ya I think that would work well with the split simulation approach I mention at the end. Use a kd tree for efficient particle to particle interactions, and then for the million small particles avoid neighbourhood lookup completely by using this "splattering" technique.

  • @MrKohlenstoff
    @MrKohlenstoff 11 หลายเดือนก่อน

    Really stunning result, amazing work! I've superficially experimented with similar things in the past and thought about using grids to approximate gravitational effects and get around the O(n²) problem - but never actually fully implemented it. But you did a damn fine job and the results are pretty amazing. :)

  • @mikhailskylark8417
    @mikhailskylark8417 2 ปีที่แล้ว +3

    Bro just calculate the overall system's center of mass (which should stay at the same point if I'm correct) and apply force to your particles.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว

      calculating the center of mass for each grid cell and taking that into account should improve things. But if I do it for the whole system that would be the equivalent of just using a 1x1 grid

  • @locallyringedspace3190
    @locallyringedspace3190 ปีที่แล้ว

    5 minutues in, just wanted to say this is a really good video. I like the presentation and the format. Thank you.

  • @loukitmyname
    @loukitmyname 2 ปีที่แล้ว +3

    Hi. Can you do a tutorial on this? Are you using compute shaders for the simulation computation?

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว +1

      technically I should be, theres a couple steps that would benefit from using compute shaders, but I've done everything here just using rasterization pipelines even though some stages are unnecessary and just add overhead. The tutorial series will cover all the techniques required for this eventually, but trying to do a full tutorial on everything here at this point would be like 4 hours long

  • @strangeanimations2518
    @strangeanimations2518 ปีที่แล้ว

    This is the coolest thing I've ever seen, I'm blown away
    wow

  • @EvanG529
    @EvanG529 2 ปีที่แล้ว +3

    Now do it in 3D

    • @mwm48
      @mwm48 9 หลายเดือนก่อน +1

      No…4D 😳

  • @matthewboire6843
    @matthewboire6843 ปีที่แล้ว

    It’s so cool that this is even possible, I love it

  • @nyx1284
    @nyx1284 3 ปีที่แล้ว +4

    6:04 he said it

  • @DescendDab
    @DescendDab ปีที่แล้ว

    You, sir, are amazing! I always love stuff like this. I wish you nothing but the best

  • @astria4157
    @astria4157 3 ปีที่แล้ว +4

    This is amazing. It reminds me of a program from a small developer that I really enjoy. I don't know anything about coding but you might find some inspiration from his work. World really be cool you could get stable orbits going and have objects collide and become larger objects. Here is the other developer: th-cam.com/video/2ksVjpxY5mI/w-d-xo.html

    • @BrendanGalea
      @BrendanGalea  3 ปีที่แล้ว

      Woah that’s pretty cool, thanks for sharing!

  • @alessandrodimitri3852
    @alessandrodimitri3852 2 ปีที่แล้ว

    Amazing! You've just created an elliptical galaxy

  • @zecuse
    @zecuse ปีที่แล้ว

    Despite knowing it's 2D, the different sized blobs moving at different speeds make it look 3D. Very nice!

  • @paulinefox5381
    @paulinefox5381 2 ปีที่แล้ว +1

    this simulation at times triggered some deeeeeep astroagoraphobia, congrats on the a simulation powerful enough to trigger a fear of space lmao

  • @mathgeekification
    @mathgeekification ปีที่แล้ว

    The formation of stars and galaxies! Excellent work!

  • @lcj3_
    @lcj3_ ปีที่แล้ว

    Good job youtube compression. You even took this one simple thing away from us.

  • @StarkRaveness
    @StarkRaveness 2 ปีที่แล้ว +1

    The beautiful nature of mathematics feels like ordered randomness

  • @laposgatti3394
    @laposgatti3394 ปีที่แล้ว +2

    You could reduce the complexity if you calculate the gravitational potential directly from the mass density distribution via the Poisson equation using the Fourier transform (there are some very fast libraries for fft) which turns the laplacian in a simple multiplication then anti-transform to get the potential in real-space. Then a simple derivation will yield the force. This would turn the problem from n^2 to nlog(n) so you could spare some calculation time to use either more particles or a higher resolution. As for the gridding you would probably want to distribute your mass via some kernel functions (this should avoid kinetic energy losses I think) for example the so called "triangular shaped cloud kernel"

    • @BrendanGalea
      @BrendanGalea  ปีที่แล้ว +1

      thank you for the suggestion!
      it was something i looked into a bit but was a bit to complicated for me to understand in the time i had available for this.
      Based on your comment and others, I think when i revist this I definitely need to take the time to properly learn about fourier transforms and add that tool to my arsenal!

  • @krodax3639
    @krodax3639 11 หลายเดือนก่อน

    the way in which the particles first contract and then explode outwards during the simulation reminds me of the big bang

  • @RagehAzzazi
    @RagehAzzazi 2 ปีที่แล้ว

    i'm blown by how smart is your optimization solution,, i thought,, this guy is gonna blow a pc in this video

  • @idjles
    @idjles ปีที่แล้ว +1

    An approach you could take is to ensure that energy is conserved after each step. After updating v and x, adjust them to preserve energy and momentum

    • @BrendanGalea
      @BrendanGalea  ปีที่แล้ว

      Ya at the very least I should keep track of the systems energy and momentum so I can see how much it’s wrong.
      For performance the ideal solution would not need to provide this corrective step which would be computationally expensive, but still be a forward Euler simulation but in such a way that accumulated errors in the systems energy and momentum locally tend to cancel out when observed on the global scale

  • @NateJGardner
    @NateJGardner 2 ปีที่แล้ว +1

    This is a really cool method! I like your idea about combining it with direct simulation. It'd make rendering beautiful space scenes with clouds of small particles very cool. Watching these scenes you rendered I'm already imagining them in the background of a 2D game, and how incredible that would be (especially with slightly different seeds every time).
    This is my favorite video I've watched this week. 👍

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว

      Wow thank you!!
      The cool thing too is that I should be able to make it interactive as well!!

  • @swyveu
    @swyveu 2 ปีที่แล้ว +1

    I already knew that god was a programmer,
    but didn't know he was on youtube!
    Nice work, man.

    • @BrendanGalea
      @BrendanGalea  2 ปีที่แล้ว

      Hahaha thank you, This comment made my day!

  • @felipedorosario4793
    @felipedorosario4793 2 ปีที่แล้ว

    This is absolutely beautiful to watch! Outstanding work!!

  • @douglasnordwall3482
    @douglasnordwall3482 ปีที่แล้ว

    Stumbled upon this, very nice done! So "simple" but yet so beautiful :'] Reminds me of the universe

  • @n8style
    @n8style 12 วันที่ผ่านมา

    Beautiful simulations there!
    The dampening and boundaries might come from converting the exponential gravity field into a series of linear fields, having a "jumpy" acceleration curve instead of smoothly increasing

  • @r-platt
    @r-platt 2 ปีที่แล้ว

    O log(n) : computer each unique interaction. Apply the vector and inverse vector to both particles.
    you can also delay applying the square root for the point to point distance.

  • @matthewjenkins914
    @matthewjenkins914 ปีที่แล้ว

    TH-cam compression did NOT like that lmao. Great video tho! While not based entirely on Newton's laws, it's really cool to see that you can get gravity-like visuals using WAY cheaper methods by thinking outside the box like this.

  • @movax20h
    @movax20h ปีที่แล้ว

    Making simulations is super fun.
    This is a bit of simpler version of a classic Barnes-Hut method. It is based on an octree (or in 2D quad tree). For GPU it might make sense to have a dense representation, but classically the representation is way more sparse, and the regions that do not have any particles are not even computed. It makes it then trully adaptive and O(n log n). The method also contains exact method of combining different tree levels. Fixed grid methods do not work too well with very non uniform distribution of particles. Bernes-Hut and FMM (below) deal with it better.
    If you want to go even further, and want to simulate billions of particles, the Fast Multipole Method is a method of choice. It is very complicated (I implemented it once around 2004, and even then I bearly understood how the approximation cutoffs work). But well implemented, it is O(n) - linear in number of particles. Magic. Not only it scales really well, it has very rigour error bounds, so one can keep track of max error and do adaptive integration.
    Both methods can be parallelized.

  • @shutup-xg9ol
    @shutup-xg9ol ปีที่แล้ว +1

    only thing more mystical than this video is the gymnastics my computer would have to go through to run this

    • @BrendanGalea
      @BrendanGalea  ปีที่แล้ว

      It’s running on a computer I built like 10 years ago so yours just might be fine 😅

    • @shutup-xg9ol
      @shutup-xg9ol ปีที่แล้ว

      nah bruv, you just built different@@BrendanGalea

  • @gertjan1710
    @gertjan1710 2 ปีที่แล้ว +1

    I think though that the dampening will prevent chaotic behaviour and particles escaping at high speed, so aesthetically a positive

  • @Swenthorian
    @Swenthorian ปีที่แล้ว +1

    Results at 6:04

  • @terohyvonen
    @terohyvonen 2 ปีที่แล้ว +1

    "Let there be light."

  • @johnsports_iii
    @johnsports_iii 2 ปีที่แล้ว

    Using the blur and gradient is genius and the result is beautiful!

  • @drsjamesserra
    @drsjamesserra 11 หลายเดือนก่อน

    Man I love it, such a great way to visualize!

  • @flipped_bit
    @flipped_bit ปีที่แล้ว

    It looks awesome. The only thing missing is to make the “time” also a gradient per cell. Because time slows down when more mass per cell and time speeds up when less mass density cell. Then u’ve fixed the mystery of what people call dark matter and the expansion of the universe.