How Computers Draw Weird Shapes (Marching Squares)

Sdílet
Vložit
  • čas přidán 31. 05. 2024
  • In this video, we start with an interesting animation of blobby objects which we introduce as metaballs. There's a lot of surprisingly intricate ideas behind making these objects render on a screen. We'll see how folks in computer graphics attempted to solve this problem through a really elegant algorithm called marching squares. Marching squares is a really powerful algorithm that allows you to render any implicit function. But what's even more impressive in my opinion is the many clever shifts in perspective that allowed a vague problems such as this one to be transformed into a clear, well-defined, and solvable problem.
    0:00 Introduction
    3:29 Circles and Ellipses
    4:57 Defining the Problem
    6:00 A Guessing Game
    8:29 Contours around Two Points
    10:35 Sampling The Space
    12:32 Breaking Down Cases
    15:00 A Clever Optimization
    17:20 How Marching Squares Works
    18:59 Parallel Marching Squares
    20:21 How Do Metaballs Work?
    24:59 Marching Cubes
    25:58 Some Parting Thoughts
    References/Additional Resources:
    jamie-wong.com/2014/08/19/meta... - the initial inspiration for the framework of this video, great introduction to metaballs and how they can be rendered using marching squares.
    www.geisswerks.com/ryan/BLOBS/... - great resource on implementing metaballs and some of the physics inspirations behind implicit functions
    Original Marching cubes paper: www.researchgate.net/publicat...
    Sebastian Lague Video on Marching Cubes:
    • Coding Adventure: Marc...
    Further reading on polynomial approximations of metaball implicit functions:
    www.researchgate.net/publicat...
    Implementation Help for Marching Cubes
    paulbourke.net/geometry/implic...
    Excellent lecture by Casey Muratori about Marching Cubes: • "Papers I Have Loved" ...
    courses.lumenlearning.com/phy... - some of the physics behind equipotential lines in electric fields
    Support: / reducible
    Twitter: / reducible20
    This video wouldn't be possible without the open source library manim created by 3blue1brown and maintained by Manim Community.
    The Manim Community Developers. (2021). Manim - Mathematical Animation Framework (Version v0.11.0) [Computer software]. www.manim.community/
    Here is link to the repository that contains the code used to generate the animations in this video: github.com/nipunramk/Reducible
    All music in the video is from Aakash Gandhi

