Skip to content

andrinr/jaxcad

Repository files navigation

jaxCAD

Differentiable SDF primitives, transformations, and constraint system built with JAX.

Warning

The API is not stable. Expect breaking changes.

JAXCAD WebGPU playground with Python source beside a live rendered scene


Features

  • 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, and vmap work out of the box

primitives

Shader compilation and live viewer

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 --open

Edit 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.

Forward rendering

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.

Development install

Clone this repo and

cd jaxcad
uv sync
pre-commit install

Tests

pytest tests/

Docs

Requires Quarto and the docs extras:

pip install -e ".[docs]"
quartodoc build   # generate API reference from docstrings
quarto preview    # serve locally at localhost:4321

Inspired by Fidget and Inigo Quilez's distance functions.


primitives

License

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.

About

Differentiable SDF primitives, transformations, constraint system and raymarching built with JAX.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages