Teaching myself C so I can build a particle simulation

Поделиться
HTML-код
  • Опубликовано: 27 сен 2024

Комментарии • 293

  • @gr4dience
    @gr4dience  4 месяца назад +121

    Hi everyone! Glad to hear you're enjoying the video, it means a lot. I added the source code in the description for those who asked (it's kind of a mess). My semester just ended so I should have some time to work on another graphics project. Let me know what you guys wanna see below! - Cheers

    • @simonzanta1403
      @simonzanta1403 4 месяца назад +3

      heyy, i really enjoyed your video about computer graphics. Im currently researching sources for my Bachelor Thesis from computer graphics and i would like to ask you, if you could share some insights on how you research topics. It would be really helpful, couse i have no idea where to find sources and mainly what to search for.

    • @gr4dience
      @gr4dience  4 месяца назад +4

      @@simonzanta1403 Public code repositories were certainly my best friend during this project! If I ever needed inspiration for some feature or felt myself getting stuck, I would do a quick search on RUclips or Google for something similar and that was usually enough to get me through. Another tip is to try breaking down your research into smaller pieces that will be easier to source (ie. "OpenGL instance rendering" as opposed to "OpenGL particles"). Hope that helps!

    •  4 месяца назад

      third

    • @vinayakk2745
      @vinayakk2745 4 месяца назад +6

      hello there, really liked your video! I'm a first year computer science student, I would like to know more about what you do and how you got here, I'd love if you'd upload a video talking about yourself, your work and your journey, it would really help and inspire me! Thank you for this great video!

    • @hanya-chan454
      @hanya-chan454 4 месяца назад

      i love the work, why dont u make gravity simulation using nueton's thurd law of motion, i tryied to do it in unity, it kinda works but somehow the particles after attracting to each other and colliding they start to repeal each other (using barn's hut algorithm , no error in my code) , maybe u can do a simulation and explain the optimization method u choose.

  • @Nipings
    @Nipings 4 месяца назад +302

    The editing in this video is incredible

    • @njorogekamau3820
      @njorogekamau3820 4 месяца назад +1

      You can achieve the same using an open source python library called manim

  • @PezzzasWork
    @PezzzasWork 4 месяца назад +169

    Super cool video! Always funny to see we all encounter the same bugs along the way :D

    •  4 месяца назад

      first

    • @thatprogramer
      @thatprogramer 3 месяца назад

      yeah!

  • @luce_9801
    @luce_9801 4 месяца назад +202

    I know what I'm doing in summer now. Thanks for the inspiration!

    • @_Rie_
      @_Rie_ 4 месяца назад +2

      me too gonna start college in august so im gonna learn C and make this happen good luck to you too

    • @Randomperson-yf2fw
      @Randomperson-yf2fw 4 месяца назад

      @@_Rie_Good luck! C is a tough language in the beginning, but it's so satisfying to use once you've conquered the main pitfalls.

  • @georgiosdoumas2446
    @georgiosdoumas2446 4 месяца назад +10

    I have studied physics in 1991-1995, and I had a semester on Fortran in the university. Then at 2004 I learned a little C, and the following years I was slowly reading a few books on C and C++ (mainly I was reading stuff about networks and linux for my jobs) . Since late 2023 I became a junior C++ developer. A few weeks I started learning OpenGL (I can give suggestions to who ever is interested). But I know that I am nowhere near the level to make such simulations! I am so impressed that you are still a university student and can produce those videos!

    • @Poe_men
      @Poe_men 3 месяца назад

      sugestions please

    • @npc386
      @npc386 2 месяца назад

      i was thinking about to implement opengl into my little javascript particle system (JPS on github) but during that i came across webgpu and i think thats the better choice. but its hard, shader scripting is another level of abstraction...

  • @samir_buch
    @samir_buch 4 месяца назад +58

    This is super impressive! Casually glossing over the fact that you taught yourself *not just C* but also how to render things with openGL is no small feat. Your in-depth knowledge of particle simulation is also pretty impressive, requiring at the very least knowledge of relatively advanced calculus and physics. And, on top of all of that, this video was very well written and edited. Overall great job, keep it up!

  • @plvr_strg
    @plvr_strg 2 месяца назад +3

    Someone: "You don't need math to be a programmer"
    Yeah, same as you don't need much strength to hold a sledgehammer... but you need it to wield it.

    • @balijosu
      @balijosu Месяц назад +1

      Good metaphor.

  • @youknowwhatlol6628
    @youknowwhatlol6628 4 месяца назад +8

    hello. i am a beginner in all those things and have just found this channel....can't say how grateful I am to you. You, my friend, are an inspiration. You are Knowledge. You are Greatness. You hold the Power.
    Thank you so much. Thanks. Would like to see more of these simluations, math-physics-chemistry-related programs and such.
    Thank you.

    • @DidIJustDoThat
      @DidIJustDoThat 4 месяца назад +1

      I am here with you also a noob

  • @nano-ai
    @nano-ai Месяц назад +1

    this is amazing. i love how you have combined the most notorious subjects like physics and linear algebra and combined them into an amazing program, all in c! absolutely wonderful quality.

  • @yourkidelias
    @yourkidelias 4 месяца назад +5

    This is a great video, and it is surprisingly well edited! I am not interested at all in physics simulation but the way you explained it really made me start paying attention and it was interesting how you used each optimisation technique to achieve even better results!

  • @Hakkyou1
    @Hakkyou1 4 месяца назад +6

    Very nice video ! You might want to also look at fluid simulation using particle called Smoothed Particle Hydrodynamics. Basically you replace the collision algorithm with a constraint on the density modulated by a kernel. It sound bad like this but you already did 90% of the work there. Keep up the good work ! See you next video.

  • @dylancode
    @dylancode 4 месяца назад +1

    The new Sebastian Lague!
    Excellent video!

  • @Arun_Kumar_x86
    @Arun_Kumar_x86 4 месяца назад +4

    this is a great video mate. this video remainds me of sabastian lague's videos. when ever i have thoughts about why i chose programming as a career i think of these kind of videos which boost my happiness and i say to myself that this is why i chose programming as a career to build cool stuffs.
    thanks mate. Great job !!

  • @abdala3475
    @abdala3475 4 месяца назад +71

    And here I am, struggling with a simple pyramid c code

    • @Pepegalord
      @Pepegalord 4 месяца назад +2

      Feel you

    • @MasterofBeats
      @MasterofBeats 4 месяца назад +1

      me fr fr

    • @wardingward4884
      @wardingward4884 4 месяца назад +3

      Its okay, I'll get harder in arrays, and pointers 💀💀

    • @nad.99
      @nad.99 4 месяца назад

      انا

    • @nad.99
      @nad.99 4 месяца назад

      @@wardingward4884 linked lists is where I gave up willingly

  • @deadboy9955
    @deadboy9955 Месяц назад +1

    So much of this is reminiscent of physics used in molecular dynamics simulations.

  • @vasq
    @vasq 4 месяца назад +5

    This is pure art. Amazing work bro.

  • @drakeolejniczak2357
    @drakeolejniczak2357 4 месяца назад +1

    That was awesome! My favorite part was when you found the linear algebra text and got your change of basis on.

  • @PridedBacon
    @PridedBacon 4 месяца назад +203

    Can you pls open-source this

    • @oldgold8247
      @oldgold8247 4 месяца назад +7

      In the description now

    • @w花b
      @w花b 4 месяца назад +8

      Gotta pay for all the spilled sweat

  • @avion85
    @avion85 4 месяца назад +4

    Good luck for your success on yt. We need more content like this.

  • @htchamber2776
    @htchamber2776 Месяц назад

    Channel name + channel banner is literally +1000 aura im gonna steal this

  • @pyrusspangj
    @pyrusspangj 3 месяца назад

    Gradience, this video is absolutely astonishing. Putting aside the great editing and video structure, the flow of your story and the way you tell it is both fascinating, and so intriguing. I adore computer science as a whole, and this is possibly one of my all time favorite videos now. What a masterpiece you've made. Subscribed, and hope to see more of what you do! :)

  • @Stylpe
    @Stylpe 4 месяца назад +1

    This is going to be a fantastic springboard for my own physics sim ideas! Starred, will fork when this makes it to the top of my project queue (it's about number 3 I'd say, but full disclosure, it might also never happen 😛)

  • @bramhuis3571
    @bramhuis3571 4 месяца назад +3

    This video is amazing! It reminds me of Sebastian Lague’s video’s.

    • @Rahim-444
      @Rahim-444 4 месяца назад

      yea very similar project

  • @waffles6555
    @waffles6555 4 месяца назад

    I took a graduate level numerical methods course (my prof contributed to some popular CFD software) and it was very cool to see the different algorithms used. Great job !

  • @kiri9979
    @kiri9979 4 месяца назад +1

    this video is amazing
    it feels like it's been made by a channel with at least a few hundred thousand subs
    keep it up !!

  • @nad.99
    @nad.99 4 месяца назад

    Halfway through this video i feel kms cuz I don’t see myself getting this good anytime soon. Man you’re awesome.

    • @kylerchen2385
      @kylerchen2385 3 месяца назад

      naw bruh you can get this good - its possible for any of us. if u wanna build something like this just fuckin believe in urself dawg u can do it. do that, and videos like this produce nothing but inspiration and excitement for your future work :)

    • @rideaux8533
      @rideaux8533 3 месяца назад

      @@kylerchen2385 its not possible for everyone, but we cant know without trying

  • @bigwalrosswalross3356
    @bigwalrosswalross3356 4 месяца назад +15

    Another awesome programmer I have to subscribe xD
    Great work

  • @agaveboy
    @agaveboy 4 месяца назад +2

    that's great c code if you've really just learned it! good job

  • @wojciechkalinowski3827
    @wojciechkalinowski3827 4 месяца назад +1

    Very nicely done! I like that you said what you did and kept it rather high level for the video. Whereas, if needed, and if you haven't already, then you can make a more detailed video for the code and maths. Great paste and keep at it!!

  • @dantedellatogna
    @dantedellatogna 4 месяца назад +4

    Now I want to do this by myself.

  • @Sirepicwin
    @Sirepicwin 4 месяца назад

    I literally just stumbled on this video, amazing and very fun to watch. Made want to actually learn C and take a break from JS for while lol

  • @jonathan2847
    @jonathan2847 4 месяца назад +15

    Engineers make a small number of good RUclips videos then dip back into the void to do their job. This is the good shit.

  • @JMW1906
    @JMW1906 4 месяца назад +1

    One more was to implement optimization is to compare the length squared (in handle collision) instead of competing the length. It means you replace a square root call (expensive) with two multiplications (one of the radius is the same), which can even be pre computed once if every sphere has the same radius:
    x²+y²+z² < 2r²

    • @gr4dience
      @gr4dience  4 месяца назад +1

      That was my initial thought as well! The only issue is that to "resolve" the collisions, you still need to push each particle apart by half their separation so you would need to compute the distance regardless. I tried moving the square root function inside that condition but it didn't make too much of a difference :)

    • @JMW1906
      @JMW1906 4 месяца назад +1

      @@gr4dience true, haven't thought about the fact that you need the value later.
      Still interesting though that it makes almost no difference when computed inside the if body. I think that means the grouping into chunks optimization to not check every sphere against every other has a good grid size and already avoids most checks, so most checks have to do the sqrt anyways.

  • @thewholeworldblurred
    @thewholeworldblurred 4 месяца назад +41

    I clicked because of C!

  • @veroxid
    @veroxid 2 месяца назад

    Something to note about a lot of the extremely high-count simulations on YT is that they are not real-time, they are pre-rendered. While it's true that Python can literally never surpass C in terms of processing speed _(considering Python is written in C)_ your biggest boost in particle numbers would have been to simply switch to having it pre-rendered before viewing it.

  • @ed7590
    @ed7590 4 месяца назад +1

    Inspiring, makes me want to drop all my JS projects and return to low level.

  • @bird5790
    @bird5790 4 месяца назад +1

    If you are working with grids, the paper "Compact, fast and robust grids for ray tracing" is very worth reading to optimize further

    • @gr4dience
      @gr4dience  4 месяца назад

      I'll check it out!

  • @arthurmac2511
    @arthurmac2511 3 месяца назад

    Now i have another reason to keep studying. You're an inspiration for me :D.

  • @justins7796
    @justins7796 4 месяца назад

    dang you're a legend if you used a physical Linear Algebra textbook to solve your problems. Subbed!

  • @dennischen2922
    @dennischen2922 4 месяца назад

    This is such an awesome project! Glad to see a fellow NC State student doing cool things!

  • @evanbarnes9984
    @evanbarnes9984 4 месяца назад +2

    Instantly subscribed! My god this is good.

  • @serhiiko7141
    @serhiiko7141 4 месяца назад +1

    this video deserves much more than 2.7 k views

  • @Dontlikeyellow
    @Dontlikeyellow 4 месяца назад +2

    When you try to optimize but your project was made in python:

  • @gabomandam7654
    @gabomandam7654 3 месяца назад

    I just love a good simulation, and even better when it's on C.

  • @elon_mysk3278
    @elon_mysk3278 4 месяца назад +1

    Hey there, Gradience!
    I have a few questions for you!
    First off, I'm curious about how you created the particle simulation using Python. Which frameworks or modules did you use? I consider myself pretty advanced in Python, but I've never seen particle simulations implemented with Python before! :D
    I'm actually in the process of teaching myself C++ with the intention of creating a particle simulation. I believe it would be incredibly useful for my work as a Research Assistant in mechanical engineering! Your video has actually motivated me quite a bit! :D
    Also, in your pinned comment, you mentioned that your semester just ended. Could you tell me more about what and where you're studying?
    Looking forward to more content from you!

    • @gr4dience
      @gr4dience  4 месяца назад +1

      Hello! For the Python version I used the NumPy and Pyrr packages for math and linear algebra respectively (they both rely on C internally for some operations/speed). Additionally I used PyGame for window/input management and OpenGL (PyOpenGL wrapper) for rendering w/ the GPU.
      You can certainly get pretty far with Python and it allowed me to prototype very quickly. The fact that you can create an entire HashMap with just 4 characters is truly remarkable. That being said, I wouldn't recommend it for a long-term project because of the poor performance and lack of real infrastructure for something like real-time simulation.
      I am currently a CS student in North Carolina. Thanks for the support and best of luck on your project!

  • @philipmichel-dv
    @philipmichel-dv 4 месяца назад

    really beautiful video . i can now see the importance o mathemetics in programming

  • @StevenMartinGuitar
    @StevenMartinGuitar 4 месяца назад +2

    "still a million bugs left to implement" 😂

  • @chairlesscrocodile
    @chairlesscrocodile 4 месяца назад +3

    Great video!

  • @space-yg
    @space-yg 4 месяца назад +2

    Yoooooo amazing video!! I learned so much from it

  • @3dgar7eandro
    @3dgar7eandro 4 месяца назад +2

    Cool Bro!

  • @lbgonpokeit
    @lbgonpokeit 4 месяца назад

    Awesome video, Man I could watch this stuff all day 😅

  • @KlojMaalem
    @KlojMaalem 23 дня назад

    nice and simple representation

  • @yoyo3257
    @yoyo3257 3 месяца назад

    When you realise that math class was not just a class
    Fantastic good job

  • @mathiasensimon
    @mathiasensimon 4 месяца назад +1

    Cant wait for more videos😊

  • @Green-Code
    @Green-Code 4 месяца назад +1

    Great video! Keep it up!

  • @sirjersey
    @sirjersey 4 месяца назад +1

    Amazing Video! Definitley learned something new :)

  • @lel7531
    @lel7531 4 месяца назад +1

    Very cool video, top notch editing

  • @_david_548k_6
    @_david_548k_6 3 месяца назад

    I don't understand nothing but this is art

  • @mohammadalaaelghamry8010
    @mohammadalaaelghamry8010 3 месяца назад

    Great video, thank you for sharing.

  • @odb7393
    @odb7393 4 месяца назад

    Great video dude!
    I notice your math library doesn’t take advantage of SIMD. Using something like cglm could be a performance boost :)

  • @romeoxxiv
    @romeoxxiv 4 месяца назад +1

    Very interesting, thank you!

  • @eggrevolver
    @eggrevolver 4 месяца назад +1

    Super cool video!
    What is the GPU used? I'm just curious how much can the owner of something widespread achieve, like GF1060/2060/3060/4060?

    • @gr4dience
      @gr4dience  4 месяца назад +1

      The system specs are in the repo in the description. Technically, the GPU I used was an Apple M1 SoC...

  • @DwellerLord
    @DwellerLord 4 месяца назад

    This is the best video I've seen all year

  • @Spencersstory
    @Spencersstory 4 месяца назад

    Sick good work man. Makes me remember why I chose computer science

  • @nothingtobelie
    @nothingtobelie 12 дней назад

    Thank you for sharing!

  • @shuraosipov
    @shuraosipov 4 месяца назад +1

    Good job, man!

  • @ArmanNadjarian
    @ArmanNadjarian 4 месяца назад +1

    Fantastic work!

  • @ticusism
    @ticusism 4 месяца назад

    Awesome! Thanks for sharing your journey.

  • @osalem192
    @osalem192 4 месяца назад

    A new Sebastian Lague!
    Keep going!

  • @futuremapper_
    @futuremapper_ 4 месяца назад +2

    Love this!

  • @Mia-tk7dz
    @Mia-tk7dz 4 месяца назад +1

    love the video! good stuff

  • @p3ntag01
    @p3ntag01 3 месяца назад

    Nice Video Dude !

  • @ronald1851
    @ronald1851 4 месяца назад +1

    awesome possum my guy

  • @VulgoGS
    @VulgoGS Месяц назад

    Awesome video !

  • @joaoruss0
    @joaoruss0 4 месяца назад +1

    First vid and 15K views? Subscribing!

  • @blvnktek
    @blvnktek 4 месяца назад +1

    You got my sub sir!

  • @gismetmajidov
    @gismetmajidov 4 месяца назад

    This is really beautiful sir. I'd like to know what you use as a framework. What framework do you use sir?

  • @Gaiuscassius565
    @Gaiuscassius565 4 месяца назад

    super cool job. Very inspiring i wish i could do something like this

  • @Fly1ngStep
    @Fly1ngStep 4 месяца назад

    i've got no fucking clue about the math and the code behind it ( only starting with html css basics) but its so cool to follow your path around it . gitcommit scene killed it on top :D

  • @coffeecatrailway
    @coffeecatrailway 4 месяца назад +1

    Now I want to go back to my snad sim project in Godot..

  • @skyt-csgo376
    @skyt-csgo376 4 месяца назад +1

    Awsome work!

  • @LethalChicken77
    @LethalChicken77 4 месяца назад +1

    When I was simulating boids (which is very similar to particle fluid), the two things the sped it up the most were compiler optimizations and spatial partitioning. For the optimizations, I went with -OFast, which was definitely the biggest proportional improvement.

  • @antonpkf
    @antonpkf 4 месяца назад

    good job b!

  • @hangnumburs
    @hangnumburs 3 месяца назад

    9:27 holy theorem!

  • @Wannabetolkien
    @Wannabetolkien 4 месяца назад

    Amazing Work ! Post more content.❤

  • @raxirex6443
    @raxirex6443 2 месяца назад

    Well put.

  • @daxmiller2670
    @daxmiller2670 4 месяца назад

    teaching myself c so I can build a universe like the one we live in

  • @MCroppered
    @MCroppered 4 месяца назад +1

    This is what gets you hired. Fantastic work.

  • @pacoelizondo514
    @pacoelizondo514 4 месяца назад

    porting this to linux will be a nice project

  • @the_speedy_dog6808
    @the_speedy_dog6808 4 месяца назад +1

    this was amazing :)

  • @oussamasebbar185
    @oussamasebbar185 4 месяца назад

    heyy man i really appreciated your video , i'd like to know the music you used t really got me hooked and i think it would be great to code ( with C ofc ) listening to it

  • @aspectreishauntingeurope
    @aspectreishauntingeurope 4 месяца назад +2

    very cute!

  • @Codrootbeyond
    @Codrootbeyond 4 месяца назад +1

    Great video

  • @rgel3762
    @rgel3762 4 месяца назад

    Just what I was looking for

  • @Alexander-pk1tu
    @Alexander-pk1tu 4 месяца назад

    Good work man!!

  • @User12319.
    @User12319. 4 месяца назад

    Hey I am just curious and wants to ask you, how your self-teaching process looks like. Are you using any books (structured learning) or just watching Videos? Secondly, how much are you going into depth? Are you more like the person who is also trying to understand the very low level stuff i.e. the memory manipulation when you call a function or how exactly the dot operator work in machine or are you more the high level person who just studies what the elements do and what its purpose without trying to understand the low level operation behind it? Appreciate your time.

  • @AndRei-yc3ti
    @AndRei-yc3ti 4 месяца назад

    Can you please show how to do a gravity simulation between 2, 3, 4, n number of bodies? That would be very interesting

  • @m3tazodeh66
    @m3tazodeh66 4 месяца назад

    This is soo cool

  • @KhoiNguyen-fj6jp
    @KhoiNguyen-fj6jp 13 дней назад

    Hey man, which graphic lib did you use to draw the 3d model?

  • @novantha1
    @novantha1 4 месяца назад

    I wonder if a person couldn't do the Euler method in practice, but use a more precise method like Verlet integration (or even a more expensive method that couldn't normally be used in real time) to train an MLP block to account for the error between the Euler method and the ground truth.
    ie: x(t + dt) = x(t) + v(t)dt - W(x)
    Where W(x) results in the estimated error value for the given step.