Metaballs and Marching Squares
jamie-wong.com
jamie-wong.com
If they are defined this way, it is easy to smoothly interpolate between two or more solids. When rendering to screen, similar techniques have to be used to convert to screen geometry in realtime.
The latest technical marvel that uses this tech is Media Molecules Dreams. With SDFs they made rich modelling tools (constructive solid geometry) that produce geometry for physics and painting-style renderer, all running on PS4. The Learning From Failure talk [2] was quite inspiring on lengths they went to achieve their artistic goals.
[1] https://www.iquilezles.org/www/articles/distfunctions/distfu... [2] https://www.youtube.com/watch?v=u9KNtnCZDMI
It shows how naively aggregating charge from across the entire field leaves a lot on the table and there are huge efficiency gains that can be achieved. The page also includes descriptions of metacubes and metatorii.
[1]: https://mostlymaths.net/2020/05/blot-painting-p5js-sketch.ht...
Let's go back in time to 1994. You are a teenager armed with a computer, modem, possibly internet access but more likely an online service such as CompuServe. Since you also have a C or Pascal compiler, and are inspired by the latest trend of 3D graphics in PC games, you download the comp.graphics.algorithims FAQ.
You read something about 'Marching Cubes' but don't really grasp anything from it. You also probably don't have access to the textbook or papers that also describe it.
Instead of this incredible visual demonstration, you get a couple paragraphs of text and some ASCII art:
----------------------------------------------------------------------
Subject 5.10: What is the marching cubes algorithm?
The marching cubes algorithm is used in volume rendering to
construct an isosurface from a 3D field of values.
The 2D analog would be to take an image, and for each pixel, set
it to black if the value is below some threshold, and set it to
white if it's above the threshold. Then smooth the jagged black
outlines by skinning them with lines.
The marching cubes algorithm tests the corner of each cube (or
voxel) in the scalar field as being either above or below a given
threshold. This yields a collection of boxes with classified
corners. Since there are eight corners with one of two states,
there are 256 different possible combinations for each cube.
Then, for each cube, you replace the cube with a surface that
meets the classification of the cube. For example, the following
are some 2D examples showing the cubes and their associated
surface.
- ----- + - ----- - - ----- + - ----- +
|:::' | |:::::::| |:::: | | ':::|
|:' | |:::::::| |:::: | |. ':|
| | | | |:::: | |::. |
+ ----- + + ----- + - ----- + + ----- -
The result of the marching cubes algorithm is a smooth surface
that approximates the isosurface that is constant along a given
threshold. This is useful for displaying a volume of oil in a
geological volume, for example.
References:
"Marching Cubes: A High Resolution 3D Surface Construction Algorithm",
William E. Lorensen and Harvey E. Cline,
Computer Graphics (Proceedings of SIGGRAPH '87), Vol. 21, No. 4, pp. 163-169.
[Watt:Animation] pp. 302-305 and 313-321
[Schroeder]It appears to be specifically the marching cubes (i.e. 3D) algorithm - this article just describes the marching squares (i.e. 2D) algorithm.
One more from GPU Gems 3: Point-Based Visualization of Metaballs on a GPU
https://developer.nvidia.com/gpugems/gpugems3/part-i-geometr...
I put together this video to show what’s going on in the process:
https://www.instagram.com/p/BwGgYyQgCO1/?igshid=1cvb4smiik3i...
A little more polished and optimized “lava lamp” type loop:
https://www.instagram.com/p/By9er1LFRKt/?igshid=iu9ouexd7tvs
Most of it was standing on the shoulders of Tim Bourke’s work [1] and making it all work in GPU shaders.
As others have mentioned, Ray Marching is also a nice approach if you don’t need polygons — you can get some really impressive and smooth effects.
Then, rather than applying a threshold to the resulting pixel/voxel contribution, you can apply a sigmoid function (or something cheaper approximating it) and get smooth edges.
You can cheat normals like you can with any other sort of height map, by measuring the differences between neighboring fragments.
like so: