GSoC 2024: Draft: Smooth Boolean Nodes and Material Blending

Smooth Boolean Nodes and Material Blending

Contact Info

Synopsis

This project has two parallel goals: on the one hand it introduces new features to the Volume Nodes and in particular Smooth Booleans and Rounding, and on the other hand it brings Smooth Boolean operations directly to meshes (although they are implicitly converted to volume grids) with the additional feature of smoothly blending materials.
These operation can be implemented without much effort when the objects in the scene are represented implicitly as Signed Distance Fields (SDF), as shown in the [Inigo Quilez’s website (Inigo Quilez :: computer graphics, mathematics, shaders, fractals, demoscene and more).
The recently added Volume Nodes allow to convert a mesh to a SDF and vice versa, and the pull request Geometry Nodes: Add SDF grid boolean nodes #118879 introduced Boolean Nodes for SDF, but at the moment the Smooth versions of these operations are not available.

To validate the approach, I implemented a demo that shows how Smooth Booleans and Rounding can be applied to meshes by converting them into Volume grids and converting the result of the operation back to a mesh. The figure below shows an example of smooth union, with increasing degree of smoothness from left to right:

While the figure below shows an example of Rounding, with roundness increasing from left to right:

Second Image

I also implemented a shader that shows how the materials can be smoothly blended by following the transition between the two geometries. The figure below compares the smooth boolean with material blending (first row) with the standard boolean operations (second row), where a diffuse material (plane) is joined with a tinted metallic object (sphere):

Benefits

The new Volume Nodes allowed to work with SDF in the geometry editor, but the number of operations that can be performed on the SDF grids is still limited. The pull request Geometry Nodes: Add SDF grid boolean nodes #118879 introduced boolean nodes, but the true power of the SDF modeling is the ability to compute smooth versions of these primitives. These new functionalities are introduced in the new SDF nodes.

The Mesh Smooth Boolean nodes allow to smoothly fuse objects and their materials. This cannot be accomplished with existing tools in Blender.

Smooth blending of shapes can be achieved with Metaballs, but with some important limitations:

  • A limited set of primitives (Ball, Capsule, Plane, Ellipsoid, Cube)
  • They do not allow to blend materials, since the same material is associated to the metaballs interacting together (controlled by the base metaball)

The Blender ‘Mesh Boolean’ node maintains the material properties of the input shapes for their corresponding sections in the resultant shape, but it does not allow to smoothly blend shapes (like metaballs).

Moreover, in Blender, applying boolean operations on non-watertight meshes often leads to unpredictable results, as also stated in the official documentation. On the other hand, the method introduced here demonstrates resilience against such inputs.

The figure shows from left to right: the non watertight mesh (there are visible holes on the bottom), union and difference with smoothness set to zero.

Project Details

The Volume Nodes expose the OpenVDB grid in the Geometry Nodes editor. OpenVDB represents efficiently a SDF using a sparse data structure also decoupling the actual data from the geometrical transformations. It also provides functions to convert between Mesh and Volume Grid and the other way around. These functionalities are already exposed by the existing Volume Nodes. OpenVDB also implements standard CSG operations (Union, Intersection and Difference) and though these functionalities are not yet available in the Geometry Node Editor they have been already exposed in Blender in the already mentioned pull request Geometry Nodes: Add SDF grid boolean nodes #118879.

However the smooth boolean operations and rounding, that are the focus of this project are not yet available in openVDB. Hence this project aims at implementing these functionalities using the OpenVDB API and exposing them as new Volume Nodes.

These operations can be parallelized since they operate independently on each element of the grid (for the rounding operation) or on grid pairs (for the boolean operators).

The implementation of the Mesh Smooth Boolean nodes relies on the OpenVDB conversion methods and extends the previously defined functions (that compute the smooth booleans on volume grids) with the blend_factor. In this way, the result is a new grid with the SDF values of the resulting geometry and the blend factors (computed for each grid element). When the mesh is reconstructed from the resulting SDF grid, the blend factor can be attached to the vertices as a new attribute.

Deliverables

Similarly to the SDF Boolean Nodes introduced in Geometry Nodes: Add SDF grid boolean nodes #118879 this project introduces a new node Called SDF Smooth Boolean. This node has a dropdown menu that allows to select one operation between Union, Difference and Intersection and updates the socket accordingly. The mockup of the user interface is shown below:

The second SDF node is the SDF Rounding node, that allows to smooth corners and edges, the user interface is shown here:

SDF Rounding

As for the meshes, this project introduces the Mesh Smooth Boolean node, that allows to select an operation between Union, Difference and Intersection. Its interface is shown below:

The output mesh will have a vertex attribute called blend_factor with values in range [0,1] as shown in the figure below:

Screenshot from 2024-03-31 13-01-34

The blend_factor can be used in the Shader Editor to blend the two materials as shown below:

Project Schedule

I am currently a PhD student in Computer Science. During the whole period of the summer of code, I will be finishing my thesis and I will have no other commitments, hence I will be able to work to the project almost full time.

Period Details
Community Bonding Period
  • I will know my Mentors and I will improve my proposal according to their guidance
  • I will also continue studying the Blender codebase and try to make other contributions and fixes to further familiarize with the environment
Week 1 - 6 I will implement the operations (smooth booleans and rounding) using the OpenVDB API. In this phase I will not deal with the UI yet, but I will implement the core functions using the OpenVDB API and no other external dependency. This phase can be further subdivided into the following steps:
  • week 1: Design of the interfaces and implementation of unit tests
  • week 2-4: Actual implementation of the functions
  • week 5-6: Data parallelization
Week 7 - 8 Implementation of the UI. In this phase I will implement the new nodes (Smooth Boolean and Rounding) and integrate them in the Blender UI.
Week 9 Integration tests
Week 10-11 I will produce the documentation and tutorials
Week 12 Buffer

Bio

I am a third year PhD student in Engineering in Computer Science at Sapienza University of Rome. I am mainly interested in Computer Graphics and Machine Learning, and actually I am working on differentiable rendering and image based surface reconstruction. I am new to Blender development but I have experience in Computer Graphics and I am proficient in C/C++, shader programming (OpenGL/GLSL), Python and CUDA.

In the past I mainly used Blender for research purposes, but its great number of features sparked my interest and I started to learn more about its use for content creation. It would be a great pleasure for me to contribute to this awesome software by having the opportunity to learn from experienced programmers.

Blender Contributions

To get familiar with the Blender codebase I implemented a feature requested by the community: the introduction of the Focus on Collection field in the Depth of Field setting in the camera properties. The pull request can be accessed here.

During the implementation of this feature I came up with a possible improvement of the Depth of Field settings and I created a post in the forum to discuss it.

40 Likes

It this something like #118879 - Geometry Nodes: Add SDF grid boolean nodes - blender - Blender Projects?

1 Like

Interesting. I think Blender should get more SDF modeling and coloring features in general, including SDF primitives and curves as an alternative to mesh objects. SDF is way more efficient for modeling and vertex-coloring than a mesh-based workflow.

I’d say: ditch Blender’s ancient metaballs and replace them with a powerful SDF primitives toolkit.

10 Likes

Hello, thank you for sharing. Yes my project is something similar but there are some important differences. First the focus of this project is the implementation of the “smooth version” of these primitives, that in my opinion is the real advantage of using SDF with respect to meshes (however it would be also very interesting to integrate smoothing in these grid boolean nodes). Then, according to what I see, these SDF grid boolean nodes are meant for volumes, not for meshes. I am aware that meshes can be converted to volumes with the volume nodes and then converted back to meshes, but with this project I was thinking to allow this manipulation directly on meshes, while masking the internal operation that relies on volume grids. However I will look into the project you sent me in more detail for possible integrations and collaborations. Thank you.

5 Likes

I totally agree, thank you for the feedback.

1 Like

Why would you mask that, tho? Implementing that as nodes allows people who know what they’re doing to dive into more granular details, while also giving you ability to create GN modifier with same exact UI for users that don’t want that.

Blender is currently trying to move existing modifiers functionalities into nodes, adding modifiers and not adding nodes would be counter-intuitive. My humble, outsider advise would be to change your proposal to add nodes and gn modifiers with those nodes, instead of hard-coded modifiers.

3 Likes

I can see idea that part of mesh can be converted to volume, and after changing volume, this mesh can be merged with meshed volume. But i wonder if this is possible to do this not only for boolean.

1 Like

If added note to general design, new modifiers will not be added. Even if this is new booleans. So this kind operations should go in geometry nodes. Feel free to just change modifier to node in description, there will not too many conceptual changes, just ability to use this operation in procedural pipeline.

Yes I clearly see the points, I am revising the proposal switching to nodes instead of modifiers, I’ll update the post soon, thank you

9 Likes

Didn’t read the thread.
But note, that this has to be a geometry nodes node, not a modifier.
The legacy modifiers will be replaced with geometry node setups completely in the future.

Does i’ll be correct if say that any attributes that is on one mesh, but not on another one, will be interpolated in this way? So what the point of having such output attribute explicitly?
In another hand, if there is no attribute propagation from inputs to outputs, how this mesh can be used for reneder (without any user attributes like UV or color)?

I’m not really deep in this topic, but does right if say that you can just have node that will increase density gradient of volume to make results of all next operations smoother?

Hello @modmoderVAAAA, thank you for your questions. I answer to the two points.

  1. Of course you can interpolate any attribute that is on one mesh but not the other in this way, but I don’t know if you can use this approach to blend two materials. Instead you can unwrap the new mesh to get UV coordinates on the resulting mesh, then you can define two different materials on the entire mesh, and you can use the explicit attribute to interpolate between the two.
  2. This is exactly what the Rounding node does but not what the Smooth Boolean Nodes do, because in this case you just want to smooth the transition between the two objects, not the entire object. For example, to compute the “hard” union between two SDF you just take the minimum between the two at each point, for smooth Union you replace the minimum with a soft minimum.

Why create a separate node for each boolean operation? I think single node SDF Smooth Boolean with dropdown list for operation type is better.

And why there is only single smooth union operation available for mesh node?

1 Like

Hello, thank you for your feedback. Of course the SDF nodes can be collapsed into a single node SDF Smooth Boolean as you are suggesting. I kept them separate to be coherent with the SDF Boolean nodes introduced in Geometry Nodes: Add SDF grid boolean nodes #118879, where each boolean is implemented with a single node.
Then I introduced only the smooth union for meshes mainly because it is the only operation (among union, difference, intersection) in which the result is a combination of the two objects, hence it requires a method to mix also the materials of the two objects (that is exactly what the Mesh Boolean Node does with the blend_factor attribute). Of course I could also introduce Mesh Smooth Difference and Mesh Smooth Intersection without the blend_factor attribute just for the sake of completeness, however they do not add new functionalities, since the same result can be obtained using the existing Mesh to SDF node, performing the boolean operation with the SDF Smooth Boolean node and converting back to mesh with the existing Grid to Mesh node.

1 Like

SDF boolean nodes were split to make use of multi input socket in union and intersect nodes, your proposal has only singular inputs for those nodes.

You have to discuss that with @jacqueslucke anyway.

Not really, you can still mix materials with difference and intersect results, like so:

4 Likes

Hello @Mikhail_Rachinskiy, I considered your observations and updated the proposal accordingly. I also tested the smooth material blending for each boolean operation in ShaderToy and the result is quite good. Thank you for the suggestions

1 Like

Thank you, updated proposal looks great!

1 Like