Working with SDF functions
In version 16.0.0, Substance 3D Designer introduced a powerful set of nodes to author SDF functions, which can be used to create and manipulate procedural 3D shapes.
SDF functions are Substance function graphs that combine SDF nodes available in the toolset and are applied to dedicated parameters in nodes that support SDF functions.
As a starting point, keep in mind the basic workflow looks like this:
- Author an SDF function in a 3D viewer node for visualizing the result.
- Copy it the final function graph (or instantiate it) into the SDF function parameter of a node that supports SDF functions, such as Shape splatter v2.
What is an SDF function?
These functions have many applications in computer graphics, such as drawing surfaces, shadow casting, contour masking, collision detection and more.
In Substance 3D Designer, SDF functions are used to create and manipulate 3D shapes in a procedural way.
The output of an SDF function
SDF function nodes may output a single float value, but importantly they internally set the values of variables that the host nodes need to know about to manipulate and draw the resulting shapes.
This means these nodes need to be used in the context of nodes that support SDF functions because it knows about these variables and integrates them natively.
The nodes include Shape splatter v2 and 3D viewer.
The Substance function graph
SDF function nodes are meant to be used in dedicated Substance function graphs, and are therefore only available in that graph type.
Node parameters that are meant to be expressed as a function use an ‘Edit function’ button.
What you need to know about Substance function graphs:
- Nodes connectors are all specialized, meaning they can only be connected to other connectors of matching color. The color represents the type of value flowing through the connection.
- Nodes do not have parameters, they can only have inputs.
- The graph has a single output node, which is the SDF function’s output value. Right-click on a node and select
Set as outputto designate it as the output node. - Similarly to Substance graphs, there are atomic nodes – the base building blocks – and instance nodes which represent other Substance function graphs.
- There are separate operators (algebraic, logical and comparison) that let you perform operations on the values in the graph, however SDF nodes have their own operators
Getting started
To author SDF functions, we first need to visualize them so we can understand the effect of the nodes and parameters we are adjusting.
The 3D viewer node has a dedicated mode for visualizing shapes authored using SDF functions: Set the node’s <b<Scene type parameter to SDF function and click the Edit function button to open the function graph that will host the SDF function itself.
The node offers dedicated features for visualizing aspects of the SDF function that will let us build them more intuitively and efficiently, such as a bounding frame and isolines.
The Physical sun/sky node can be used to quickly set up environment lighting in the 3D viewer.
| table 0-row-2 html-authored no-header | |
|---|---|
|
All SDF function nodes as well as their input connectors have tooltips that will let you know more about their purpose and how to use them. Make sure to check them out! |
|
Setting node values
As with all nodes in Substance function graphs, SDF function nodes do not have parameters but only input connectors which are used as parameters.
To set the value of those inputs, you can use constant nodes such as Float, Float3 and Integer3.
You may create these the usual way through the node menu, or you can drag a new connection from the connectors to benefit from a filtered list of nodes of matching types.
Most input connectors of SDF function nodes have a default value, which is disclosed in its tooltip.
| table 0-row-2 html-authored no-header | |
|---|---|
|
If you do not need to keep some values visible at all times, dock nodes to save space and declutter the graph. You can also use comments to keep track of the values. |
|
The bounding frame
Isolines
SDF function nodes categories
SDF functions nodes are categorized in the Library based on their function and purpose.
You can create as many Library views as needed to organize your workspace in such a way that the SDF functions toolset is arranged by category while keeping everything on hand. Go to Windows > New Library view to add separate, independent views of the Library.
Primitives
The base building blocks of SDF functions, which let you create basic shapes such as spheres, boxes, cylinders and more.
Operators
These nodes let you combine and modify shapes created with primitives. They include:
- Straight boolean operators such as Union, Intersection and Subtraction that let you combine shapes in various ways.
- Deforming boolean operators such as Rounding and Morph that let you combine shapes with a blending effect.
- Other specialized operators such as Shell and Symmetry that let you modify and/or duplicate a shape.
Transforms
Shapes can be transformed in various ways, such as being translated, rotated, scaled, twisted and more.
These nodes let you perform these transformations by transforming the space itself in which the surfaces are defined.
That space is referred to as P, move on to the next section to understand more about what that means and how space transformation works.
Material
Basic material management is available for shapes authored using SDF functions.
You can define basic material attributes: color, roughness and metalness, to be used for direct visualization in the 3D viewer node or as a base for material work in the Shape splatter v2 nodes.
You can also assign material IDs to different parts of a shape to separate them.
Learn more on applications of these nodes below.
The ‘P’ input
If you use a transform node in a function, and down the line a node generates an unexpected result, it is likely caused by that transformation not being propagated to the other nodes involved. Thus SDF nodes are not working in the same transformed space and therefore not interacting with each other as expected.
To understand how space transformation works, it is important to understand that SDF functions calculate the distance to a surface by evaluating the position of a point in space relative to that surface. When we apply a transformation to the space, we are essentially changing the position of points in space relative to the surfaces, which in turn changes the surfaces themselves.
A transformed space is shared across node using the dedicated P input, which you can find in most SDF nodes. The ‘P’ stands for world space Position: A 3D vector representing the coordinates of a point in world space.
When we apply a transformation to the space, we are modifying the value of P for each point, which changes how the SDF function evaluates the distance to the surface.
The Offset P and Rotate P nodes let you propagate translations and rotations across all nodes that should inherit that transformation and create shapes in the context of the transformed space.
For instance, several shapes can be rotated the same way by connecting the same to the P input of all the nodes creating those shapes.
This is not merely a matter of convenience, it is making sure SDF nodes work with the same positions in space.
Small spheres are tiled to visualize space as a 3D grid.
Without using a shared P, note how the bent cylinder uses the tiled grid space.
With the shared P, shapes can be correctly defined in a shared rotated space.
Using SDF functions in the ‘Shape splatter v2’ nodes
Once you have completed an SDF function in the context of the 3D viewer node, you can copy the entire function and paste it in the Shape splatter v2 node to use it as a shape generator for that node.
Set the Shape type parameter to SDF function, then go to the Pattern SDF function parameter and click the Edit function button to open the parameter’s function graph.
You can then paste the function you copied from the 3D viewer node in that graph. (Do not forget to set the function graph’s output node again!)
Make sure to adjust the SDF bounding frame size parameter to match the bounding frame you were using in the 3D viewer node and ensure the shape is drawn properly.
Shape splatter v2 with a Shape type set to SDF function. Note the SDF bounding frame size was adjusted to fit the shape.
- Any update you make to the function will be reflected in both nodes without needing to copy-paste it again. This is a great quality-of-life improvement for complex shapes.
- The graph can have a descriptive name that will be visible in the instance nodes, which will make using your own library of SDF shapes much more manageable and your graphs more readable.
- You can create inputs for the function graph that you can use with Get nodes. These inputs will be exposed as input connectors in the instance node, and will let you easily make variations of your shapes.
Material ID
An SDF shape can have a material ID assigned to it, which is an integer value that can be used to differentiate parts of the shape and assign different materials to them in the 3D viewer and Shape splatter v2 nodes.
Note that surfaces with different material IDs are split with a hard edge across blended shapes, as is visible in the example below.
Use the Set material ID node after the portion of a shape you want to tag with a specific material ID, and use an Integer constant node to set the desired material ID value.
In the 3D viewer node, set the Output parameter to Material ID to visualize the material IDs of the shapes.
On the right, the output of two 3D viewer nodes are composited to show the normals of the shape (left) and its material IDs (right), to provide a glimpse of how material IDs are split in blended shapes.
Material IDs can be leveraged by Shape splatter v2 companion nodes:
- Shape splatter v2 mapper nodes can use these material IDs to assign different patterns.
- Shape splatter v2 to mask can mask part of shapes according to their material ID.
Color, roughness and metalness
The Set color, Set roughness and Set metalness nodes let you define these material attributes for shapes in the SDF function.
Then, when using that SDF function as a shape type in the Shape splatter v2 node, these material attributes will be available as maps in the SDF color, SDF roughness and SDF metalness outputs of the node. These maps may serve as a base for more complex material work using other nodes.
Note that distinctly from material IDs, values are interpolated across blended shapes as a gradient, as is visible in the examples below.