render.raymarch.render.raymarch
render.raymarch.render.raymarch(
sdf,
camera_pos=jnp.array([5.0, 5.0, 5.0]),
look_at=jnp.array([0.0, 0.0, 0.0]),
light_dirs=jnp.array([0.5, 1.0, 0.3]),
light_colors=None,
resolution=(200, 200),
fov=0.6,
max_steps=64,
max_dist=20.0,
shadow_steps=24,
shadow_hardness=8.0,
gamma=2.2,
ambient=0.0,
aa_samples=1,
background_color=jnp.array([0.0, 0.0, 0.0]),
refract_steps=0,
fd_normals=False,
normal_eps=0.0001,
reflect_steps=0,
env_map=None,
trace_mode='sphere',
bisect_steps=8,
)Render an SDF via sphere tracing and return an RGB image array.
Uses jax.vmap over pixels and jax.lax.scan for the inner march loop. Supports multiple colored lights, transparency, refraction, and mirror reflections.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| sdf | Callable[[Array], Array] | Signed distance function, callable (point: Array[3]) → Array[]. |
required |
| camera_pos | Array | Camera position in world space. | jnp.array([5.0, 5.0, 5.0]) |
| look_at | Array | Point the camera looks toward. | jnp.array([0.0, 0.0, 0.0]) |
| light_dirs | Array | Light direction(s) toward the light source(s). Shape (3,) for a single light or (N, 3) for N lights. |
jnp.array([0.5, 1.0, 0.3]) |
| light_colors | Array | None | RGB color(s) of the light(s), shape (3,) or (N, 3). Defaults to white [1, 1, 1] for every light. |
None |
| resolution | tuple[int, int] | Output image size as (height, width). | (200, 200) |
| fov | float | Half-width field-of-view parameter. | 0.6 |
| max_steps | int | Sphere tracing iterations per ray. | 64 |
| max_dist | float | Rays beyond this distance are treated as misses. | 20.0 |
| shadow_steps | int | Iterations for the soft shadow ray. | 24 |
| shadow_hardness | float | Shadow sharpness (higher = harder edges). | 8.0 |
| gamma | float | Gamma correction exponent (1.5 default, 2.2 = sRGB standard). | 2.2 |
| ambient | float | Constant ambient light added to all hit pixels (0 = fully black shadows, higher = lifted shadows). | 0.0 |
| aa_samples | int | Super-sampling factor for antialiasing. 1 = no AA; 2 = 2×2 SSAA (4× rays, box-filtered); 3 = 3×3, etc. | 1 |
| background_color | Array | RGB color returned for rays that miss all geometry. Ignored when env_map is provided. Default is black. |
jnp.array([0.0, 0.0, 0.0]) |
| refract_steps | int | Number of interior march steps for glass refraction. 0 disables refraction (legacy behaviour). Try 32–64 for glass. | 0 |
| fd_normals | bool | Use central finite differences for surface normals instead of jax.grad. Eliminates 2nd-order AD overhead when rendering inside jax.grad(loss_fn). Default False (AD normals). |
False |
| normal_eps | float | Step size for finite-difference normal estimation. | 0.0001 |
| reflect_steps | int | Sphere-tracing iterations for mirror reflections (0 disables). Uses material reflectivity to blend. Try 32. |
0 |
| env_map | Array | None | Optional equirectangular HDR environment map, shape (H, W, 3). When set, miss rays and reflected rays that miss geometry sample this map instead of background_color. Load any .hdr or .exr file with imageio and pass through jnp.asarray, or generate one with :func:~jaxcad.render.raymarch.env.make_gradient_sky. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | Float32 numpy array of shape (H, W, 3) with values in [0, 1]. |