How Computers Draw Weird Shapes (Marching Squares)

  Рет қаралды 407,068

Reducible

Reducible

Күн бұрын

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

Пікірлер: 527
@mrvzhao
@mrvzhao 2 жыл бұрын
Bravo! Now, after hearing 'metaball' so many times in 27 minutes, I'm off to get myself some meatballs...
@Reducible
@Reducible 2 жыл бұрын
Every time I read the word metaballs in the script, I got hungry. I feel you :)
@igxniisan6996
@igxniisan6996 2 жыл бұрын
You just stole my copyrighted thought.. And now I've to think of a different comment 😑....
@Blox117
@Blox117 2 жыл бұрын
shameful that you aren't off to get batman
@humankerbal3623
@humankerbal3623 2 жыл бұрын
Off to ikea
@redfoxlightning
@redfoxlightning 2 жыл бұрын
@@igxniisan6996 I know THAT feeling xD
@TiagoTiagoT
@TiagoTiagoT 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
Yup, that's pretty much how I know it too.
@RottenFishbone
@RottenFishbone 2 жыл бұрын
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 2 жыл бұрын
I used a similar method to have "equal distance travel" around obstacles, to create realistic borders for a DnD campaign I ran.
@MrNicePotato
@MrNicePotato 2 жыл бұрын
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.
@_Baku
@_Baku 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
As a wizard, I agree. Just use a force field.
@guilhermetorresj
@guilhermetorresj 2 жыл бұрын
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 2 жыл бұрын
SAME!!!
@Mutual_Information
@Mutual_Information 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
he should have submitted something for SoME1 but i guess he's more in the CS side of things
@_okedata
@_okedata 2 жыл бұрын
@@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 2 жыл бұрын
@@_okedata oooohhh so that's why i don't see any familiar names on the compet
@suvigyavijay
@suvigyavijay 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@Reducible Can't wait for a video on this!
@sponge1234ify
@sponge1234ify 2 жыл бұрын
@@Reducible +1 support on that video!
@georgeskhater487
@georgeskhater487 2 жыл бұрын
@@Reducible we want this
@QuanrumPresence
@QuanrumPresence 2 жыл бұрын
@@Reducible Please do :). We will wait
@fredericmazoit1441
@fredericmazoit1441 2 жыл бұрын
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 2 жыл бұрын
Wow, an interesting application of it I hadn't realized! Thanks for sharing that story!
@zyansheep
@zyansheep 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: kzbin.info/www/bejne/m3anZZWJoL52eJo
2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
Happened with me too!
@geeshta
@geeshta 2 жыл бұрын
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 2 жыл бұрын
It's known as the scintillating grid illusion.
@TheRealBoof
@TheRealBoof 2 жыл бұрын
@@DanDeebster 💯💯💯 Thank you!!!
@jursamaj
@jursamaj 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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.
@ginsYT
@ginsYT 2 жыл бұрын
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!
@hjups
@hjups 2 жыл бұрын
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 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 2 жыл бұрын
​@@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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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.
@N____er
@N____er 2 жыл бұрын
"Important note: do not confuse metaballs with meatballs" this got me bursting in laughter
@98perova
@98perova 2 жыл бұрын
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.
@ballman2010
@ballman2010 2 жыл бұрын
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.
@okiguessineedahandle
@okiguessineedahandle 2 жыл бұрын
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.
@mahousenshi00
@mahousenshi00 2 жыл бұрын
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.
@alegian7934
@alegian7934 2 жыл бұрын
3 concepts i understand very well individually, beautifully merged into one problem. Awesome vid!
@Balawi28
@Balawi28 2 жыл бұрын
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.
@gasparliboreiro4572
@gasparliboreiro4572 2 жыл бұрын
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
@juanma4978
@juanma4978 2 жыл бұрын
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!
@ProjectPhysX
@ProjectPhysX 2 жыл бұрын
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 :)
@Number_Cruncher
@Number_Cruncher 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.
@uy-ge3dm
@uy-ge3dm 2 жыл бұрын
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.
@nanamacapagal8342
@nanamacapagal8342 Жыл бұрын
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.
@bigphatballllz
@bigphatballllz 2 жыл бұрын
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 2 жыл бұрын
Yes, absolutely! I recommend it at 25:51, it's an excellent video on the topic.
@bigphatballllz
@bigphatballllz 2 жыл бұрын
@@Reducible Yeah, thanks for replying! BTW, you should have participated in SoME. You could have won :)
@MagicGonads
@MagicGonads 2 жыл бұрын
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)
@nstryder-music
@nstryder-music 2 жыл бұрын
after seeing countless videos on marching squares/cubes and not understanding the "why" behind it, this video finally made me get it! Thank you!
@peterronhovde
@peterronhovde 2 жыл бұрын
I liked how you broke the technical problems down into bite-sized bits while keeping the element of discovery. Good job.
@adrianrevill7686
@adrianrevill7686 2 жыл бұрын
Excellent video, I have tried several times to understand marching cubes, now re-watching Sebastian's video makes complete sense.
@jackwang8105
@jackwang8105 2 жыл бұрын
This video deserves more views!!! Thanks for your work!
@BrianAmedee
@BrianAmedee 2 жыл бұрын
This is such an impressively simple explanation for a complicated topic! Nicely done!
@PGETSA17
@PGETSA17 Жыл бұрын
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.
@iaobardar3452
@iaobardar3452 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.
@CrushedAsian255
@CrushedAsian255 2 жыл бұрын
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)
@user-qx1mw6xs4n
@user-qx1mw6xs4n Жыл бұрын
One of the clearest explanation i saw , Hats off man.
@skeletonboxers7336
@skeletonboxers7336 Жыл бұрын
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.
@garr061
@garr061 2 жыл бұрын
Wildly satisfying. Thank you for the explanation!
@sadpancake6563
@sadpancake6563 2 жыл бұрын
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.
@berkansivrikaya9055
@berkansivrikaya9055 2 жыл бұрын
Great video. I randomly started then couldn't leave it. The ideas 💥 me away. 👍
@danielfernandes1010
@danielfernandes1010 2 жыл бұрын
The reveal of the metaball function was beautiful! Thank you for your amazing videos!
@oriyonay8825
@oriyonay8825 Жыл бұрын
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!
@sebbes333
@sebbes333 2 жыл бұрын
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.
@ChrisOffner
@ChrisOffner Жыл бұрын
Absolutely beautiful explanation and presentation! Thank you so much. ❤️
@adrianv.v.4445
@adrianv.v.4445 2 жыл бұрын
I'm discovering so many incredible math channels, keep up the content! ^^
@agargamer6759
@agargamer6759 2 жыл бұрын
What a beautiful idea and explanation!
@darshigoswami5124
@darshigoswami5124 2 жыл бұрын
Would love if you make a video detailing the process of procedural generation... your videos are an absolute masterpiece .
@stjernis
@stjernis 2 жыл бұрын
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.
@AlfredDiffer
@AlfredDiffer 2 жыл бұрын
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.
@ikocheratcr
@ikocheratcr 2 жыл бұрын
Very nice explanation of marching squares and metaballs.
@Bruh-sp2bj
@Bruh-sp2bj 2 жыл бұрын
hope you do more videos, you may be one of the best computer science channels that Ive seen so far.
@caseytailfly
@caseytailfly 2 жыл бұрын
Great video, I don’t do much graphics programming nowadays but this makes me want to! 👏
@saifullahrahman
@saifullahrahman 2 жыл бұрын
This was so awesome. Thanks!
@canteatpi
@canteatpi 2 жыл бұрын
like the bit about parallel computing, also great video
@danielsantrikaphundo4517
@danielsantrikaphundo4517 Жыл бұрын
Awesome video. Definitely going to try it out in Processing
@jacobyoung6876
@jacobyoung6876 2 жыл бұрын
Such an excellent explanation!
@PiercingSight
@PiercingSight 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.
@yah3136
@yah3136 2 жыл бұрын
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 :-)
@MrLuigiBean1
@MrLuigiBean1 2 жыл бұрын
THIS VIDEO WAS *SO COOL.* Thank you!
@Diego01201
@Diego01201 2 жыл бұрын
This video must have given a hell of a work. Great job.
@monsieuralexandergulbu3678
@monsieuralexandergulbu3678 2 жыл бұрын
Amazing, as always
@feha92
@feha92 2 жыл бұрын
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.
@umedina98
@umedina98 Жыл бұрын
This video is amazing! Thanks!
@A_Box
@A_Box 2 жыл бұрын
I have no idea how or when I subscribed but holy heck, this is amazing.
@KenHilton
@KenHilton 2 жыл бұрын
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.
@AWESOMEEVERYDAY101
@AWESOMEEVERYDAY101 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 2 жыл бұрын
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!
@sajaali4516
@sajaali4516 2 жыл бұрын
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?
@araghon007
@araghon007 2 жыл бұрын
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.
@Thor_the_Doge
@Thor_the_Doge 2 жыл бұрын
Holy crap, didn't know I was into computer graphics but I find this mindblowingly fascinating
@dominiquefortin5345
@dominiquefortin5345 2 жыл бұрын
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.
@SaiponathGames
@SaiponathGames 2 жыл бұрын
I taught my classmates how Gravitational Field works by showing this video! It was very helpful thanks ya! :)
@stefanguiton
@stefanguiton 2 жыл бұрын
Excellent video!
@kankawabata3398
@kankawabata3398 2 жыл бұрын
Every one of your videos would have been a top contender for 3b1b challenge! Thank you for educating us!
@chotai
@chotai 2 жыл бұрын
I guess, both are using manim if you're talking about the concepts and teaching personalities, yeah surely they're
@willbe3043
@willbe3043 2 жыл бұрын
Beautiful video!
@aragonnetje
@aragonnetje 2 жыл бұрын
I am so happy my initial idea of a function for metaballs was correct!
@HerbertLandei
@HerbertLandei 2 жыл бұрын
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).
@thomas_c
@thomas_c 2 жыл бұрын
Thanks, it's very interesting!
@marcoscastaneda2567
@marcoscastaneda2567 2 жыл бұрын
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
@Taterzz
@Taterzz 2 жыл бұрын
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.
@vasilnikolov8576
@vasilnikolov8576 2 жыл бұрын
This channel is an amazing find!
@gradyking4739
@gradyking4739 2 жыл бұрын
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!
@thedebapriyakar
@thedebapriyakar Жыл бұрын
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?!
@rysea9855
@rysea9855 2 жыл бұрын
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!
@br45entei
@br45entei 2 жыл бұрын
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
@SreenikethanI
@SreenikethanI 2 жыл бұрын
ayy thats nice
@dalmationblack
@dalmationblack 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!
@freescape08
@freescape08 2 жыл бұрын
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.
@mindmelter1098
@mindmelter1098 2 жыл бұрын
Amazing video!
@tarcisiosurdi
@tarcisiosurdi 2 жыл бұрын
Amazing video!!
@alhdlakhfdqw
@alhdlakhfdqw Жыл бұрын
really amazing video thank you very much! :) subbed already
@MisterGeekey
@MisterGeekey 2 жыл бұрын
Very cool video thank you !
@OhItsCalvin
@OhItsCalvin Жыл бұрын
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
@mightloki8181
@mightloki8181 2 жыл бұрын
this is wonderful, however I was thinking of another approach (I still don't know if it's applicable in all scenarios) what if we tried to find only one point (x,y) with a value of 1 then calculate the gradiant vector at that point, knowing that a slight mouvement in the direction of the orthogonal vector to the gradient result in no change of value, we can slightly move the point (x,y) orthogonally to the gradient vector that way we can pretty much assume that the value of the function f(x,y) at the new location is technically the same. the only problem this could face is that after several iterations the error value can grow until it's not tolerated anymore. but in some cases it would be perfectly fine. I would be very grateful to hear your thoughts about this :)
@reto8988
@reto8988 2 жыл бұрын
Amazing video!! It suprisingly gave me ideas to continue coding one of my projects Edit, the fields reminded me of topology
@ThankYouESM
@ThankYouESM 2 жыл бұрын
There's a similar one which seems to be called an organic maze that look like corals... but the pathways keeps changing in that liquid like fashion. It doesn't look like a warped version of a horizontal by vertical type of maze, but maybe of every angle shifting around while warped with Perlin noise as the walls constantly slither everywhere into the next wall.
@user-hk3ej4hk7m
@user-hk3ej4hk7m 2 жыл бұрын
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.
@nickwallette6201
@nickwallette6201 2 жыл бұрын
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 . . . "
@Tom.Bombadil
@Tom.Bombadil 2 жыл бұрын
Manim is everywhere now and I’m loving it!
@klaxalk
@klaxalk 2 жыл бұрын
Brilliant!
Coding Marching Squares
26:28
The Coding Train
Рет қаралды 176 М.
How PNG Works: Compromising Speed for Quality
32:00
Reducible
Рет қаралды 626 М.
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 4,9 МЛН
100❤️
00:20
Nonomen ノノメン
Рет қаралды 75 МЛН
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 183 МЛН
Каха ограбил банк
01:00
К-Media
Рет қаралды 5 МЛН
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,4 МЛН
The Fast Fourier Transform (FFT): Most Ingenious Algorithm Ever?
28:23
Thinking outside the 10-dimensional box
27:07
3Blue1Brown
Рет қаралды 3 МЛН
What is the Ultraviolet Catastrophe?
40:29
Physics Explained
Рет қаралды 2 МЛН
The Beauty of Bézier Curves
24:26
Freya Holmér
Рет қаралды 1,9 МЛН
I Made Minecraft Without Blocks
10:39
Sam Hogan
Рет қаралды 5 МЛН
Coding Adventure: Ant and Slime Simulations
17:54
Sebastian Lague
Рет қаралды 1,8 МЛН
Huffman Codes: An Information Theory Perspective
29:11
Reducible
Рет қаралды 222 М.
Fluid dynamics feels natural once you start with quantum mechanics
33:00
braintruffle
Рет қаралды 2,1 МЛН
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 4,9 МЛН