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:

  1. Author an SDF function in a 3D viewer node for visualizing the result.
  2. 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.

Mograph of the 3D SDF functions nodes feature in Substance 3D Designer

What is an SDF function?

Just like mathematical functions can be plotted in 2D as curves, they can be plotted in 3D as surfaces.

A signed distance field is a mathematical function that defines a surface in 3D space by calculating the distance from any point in space to the nearest point on the surface.

Let us break down the name 'signed distance field' to understand it better:

  • Signed means that the function returns a positive value if the point is outside/in front of the surface, a negative value if the point is inside/behind the surface, and zero if the point is exactly on the surface.
  • Distance refers to the fact that the function calculates the distance from any point in space to the *nearest* point on the surface.
  • Field means the function describes a field of values, as each point in space has a corresponding value that represents its distance to the nearest surface.
Visualization of the shape produced by an SDF function, with sweeping isolines.

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 output to 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
Example of a function graph defining an SDF function
working-with-sdf-function-graph.png

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.

Setting up 3D viewer node for SDF function visualization.

TIP
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!

Tooltip for input connector on SDF function node.

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.

Constant nodes used to edit SDF primitive.

TIP
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.

Tooltip for input connector on SDF function node.

The bounding frame

To ensure a shape defined by an SDF function is fully drawn, it is important to adjust the bounding frame of the scene properly.
The bounding frame is a box in 3D space that defines the bounds in which the SDF function is evaluated and drawn. If the bounding frame is too small, parts of the shape may be trimmed. If it is too large, it may lead to unnecessary computations and longer processing times.

The Bounding frame parameter lets you enable the visualization of the bounding frame. You can then adjust the size of the bounding frame by changing the values of the Bounding frame size parameter.

Use the Colorize out of frame parameter to visualize the areas outside the bounding frame in bright red so you can adjust the frame accordingly.

Bounding frame feature of 3D viewer node, for SDF functions.

Isolines

Because transforming shapes involves actually *transforming the space* in which they are drawn, the result of nodes used after some transformations may be surprising.
In those cases, it is helpful to visualize the space itself, and that can be done by visualizing the distance field of the shape.

For that, the 3D viewer node uses isolines, which are repeating contour lines representing a given distance from the shape's surface. The SDF isolines parameter enables that visualization.
The isolines are drawn on a horizontal plane placed at the height specified by the SDF isolines position parameter.

Seeing how isolines are deformed by the transformations applied to the shape can help understand how the shape itself is transformed, and adjust the parameters of the nodes accordingly.

Bounding frame feature of 3D viewer node, for SDF functions.

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.

Example workspace
working-with-sdf-workspace.png

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.

Controlling space transformation using the 'P' input of SDF function nodes.
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.

working-with-sdf-shape-splatter-v2.png
Shape splatter v2 with a Shape type set to SDF function. Note the SDF bounding frame size was adjusted to fit the shape.

TIP
To easily reuse an SDF function, copy it to a new Substance function graph and use that graph as an instance node in both the 3D viewer and the Shape splatter v2 nodes.
This provides several benefits:
  • 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.

working-with-sdf-material-id.png
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:

SDF material IDs for color mapping in Shape splatter v2 mapper color node. Material IDs used for color mapping
in Shape splatter v2 mapper color
SDF material IDs for triplanar mapping in Shape splatter v2 mapper color node. Material IDs used for triplanar mapping
in Shape splatter v2 mapper color
SDF material IDs for masking in Shape splatter v2 to mask node.
Material IDs used for masking
in Shape splatter v2 to mask

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.

SDF color output of Shape splatter v2 node. SDF color output
SDF roughness of Shape splatter v2 node.
SDF roughness output
SDF metalness of Shape splatter v2 node. SDF metalness output
recommendation-more-help
dd48abc6-e399-43d2-9777-578ec70c5a23