Implicit geometry (PyTorch)

rayd.torch SdfGrid, SdfGridBatch, sdf_intersect, SurfelCloud, SurfelScene, and MixedScene - signed-distance grids, surfels, and mixed scenes on CUDA tensors.

This page covers signed-distance grids, surfels, and mixed scenes in rayd.torch. Inputs are CUDA float32 tensors; tensors that require a gradient make the result differentiable. For a walkthrough, see Use SDF grids and surfels.

SdfGrid#

SdfGrid(values: Tensor, position: Tensor, rotation: Tensor, scale: Tensor)
valuesTensorrequired

(Nx, Ny, Nz) vertex-centered signed distances in world units, negative inside.

positionTensorrequired

(3,) center of the box.

rotationTensorrequired

(4,) scalar-first unit quaternion (qw, qx, qy, qz).

scaleTensorrequired

(3,) full side lengths of the box.

MethodReturns
intersect(ray, *, active=None, max_steps=64, relaxation=0.9, eps_hit=None)SdfIntersection
visible(start, end, active=None, *, max_steps=64, relaxation=0.9, eps_hit=None)(N,) bool tensor
trace_reflections(ray, max_bounces, active=None, *, max_steps=64, relaxation=0.9, eps_hit=None)ReflectionChain

max_steps caps the sphere-tracing steps, relaxation is the fraction of the sampled distance to step, and eps_hit=None derives the hit threshold from the grid.

SdfGridBatch#

SdfGridBatch(values: Tensor, position: Tensor, rotation: Tensor, scale: Tensor)

G >= 2 grids of the same resolution: values (G, Nx, Ny, Nz), position (G, 3), rotation (G, 4), scale (G, 3). Property grid_count; grid(i) returns one SdfGrid; intersect(ray, *, active=None, max_steps=64, relaxation=0.9, eps_hit=None) returns a tuple of SdfIntersection, one per grid.

sdf_intersect#

sdf_intersect(grid: SdfGrid, origins: Tensor, directions: Tensor, *, tmax: float = inf,
              max_steps: int = 64, relaxation: float = 0.9, eps_hit: float | None = None) -> SdfIntersection

Intersects rays given as (N, 3) origin and direction tensors with one grid.

hit = rt.sdf_intersect(grid, origins, directions)
print(hit.t, hit.hit_mask)

SdfTraceOptions#

SdfTraceOptions(max_steps: int = 64, relaxation: float = 0.9, eps_hit: float | None = None)

Frozen options for MixedScene.add_sdf and add_sdf_batch.

SdfIntersection#

t, hit_mask, position, normal, steps.

SurfelCloud#

SurfelCloud(center: Tensor, tangent_u: Tensor, tangent_v: Tensor, opacity: Tensor | None = None, value: Tensor | None = None)

(N, 3) centers and Gaussian tangent axes; (N,) opacity and scalar value. None fills ones. Property surfel_count.

SurfelTraceOptions#

SurfelTraceOptions(alpha_min=1/255, cutoff=inf, alpha_cap=0.99, max_candidate_hits=8,
                   face_forward=True, opacity_aware_proxy_bounds=False, transmittance_min=0.03)

Same meaning as the Dr.Jit SurfelTraceOptions fields of the same name.

SurfelScene#

SurfelScene(cloud: SurfelCloud, options: SurfelTraceOptions | None = None)
MethodReturns
build() -> None, is_ready() -> boolbuild state
intersect(ray, active=None)SurfelIntersection
visible(start, end, active=None)(N,) bool tensor
trace_reflections(ray, max_bounces, active=None)ReflectionChain
composite_alpha(ray, active=None)SurfelComposite
transmittance(ray, active=None)(N,) tensor

Properties: surfel_count, triangle_count, build_count. Rendering (render, SurfelAppearance) is available only in the Dr.Jit backend.

SurfelIntersection has t, p, n, local_uv, gaussian_weight, opacity, alpha, value, surfel_id, triangle_id, and is_valid(). SurfelComposite has intensity, alpha, transmittance, depth, candidate_count, candidate_buffer_full, and is_valid().

MixedScene#

MixedScene(trace_backend: str = "auto", edge_bvh_backend: str = "auto")
MethodReturns
add_mesh(mesh, dynamic=False)geometry id
add_sdf(grid, options=None)geometry id
add_sdf_batch(batch: SdfGridBatch, options=None)geometry id
add_surfel(surfel, options=None)geometry id; surfel is a SurfelCloud or a SurfelScene
build() -> None, is_ready() -> boolbuild state
intersect(ray, active=None, flags=RayFlags.All)Intersection
visible(start, end, active=None)(N,) bool tensor
transmittance(ray, active=None)(N,) tensor
trace_reflections(ray, max_bounces, active=None)ReflectionChain

Properties: num_meshes, num_sdfs, num_surfel_scenes. There are no edge or diffraction methods.