Image not available

684x580

blender_sdf.jpg

🧵 SDFs in Blender

Anonymous No. 927435

I've watched this:
https://www.youtube.com/watch?v=8--5LwHRhjk
And I've attempted to transfer some of the formulas into the Metaball system.
This is very early work (as in I did it yesterday) but I can see a lot of potential.

Image not available

655x518

blender_sdf_2.jpg

Anonymous No. 927436

This just to give you an idea of how versatile SDFs are. There are a thousand better ways to do architectural stuff, but this to show how versatile SDFs can be compared to Metaballs.

Anonymous No. 927439

Let me know if you may be interested in a re-write of the Metaball system in Blender that supports SDFs and let me know if you want to see some code.

Anonymous No. 927454

>>927439
I would be interested

Image not available

621x518

blender_sdf_3.jpg

Anonymous No. 927459

The good news is that the existing Metaballs tesselator works just fine. So most of the changes are confined to densfunc() and metaball() in mball_tesselate.c
The bad news is that Metaballs aren't sensitive to the order of insertion into the scene, SDFs are, so the bizarre Metaball naming scheme logic that's in use now will have to be re-thought.

Anonymous No. 927460

>>927435
Speaking of signed distance fields, I wonder if Eevee could ever get SDFGI like Godot 4.0 is getting. It would be a lot better than what we have now.

Image not available

885x721

blender_sdf_4.jpg

Anonymous No. 927464

I also wanted to mention that it's possible to work with SDFs in Blender 3.3 with Geometry Nodes. I've tried it, it works but it's also rather impractical due to the amount of nodes it requires.
To re-purpose the existing Metaball system I think it's a more viable solution.

Anonymous No. 927467

just use magicacsg. shit's free and great.
substance modeller if you're mentally ill.

Anonymous No. 927468

>>927435
why would anyone even need this

Anonymous No. 927476

>>927467
Because I also want the rest of blender.
>>927468
Nobody really needs computers and/or the internet.

Anonymous No. 927486

>>927468
It would be useful to me for what its worth

Not to mention CSG is a more fun way for people to dip their toes into 3d or to block out ideas without fully committing

Anonymous No. 927488

I'll post again when I'll have more work done and I'll be able to demonstrate this better. For now I wanted to put the idea out there.
One thing I forgot to mention is that the rigging system, static constraints and animations already work with the SDF modification.
What's missing is the ability to create hierarchies of primitives. Metaballs don't require it, but SDFs require it to control smoothing radiuses and fuse primitives selectively.

Image not available

505x569

blender_sdf_5.jpg

Anonymous No. 927760

Some more work done. This is about 10 SDF ellipsoids in total.

Image not available

615x586

blender_sdf_6.jpg

Anonymous No. 927763

I've also made this coin bank. A lot more work is required to improve the details, the workflow and the editing but it's very fun to work with.

Anonymous No. 927861

>>927439
I'd like to see the code, I'd like to try this out myself

Image not available

510x474

blender_sdf_9.jpg

Anonymous No. 927896

These are the primitive I've implemented so far to replace the existing Metaball types. Many more to come. I've also tried to sculpt a little bit but I'm a programmer and I have no idea how to draw things. But it works and it's fun to use.
The code is not ready at the moment because I've implemented this on top of Blender 2.76b. I plan to port it to 3.3 and make a patch.

Image not available

643x573

blender_sdf_8.jpg

Anonymous No. 927899

This is just to demonstrate mirror and subtraction which I did yesterday. I'll find a way to make this available. For now if you've watched some Inigo Quilez videos and you open "mball_tesselate.c" in the Blender source tree, it's kind of straightforward what I've done.

Image not available

643x555

blender_sdf_7.jpg

Anonymous No. 927906

I've checked Blender 3.3 and I saw that the Metaball system hasn't been touched in 20 years. I'm surprised they even ported it over when they dropped the game engine.
I'm aware that there are many much better programs dedicated to implicit surfaces but I think there's value for something deliberately simple but well integrated which can be used to make drafts and get models started.

Anonymous No. 927916

>>927896
>The code is not ready at the moment because I've implemented this on top of Blender 2.76b

I actually still use Bender 2.7 sometimes, so could you share the code for Blender 2.76b?

