I would try out rust if I were you. It's like C++, but has a first party build system and package manager. It's also memory safe without a garbage collector!
Thanks for the new video! I've not done much related to programming, but collision optimization has been an interest of mine for quite a while. It's great to see such an easy explanation into spacial partitioning.
Back when I was growing up, Black and White 2 by Lionsgate was my jam. In the screen before the main menu, a bunch of particles streamed into a box and made the Lionsgate logo.... but you could also mess around with them using your mouse and screw the whole thing up. But if you didn't, it always ended up perfectly. I used to wonder how on earth they managed to implement a physics engine that kept producing the same result over and over, and now almost a decade later you've answered that lingering question. Keep up the amazing work!
@@official-obama are float rounding errors deterministic? if so then it's fine, because the simulation will end up the same both times, even if the math may be wrong behind the scenes
I love seeing the grains appear in the crystal lattices that appear. I'd love to see this applied with more physics rules to simulate microstructures to create visual aids for understanding alloys, solid state chemistry, etc.
Amazing video as always!! I love how you show a simple version of the code as a demonstration tool. Very similar to Sebastian Lague, I really hope I could get this good at video making at some point.
Only because threads can vary in their timing of when they run because they can be used by the OS. But if you write the code correctly, it will be deterministic because the objects won't vary according to which got updated first.
@@rorymax yeah but an entire os could be considered chaotic. Some process depend of the internet. The system is so complex it will never be deterministic unless unplugged from the internet and the code is running without an OS. Still an interesting topic tho, I want to dig deeper.
@@pascha4527 oh it’ll still be deterministic, there would just be so many variables that you’d never be able to replicate or even know all the starting conditions. But if you had all those variables, and enough time and computation power, you’d be able to determine the outcome
This is so satisfying :) It would be interestig to see how the chicken picture changed if you re-run the simulation with the exact same settings, except slightly changing the settings of one single object. Like i depiction of the butterfly effect. The more complex the interaction is, the more warping of the chicken should be visible.
Watching the objects construct the image is so satisfying!! I'm sure if you made videos dedicated to showcasing more images being filled, and even made shorts, they would be very successful!
I absolutely love how well you demonstrated the issues of multithreading in a very visual manner by showing how multiple threads could not produce the same deterministic result if overlaps between threads are not properly handled. I really feel like I learned some valuable things from this video. Thanks, it was awesome!
Such a joyful video dude. (I scrambled myself around 2 months ago to optimise an application with thousands of collidable objects , couldn't get the multithreading tho) Awesome job!
This is mind blowing. I always thought fluid/particle simulation is something very complicated, but here it is effortless. Thanks for the sources! I'll try to make my own engine using platform-independent compiler and graphic library.
I know the acronym STEAM is a bit of a reach (STEM + Arts), but this work is truly at the intersection of science and art. Well done - and beautifully explained!
So I've been pretty addicted to your work, such great visuals, always helpful information, typically open source code, each concept well segmented. It's been a real treat watching you. I've been curious to see your implementation on a few things, but recently the concept of falling sand engines like MARF's here on youtube, which supply much more realistic physics then a simple 'fall, fall left, fall right' simulation. I'd be really fascinated to see your approach, and the evolution of the process when it comes to levels of optimization.
man, this is depressing and impressive at the same time. I've spent a whole year in last year of my BSc making a 2d physics engine and its still was wonky af to a point that its an embarrassment to show anyone, and here you whoop it up in like 2 months that is effectively a perfection
You also have to concede that thr yter only uses 2d circles, whose collisions are veryy easy to check and require much less work! Dont beat yourself up about it
You're going to learn a lot by trying, failing, then either figuring it out or seeing how someone else did it. The older you get, you don't stop failing when you try something new or difficult, you just know how much time to give yourself to figure it out. I get why it's depressing and impressive, but I hope that you're still excited to solve these interesting problems just so you can feel your own brain grow, you'll get there before you realize!
Each improvement increases the probability of the next improvement. You didn't spend a year making a 2d physics engine. You spent a year improving the quality of all future physics engines you will go on to build.
also he can only do this in two minutes because he spent years working on improving his skills and understanding. Keep going and you'll be amazed at how much progress you make.
incroyable. Ca fait une 1h30 que je suis scotché à vos vidéo. Elle est tellement qualitative. Bravo pour votre travail vraiment, et merci pour le voyage :)
I would be really interested to see the addition of other shapes to the simulation. Adding polygons or even non convex shapes would be a lot more challenging but very interesting.
I LOVE YOUR VIDEOS!!! Your code is so elegant in so many ways, and your videography is perfect, plus your voice, just everything man, seriously awesome!
Here's an interesting problem I ran into some months ago. I'd like to propose it to you and see if you come up with something cool, if you're interested. Imagine a 2D plane populated by entities with circular colliders, not dissimilar to what you're doing here. There is also an attractor entity which moves around arbitrarily. Each simulation step, the entities find the direction of the attractor as a normalized vector and store it as an intended direction of motion. They then check for collision with one another, and when overlaps are found, they add the response vector to their stored vector, so that they end up with a sum of all their desired motion vectors. This vector is then normalized and multiplied by the desired speed of the entity, so that they will move toward the attractor while repelling one another if they get too close. So far so good. The issue arose when I started using SIMD to accelerate the simulation and allow for more active entities. The SIMD radically improved the rate at which they can all find the direction toward the attractor, but for collision I ran into the problem that the data for the SIMD was not sorted into regions in order to accomplish the grid optimization like you did here. It's possible to sort them by their x positions, but it seemed like rearranging them this way for every update would take up more time than the SIMD calculation would save. Unfortunately, I set that project down because of some life issues and now I don't know if I still have it around, but I'd be interested to hear if you have any ideas about to deal with this kind of problem. Thank you for the great videos!
@@andreyrumming6842 Mainly, yes. The SIMD registers hold four 32-bit values, so I would select an entity to test and load it into a register twice (x,y,x,y) and then have a pointer to the other entities that would be used to load the other registers, then increment by 4 and continue loading, etc. By interleaving the loads and the math it was possible to get good performance from this, because one register could be working while the next is loading, and each register is doing the math for two entities at a time. This required the position vectors to be serialized, so each entity had an index into an array of x,y pairs. This meant that sorting the pairs would also require updating the indices in the owning entities, which was another layer of complexity. I'm certain that big game companies with fancy physics engines have some way that they're able to cheaply sort entities so they don't have to do On^2 collision tests every frame. I just don't know what that method is. Alternatively, they may all just be doing this kind of thing in CUDA or something.
This is an awesome video! It seems to me if you wanted to simulate objects with an arbitrary radius you would need each cell to be the size of the largest object. I'm not sure if there's a better way to do it, but maybe that's a good idea for a follow up video?
you could make the object register into multiple cells and also read a larger neighborhood. That being said, as far as I know there are other space partitioning techniques which don't use a fixed grid and are more adaptable
Great video, it was already clear from your previous ones but you underscored it well here :) Also I think you should switch the order of y and x loops at 5:00 for better memory access in canonical order
I am not using 2D arrays (which are indeed row major). I use column major because it allows for better load balancing between threads since in the simulations of the video objects are horizontally spread
This is so fascinating. I'm going to school so that I can work on stuff like this and it makes me so excited when I see videos like this. Thanks for all the insight.
A great tutorial! I usually just do a dt step followed by N collision steps, gotta try your substepping method sometime :) I've once made a similar tutorial, without threading but with friction, damped springs, and ball-stick collisions.
The big advantages with sub steps is that, since objects travel smaller distances in one physics frame, errors are a lot easier to handle for the solver and it also greatly mitigate the tunneling effect, leading to way more stable simulations
It's been a long time since the last time I paused a video and go down to intentionally click sub+like before I finish a video because I don't want to forget about it. More content this quality sir and you're on top of UA-cam.
@@tetryds I've done some chemistry simulation in Lennard-Jones potential, it's pretty fun to play with, trying out different combinations of interaction parameters. I have several videos on this topic on my channel.
@@tetryds Molecular simulations are not exactly difficult though. There is much to do in implementation but the principles are not much more difficult than this.
The problem with chemistry is, reactions cannot be described classically by collisions in an "ab initio" way. You'll end up with random results unless you introduce some "unphysical" parameters, like the parameters of a given interaction potential between atoms. But these parameters can only be determined by fitting onto experimental data. So we're back to square one basically. The only way to accurately reproduce chemical reactions through physics simulations is quantum mechanical algorithms, which are much more computationally expensive, and can handle *at most* tens of atoms for a good computer before they start to really stutter. And they aren't real time simulations either, they have to be computed over the course of days or weeks. What can be done somewhat successfully is describing diffusion dynamics, or maybe crystallization, using this kind of physics engine. But not chemical reactions sadly.
@pietrotettamanti3183 Your comment may be the most underrated one i've ever read. i give you a cookie, because no one did. WORLD! GIVE THIS MAN A COOKIE JAR, NOW.... But ... quantum application might give you no cookie, or maybe a plenty jar... Who know...
Checking for a collision between grid cells can be done only for half of the neighbouring cells. For example you can only check left, top-left, top and top-right neighbours. All other collisions for examle between current cell and right neighbour, will be checked once that neighbour becomes current cell
Yes absolutely, I still do the full check since it is like doing 2 solver iterations but faster that really doing 2 iterations and it help a lot with stability
I'm curious about that too.. For something like this, I'm not sure how much further benefit could be obtained by using k-d trees. Tho I'm by no means an expert on them, in this case I wouldn't think the empty space would cost much different, and the objects are all the same size, so not much dynamic adjustment is needed in that regard. The one time I tried implementing them, it cost more in performance to manage the kd-tree, than it took to just run everything in a fixed-grid like this video used. Tho again, I probably wasn't using them as expertly as other people might.. heh
Never tried them but I tend to think that very simple / straightforward and cache efficient structures generally win, specially if the world size isn’t huge
@@user-dh8oi2mk4f I don't remember, it was years ago and I was barely comprehending tutorials on it at the time, as it was. I just remember the feeling like it was the programming equivalent of chasing after a perpetual motion machine, or teetering on the edge of "The Tyranny of the Rocket Equation".. lol
Awesome as always! I'm curious if the grid-iterating approach causes any kind of bias in the physics? Like if updating the collisions left-to-right in the grid adds any kind of preference for stuff moving to the right?
Dude I am a high schooler and i wanted to make a thread pool for multithreaded collision detection and i even thought there would be issue with 2 threads writing to the same Ram adress and i would have fixed it in the same way.i am feeling proud that I thought of all the same optimisation as you.i first thought of a qaud tree but couldn't find a way to multithread it
That's awesome! The overall structure looks like a polycrystal and those imperfections - like dislocations. The hexagonal planar structures look exactly like graphene.
7:22 Curious fact, the formation that the particles had at that time is the same as that of a glass-type material (if we assume that each particle is an atom of course), that is, hundreds of tiny crystals (periodic formation of atoms or molecules) arranged in different directions, that is exactly why they are seen as "cracks" in said simulation 10:11 That would already be a more precise vision of what happens in reality, with each crystal having thousands or even millions of atoms arranged in a certain way. by the way PezzzasWork , You could do this same type of simulation but in 3D, and by the way, make it voxel type ?to avoid potential performance issues when using polygons
7:24 is so cool, for unrelated reasons haha. It's a perfect visual explaination of why crystallites and grain boundaries form in crystalline materials with fast crystal growth. The actual mechanism is actually a bit different but the deeper concept holds very well.
Wow! So cool! I have loved the idea of known-future-simulation-states for 'formation' effects (I work in vfx) and this really did that in a superb way, top work Pezzza!
If you pause at 5:12 and look at the code closely, this algorithm doesn't find collision between the objects of the border cells. This is because we're iterating only over the inner part of the grid without the borders - which is responsible for what is stored in "current_cell". So even if neighbour iteration includes "current_cell", effectively ensuring each inner cell of the grid is checked for collisions with itself, the same cannot be said about "other_cell". In no situation do you ever call check_cells_collisions(other_cell, other_cell) because the cell collisions are only ever checked in the context of "current_cell"
This made me smile. Watched some boring stuff tonight and then found something creative and amusing. Bonus points for using a code indent scheme that lines up brackets, unlike the insane lopsided system that has been popular for most of this century.
Incredible work! I'm not into programming, yet you managed to make it really interesting, even for me. Worth a lil' subscription imo. Also, your accent sounds like you're french. Edit: just checked and yep you are
The partitioning of the grid into thread groups (“causal domains”) effectively creates a “speed of causality” for your cosmos which is like the speed of light for our cosmos.
Very interesting video, I've actually been thinking about implementing my own basic physics checker for a really tiny multiplayer game to increase the efficiency and lower the server requirements (though I'm using C#11, but the algorithmical / threading issues apply all the same) thanks a bunch for this very interesting video
Fantastic! Really beautiful simulation! I have also invented the same technique by myself (I know that I'm not the first who though about it but at least I figured it out by myself), but never got to realize it. Glad to see how well it actually works! Probably it will run a couple dozen times faster if you run it with CUDA.
your videos are so under-appreciated! try taking snippets of the videos and either uploading them to UA-cam Shorts, or upload a summary to Reddit. maybe even make a 2-minute summary and put it on UA-cam Shorts too! so many views to be had there
This video gave me the push the ditch a physics engine for my project and write my own. They are way too smart for my needs, and a simpler one like this (with some additions that fit my needs, like grouping objects or base displacement on weight) will provide a much better base for the logic.
Помню как в тетради себе разрабатывал решение для оптимизированной физики. Точно также меня не устраивало проверять коллизию между каждой парой обьектов и я рисовал себе сетки. Жаль, что я в программировании делетантом был :) А на шейдерах в Unity делал симуляцию частиц, которая несмотря на многопоточность, была детерминированной, засчет расчета физики в 2 шага. Как в шахматах считалась физика сначала у белых клеток, затем у черных. И забагованной симуляция тоже была, но всё равно крутой. И радость и тоска от этого видео, что подобные вещи рассказываю не я, а автор видео. Когда-нибудь обязательно дорасту до такого уровня, я работаю над этим.
Your original verlet integration video is what got me more interested in C++ & physics simulation, so excited to see this new one come out!
I hope you will like it :)
I would try out rust if I were you. It's like C++, but has a first party build system and package manager. It's also memory safe without a garbage collector!
@@firexgodx980 +1 and SFML is being (ported to Rust) -> wrapped in rust 🙂
@@tyrendel awesome, where can I follow the progress?
how about mojo? grammar and library of python and speed of C++
Thanks for the new video! I've not done much related to programming, but collision optimization has been an interest of mine for quite a while. It's great to see such an easy explanation into spacial partitioning.
Great work as always. You're one of the few channels that actually excites me when a new upload appears in my feed.
Thank you!
Back when I was growing up, Black and White 2 by Lionsgate was my jam. In the screen before the main menu, a bunch of particles streamed into a box and made the Lionsgate logo.... but you could also mess around with them using your mouse and screw the whole thing up. But if you didn't, it always ended up perfectly. I used to wonder how on earth they managed to implement a physics engine that kept producing the same result over and over, and now almost a decade later you've answered that lingering question. Keep up the amazing work!
Do not use floats and only integers, and you'll be fine.
Lionhead. Lionsgate is the film production company.
@@Gregzenegairintegers also have rounding errors, floats are also deterministic, floats also do not spontaneously change
@@official-obama are float rounding errors deterministic? if so then it's fine, because the simulation will end up the same both times, even if the math may be wrong behind the scenes
@@JTtheking134 yeah probably, randomizing the rounding would probably be useless
but it might be different on different systems
I'll never regret subscribing.
Edit: POG almost 1K likes
🤣🤣🤣🤣
Same
Me neither
Facts!
Nobody will
I love seeing the grains appear in the crystal lattices that appear. I'd love to see this applied with more physics rules to simulate microstructures to create visual aids for understanding alloys, solid state chemistry, etc.
Totally agree, I flipped when I saw the grain boundaries forming with minimal physics incorporated
Amazing video as always!! I love how you show a simple version of the code as a demonstration tool. Very similar to Sebastian Lague, I really hope I could get this good at video making at some point.
You always outdo youself on the outro, love your work and knowledge! Thanks for sharing it with all of us!
The fact that multi-threading made it not deterministic was really interesting
Only because threads can vary in their timing of when they run because they can be used by the OS. But if you write the code correctly, it will be deterministic because the objects won't vary according to which got updated first.
@@TheRainHarvester but from the outside, you never know which will be used until you check... sounds familiar
Technically still deterministic though :p
@@rorymax yeah but an entire os could be considered chaotic. Some process depend of the internet. The system is so complex it will never be deterministic unless unplugged from the internet and the code is running without an OS. Still an interesting topic tho, I want to dig deeper.
@@pascha4527 oh it’ll still be deterministic, there would just be so many variables that you’d never be able to replicate or even know all the starting conditions. But if you had all those variables, and enough time and computation power, you’d be able to determine the outcome
Wow. Your videos are so technically impressive! Great job
I've been having problems trying to multithread my sim, that idea to use 2 passes is genius! Thank you so much
This is so satisfying :)
It would be interestig to see how the chicken picture changed if you re-run the simulation with the exact same settings, except slightly changing the settings of one single object. Like i depiction of the butterfly effect. The more complex the interaction is, the more warping of the chicken should be visible.
That would’ve been awesome
@@leonhardolaye-felix8811 Thank you for using the apostrophe correctly :D
Watching the objects construct the image is so satisfying!! I'm sure if you made videos dedicated to showcasing more images being filled, and even made shorts, they would be very successful!
your videos are really inspiring. whenever i watch your videos i find myself while codding
I absolutely love how well you demonstrated the issues of multithreading in a very visual manner by showing how multiple threads could not produce the same deterministic result if overlaps between threads are not properly handled. I really feel like I learned some valuable things from this video. Thanks, it was awesome!
I'd absolutely love to see more of this. This is fantastic.
Thank you very much!
@@PezzzasWork you're an inspiration :)
Such a joyful video dude. (I scrambled myself around 2 months ago to optimise an application with thousands of collidable objects , couldn't get the multithreading tho) Awesome job!
This is mind blowing. I always thought fluid/particle simulation is something very complicated, but here it is effortless. Thanks for the sources! I'll try to make my own engine using platform-independent compiler and graphic library.
I know the acronym STEAM is a bit of a reach (STEM + Arts), but this work is truly at the intersection of science and art. Well done - and beautifully explained!
So I've been pretty addicted to your work, such great visuals, always helpful information, typically open source code, each concept well segmented. It's been a real treat watching you. I've been curious to see your implementation on a few things, but recently the concept of falling sand engines like MARF's here on youtube, which supply much more realistic physics then a simple 'fall, fall left, fall right' simulation. I'd be really fascinated to see your approach, and the evolution of the process when it comes to levels of optimization.
man, this is depressing and impressive at the same time. I've spent a whole year in last year of my BSc making a 2d physics engine and its still was wonky af to a point that its an embarrassment to show anyone, and here you whoop it up in like 2 months that is effectively a perfection
tbf, it's not like he made the physics engine from scratch, he just found a great way to calculate collisions in a very efficient way
You also have to concede that thr yter only uses 2d circles, whose collisions are veryy easy to check and require much less work!
Dont beat yourself up about it
You're going to learn a lot by trying, failing, then either figuring it out or seeing how someone else did it. The older you get, you don't stop failing when you try something new or difficult, you just know how much time to give yourself to figure it out. I get why it's depressing and impressive, but I hope that you're still excited to solve these interesting problems just so you can feel your own brain grow, you'll get there before you realize!
Each improvement increases the probability of the next improvement.
You didn't spend a year making a 2d physics engine.
You spent a year improving the quality of all future physics engines you will go on to build.
also he can only do this in two minutes because he spent years working on improving his skills and understanding. Keep going and you'll be amazed at how much progress you make.
The visualisations in this video are amazing. They communicate the problem space so effectively. Nice work!
This led me on my own rabbit hole for vertlet physics, and each step you did took me hours to do. Your videos are amazing!
incroyable.
Ca fait une 1h30 que je suis scotché à vos vidéo.
Elle est tellement qualitative.
Bravo pour votre travail vraiment, et merci pour le voyage :)
Merci beaucoup :)
I would be really interested to see the addition of other shapes to the simulation. Adding polygons or even non convex shapes would be a lot more challenging but very interesting.
I LOVE YOUR VIDEOS!!! Your code is so elegant in so many ways, and your videography is perfect, plus your voice, just everything man, seriously awesome!
The chicken is now a symbol of success
you nailed it, really like your content , hope to see your channel's fast growth SOON , thanks
Here's an interesting problem I ran into some months ago. I'd like to propose it to you and see if you come up with something cool, if you're interested.
Imagine a 2D plane populated by entities with circular colliders, not dissimilar to what you're doing here. There is also an attractor entity which moves around arbitrarily. Each simulation step, the entities find the direction of the attractor as a normalized vector and store it as an intended direction of motion. They then check for collision with one another, and when overlaps are found, they add the response vector to their stored vector, so that they end up with a sum of all their desired motion vectors. This vector is then normalized and multiplied by the desired speed of the entity, so that they will move toward the attractor while repelling one another if they get too close.
So far so good. The issue arose when I started using SIMD to accelerate the simulation and allow for more active entities. The SIMD radically improved the rate at which they can all find the direction toward the attractor, but for collision I ran into the problem that the data for the SIMD was not sorted into regions in order to accomplish the grid optimization like you did here. It's possible to sort them by their x positions, but it seemed like rearranging them this way for every update would take up more time than the SIMD calculation would save.
Unfortunately, I set that project down because of some life issues and now I don't know if I still have it around, but I'd be interested to hear if you have any ideas about to deal with this kind of problem.
Thank you for the great videos!
A fascinatingly complex issue. So effectively the whole problem is unsorted data every frame?
@@andreyrumming6842 Mainly, yes. The SIMD registers hold four 32-bit values, so I would select an entity to test and load it into a register twice (x,y,x,y) and then have a pointer to the other entities that would be used to load the other registers, then increment by 4 and continue loading, etc. By interleaving the loads and the math it was possible to get good performance from this, because one register could be working while the next is loading, and each register is doing the math for two entities at a time. This required the position vectors to be serialized, so each entity had an index into an array of x,y pairs. This meant that sorting the pairs would also require updating the indices in the owning entities, which was another layer of complexity.
I'm certain that big game companies with fancy physics engines have some way that they're able to cheaply sort entities so they don't have to do On^2 collision tests every frame. I just don't know what that method is. Alternatively, they may all just be doing this kind of thing in CUDA or something.
This is one of your best videos so far man I can tell you spent a lot of time on this and it payed off well
This is an awesome video!
It seems to me if you wanted to simulate objects with an arbitrary radius you would need each cell to be the size of the largest object. I'm not sure if there's a better way to do it, but maybe that's a good idea for a follow up video?
you could make the object register into multiple cells and also read a larger neighborhood.
That being said, as far as I know there are other space partitioning techniques which don't use a fixed grid and are more adaptable
Quad Tree for 2D and OctTree for 3D is pretty much that
I keep coming back to these video's because they are such good learning subjects, thanks for making them Pezza! you are an absolute legend.
That has got to be the coolest "thanks for watching" screen I have ever seen
indeed :)
I love this, the start of a computer game engine!
The background music is great, adds audible depth to learning about the computing techniques
i would pay money for a thing that lets you generate an image with thousands of circles, honestly the coolest coding thing i've seen in a while!
This is beautiful. I am so happy I found this. Elegant. Exact. Optimised. Well explained. Shared source. 10/10. Thank you. ❤
Great video, it was already clear from your previous ones but you underscored it well here :)
Also I think you should switch the order of y and x loops at 5:00 for better memory access in canonical order
I don't know how 2d Arrays are implemented in the language he's working with, but it makes sense. It should help with the cache.
I am not using 2D arrays (which are indeed row major). I use column major because it allows for better load balancing between threads since in the simulations of the video objects are horizontally spread
Your channel is too good to be real. That was fascinating. Keep the clean work.
La meilleure chaîne qui me vend du rêve, encore un super programme comme d'habitude 🙂
This is so fascinating. I'm going to school so that I can work on stuff like this and it makes me so excited when I see videos like this. Thanks for all the insight.
A great tutorial! I usually just do a dt step followed by N collision steps, gotta try your substepping method sometime :)
I've once made a similar tutorial, without threading but with friction, damped springs, and ball-stick collisions.
The big advantages with sub steps is that, since objects travel smaller distances in one physics frame, errors are a lot easier to handle for the solver and it also greatly mitigate the tunneling effect, leading to way more stable simulations
@@PezzzasWork what is the tunneling effect?
It's been a long time since the last time I paused a video and go down to intentionally click sub+like before I finish a video because I don't want to forget about it. More content this quality sir and you're on top of UA-cam.
Are you interested in chemestry? Because I would love to see your interpretation of an atomic-level physics simulator.
This is pretty cool but it is just a standard collision simulation
@@tetryds I've done some chemistry simulation in Lennard-Jones potential, it's pretty fun to play with, trying out different combinations of interaction parameters. I have several videos on this topic on my channel.
@@tetryds Molecular simulations are not exactly difficult though. There is much to do in implementation but the principles are not much more difficult than this.
The problem with chemistry is, reactions cannot be described classically by collisions in an "ab initio" way.
You'll end up with random results unless you introduce some "unphysical" parameters, like the parameters of a given interaction potential between atoms. But these parameters can only be determined by fitting onto experimental data. So we're back to square one basically.
The only way to accurately reproduce chemical reactions through physics simulations is quantum mechanical algorithms, which are much more computationally expensive, and can handle *at most* tens of atoms for a good computer before they start to really stutter. And they aren't real time simulations either, they have to be computed over the course of days or weeks.
What can be done somewhat successfully is describing diffusion dynamics, or maybe crystallization, using this kind of physics engine. But not chemical reactions sadly.
@pietrotettamanti3183
Your comment may be the most underrated one i've ever read.
i give you a cookie, because no one did.
WORLD! GIVE THIS MAN A COOKIE JAR, NOW....
But ... quantum application might give you no cookie, or maybe a plenty jar... Who know...
Checking for a collision between grid cells can be done only for half of the neighbouring cells. For example you can only check left, top-left, top and top-right neighbours. All other collisions for examle between current cell and right neighbour, will be checked once that neighbour becomes current cell
Yes absolutely, I still do the full check since it is like doing 2 solver iterations but faster that really doing 2 iterations and it help a lot with stability
Very nice! Have you tried k-d-trees yet? If you have, what performance gains were there
I'm curious about that too.. For something like this, I'm not sure how much further benefit could be obtained by using k-d trees. Tho I'm by no means an expert on them, in this case I wouldn't think the empty space would cost much different, and the objects are all the same size, so not much dynamic adjustment is needed in that regard.
The one time I tried implementing them, it cost more in performance to manage the kd-tree, than it took to just run everything in a fixed-grid like this video used. Tho again, I probably wasn't using them as expertly as other people might.. heh
Never tried them but I tend to think that very simple / straightforward and cache efficient structures generally win, specially if the world size isn’t huge
@@GrumpDog What algorithm did you use for adjustments/refitting?
@@user-dh8oi2mk4f I don't remember, it was years ago and I was barely comprehending tutorials on it at the time, as it was.
I just remember the feeling like it was the programming equivalent of chasing after a perpetual motion machine, or teetering on the edge of "The Tyranny of the Rocket Equation".. lol
Your physics simulation videos are absolutely mesmerizing... and so educational! I've been following along implementing my own physics engine!
Awesome as always! I'm curious if the grid-iterating approach causes any kind of bias in the physics? Like if updating the collisions left-to-right in the grid adds any kind of preference for stuff moving to the right?
every collision moves the objects in opposite directions, so the center of mass doesn't change
The ideas are so easy, but I never would have even thought about them. So good!
Dude I am a high schooler and i wanted to make a thread pool for multithreaded collision detection and i even thought there would be issue with 2 threads writing to the same Ram adress and i would have fixed it in the same way.i am feeling proud that I thought of all the same optimisation as you.i first thought of a qaud tree but couldn't find a way to multithread it
your videos always make my day. and every time they blow my mind
Now write a physics system ON scratch
@Flook1it’s only 3 likes lol
Id love for him to do that.
I like how your "Thanks for watching" being always pretty long, it feels like really sincere.
woooo!
I liked seeing the grain boundaries between the particle "crystals"
Loved the multi-threading aspect. Fun stuff!
That's awesome! The overall structure looks like a polycrystal and those imperfections - like dislocations. The hexagonal planar structures look exactly like graphene.
Insanely enjoyable and well made video!
This is all stuff I've seen in Game Dev school, ah the nostalgia
7:22 Curious fact, the formation that the particles had at that time is the same as that of a glass-type material (if we assume that each particle is an atom of course), that is, hundreds of tiny crystals (periodic formation of atoms or molecules) arranged in different directions, that is exactly why they are seen as "cracks" in said simulation
10:11 That would already be a more precise vision of what happens in reality, with each crystal having thousands or even millions of atoms arranged in a certain way.
by the way PezzzasWork , You could do this same type of simulation but in 3D, and by the way, make it voxel type ?to avoid potential performance issues when using polygons
You May like the crystalline forms that emerged on on my PPS videos. Even beating hearts!
7:24 is so cool, for unrelated reasons haha. It's a perfect visual explaination of why crystallites and grain boundaries form in crystalline materials with fast crystal growth. The actual mechanism is actually a bit different but the deeper concept holds very well.
This is so cool! You are such an inspiration to me, as someone who is learning raylib for C++
Wow. That was amazing. Best video about coding I've ever seen! Subbed on the spot!
I've recently been struggling with this exact problem, this has given me some new ideas, thanks!
I like how your video quality is increasing with every video. Awesome stuff
That outro was S-Tier, loved it.
The worst part of yoir channel is that it's so high quality that we don't get frequent videos. Keep it up! Love the content.
Watching you write code is so satisfying.
I thought you'd use OpenMP to manage threads, but you actually programmed the communication, thanks for sharing such amazing piece of work!
C'est tellement impréssionant! Continue avec les vidéos incroyable mon gars.
Extremely satisfying, awesome work!
that's a very cool effect, and thanks for explaining so clearly.
Very well made video. Love the animations during the explaination at the beginning
Wow! So cool! I have loved the idea of known-future-simulation-states for 'formation' effects (I work in vfx) and this really did that in a superb way, top work Pezzza!
If you pause at 5:12 and look at the code closely, this algorithm doesn't find collision between the objects of the border cells.
This is because we're iterating only over the inner part of the grid without the borders - which is responsible for what is stored in "current_cell". So even if neighbour iteration includes "current_cell", effectively ensuring each inner cell of the grid is checked for collisions with itself, the same cannot be said about "other_cell".
In no situation do you ever call check_cells_collisions(other_cell, other_cell) because the cell collisions are only ever checked in the context of "current_cell"
Yes, this is on purpose. I placed constraints to ensure that no object are going to these border cells meaning that no checks are required
Dude that outtro image was just pure swag. Well played
Wow, this is a super nice physics engine, and it's so simple that even I understand the code.
This made me smile. Watched some boring stuff tonight and then found something creative and amusing. Bonus points for using a code indent scheme that lines up brackets, unlike the insane lopsided system that has been popular for most of this century.
Incredible work! I'm not into programming, yet you managed to make it really interesting, even for me. Worth a lil' subscription imo.
Also, your accent sounds like you're french.
Edit: just checked and yep you are
bro your content is insane and very inspiring, keep it up
Thank you very much!
If this isn't quality content, I don't what is.
Thanks for another perfect video.
The partitioning of the grid into thread groups (“causal domains”) effectively creates a “speed of causality” for your cosmos which is like the speed of light for our cosmos.
i know exactly why and how it happens, but it still feels like magic when the circles line up like that
Realy intresting video! Thanks for showing the code and your progress
Very interesting video, I've actually been thinking about implementing my own basic physics checker for a really tiny multiplayer game to increase the efficiency and lower the server requirements (though I'm using C#11, but the algorithmical / threading issues apply all the same) thanks a bunch for this very interesting video
4:12 - Also, to support multiple sizes, you can resize the grid to accomodate the biggest object
This has to be one of the best outros for a video i have seen
This is so cool! The last simulation really resembled saturn with its rings :)
Fantastic! Really beautiful simulation!
I have also invented the same technique by myself (I know that I'm not the first who though about it but at least I figured it out by myself), but never got to realize it. Glad to see how well it actually works! Probably it will run a couple dozen times faster if you run it with CUDA.
your videos are so under-appreciated!
try taking snippets of the videos and either uploading them to UA-cam Shorts, or upload a summary to Reddit. maybe even make a 2-minute summary and put it on UA-cam Shorts too! so many views to be had there
That’s a great suggestion, I will try to make shorter versions of my videos :)
This video gave me the push the ditch a physics engine for my project and write my own. They are way too smart for my needs, and a simpler one like this (with some additions that fit my needs, like grouping objects or base displacement on weight) will provide a much better base for the logic.
Fantastic video and great explanation behind everything!
7:45 the fact that you have a French accent but said "et voilà " like a english person would, bro you got me
Помню как в тетради себе разрабатывал решение для оптимизированной физики. Точно также меня не устраивало проверять коллизию между каждой парой обьектов и я рисовал себе сетки. Жаль, что я в программировании делетантом был :)
А на шейдерах в Unity делал симуляцию частиц, которая несмотря на многопоточность, была детерминированной, засчет расчета физики в 2 шага. Как в шахматах считалась физика сначала у белых клеток, затем у черных. И забагованной симуляция тоже была, но всё равно крутой.
И радость и тоска от этого видео, что подобные вещи рассказываю не я, а автор видео. Когда-нибудь обязательно дорасту до такого уровня, я работаю над этим.
Yes. Spatial partitioning and multithreading, the keys to good performance.
10:49
Small particular: you missed a column. You divided in 5 and 3.
But the message not change, is incredible
The world needs more 2D physics tools. In gamedev, in motion graphics... Great work and very informative
That was art. Congratulations, gentleman.
This was really awesome, I really loved the video and was really interesting and Informative, thank you!
Kind of unrelated but I like how your simulation also can show lattice structures and lattice imperfections. Pretty cool.
That sunglass chicken image is so simple yet it blows my mind. Love this
very cool i wish i could do cool things like you