Initializing 3D Canvas...

Sdf Booleans

1 min read1 page

Constructive Solid Geometry on SDFs reduces to simple scalar operations. Union uses min, intersection uses max, and subtraction combines max with negation.

SDF CSG:

1. Union: min(d1, d2) — closest surface wins. 2. Intersection: max(d1, d2) — only overlap region. 3. Difference: max(d1, -d2) — carve d2 from d1.
python
1# SDF Boolean operations combine two distance fields
2# using simple scalar operations: min, max, negation.
3
4def sdf_union(d1, d2):
5 return min(d1, d2) # Closest surface wins
6
7def sdf_intersection(d1, d2):
8 return max(d1, d2) # Farthest surface wins
9
10def sdf_difference(d1, d2):
11 return max(d1, -d2) # Keep d1, carve out d2
1 min read1 page

Union produces the combined volume of both shapes. At each point, the minimum SDF value determines which surface is visible.

Union:

1. Evaluate both SDFs at query point. 2. Return the minimum value. 3. Resulting shape is the outer hull of both inputs.
python
1# SDF Union: min of two distance fields
2def sdf_union(d1, d2):
3 """Keep the surface closest to the query point."""
4 return min(d1, d2)
5
6# Union merges two shapes by selecting the minimum
7# signed distance at every spatial sample point.
Separation
1.50
1 min read1 page

Intersection retains only the overlapping volume. The maximum SDF value ensures both surfaces constrain the result.

Intersection:

1. Evaluate both SDFs at query point. 2. Return the maximum value. 3. Only regions inside both shapes remain.
python
1# SDF Intersection: max of two distance fields
2def sdf_intersection(d1, d2):
3 """Keep only the overlapping region."""
4 return max(d1, d2)
5
6# The result is the region where both shapes exist
7# simultaneously (both d1 and d2 are negative).
Separation
1.50
1 min read1 page

Difference carves shape B out of shape A. Negating d2 flips its interior, then max selects only the region of A outside B.

Difference:

1. Negate d2 to flip its inside/outside. 2. Take max(d1, -d2) to keep A minus B overlap. 3. Sharp edges appear at the intersection boundary.
python
1# SDF Difference (Subtraction): max(d1, -d2)
2def sdf_difference(d1, d2):
3 """Remove shape B from shape A."""
4 return max(d1, -d2)
5
6# Negating d2 flips its inside/outside, then taking
7# the max keeps only the part of A that is outside B.
Separation
1.50
2 min read1 page

Smooth union blends two SDFs using polynomial interpolation near the intersection boundary, creating organic fillet-like transitions.

Smooth Union:

1. Compute blending factor h from distance difference and radius k. 2. Subtract smooth correction term from hard min result. 3. Larger k produces wider, smoother blend radius.
python
1# Smooth union using polynomial blending
2def sdf_smooth_union(d1, d2, k):
3 """Smooth min blending two SDFs with radius k."""
4 h = max(k - abs(d1 - d2), 0.0) / k
5 return min(d1, d2) - h * h * k * 0.25
6
7# k controls the blending radius.
8# k=0 reduces to hard min (standard union).
Blend Radius (k)
1.00
2 min read1 page

Smooth subtraction applies the same polynomial blending to the difference operation, creating rounded cavities instead of sharp cuts.

Smooth Subtraction:

1. Negate d2 and compute blending factor with d1. 2. Add smooth correction term to hard max result. 3. Larger k rounds the carved edges more aggressively.
python
1# Smooth subtraction using polynomial blending
2def sdf_smooth_sub(d1, d2, k):
3 """Smooth difference: carve d2 from d1 with blend radius k."""
4 h = max(k - abs(-d2 - d1), 0.0) / k
5 return max(-d2, d1) + h * h * k * 0.25
6
7# Same polynomial blending as smooth union,
8# but applied to the difference operation.
Blend Radius (k)
1.00
1 min read1 page

Chamfer blending creates a flat 45-degree bevel at the intersection edge by adding a diagonal distance term to the max operation.

Chamfer:

1. Compute standard intersection via max(d1, d2). 2. Add chamfer term: (d1 + d2) * sqrt(0.5) - r. 3. Take max of all three terms. Radius r controls bevel width.
python
1# Chamfer intersection: creates a 45-degree bevel
2def sdf_chamfer_intersection(d1, d2, r):
3 """Chamfer blend at intersection edges."""
4 import math
5 return max(max(d1, d2),
6 (d1 + d2) * math.sqrt(0.5) - r)
7
8# The chamfer term adds a diagonal cut where
9# the two surfaces meet, creating a flat bevel.
Chamfer Radius
0.80
2 min read1 page

Fillet blending rounds the intersection edge using a circular arc profile by combining the positive parts of both distance fields.

Fillet:

1. Compute standard intersection via max(d1, d2). 2. Add fillet term: sqrt(max(d1,0)^2 + max(d2,0)^2) - r. 3. Take max of both. Radius r controls fillet curvature.
python
1# Fillet intersection: creates a rounded edge
2def sdf_fillet_intersection(d1, d2, r):
3 """Round fillet blend at intersection edges."""
4 import math
5 return max(max(d1, d2),
6 math.sqrt(max(d1, 0)**2 + max(d2, 0)**2) - r)
7
8# The fillet term uses the Euclidean combination of
9# the positive parts of d1 and d2, producing a circular
10# arc at the intersection edge.
Fillet Radius
0.80