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.
| Feature | Default | Description |
|---|---|---|
cli | yes | The alice-sdf command-line tool (clap). |
image | PNG / JPEG decoding for heightmaps and texture fitting. | |
texture-fit | Fit a bitmap texture with procedural noise formulas. Implies image and cli. | |
jit | Native evaluation through Cranelift (scalar and 8-wide). | |
gpu | GPU evaluation and WGSL output through wgpu. | |
gpu-mesh | Marching cubes on the GPU. Implies gpu. | |
volume | Bake a field into a 3D texture. Implies gpu. | |
glsl | GLSL output (Unity, OpenGL, Vulkan, Shadertoy). | |
hlsl | HLSL output (Unreal Engine, DirectX). | |
msl | Metal Shading Language output, converted from WGSL with naga. Implies gpu. | |
blinkscript | BlinkScript output for Nuke. Implies hlsl. | |
rust | Dependency-free Rust source (fn sdf, fn normal) bit-identical to eval_compiled, for build.rs. | |
all-shaders | gpu, glsl, hlsl, msl and blinkscript. | |
svo | Sparse voxel octree. | |
svo-gpu | Sparse voxel octree with GPU support. Implies svo and gpu. | |
destruction | Voxel destruction. | |
terrain | Heightmap terrain with erosion and caves. | |
gi | Cone-traced global illumination. Implies svo. | |
aaa | volume, gpu-mesh, svo-gpu, destruction, terrain and gi. | |
ffi | C ABI for C, C++, C#, Unity and Unreal Engine. | |
unity | ffi and glsl. | |
unreal | ffi, hlsl, glsl and gpu: what the Unreal Engine plugin calls. | |
python | Python bindings (PyO3 + NumPy). | |
godot | Godot 4 GDExtension. | |
wasm | WebAssembly bindings through wasm-bindgen (built for wasm32 only). | |
openvdb | OpenVDB float grid input and output. | |
physics | AGPL. SDF colliders and simulation modifiers for alice-physics. | |
codec | AGPL. Volume compression with alice-codec. | |
sdf-cache | AGPL. Evaluation cache with alice-cache. | |
asp | ALICE Streaming Protocol packets with libasp (its default features only). | |
font | Glyph 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