Anonymous No. 927919

>>927916
https://sourceforge.net/projects/snes9l/files/blender-2.76b-sdf.diff/download
The interface is almost the same. "Threshold" now means smooth radius and "Stiffness" now means roundness.

Anonymous No. 927922

Anything else works as explained in:
https://docs.blender.org/manual/en/latest/modeling/metas/index.html
including the bug where if your rename a meta object to separate it, it doesn't automatically updates the viewport. You have to cycle between Object mode and Edit mode. Maybe that bug is still there in 3.3

Anonymous No. 927927

I've checked and the update bug has been fixed in 3.3
Maybe take a look at the diff I've posted above, but to compile 2.76b on a modern system is a bit arduos. I've used it because I had it already prepared for some other project, but I'll be moving everything to 3.3 when I'll get a chance.
The major difference between Metaballs and SDFs is that with SDFs it's possible to specify (somewhat) precise measurements and the primitives don't affect each other past the smoothing radius, so they don't distort at a distance and fuse in a predictable way.
The resulting surfaces are (almost) guaranteed to be continuos and that may be important for 3D printing. Not to mention, to make everything look like a dildo.

Image not available

483x524

blender_sdf_10.jpg

Anonymous No. 927928

The bug where you have to go into Wireframe mode to be able to select the individual Metaballs because the geometry obscures the gizmos is still there in 3.3 That tells me Metaballs haven't hand many users.
I've fixed that bug in my version.

Anonymous No. 927936

>>927919
Thank you so much anon!

Image not available

616x692

blender_sdf_11.jpg

Anonymous No. 927997

A little bit more structure. I know nothing about anatomy and/or art but that's more or less what I wanted to be able to do.

Image not available

551x687

blender_sdf_12.jpg

Anonymous No. 928001

Convert to mesh -> Sculpt -> Decimate 50%
Again this is programmers art. I just wanted to show that the workflow is viable and final mesh can be reasonable with about 1300 faces.

Image not available

1687x1171

Screenshot_2022-1....png

Anonymous No. 928015

>>927435


https://www.youtube.com/watch?v=BM2tWwBRnfs

https://www.youtube.com/watch?v=RHySGIqEgyk

Honestly I would fucking love to have SDF's in blender for speeding up and unfucking cloth simulation clipping. Also, implicit skinning is hot

Anonymous No. 928033

>>928015
That's something I want to explore eventually. For now I've implemented a simple cubic interpolator because it's the one that gives the best specular highlights. However there are many more choices and I believe it's possible to differentiate between the outside and the inside of a bend, and to switch between two different interpolators accordingly.

Anonymous No. 928042

>>928001
Keep it up anon! It would also be cool if there is an easy way for us to add our own distance functions to the script as primitives. You could also support 3d texture cached distance fields as primitives!

Image not available

871x351

blender_sdf_20.jpg

Anonymous No. 928083

>>928042
Unfortunately correct SDF primities are kinda hard to invent. Here are most of them:
https://iquilezles.org/articles/distfunctions/
But useful effects such as CSG, bending and displacement are possible.
In Blender 3.3 there's a geometry node called Geometry Proximity which basically turns any mesh into an approximate SDF. You could experiment with that.

Image not available

877x357

blender_sdf_21.jpg

Anonymous No. 928086

The node group above represent ann SDF primitive. The output of several of those then goes into pic related.
Notice the Minimum node. To take the minimun of two SDF values is equivalent to a non-smooth CGS Union operation.
This should be enough to get you started if you want to so some advanced experiments.

Anonymous No. 928215

A couple small updates.
What you can see in pic related is the formula for a single SDF ellipsoid in Geometry Nodes. It's complicated but it's doable.

Image not available

774x698

blender_sdf_30.jpg

Anonymous No. 928216

Forgot the picture.

Image not available

518x619

blender_sdf_31.jpg

Anonymous No. 928218

Due to the fact that normals can be calculated to a higher resoluton than the undelying mesh, trn out the Toon shader works really well.
I've also cleaned up the code in the SDF patch for Blender 2.76b. It's the same functionality but easier to read now.
https://sourceforge.net/projects/snes9l/files/blender-2.76b-sdf.diff/download