Komentáře • 527

  • @TiagoTiagoT
    @TiagoTiagoT Před 2 lety +500

    A "cheaty" way to draw metaballs is to start with a black-and-white picture with solid circles (or any shapes, since they could be constructed by combining circles), apply gaussian blur, then reduce it back from grayscale to purely black-and-white with a threshold function.

    • @gershommaes902
      @gershommaes902 Před 2 lety +132

      That actually sounds like it resolves to essentially the same approach seen here! Additive gaussian blurs will behave like sums of inverse-radius functions. (No marching squares tho; just per-pixel shading)

    • @Kaytsey
      @Kaytsey Před 2 lety +15

      Yup, that's pretty much how I know it too.

    • @RottenFishbone
      @RottenFishbone Před 2 lety +17

      Accidentally did exactly that when trying to make light blending. First thing I thought when he said "how would you go about this?"

    • @Crazymoniker
      @Crazymoniker Před 2 lety +6

      I used a similar method to have "equal distance travel" around obstacles, to create realistic borders for a DnD campaign I ran.

    • @MrNicePotato
      @MrNicePotato Před 2 lety +11

      Well this video tries to get the the bare bones of computer graphics and "applying gaussian blur" involves just as much math and deliberation as the video.

  • @mrvzhao
    @mrvzhao Před 2 lety +859

    Bravo! Now, after hearing 'metaball' so many times in 27 minutes, I'm off to get myself some meatballs...

    • @Reducible
      @Reducible  Před 2 lety +139

      Every time I read the word metaballs in the script, I got hungry. I feel you :)

    • @igxniisan6996
      @igxniisan6996 Před 2 lety +23

      You just stole my copyrighted thought..
      And now I've to think of a different comment 😑....

    • @Blox117
      @Blox117 Před 2 lety +6

      shameful that you aren't off to get batman

    • @humankerbal3623
      @humankerbal3623 Před 2 lety +3

      Off to ikea

    • @redfoxlightning
      @redfoxlightning Před 2 lety +6

      @@igxniisan6996 I know THAT feeling xD

  • @_Baku
    @_Baku Před 2 lety +259

    Maybe it's my physics background, but when you asked how we would approach it, my mind immediately went to contour lines on a potential field. Of course, I had no idea how to use that to actually render the metaballs, but I'll take what I can get.

    • @moustholmes
      @moustholmes Před 2 lety +17

      Same, I immediately thought they look like a contour of inverse square law. Funny that you really get at feel for how different functions looks and behaves in different situations.

    • @Reducible
      @Reducible  Před 2 lety +54

      Haha yeah, secretly, my favorite part of making this video was explaining that really cool connection with potential lines in an electric field. For me, it was just an amazing connection. I love hearing how people from different backgrounds think about these problems. Thanks for sharing!

    • @alpers.2123
      @alpers.2123 Před 2 lety +13

      As a wizard, I agree. Just use a force field.

    • @guilhermetorresj
      @guilhermetorresj Před 2 lety +6

      As an electrical engineer, I had the exact same though as you did. Marching squares makes it a lot more efficient, and that was the part I couldn't come up with by myself.

    • @SreenikethanI
      @SreenikethanI Před 2 lety +1

      SAME!!!

  • @Mutual_Information
    @Mutual_Information Před 2 lety +189

    It’s wild to me how simple seeming tasks require such clever algorithms. Makes you appreciate a lot of the craziness computers do behind the scenes.

  • @Adamreir
    @Adamreir Před 2 lety +279

    There’s an inflatuon of Manim films being created right now, but yours really stand out! I mean, this is 3b1b level. Amazing!

    • @mayabartolabac
      @mayabartolabac Před 2 lety +14

      he should have submitted something for SoME1 but i guess he's more in the CS side of things

    • @_okedata
      @_okedata Před 2 lety +15

      @@mayabartolabac CS is allowed in SoME1, i think its more because SoME1 was to encourage people who are thinking about starting a channel to start, whilst he already has videos

    • @mayabartolabac
      @mayabartolabac Před 2 lety +2

      @@_okedata oooohhh so that's why i don't see any familiar names on the compet

  • @suvigyavijay
    @suvigyavijay Před 2 lety +530

    Amazing, once you understand marching squares/cubes and how they are "embarrassingly" parallel, you seem to understand that why graphics cards are much more powerful at rendering than a normal processor. This is probably always skipped when people explain the difference between CPUs and GPUs.

    • @Reducible
      @Reducible  Před 2 lety +153

      Yeah I actually originally had an entire section of the script dedicated to the differences of the CPU and GPU and how there are specialized programs called shaders that allow a path of communication with the GPU for highly parallel operations. In practice, almost any high performance implementation of marching squares should use shaders. I wanted to go there, but if I did, it would be an hour long video :)
      Perhaps some time in the future.

    • @joepgeuskens527
      @joepgeuskens527 Před 2 lety +28

      @@Reducible Can't wait for a video on this!

    • @sponge1234ify
      @sponge1234ify Před 2 lety +8

      @@Reducible +1 support on that video!

    • @georgeskhater487
      @georgeskhater487 Před 2 lety +6

      @@Reducible we want this

    • @QuanrumPresence
      @QuanrumPresence Před 2 lety +4

      @@Reducible Please do :). We will wait

  • @fredericmazoit1441
    @fredericmazoit1441 Před 2 lety +92

    Unknowingly, you brought me 30 years ago.
    Back then, I was obsessed with Mandelbrot sets. I had programmed a rendering algorithm for it but it took ages to complete, and I was desperately trying to find a faster way. In the end, I succeeded but, reinventing a variant of marching squares.
    1. First compute all the points on a, say 16*16 grid. This is roughly 16*16=256 times faster than computing all the whole image.
    2. For any center of a 16*16 square, if all corners have the same value, then set the center value to be the same. Otherwise, compute it. You end up with a "diamond" grid.
    3. For each diamond, do the same. You and up with an 8*8 grid.
    Go back to step 1 until you have an 1*1 grid.
    With this, I could draw a Mandelbrot set much, much faster than before.
    Once I had done this, I wanted to compute in real time animations on the Mandelbrot set. To save even more time, I used the old picture to guess the points on the first 16*16 grid. If all the neighbors of a point on the old 16*16 gris had the same value, then I guessed that the corresponding point on the new grid also had the same value.
    Both technics can be used to speed up marching squares for graphics animations but the drawback is the it becomes far less obvious how to obtain a parallel version.

    • @Reducible
      @Reducible  Před 2 lety +22

      Wow, an interesting application of it I hadn't realized! Thanks for sharing that story!

    • @zyansheep
      @zyansheep Před 2 lety +2

      Yo I literally came up with this search-then-refine idea while I was watching the video. Kinda reminds me of how collision detection works with kd-trees.
      This video: czcams.com/video/eED4bSkYCB8/video.html

    •  Před 2 lety

      Fractint had even more tracks up its sleeves back in the day to render fractals really fast even on underpowered 80386s.
      You can use the amazing.fact that the Mandelbrot set is connected.

  • @TheBookDoctor
    @TheBookDoctor Před 2 lety +84

    I've certainly heard about marching cubes in the past, and have even seen Sebastian's video before. But framing it as a general purpose solution for finding implicit curves, wow. To me, that's a very "sticky" way of explaining it. Fabulous!

  • @TheRealBoof
    @TheRealBoof Před 2 lety +39

    11:10 is a really trippy visual illusion that I've never seen before! Some of the blue dots look like black dots with a blue outline, but when you go to look at that dot it changes back into a solid blue dot.

    • @nisargbhavsar25
      @nisargbhavsar25 Před 2 lety +2

      Happened with me too!

    • @geeshta
      @geeshta Před 2 lety +3

      If you actually look at one place for long enough, the outline dots will disappear completely and only the grid will be left in your peripheral vision! For your brain it's much easier to just assume it's a simple grid so it "caches" a simple grid instead of actually focusing on what you actually see!

    • @DanDeebster
      @DanDeebster Před 2 lety +3

      It's known as the scintillating grid illusion.

    • @TheRealBoof
      @TheRealBoof Před 2 lety

      @@DanDeebster 💯💯💯 Thank you!!!

  • @jursamaj
    @jursamaj Před 2 lety +75

    Just a clarification: those oblong shapes are *not* ellipses.
    Also, this algorithm only works well if all the details of your shape are significantly larger than your starting grid. If not, then the 16 classifications can be *way* off from the shape.

    • @cooperfeld
      @cooperfeld Před 2 lety +6

      Thanks for clearing up, I had a similar thing in mind: What if the shape has very fine details, like a couple of jags inside such a grid cell, and what about shapes with many small holes? Either you need a very fine grid resolution (inefficient for realtime applications), or use quad/oct trees at the expense of simplicity. It's fine like it is for simple, smooth shapes. Yet I wished for a more universal concept covering all shapetypes - I suppose that's a lot asked). Very good video illustration on this topic though!

    • @TurtleKwitty
      @TurtleKwitty Před 2 lety +8

      @@cooperfeld If you need that much precision then nothing is stopping you from making the grid 1px in size, and thank the gpu for being good at its job haha

    • @McPhage
      @McPhage Před 2 lety +11

      You're right, but that same problem occurs with any sampling-based method-details of the contour might get lost between samples. So you need to pick a resolution which corresponds to how much complexity your implicit function has.

    • @Reducible
      @Reducible  Před 2 lety +24

      Yes, you are correct -- I put the "Ellipses" part in quotation purposefully here, but I probably should have been more clear. And also, good point on the details of the shape, this is an important consideration when implementing this in practice.

    • @guilhermetorresj
      @guilhermetorresj Před 2 lety +9

      Yah, the grid resolution is basically some 2D analogy with a low pass filter. Any details whose features are significantly smaller than a cell of the grid will be lost.

  • @hjups
    @hjups Před 2 lety +33

    If you have time, you might want to experiment with implementing adaptive refinement. A coarse grid produces jagged resolutions, and a fine grid wastes a lot of computation. Instead, you can successively divide the boundary cells into smaller cells until you reach some pre-set number of levels, and then apply marching squares to the list of edges within the adaptive grid. A similar method is used in many computational fluid dynamics codes.
    You would also have the option at that point to skip the marching squares stage if you divide down to the point where you grid matches the output resolution (the pixel is either filled or not). If you're wondering about parallelization for such an implementation, typically the domain is divided into chunks based on the number of parallel processors, and if one chunk becomes overloaded with computation while others are idle, then it can shed some of the load to the idle processors (who then take on those sub-chunk regions). Also, you can utilize the previous state (for an animation or simulation) as a starting point for the next time step. There you know that grid cells need to be merged or subdivided further, which would be based on the function evaluations in the next time step. It can quickly become very complicated, but it's always cool to see the grid changing every timestep.

    • @HenryLoenwind
      @HenryLoenwind Před 2 lety +2

      And if you want to optimize even further, you can use your knowledge of the function: For metaballs, there are n known locations (where n is the number of circles) that must be inside the function (the centers of the circles). If you start marching there until you hit an edge and then follow the edge, you reduce the number of squares you need to look at dramatically. Or even better, you start at distance r away from each center and march outward until you find the edge.

    • @hjups
      @hjups Před 2 lety

      ​@@HenryLoenwind That could help to accelerate this specific problem, but not the more general problem of arbitrary functions (which is the more interesting case). Although, there are methods for basically phrasing general functions in the form of overlapping radial functions (essentially a basis transformation - that's essentially the difference between grid based and particle based fluid dynamics simulations, and you could use the center -> edge marching method to convert the particle case to the grid case). Note that the edge distance R is only known in the case where particles / meatballs don't overlap, when they do, the potential field is shifted and that distance is no longer correct. One disadvantage to doing the radial walking approach though, is that you may end up visiting a cell multiple times which wastes computation. Also it's not embarrassingly parallel anymore, nor is it regular in the memory access patern.

    • @mettaursp309
      @mettaursp309 Před 2 lety

      I think the strengths of this type of technique really shine with the 3D sibling: marching cubes. Jagged edges like that become much less apparent on 3D geometry once you start diving into vertex value interpolation, used for smoothing surface normals across a triangle & more, and other more advanced techniques that break up the visual patterns.
      It's not necessarily the best there either, because there are more refined competing algorithms that do similar things like dual contouring or marching tetrahedra, but it's still a perfectly fine technique that can be used to great effect.
      It's a popular style of technique because it makes great use of modern hardware, works well in general cases, and often gets close enough to the desired result that no real end user is ever going to notice something is off.

  • @Ironypencil
    @Ironypencil Před 2 lety +23

    A very interesting application of these iso fields is "signed distance functions" used in raymarching, which allow highly performant rendering of 3d fractals.

    • @MichaelPohoreski
      @MichaelPohoreski Před 2 lety +9

      Signed Distance Fields can also be used in font rendering. (Valve literally wrote the white paper on it.) Unreal Engine 5 also uses then for virtual geometry.

  • @ginsYT
    @ginsYT Před 2 lety +11

    Great video! When you said at the start, "How would you even start?", I decided to pause the video and accept the challenge (i guess I'm one of the people who is "anything like you" :D). I theorycrafted a solution and implemented a proof of concept in simple JavaScript with Canvas.
    Then I watched the video to compare with your results, and it turns out I arrived at the same shape function, just my rasterization was slightly different (pixel based instead of vector based), but I suppose both approaches lend themselves to different applications.
    The last part really resonated with me, because I'd heard of all these concepts in one way or another in university lectures. While I didn't quite "forget" them and was happy to find them somewhere in the back of my mind to apply to this problem, tackling a "practical" challenge such as this one, outside of the "campus environment", refreshed me on these subjects, enhanced my understanding of them and is really going to cement them in my brain!

  • @okiguessineedahandle
    @okiguessineedahandle Před 2 lety +4

    One ~kinda~ extension / similar concept of this I personally like is the use of signed-distance functions in ray marched rendering, allowing you to render perfectly mathematical objects with high precision by just sequentially polling a math function to ask "how far away am I from the surface of the closest function" then pushing your ray tracing ray forward by that amount in space (therefor never passing any object which the ray may intersect with) with this you can then render 3d fractals with incredible detail fairly easily. if you want to render multiple fractles its also easy as you just take the minimum of their signed distance funciton.

  • @gasparliboreiro4572
    @gasparliboreiro4572 Před 2 lety +7

    9:27 this method is really good for finding the border of a shape, but in concave shapes only!
    if you have a convex shape you will only find 1 border that cuts the line between the two points

  • @N____er
    @N____er Před 2 lety +10

    "Important note: do not confuse metaballs with meatballs" this got me bursting in laughter

  • @98perova
    @98perova Před 2 lety +3

    Great video! I like how you explain the algorithm as the solution to a specific problem, it gives more insight on why the algorithm is how it is, and it's something that other videos on marching square lack.

  • @mahousenshi00
    @mahousenshi00 Před 2 lety +6

    When you are on the point that you can teach it, like you did here, you "groked" the concept. You may forget details but the concept will live forever on your toolbox.

  • @Balawi28
    @Balawi28 Před 2 lety +6

    You are a wonderful narrator, I really enjoyed every section of the video, how you begin with a well-defined goal, and how you reach the final goal in a beautiful eased flow.

  • @ProjectPhysX
    @ProjectPhysX Před 2 lety +17

    I use the 3D variant of this - marching cubes - to render simulated fluids volumetrically, directly on the GPU in parallel. The simulation determines the very limited lattice resolution, so resolution is not a free parameter in my case. See my channel for examples :)

  • @MagicGonads
    @MagicGonads Před 2 lety +9

    One thing missing is properly deciding how to do the thickness of the line segments within the squares.
    You naively just used a rectangle but what you actually want is a trapezium, so the edges do not have little triangular gaps between squares (and so they don't overlap, though that's less important if the shape is entirely opaque)

  • @ballman2010
    @ballman2010 Před 2 lety

    I watched the full video and then came back a few days later because I kept thinking about it, and I had to show my appreciation for such a clear explanation. VERY well done, I have zero doubt that I could implement this algorithm based solely on this video. I've read a lot of published articles that I wouldn't say this about. Well done.

  • @alegian7934
    @alegian7934 Před 2 lety +1

    3 concepts i understand very well individually, beautifully merged into one problem. Awesome vid!

  • @sebbes333
    @sebbes333 Před 2 lety +4

    eg. 25:17 You can probably improve the drawing speed by marking the neighboring cubes (or squares) around every place where you HAVE drawn a line (like an array with coordinates), then the marked cubes gets checked first for any lines (and surrounding cubes are marked again if a line is drawn), you can speed it up even further by analyzing the direction of the line & only add the spaces in the CORRECT direction to the marked list (can add the other surrounding cubes to a list of lower priority).
    Then you can have like just one computer core running the normal marching square algorithm, just in case there is another object that isn't connected, so you "brute force" its detection.

  • @uy-ge3dm
    @uy-ge3dm Před 2 lety +3

    I've watched only the introduction section and I've almost solved the problem myself, and it looks exactly like the animation! Here is my solution.
    Inspired by the how the influence of the other circle diminishes drastically as it moves further away as well as how an ellipse has two foci, I realized that the equation 1/sqrt((x-d)^2+y^2) + 1/sqrt((x+d)^2+y^2) = 1 reproduces the exact behavior, where d is half the distance between the centers. Testing this out in desmos gives the correct behavior. Adding more circles works by simply adding more 1/sqrt(distance) terms to the LHS, so the program really just needs to keep track of circle positions and be able to draw the resulting curve. Drawing the resulting curve is obviously the hard part.

  • @sadpancake6563
    @sadpancake6563 Před 2 lety +8

    You don't need marching squares for metaballs, you can create the same effect using only shaders, maybe ddxy for antialiasing. But yes, marching squares, cubes are amazing.

  • @BrianAmedee
    @BrianAmedee Před 2 lety +1

    This is such an impressively simple explanation for a complicated topic! Nicely done!

  • @juanma4978
    @juanma4978 Před 2 lety +1

    I literally rediscovered by my own what you explain in the sections "contours around two points" and "sampling the space" some days ago when designing a method for aproximating the shape of a given curve with no known expression. I couldn't believe it when you explained what I had just written on my notebook, math is amazing, two persons will always reach the same conclusion even without knowing of each other. Really loved your vid, amazing work, keep it up!

  • @Number_Cruncher
    @Number_Cruncher Před 2 lety +2

    Your videos are just amazing and so inspirational. I felt a bit ashamed though, having majored in physics and not having had the slightest clue initially that electric charges where acting behind the scenes. Just, incredible. Thank you very much.

  • @PiercingSight
    @PiercingSight Před 2 lety +2

    When I made a stupid small lava lamp app a long long time ago, my first approach was literally just to make blurry white circles on a black background, add them together, and then clamp the pixel values above and below a specific value between black and white. Just use that as a mask for some texture, add shading and other effects, and boom. That's it. It just instinctively made sense.
    In this case, your metaballs use an inverse square "blur" instead of a linear "blur" or a Gaussian "blur" (which I used). There are many interesting functions that could be used to make different kinds of "metaballs", but the inverse square seems to be the most common function used, probably because it goes to infinite distance, resulting in smoother metaballs.

  • @jackwang8105
    @jackwang8105 Před 2 lety +1

    This video deserves more views!!! Thanks for your work!

  • @iaobardar3452
    @iaobardar3452 Před 2 lety +2

    That was a great description! I’ve heard of marching squares before, but seeing this video has helped me see it a different way. Could you make a video about dual contouring? It’s another similar method that has cleaner results but is more complicated.

  • @nstryder-music
    @nstryder-music Před 2 lety

    after seeing countless videos on marching squares/cubes and not understanding the "why" behind it, this video finally made me get it! Thank you!

  • @user-qx1mw6xs4n
    @user-qx1mw6xs4n Před rokem

    One of the clearest explanation i saw , Hats off man.

  • @adrianrevill7686
    @adrianrevill7686 Před 2 lety

    Excellent video, I have tried several times to understand marching cubes, now re-watching Sebastian's video makes complete sense.

  • @nanamacapagal8342
    @nanamacapagal8342 Před rokem

    The way you rediscovered this topic of metaballs is actually pretty relatable. I've learned much more in pretty much any topic (mostly computer science) by simply playing around, looking into things, solving problems, and creating projects, than by taking a course.

  • @PGETSA17
    @PGETSA17 Před rokem

    I really really love this video, and now I understand a lot of new things. When you introduced the problem, I had the same 3 questions that you proposed! Thank you, great video.

  • @peterronhovde
    @peterronhovde Před 2 lety

    I liked how you broke the technical problems down into bite-sized bits while keeping the element of discovery. Good job.

  • @garr061
    @garr061 Před 2 lety

    Wildly satisfying.
    Thank you for the explanation!

  • @ChrisOffner
    @ChrisOffner Před rokem

    Absolutely beautiful explanation and presentation! Thank you so much. ❤️

  • @bigphatballllz
    @bigphatballllz Před 2 lety +10

    For the curious among us, sabestian lague made a video about marching squares generalized to 3D in his terraforming video. This was a great explaination for the 2D case!

    • @Reducible
      @Reducible  Před 2 lety +2

      Yes, absolutely! I recommend it at 25:51, it's an excellent video on the topic.

    • @bigphatballllz
      @bigphatballllz Před 2 lety

      @@Reducible Yeah, thanks for replying! BTW, you should have participated in SoME. You could have won :)

  • @stjernis
    @stjernis Před 2 lety +6

    Nice exposition, but I was left wondering about the special cases where you may miss a local maxima or minima within a square. For the metaball problem that should be relatively easy to avoid reliably since all local maxima are given (= the coordinates of the balls), but if you're working with an arbitrary function it's a risk, regardless how fine a grid you use (and for fractals it's a certainty). I can imagine these things are a bit messy to go into, but I think it's worth mentioning.

  • @adrianv.v.4445
    @adrianv.v.4445 Před 2 lety

    I'm discovering so many incredible math channels, keep up the content! ^^

  • @danielfernandes1010
    @danielfernandes1010 Před 2 lety

    The reveal of the metaball function was beautiful! Thank you for your amazing videos!

  • @berkansivrikaya9055
    @berkansivrikaya9055 Před 2 lety

    Great video. I randomly started then couldn't leave it. The ideas 💥 me away. 👍

  • @oriyonay8825
    @oriyonay8825 Před rokem +2

    i love this video!
    an idea i had while watching it would be to keep a queue of all squares that the contour passes through the contour. then we could iteratively divide each square in the queue into four smaller squares and perform the same root-finding algorithm on them to further refine the quality of our contour, and push those four squares back onto the queue. we discard squares from the queue once they reach a certain size (i.e., once they're small enough).
    i wonder if anyone's done that!

  • @skeletonboxers7336
    @skeletonboxers7336 Před rokem

    computer graphics was one of the classes that just never lined up during my time in university. so ive been spending my time since graduation learning concepts of things i missed out on (and job hunting as well lol) and this has to be one of my favorite concepts to be self teaching. i heard the class was hell, and i guess im glad in a way to be learning it through more digestible and paced content from creators like you.

  • @CrushedAsian255
    @CrushedAsian255 Před rokem +1

    Thanks so much for making this video! This encouraged me to try making my own metaball renderer using marching squares, which I completed. It works well but did take like ~3 days to write. (mostly bug fixing the marching squares)

  • @yah3136
    @yah3136 Před 2 lety

    There is tow kinds of auditors, the ones who tries to show he understand the subject, and the ones where the auditor make you understand the subject : you are clearly one of the second category, congratulations.
    And referencing Sebastian Lague who is such a source of inspiration for just the cherry on the cake, you got a new subscriber :-)

  • @Bruh-sp2bj
    @Bruh-sp2bj Před 2 lety

    hope you do more videos, you may be one of the best computer science channels that Ive seen so far.

  • @Taterzz
    @Taterzz Před 2 lety +3

    you know after seeing the contour cases i couldn't help but think that that's exactly the style of tiling that pixel art uses. with those basic shapes, they can essentially create any style of terrain and make it look organic.

  • @jacobyoung6876
    @jacobyoung6876 Před 2 lety

    Such an excellent explanation!

  • @agargamer6759
    @agargamer6759 Před 2 lety

    What a beautiful idea and explanation!

  • @darshigoswami5124
    @darshigoswami5124 Před 2 lety +2

    Would love if you make a video detailing the process of procedural generation... your videos are an absolute masterpiece .

  • @ikocheratcr
    @ikocheratcr Před 2 lety

    Very nice explanation of marching squares and metaballs.

  • @AWESOMEEVERYDAY101
    @AWESOMEEVERYDAY101 Před 2 lety +2

    As soon as the physics connection was made it was like a wave of everything hitting me at once of what I had learnt in physics class and realised i've also fallen into the study-test-forget loop.

  • @kevincsellak296
    @kevincsellak296 Před 2 lety

    My first thought was “so I need a function that gives lower values than any of its arguments, and which, if all but one of its arguments are large, gives approximately the remaining small one,” and my mind immediately went to the “if I can paint a house in x time and you can do it in y, how long does it take combined.” From there it was just a matter of generalizing the problem, because I didn’t know whether the terms were raised to a power before summation, whether there was a skew or weight function, that kind of stuff. I spent an hour or so defining what kind of metric space would be necessary. I suspected that there’d be a quadratic somewhere in your version at first, but that turns out not to be the case. Eventually, I settled on just leaving out the power variable, seen as a weight function could invorporate powers anyway. I didn’t make the connection to field lines and potentials until you mentioned it. Neat!

  • @KenHilton
    @KenHilton Před 2 lety

    I had seen marching cubes on Sebastian Lague's channel already, so when I saw you start talking about marching squares I thought to myself "I wonder if he'll bring up Sebastian's video once he gets to cubes?" and I cackled out loud when you did.

  • @AlfredDiffer
    @AlfredDiffer Před 2 lety +1

    Nicely done. That 'play with it' step at the end for actually learning it is exactly what many of us want our students doing with homework problems, but scores for homework tend to make students optimize a little different. That stops in grad school eventually and we 'play' with our research topics. My experience is we don't really know a thing until we play with that thing. We might pass exams and get good scores, but that's not really a measure of what we've learned.

  • @HerbertLandei
    @HerbertLandei Před 2 lety

    One important point: Marching squares / cubes is not limited to formulas, but also to measured values. Once upon a time a wrote a 3D metaball demo (using the marching tetrahedra version), and was contacted by a student who wanted to use the code to visualize computer tomography scans. From the slices of some example scans we interpolated a 3d "function" and once the right countour value was used, the algorithm showed the brain or other organs in 3d (using a game engine, JME to be precise).

  • @monsieuralexandergulbu3678

    Amazing, as always

  • @canteatpi
    @canteatpi Před 2 lety +1

    like the bit about parallel computing, also great video

  • @danielsantrikaphundo4517

    Awesome video. Definitely going to try it out in Processing

  • @caseytailfly
    @caseytailfly Před 2 lety +1

    Great video, I don’t do much graphics programming nowadays but this makes me want to! 👏

  • @MrLuigiBean1
    @MrLuigiBean1 Před 2 lety

    THIS VIDEO WAS *SO COOL.*
    Thank you!

  • @vasilnikolov8576
    @vasilnikolov8576 Před 2 lety

    This channel is an amazing find!

  • @umedina98
    @umedina98 Před rokem

    This video is amazing! Thanks!

  • @thedebapriyakar
    @thedebapriyakar Před rokem

    I absolutely fucking love your energy, Reducible. Love your videos. I really wanted to know how you would approach the study of computer graphics if you were given the chance to start out again?!

  • @dominiquefortin5345
    @dominiquefortin5345 Před 2 lety

    A possible accelerated technique would be to use a priority queue and partitioning of the render space. The partitioning is done by taking the render space (square for 2d; cube for 3d) and cutting in 1/2 each dimension (getting 4 sub-squares or 8 sub-cubes for each cut). You assigne a level to each partition. The whole render space is level 0 then on the first cut is level 1 and so on). The priority order would be from highest priority (a corner has a inside dot, level is low); (a corner has a inside dot, level is higher); (a corner has no inside dot, level is higher); (a corner has no inside dot, level is low). You can stop when you have reached a certain level or reached a time limit or a combination of the two. Since a point is shared by multiple level you don't have to recalculate the function for does points. This is also "embarrassingly" parallel.

  • @saifullahrahman
    @saifullahrahman Před 2 lety

    This was so awesome. Thanks!

  • @narwhalkid
    @narwhalkid Před 2 lety +2

    bro having all the metaballs combine at once is like the dvd logo hitting a corner

  • @willbe3043
    @willbe3043 Před 2 lety

    Beautiful video!

  • @Diego01201
    @Diego01201 Před 2 lety

    This video must have given a hell of a work. Great job.

  • @stefanguiton
    @stefanguiton Před 2 lety

    Excellent video!

  • @feha92
    @feha92 Před 2 lety +1

    Interesting video, that really helped explain to me how to do something I wondered about before but never figured out a nice equation for (granted, my initial problem was a bit different: I wanted convex meshes of arbitrary shape to merge like this to other convex meshes, *except they should abide to preservation of volume*. And that they should _actually_ merge them once they touch, at least once they merged enough for the resulting shape to be convex).
    The idea of simply adding two field-functions together is a rather neat way of doing that (even if I have no clue how to generate an equation for arbitrary convex 3d shapes - and I am rather certain volume won't be preserved - but it should be possible to preserve "mass" which is "good enough") which I never really considered (had somehow tunnelvisioned myself into trying to describe the shapes with parametric functions which only worked somewhat because my meshes were still only spheres)
    And something that stuck out to me in that video as soon as you mentioned adding them together, was that you never addressed a rather obvious performance concern/optimization. If you are to add the equations for 2 metaballs, you are inevitably going to take an infinite amount of time (the grid is infinite). And even if you limit the grid, traversing it in its entirety for every frame to calculate each cells value would be ill-advised.
    So should probably have been some mention that the best way to go about it is probably to compute each sphere individually, adding the value of its equation to the cells near it (using a threshold for when to consider its contribution "negligible", so you can limit the amount of cells considered (or you would, again, end up traversing out to infinity). If you have the memory to spare, you can even optimize further by caching the (local) positions considered relevant, and their respective value.

  • @A_Box
    @A_Box Před 2 lety

    I have no idea how or when I subscribed but holy heck, this is amazing.

  • @Thor_the_Doge
    @Thor_the_Doge Před 2 lety +1

    Holy crap, didn't know I was into computer graphics but I find this mindblowingly fascinating

  • @br45entei
    @br45entei Před 2 lety +3

    16:16 me, not quite understanding what I'm watching, but having a little maths knowledge: "couldn't you just lerp? idk"
    17:02 me, still trying to understand everything he just said
    17:05 me: "Wait, linear interpolation?! That's lerp! Heck yea, I predicted it!"
    lmao

  • @nickwallette6201
    @nickwallette6201 Před 2 lety

    I can tell I've found my people when the narration begins with "if you're like me, you immediately wonder how you even begin to approach solving a problem like this one" _while_ I'm casually thinking in my head something like: OK, so there are obviously points in the middle of the circles that are basically a vector, and when there's a collision with another circle, the two combine their area until those vectors force them apart . . . "

  • @yelmoralardclaw
    @yelmoralardclaw Před 2 lety

    I'm on 1:07, so a bit of head-on idea:
    1. Make canvas;
    2. Make N circle objects move independently;
    3. On each render step, trace the NxN network of connections between any two circles
    4. For each two circles that come in 'contact', calculate four points where the circles merge - expression can be made out of an equation system for circle and say, hyperbole (for which the line that connects centres of circles would be both a symmetry axis and an asymptote), in such case it would be two equation systems;
    5. Aaand gradually render outline, have never practiced this part.
    Upd: yep, the whole video about p.5. Good one!

  • @tarcisiosurdi
    @tarcisiosurdi Před 2 lety

    Amazing video!!

  • @alhdlakhfdqw
    @alhdlakhfdqw Před rokem

    really amazing video thank you very much! :) subbed already

  • @OhItsCalvin
    @OhItsCalvin Před rokem

    amazing video. I can't even explain how inspiring your channel is to me! It would be nice if you would make a video that documents your process for making videos

  • @SaiponathGames
    @SaiponathGames Před 2 lety

    I taught my classmates how Gravitational Field works by showing this video! It was very helpful thanks ya! :)

  • @araghon007
    @araghon007 Před 2 lety

    I've been on a journey on using signed distance functions and marching cubes. I'm trying to make a 3D modelling program that lets you make polygonal meshes from SDFs, but along the way I also had to learn quite a bit about OpenGL and making GUI and handling cameras, coordinate systems and all soft of stuff that I just don't quite know how to learn.
    Also, I started off by sampling random points within the function's bounds and filtering by distance, then I moved onto raymarching all points towards the surface until I realized that I could just use marching cubes to get a much better result. Then I also started learning about all sorts of other techniques, best of which I found was dual contouring, which I still have yet to figure out how to even begin implementing it. Not to mention parallelization, GPU compute, memory limitations and octrees.

  • @mindmelter1098
    @mindmelter1098 Před 2 lety

    Amazing video!

  • @HansLemurson
    @HansLemurson Před 2 lety +1

    The animation of the meta-balls reminds me of playing with blurry shadows on the ground, cast by the sun. Bringing my finger shadows together seems to make them "stretch" and try to merge in a strange way.

  • @dalmationblack
    @dalmationblack Před 2 lety +2

    I think you mentioned a few different words for implicit curves but I don't think you said either "level sets" or "level curves", which is how I first came across them when taking multivariable.
    Of course, I had also had them introduced to me as "equipotential" in physics classes, so it's just interesting to see how the same concept gets different names across so many fields!

  • @hozelda
    @hozelda Před 2 lety

    The "potential" function in the animations seems to be more like R^2/r^2 (like a force) instead of R/r. Can you confirm?
    As two bubbles are approaching each other they seem to grow very little until they are very close. Additionally, the max growth of radius for two overlapping bubbles vs one seems to be closer to times sqrt(2) rather than times 2.
    Example:
    A. for the 1/r case (as stated in the video): R=5 leads to a bubble with radius 5 since R/r boundary of 1 occurs when r=5 also. With 2 bubbles overlapping, 5/10 + 5/10 = 1 so the new circle from two overlapping centers has radius 10.
    B. For the 1/r^2 case (as suggested by the animations): R=5 leads to a bubble with radius 5 just like above since 5^2/5^2 = 1. But for two bubbles overlapping, we have 5^2/7^2 +5^2/7^2 is about 1, meaning the new boundary of the larger bubble with 2 centers is around 7 units (7/5 = sqrt(2)).

  • @gradyking4739
    @gradyking4739 Před 2 lety

    Completely unrelated to the video (which by the way is incredibly insightful), but I enjoyed the scintillating grid optical illusion that happens around 11:00, where black dots appear superimposed on the dots that one’s eyes is not focused on. Anyways, really cool video!

  • @marcoscastaneda2567
    @marcoscastaneda2567 Před 2 lety

    The way the metaballs merged together reminded me of when poles in a function passed through the Laplace transfom move close together. I guess it makes sense since they are the "peaks" caused by the denominators. Then if you intersect a horizontal plane at some fixed level, you have your isolines. It would be cool to see the 3D function that is moving through the plane and generating those metaballs

  • @thomas_c
    @thomas_c Před 2 lety

    Thanks, it's very interesting!

  • @user-hk3ej4hk7m
    @user-hk3ej4hk7m Před 2 lety

    Another approach that I'm very partial to is using interval arithmetic. It's standard for intervals to use the extended real set, so you can literally plug (-oo, oo) into a variable and know if the equation could even be satisfied. If you're drawing onto a screen, you can plug in an interval equivalent to the viewport, and then do binary search to find the contour, since you can just discard regions where the condition is not met at all, it's not necessary to test all pixels on the screen.

  • @roach1628
    @roach1628 Před 2 lety +1

    I am in second year of an engineering degree. I hate all my courses and I could not care less about any of them. While I do my course work or bash my head against my desk I just wish I had time to work on the things I want to work on. Never have I heard something I resonate with so strongly.
    "And I think for me, framing it in a way where my goal was actually to build something using it and then learning the details as I went through the journey was a lot more meaningful than listening to it from a standard lecture."

  • @sajaali4516
    @sajaali4516 Před 2 lety +4

    This was so amazing! I have a question, I'm trying to animate a honey drop as it falls and I feel like this's is very related to it the only problem is finding the potential field for the drop , but could the method you showed work for modeling a honey drop or do I have to use other methods like the Navier-Stokes equations?

  • @aragonnetje
    @aragonnetje Před 2 lety

    I am so happy my initial idea of a function for metaballs was correct!

  • @freescape08
    @freescape08 Před 2 lety

    That's funny, when you initially posed the question, I was imagining a sum of all metaballs' fields constructively interfering and figured it must be close, but probably isn't an incredibly accurate model of what I was seeing. I was actually thinking of making a spreadsheet to try visualising it. I've never tried programming any graphics beyond what my calculator could do.

  • @rysea9855
    @rysea9855 Před 2 lety

    Haha! I was bored in class the other day, and randomly decided to write some stuff about how you could merge balls together, and what I came up with is shockingly similar to the metaball formula you showed!

  • @MisterGeekey
    @MisterGeekey Před 2 lety

    Very cool video thank you !

  • @kankawabata3398
    @kankawabata3398 Před 2 lety

    Every one of your videos would have been a top contender for 3b1b challenge! Thank you for educating us!

    • @chotai
      @chotai Před 2 lety

      I guess, both are using manim
      if you're talking about the concepts and teaching personalities, yeah surely they're