RUST · PROCEDURAL GEOMETRY & SDFS

sdf-math-rs — 2D & 3D Signed Distance Field Primitives, Booleans & Raymarching in Rust

sdf-math-rs is a pure Rust analytical geometry library implementing Inigo Quilez's 2D and 3D Signed Distance Field (SDF) primitives, smooth polynomial booleans, and domain repetition operators. It enables real-time CPU/SIMD sphere tracing, analytical surface normal estimation, and procedural mesh generation.

$ cargo add sdf-math-rs
GitHub ↗
Mode: 3D Raymarching
FPS: 60
Cursor: 0.0, 0.0
Distance: --

3D Geometry & CSG

Primary Shape
Secondary Shape
CSG Blend Mode
Smooth Radius (k) 0.45
Twist Transform (k) 0.0
Harmonic Noise 0.0

Lighting & Shading

Light Azimuth 45°
Ambient Occlusion 1.0
Soft Shadow Penumbra 16.0

Inigo Quilez Formulation

Polynomial Smooth Minimum:
h = max(k - |a - b|, 0.0) / k
smin(a, b, k) = min(a, b) - h² · k · 0.25
Tetrahedron Gradient (O(4)):
k₀=(1,-1,-1), k₁=(-1,-1,1)
k₂=(-1,1,-1), k₃=(1,1,1)
N = normalize(∑ kᵢ · scene(p + kᵢ · ε))

Performance Benchmarks

3D Compound Eval: 2.73 ns (366M/s)
Raymarch Trace: 0.22 µs (4.62M/s)
O(4) Normal Gradient: 9.94 ns (100M/s)
2D Glyph Geometry: 2.14 ns (466M/s)
View Full Benchmarks Report →

Mathematical Accuracy & Parity

Sphere SDF Parity: Δ = 0.00 × 10−6
Normal Gradient Dot: > 0.99999
Raymarch Precision: Δt = 4×10−5
CSG Metric Conservation: 100% Exact