RayD
Differentiable GPU ray geometry for custom renderers and RF simulators, with Dr.Jit and PyTorch backends built on CUDA and OptiX.
RayD is a CUDA/OptiX library of differentiable ray geometry primitives: ray-mesh intersection, nearest-edge queries, segment visibility, specular reflection chains, and RF multipath accumulation. It is for people who build their own renderer, RF or acoustic simulator, sensing pipeline, or inverse-design loop and need direct control over ray-scene queries and their gradients.
RayD is not a renderer. It has no materials framework, emitters, integrators, scene loaders, or image I/O. Channel and other WiTwin solvers use it as their geometry layer.
Two backends, one vocabulary#
RayD ships two independent Python backends. Each one owns its arrays, GPU memory, CUDA stream, OptiX pipelines, and autodiff graph.
| Backend | Import | Arrays and autodiff | Distribution |
|---|---|---|---|
| Dr.Jit | import rayd.drjit as rd | drjit.cuda arrays, dr.backward / dr.forward | rayd-drjit |
| PyTorch | import rayd.torch as rt | CUDA torch.Tensor, torch.autograd, forward AD, torch.compile | rayd-torch |
Both backends use the same names where their features overlap: Mesh, Scene, Ray, scene.intersect, scene.nearest_edge, scene.visible, scene.trace_reflections. The parent rayd namespace selects no default backend, and objects never cross from one backend to the other.
Example#
This traces one ray against a triangle and differentiates the hit distance with respect to the vertices (Dr.Jit backend):
import drjit as dr
import rayd.drjit as rd
mesh = rd.Mesh(dr.cuda.Array3f([0, 1, 0], [0, 0, 1], [0, 0, 0]), dr.cuda.Array3i([0], [1], [2]))
vertices = dr.cuda.ad.Array3f([0, 1, 0], [0, 0, 1], [0, 0, 0])
dr.enable_grad(vertices)
mesh.vertex_positions = vertices
scene = rd.Scene()
scene.add_mesh(mesh)
scene.build()
hit = scene.intersect(rd.RayAD(dr.cuda.ad.Array3f([0.25], [0.25], [-1.0]), dr.cuda.ad.Array3f([0], [0], [1])))
dr.backward(dr.sum(hit.t))
print(hit.t, dr.grad(vertices).z) # [1] [0.5, 0.25, 0.25]What RayD provides#
- Closest-hit ray-mesh intersection with gradients to vertices, transforms, and rays.
- Scene acceleration through OptiX, with an automatic pure-CUDA fallback when OptiX is unavailable.
- Point-to-edge and ray-to-edge nearest queries, and top-k nearest edges, over a scene-global edge BVH.
- Batched segment, pair, chain, and edge visibility.
- Specular reflection chains with image sources, equivalent-path correction (EPC), and reflected field accumulation on receiver grids.
- Direct and chained diffraction accumulation and path export.
- Differentiable signed-distance-field grids and Gaussian surfels, alone or mixed with meshes in a
MixedScene. - Replicated multi-GPU execution in the PyTorch backend.
Where to go next#
Install from PyPI and check the CUDA, OptiX, and driver requirements.
Build a scene, intersect rays, and read gradients in either backend.
Backends, the differentiation contract, scene build and sync, and edges.
Task-focused how-tos for intersection, edges, visibility, and multipath.
Worked optimization examples with full code and output.
Every public class, function, argument, and default in both backends.