Differentiable SDF primitives, transformations, and constraint system built with JAX.
Warning
The API is not stable. Expect breaking changes.
- SDF primitives — sphere, box, capsule, cylinder, torus, and more
- Boolean ops — union, intersection, subtraction with smooth blending
- Transforms — translate, rotate, scale, mirror, repeat
- Forward raymarcher — early-exit sphere tracing, reconstructed silhouettes, GGX materials, soft shadows, reflections, refraction, and anti-aliasing
- Shader backends — compile 3D SDFs through StableHLO to GLSL or WGSL
- WebGPU viewers — interactively inspect SDFs in a browser playground or Jupyter
- Constraint system — geometric constraints (distance, angle, coincident) with Riemannian gradient descent and Newton projection onto the constraint manifold
- JAX-native — every scene is a pure function;
jit,grad, andvmapwork out of the box
Compile an SDF to a standalone shader function:
from jaxcad.backends import GLSLBackend, WGSLBackend
from jaxcad.sdf.primitives import Sphere
sphere = Sphere(radius=1.0)
glsl = GLSLBackend().compile_sdf(sphere)
wgsl = WGSLBackend().compile_sdf(sphere)The Jupyter viewer is an optional dependency:
pip install -e ".[viewer]"from jaxcad.viewer import SDFViewer
SDFViewer(sphere)See the WebGPU viewer notebook for composition and hot-reload examples.
For a split-pane Python editor and live WebGPU preview, start the local playground:
jaxcad-viewer --open
# or: python -m jaxcad.viewer.playground --openEdit the example on the left and run it with Ctrl+Enter (or Cmd+Enter). The
program must assign its final SDF to scene. The server only listens on localhost
and compiles each edit in a timed child process, but the editor still executes
Python on your machine—only run code you trust.
The WebGPU viewer guide includes a live interactive scene and covers the local playground, camera controls, generated shader inspection, and the Jupyter widget.
For offscreen OpenGL rendering, install the glsl extra instead.
The image renderer groups scene data and quality controls explicitly:
from jaxcad.render import Camera, RenderSettings, Scene, render_scene
from jaxcad.sdf.primitives import Sphere
scene = Scene(
Sphere(1.0),
camera=Camera(position=(0, 1.5, 5), target=(0, 0, 0)),
)
image = render_scene(scene, RenderSettings.balanced((240, 320)))Use RenderSettings.draft(), .balanced(), or .high_quality() to choose an
explicit performance/fidelity trade-off. See the forward renderer guide
for mode and quality comparisons.
Clone this repo and
cd jaxcad
uv sync
pre-commit installpytest tests/Requires Quarto and the docs extras:
pip install -e ".[docs]"
quartodoc build # generate API reference from docstrings
quarto preview # serve locally at localhost:4321Inspired by Fidget and Inigo Quilez's distance functions.
Elastic License 2.0 — free for personal, research, and internal business use. Offering jaxcad as a hosted or managed service requires a commercial license. Contact andrin.rehmann@gmail.com for commercial enquiries.