Anonymous No. 928245

>>928218
Thanks!

Image not available

590x461

blender_sdf_40.jpg

Anonymous No. 928435

Tapered ellipsoids

Image not available

788x702

blender_sdf_41.jpg

Anonymous No. 928437

And the same thing in Geometry nodes.

Image not available

1442x875

blender_sdf_50.jpg

Anonymous No. 928504

I've modified the Blender interface a little bit. I understand this is highly heretical but...
As you can see you can now access precise position and rotation of a Meta element on the 3D viewport sidebar. Moved all the other parameters to the object properties.
I've also added the "Mirror X+" option, which is really useful and still a little bit buggy.

Anonymous No. 928517

Keep in mind that "Threshold" now means smooth radius between primitives and "Stiffness" now means roundness or taper depending on the primitive.
Download link is still the same:
https://sourceforge.net/projects/snes9l/files/blender-2.76b-sdf.diff/download
Consider that Meta elements can be parented to bones and animated, you're not just sculpting a volume like in Substance Modeler.

Image not available

761x570

blender_sdf_70.jpg

Anonymous No. 928785

Another face. Just because I've made it while testing. Behold my lack of artistic talent.

Image not available

661x663

blender_sdf_71.jpg

Anonymous No. 928787

I've watched the video of the guy who makes Grease pencil animations from the Blender conference. I wonder if it could be used to complement SDF shapes and add fine details.

Image not available

588x689

blender_sdf_72.jpg

Anonymous No. 928812

Yes. Grease pencil writes on meta surfaces. This opens up a lot of possibilities.

Anonymous No. 928841

>>928517
Thank you so much for your hard work!

Image not available

564x688

blender_sdf_90.jpg

Anonymous No. 929034

Tapered, bent, mirrored and subtracted ellipsoids. I hanven't properly implemented them yet, but just to show it's possible.

Image not available

637x692

blender_sdf_91.jpg

Anonymous No. 929097

Tapering works. Bending is also possible but it's somewhat expensive and I have no idea how to do the bounding box calculations, so I'll try to do without it.

Anonymous No. 929122

>>927435
Why don’t you just model it normally?

Anonymous No. 929139

Depends on your definition of "normally". One reason could be that this way I don't have to worry about things such as mesh topology. But there's also another reason. I'm not an artist. I have no idea how to draw anything. All I know is that 2D artists assemble figures out of ellipses because 3D ellipsoids flatten into ellipses when you project them.

Anonymous No. 929186

Just implement openVDB. There is no need to start from scratch.

Anonymous No. 929194

>>929186
The way Metaballs work in Blender is that although the formulas describe a volume (and you can in fact generate volumetric data from Metaballs) in this type of visualization you only care about surfaces and you never fully develop the volumetric data.
In this experiment I haven't changed any of that logic. I've just replaced the Metaballs formulas with other formulas based on SDFs which I think are better looking.

Image not available

716x556

blender_sdf_93.jpg

Anonymous No. 929249

In Blender 3.4 the object on the left is an SDF primitive that I've assembled in Geometry nodes, on the right is a stock metaball.
It looks like Geometry nodes now uses something like Naive surface nets to generate polygons from volumes. Metaballs instead still use Marching cubes.
I haven't looked at the code but I don't think it's a coincidence that OpenVDB implemented Naive surface nets relatively recently? I'm not 100% sure but it looks like if you want to play with OpenVDB, you can do so in Geometry nodes.

Image not available

648x661

blender_sdf_95.jpg

Anonymous No. 929270

Another test head. This time I've used Freestyle and a tapered ellipsoid to do the mouth part.

Anonymous No. 929286

>>929270
Do you have any tools for symmetry? The math should be super simple in theory, just take the absolute value of one of the components of position when calculating distance

Anonymous No. 929296

>>929286
Yes. I have:
if (process->flag2 & MB_MIRROR_X)
x = fabsf(x);
At the start of the metaball() function and:
if (process->flag2 & MB_MIRROR_X)
tempmin[0] = -tempmax[0];
somewhere in the init_meta() function to adjust the bounding box.
That works and it's really useful but it also creates an interesting problem I haven't fully solved yet.

Anonymous No. 929298

