Skip to main content

Crate alice_sdf

Crate alice_sdf 

Source
Expand description

§ALICE-SDF

Signed distance functions for Rust. A shape is a tree of primitives, CSG operations, transforms and modifiers (SdfNode). The crate evaluates the tree on the CPU (scalar, SIMD, BVH and JIT evaluators), transpiles it to GLSL, WGSL, HLSL and Metal, and turns it into meshes and file formats.

The CPU evaluators return bit-identical distances for the same tree and point on every platform CI tests: every transcendental goes through alice-det-math and a * b + c is never fused. The GPU shaders agree with the CPU within a tolerance.

§Example

use alice_sdf::prelude::*;

// A unit sphere minus a box (box3d takes full extents)
let shape = SdfNode::sphere(1.0).subtract(SdfNode::box3d(1.0, 1.0, 1.0));

// Signed distance: negative inside, zero on the surface, positive outside
let p = Vec3::new(0.9, 0.0, 0.0);
let d = eval(&shape, p);
assert!(d < 0.0);

// Compiled to bytecode for repeated evaluation, with the same bits
let compiled = CompiledSdf::compile(&shape);
assert_eq!(eval_compiled(&compiled, p).to_bits(), d.to_bits());

// A triangle mesh by marching cubes
let mesh = sdf_to_mesh(
    &shape,
    Vec3::splat(-1.5),
    Vec3::splat(1.5),
    &MarchingCubesConfig::default(),
);
assert!(!mesh.indices.is_empty());

§Cargo features

The physics, codec and sdf-cache features link crates licensed AGPL-3.0-or-later; the default features and all others do not.

FeatureDefaultDescription
cliyesThe alice-sdf command-line tool (clap).
imagePNG / JPEG decoding for heightmaps and texture fitting.
texture-fitFit a bitmap texture with procedural noise formulas. Implies image and cli.
jitNative evaluation through Cranelift (scalar and 8-wide).
gpuGPU evaluation and WGSL output through wgpu.
gpu-meshMarching cubes on the GPU. Implies gpu.
volumeBake a field into a 3D texture. Implies gpu.
glslGLSL output (Unity, OpenGL, Vulkan, Shadertoy).
hlslHLSL output (Unreal Engine, DirectX).
mslMetal Shading Language output, converted from WGSL with naga. Implies gpu.
blinkscriptBlinkScript output for Nuke. Implies hlsl.
rustDependency-free Rust source (fn sdf, fn normal) bit-identical to eval_compiled, for build.rs.
all-shadersgpu, glsl, hlsl, msl and blinkscript.
svoSparse voxel octree.
svo-gpuSparse voxel octree with GPU support. Implies svo and gpu.
destructionVoxel destruction.
terrainHeightmap terrain with erosion and caves.
giCone-traced global illumination. Implies svo.
aaavolume, gpu-mesh, svo-gpu, destruction, terrain and gi.
ffiC ABI for C, C++, C#, Unity and Unreal Engine.
unityffi and glsl.
unrealffi, hlsl, glsl and gpu: what the Unreal Engine plugin calls.
pythonPython bindings (PyO3 + NumPy).
godotGodot 4 GDExtension.
wasmWebAssembly bindings through wasm-bindgen (built for wasm32 only).
openvdbOpenVDB float grid input and output.
physicsAGPL. SDF colliders and simulation modifiers for alice-physics.
codecAGPL. Volume compression with alice-codec.
sdf-cacheAGPL. Evaluation cache with alice-cache.
aspALICE Streaming Protocol packets with libasp (its default features only).
fontGlyph outlines from alice-font. Inert on crates.io: also needs --cfg alice_font_bridge and a local alice-font.

Module overview: https://github.com/ext-sakamoro/ALICE-SDF/blob/main/docs/MODULES.md

Re-exports§

pub use cache::compute_cache_key;
pub use cache::hash_sdf_node;
pub use cache::CacheConfig;
pub use cache::ChunkCoord;
pub use cache::ChunkedCacheConfig;
pub use cache::ChunkedMeshCache;
pub use cache::MeshCache;
pub use cache::MeshCacheKey;
pub use eval::eval;
pub use io::load;
pub use io::save;
pub use mesh::sdf_to_mesh;
pub use mesh::sdf_to_mesh;
pub use types::SdfNode;
pub use types::SdfTree;

Modules§

animation
Animation System for SDF parameter morphing
autodiff
Forward-mode Automatic Differentiation via Dual Numbers
cache
SDF hash-based mesh cache with LRU eviction
collision
SDF-to-SDF collision detection.
compiled
Compiled SDF: Cache-efficient linearized evaluation
constraint
Parametric SDF constraint solver
destruction
Voxel Destruction System (Deep Fried Edition)
diff
CSG Tree structural diff and patch
eval
SDF Evaluation (Deep Fried Edition)
ffi
Foreign Function Interface (FFI) for ALICE-SDF (Deep Fried Edition)
fidelity
What a field’s distance claim is worth.
gi
Cone Tracing Global Illumination (Deep Fried Edition)
heatmap
Distance field cross-section heatmap visualization
incremental
Incremental parameter update support for CompiledSdf.
interval
Interval Arithmetic for SDF evaluation
io
File I/O for SDF trees (Deep Fried Edition)
llm_schema
LLM integration utilities for ALICE-SDF
material
PBR Material System for AAA rendering
measure
Volume, surface area, and center-of-mass estimation
mesh
Mesh conversion for SDFs (Deep Fried Edition v2)
modifiers
Modifier operations for SDFs (Deep Fried Edition)
morphology
Morphological operations on signed distance fields.
neural
Neural SDF — small MLP that approximates a Signed Distance Field.
npr
NPR (Non-Photorealistic Rendering) primitives
operations
CSG (Constructive Solid Geometry) Operations (Deep Fried Edition)
optimize
CSG tree optimization pass
prelude
Prelude - commonly used types and functions
primitives
Primitive SDF shapes (Deep Fried Edition)
raycast
Raymarching for SDFs (Deep Fried v2 Edition)
sdf2d
Pure 2D SDF evaluation module
shell
Variable-thickness offset surface (shell) modifier
soa
SoA (Structure of Arrays) Memory Layout for SIMD-Optimized Evaluation
svo
Sparse Voxel Octree (Deep Fried Edition)
terrain
Terrain System (Deep Fried Edition)
tight_aabb
Auto tight AABB computation for SDF trees
transforms
Transform operations for SDFs
types
Core types for ALICE-SDF
validity
Printability validation — ValidityReport.

Constants§

SEMANTICS_ID
The numeric semantics the CPU evaluators compute distances with
VERSION
Library version