SDF T3D¶
Summary¶
The SDF T3D evaluates a signed distance function you write in GLSL at every voxel. The SDF parameter points to a
Text DAT defining float SDF(vec3 p); the result is either the shape, filled and antialiased like the other shape
generators (Mode Inside), or the distance itself (Mode Distance), for use as a distance field by other
operators.
uniform vec4 uSize; // a block on the Vectors page named uSize
float SDF(vec3 p){ // p: voxel position, volume centre at 0, units of the width
vec3 q = abs(p) - uSize.xyz;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0); // a box
}
Inigo Quilez's distance functions drop in directly. The position is transformed by the transform parameters first, so rotating or scaling the shape needs no code; with Aspect Correction on, a sphere of radius r stays round in a non-cubic volume. Uniforms come from the Vectors, Arrays and Matrices pages, and compile errors appear in the docked Info DAT. The first input sets the resolution and, by default, the shape is composited over it: see Combining volumes.
Parameters - SDF Page¶
Mode Mode ⊞ - What the output holds.
- Distance
Distance- The signed distance itself, minus Offset, in every channel: negative inside, positive outside, in the shape's own units (units of the volume's width, before the transform's scale). Use a float Pixel Format, or the negative half is clamped away. - Inside
Inside- The shape, blended from Background Color to Fill Color across Softness.
SDF Sdf - The Text DAT with the distance function. It must define float SDF(vec3 p), returning the signed distance from p (the voxel's position, transformed, with the volume's centre at 0) to the surface, and declares any uniforms it uses. It is prepended to the operator's compute shader, so it can hold helper functions too. Placing the operator creates a docked example (a hollow box frame) and an Info DAT for compile errors.
Offset Offset - Subtracted from the distance: positive values grow the shape outwards by that much, negative values shrink it. Also rounds sharp edges when growing.
Aspect Correction Aspectcorrection - Keeps the shape's proportions in voxels when the volume is not a cube: sizes along Y and Z are measured in units of the width, so a sphere stays round (measured: Radius 0.1 in 128 × 64 × 32 is 26 voxels across on every axis). Off, each axis runs from −0.5 to 0.5 across its own extent and the shape stretches with the volume (26 × 12 × 6 voxels).
Transform Order Xord ⊞ - Order in which scale, rotate and translate are applied to the shape.
- Scale Rotate Translate
srt - Scale Translate Rotate
str - Rotate Scale Translate
rst - Rotate Translate Scale
rts - Translate Scale Rotate
tsr - Translate Rotate Scale
trs
Rotate Order Rord ⊞ - Order of the rotations about X, Y and Z.
- Rx Ry Rz
xyz - Rx Rz Ry
xzy - Ry Rx Rz
yxz - Ry Rz Rx
yzx - Rz Rx Ry
zxy - Rz Ry Rx
zyx
Translate Tx Ty Tz ⊞ - Moves the shape. The volume's centre is 0, and each axis is measured as a fraction of its own extent: 0.5 moves the shape's centre to the face of the volume.
Rotate R1 R2 R3 ⊞ - Rotation of the shape about each axis, in degrees, around Pivot.
Scale Sx Sy Sz ⊞ - Scale of the shape along each axis, around Pivot.
Pivot Px Py Pz ⊞ - Pivot of rotation and scale, measured like Translate. The default 0 is the volume's centre.
Uniform Scale Scale - Uniform scale, multiplied with Scale per axis.
Fill Color Fillcolorr Fillcolorg Fillcolorb ⊞ - Colour inside the shape.
Fill Alpha Fillalpha - Alpha inside the shape.
Background Color Bgcolorr Bgcolorg Bgcolorb ⊞ - Colour outside the shape.
Background Alpha Bgalpha - Alpha outside the shape. 0 leaves the outside empty, so the shape composites cleanly.
Pre-Multiply RGB by Alpha Premultrgbbyalpha - Multiplies Fill Color and Background Color by their alphas, giving premultiplied output.
Softness Softness - Width of the edge, in units of the volume's width: the output blends from Background to Fill between Softness outside and Softness inside the surface, and is halfway at the surface itself. 0 gives a hard edge: every voxel is either Fill or Background. The edge is measured in the shape's own space, so Scale scales it too.
Parameters - Output Page¶
Combine with Input Combineinput ⊞ - How the generated volume uses the first input, when one is connected.
- Set Resolution Only
res- The input only sets the output resolution; its content is discarded. - Composite and Set Resolution
compres- The generated volume is composited with the input using Operation.
Operation Operand ⊞ - Compositing operation between the generated volume and the first input, with the same options as TouchDesigner's Composite TOP. The generated volume is the first operand: with Over, it sits on top of the input.
Swap Order Swaporder - Swaps the operands of Operation, so the input comes first.
Parameters - Vectors Page¶
Vector Vec - Vector uniforms for the SDF DAT. Each block's Name becomes a vec4 uniform with Value; declare it in the DAT as uniform vec4 <Name>;.
Name Vec0name - Name of the uniform, as declared in the SDF DAT.
Value Vec0valuex Vec0valuey Vec0valuez Vec0valuew ⊞ - Value of the uniform, up to four components.
Parameters - Arrays Page¶
Array Array - Array uniforms from CHOPs, as the GLSL TOP's Arrays page: Name, element Type, the CHOP, and Array Type (Uniform Array, or Texture Buffer for large arrays, read with texelFetch).
Name Array0name - Name of the array uniform, as declared in the SDF DAT.
Type Array0type ⊞ - Element type of the array.
- float
float - vec2
vec2 - vec3
vec3 - vec4
vec4
CHOP Array0chop - The CHOP whose channels fill the array.
Array Type Array0arraytype ⊞ - Uniform Array works on every GPU but holds few values; Texture Buffer holds large arrays, read with texelFetch from a samplerBuffer.
- Uniform Array
uniformarray - Texture Buffer
texturebuffer
Parameters - Matrices Page¶
Matrix Matrix - Matrix uniforms for the SDF DAT: Name and the operator or CHOP that supplies the 4 × 4 matrix, as the GLSL TOP's Matrices page. Declare them as uniform mat4 <Name>;.
Name Matrix0name - Name of the matrix uniform, as declared in the SDF DAT.
Matrix Matrix0value - The operator or CHOP that supplies the matrix.
Parameters - Common Page¶
Output Resolution Outputresolution ⊞ - Where the output's width, height and depth come from. With nothing connected to the first input the operator always uses Resolution, whichever option is set.
- Use Input
useinput- The first input's width, height and depth. - Custom
custom- The Resolution parameter.
Resolution Resolution1 Resolution2 Resolution3 ⊞ - Width, height and depth of the output in voxels. Used when Output Resolution is Custom, or when the first input is not connected. Memory is width × height × depth × bytes per voxel of the Pixel Format: 256³ at 16-bit float RGBA is 128 MiB.
Input Smoothness Inputfiltertype ⊞ - Filtering of the internal GLSL TOPs' input samplers, as TouchDesigner's Input Smoothness. Inputs are read at normalised coordinates, so this matters whenever the input and output resolutions differ or an input is transformed. Nearest Pixel returns voxels unblended; Interpolate Pixels is trilinear.
- Nearest Pixel
nearest - Interpolate Pixels
linear - Mipmap Pixels
mipmap
Passes Npasses - Has no effect on this operator: its shaders are compute shaders, which read the connected input on every pass, so extra passes repeat identical work. Leave it at 1.
Pixel Format Format ⊞ - Pixel format of the output. Use Input takes the first input's format. With nothing connected, Use Input resolves to 8-bit fixed (RGBA), which clamps values to 0–1 and quantises them to 1/255: set a float format for signed distances, densities above 1, velocities or anything else outside 0–1.
Bypass Bypass - Passes the first input through unchanged and skips the operator's work. With nothing connected the output is a single black voxel.
Version Version - T3D version of this operator. Read-only information; include it when reporting a problem.
Copyright Copyright - Author and licence information. Read-only.
Operator Inputs¶
- Input 0: Composite Input
T3D_in1- Optional. Sets the output resolution when Output Resolution is Use Input, and with Combine with Input at Composite the shape is composited with it using Operation.
Operator Outputs¶
- Output 0: Output
T3D_output- The shape, as colour and alpha.
Performance¶
GPU time when the operator recooks: 0.046 ms at 64³, 0.057 ms at 128³, all of its passes summed (GeForce RTX 4090, TouchDesigner 2025.33230). An operator whose inputs and parameters are unchanged does not recook and costs nothing.