The problem is caused by the find_first_points() function, which is responsible for quickly finding solid volumes.
It assumes that the center of the bounding box is in the solid part of the volume. With mirroring and subtraction, that may not be true, so sometimes it misses unconnected parts of a figure.
I'm still looking for a better way to do it and I would also like to replace the Marching cubes algorithm with Naive surface nets. But none of that is strictly necessary.

Image not available

654x690

blender_sdf_96.jpg

Anonymous No. 929303

The solution would be to port everything over to Blender 3.5 and OpenVDB. But I'll let the Blender people do that.
Something I've noticed while trying to implement SDFs in Geometry nodes is that although they work perfectly, they're also 20x slower in the update phase compared to the 15 years old Marching cubes code.
That's a little too much for me to take on because I'm not planning on selling anything. I just wanted to test an idea.

Image not available

652x661

blender_sdf_97.jpg

Anonymous No. 929441

Just a curiosity. As I've mentioned, with Metaballs the order in which the primities are assembled doesn't matter. With SDFs sometimes it does.
Initially I couldn't re-order the primitives because somebody had put a BVH structure into the code, which I had to remove.
And so I did. But then I began to wonder why somebody would have put such a thing in there in the first place.
The only reason I can think of is if it was there to support some custom Python script which would generate thousands of Metaballs for the purpose of perhaps making crude simulations of streams of dense, viscous, globulous fluids.
A sort of precursor to proper fluid simulations.

Image not available

656x660

blender_sdf_11.jpg

Anonymous No. 929562

Made an attempt to develop the rest oft the body. I know that the proportions are not right. I haven't followed any model and I'm not concerned with that at this time. The whole figure is about 15 (tapered) ellipsoids, so it's easy to move them around.
I think that the algorithm is fast enough to support a whole mannequin without any special video card requirements and it does (sometimes) create the right shapes with little input.

Anonymous No. 930357

>>928218
That's really interesting.
Sadly, the Toon shader is gone from 2.8 and onwards.

Anonymous No. 930377

>>929441
This is cool. Do you think it would work better if you separate the nose into a different object? Unless you're modeling an Asian, human head has something of a valley that goes across the face under the brow line, then nose and eyes fit into it. Also, ears.

Anonymous No. 930378

>>930377
I mean, ears are missing. Not that they somehow come together with nose and eyes.

Anonymous No. 930535

>>929441
In the meantime I've implemented some more features that will allow more detail. I'll post some examples as soon as I make them. But keep in mind that this method is not very useful for people who can already create correct, realistic, highly detailed models with subdivisions surfaces. This is meant for prototyping or cartoons.

Image not available

658x666

blender_sdf_10.jpg

Anonymous No. 930543

I mean... You can go crazy with the number of primitives and in theory get all detail that you want, but I think it defeats the purpose of this method.

Image not available

658x667

blender_sdf_12.jpg

Anonymous No. 930545

A little better. Maybe.

Anonymous No. 933288

Is the code for this released? I know python but I've never done blender scripts before, is there a easy way for me to pick up where anon left off?

Image not available

680x838

meta dingleberry ....png

Anonymous No. 933453

>>927435

Image not available

620x663

blender_sdf_10.jpg

Anonymous No. 933477

>>933288
The code is available but it's not a Python script. It's a patch that overwrites the metaballs code with SDF code. It's very interesting if you're a programmer and know how recompile Blender.
https://download.blender.org/source/blender-2.76b.tar.gz
https://www.python.org/ftp/python/3.4.10/Python-3.4.10.tgz
https://sourceforge.net/projects/snes9l/files/blender-2.76b-sdf.diff/download
That's what you need to replicate it. However it's possible to do similar things in Geometry Nodes. Maybe someday I'll write a tutorial.
Also, take a look at this:
https://www.youtube.com/@womp3D
I haven't tried it personally but it looks a lot like what I'm trying to do.

Image not available

795x738

blender_sdf_11.jpg

Anonymous No. 933482

Kinda like so. It's a little awkward to set up but maybe they'll improve Geometry Nodes in the future.

Image not available

651x660

blender_sdf_13.jpg

Anonymous No. 933483

Just for completeness. I haven't put mach effort on the back side of the mannequin, but it's there.