Reflection (Dr.Jit)
rayd.drjit reflection API - trace_reflections, EPC path solving, reflected field evaluation, grid accumulation, their options, materials, and result records.
These rayd.drjit.Scene methods trace specular reflections. For a walkthrough, see Trace reflection paths.
Per-slot arrays hold ray_count * max_bounces entries, ray-major: slot r * max_bounces + b is bounce b of ray r. Unused slots have a primitive id of -1. Lengths are in scene units.
Scene.trace_reflections#
trace_reflections(ray, max_bounces, active=True, symbolic=True)
trace_reflections(ray, max_bounces, options: ReflectionTraceOptions, active=True, symbolic=True)
trace_reflections(ray, max_bounces, deduplicate=False, canonical_prim_table=[], image_source_tolerance=1e-5, active=True, symbolic=True)Follows each ray through up to max_bounces specular reflections.
Rays to trace. A RayAD returns AD records.
Maximum reflections per ray.
Deduplication and export settings. Alternatively pass deduplicate, canonical_prim_table, and image_source_tolerance as keywords.
TrueLane mask.
TrueSelects the result layout: True returns a ReflectionTrace (one ReflectionBounce per bounce), False returns a flat ReflectionChain.
trace = scene.trace_reflections(ray, 2)
first = trace.bounce(0)
chain = scene.trace_reflections(ray, 2, symbolic=False)ReflectionTraceOptions#
| Field | Default | Meaning |
|---|---|---|
deduplicate | False | merge rays that share the same reflector sequence |
canonical_prim_table | [] | map from global primitive id to a canonical id used for deduplication |
image_source_tolerance | 1e-5 | distance under which two image sources are treated as equal |
export_mode | REFLECTION_EXPORT_FULL | result payload: full, minimal, or counts only |
return_trailing | True | trace and export the segment after the last reflection |
ReflectionTrace#
| Field | Meaning |
|---|---|
ray_count, max_bounces | input size and slot capacity |
bounce_count | valid reflections per ray |
discovery_count | number of rays merged into each path by deduplication |
representative_ray_index | ray chosen to represent a merged group |
dedup_keep_mask | rays that survived deduplication |
deduplicate_requested, deduplicate_applied | whether deduplication was asked for and ran |
bounces | list of ReflectionBounce, one per bounce level |
bounce(i) returns bounces[i]. is_valid() returns the per-ray mask of rays with at least one reflection.
ReflectionBounce#
One bounce for every ray: t (distance from the previous point), hit_points, geo_normals, image_sources (mirror image of the source across this reflector), plane_points, plane_normals, shape_ids, prim_ids, local_prim_ids, global_prim_ids. is_valid() is prim_ids >= 0.
ReflectionChain#
The flat layout. Per-ray fields: bounce_count, discovery_count, representative_ray_index, trailing_t (length of the segment after the last reflection), trailing_prim (primitive it hits), trailing_dir, trailing_origin. Per-slot fields: the ReflectionBounce fields. ray_count and max_bounces give the layout. ReflectionChain is also what SdfGrid, SurfelScene, and MixedScene return from trace_reflections.
Scene.trace_refl_epc#
trace_refl_epc(ray: Ray, receiver: Array3f, max_bounces: int, options: ReflEpcOptions | None = None, active: Bool = True) -> ReflEpcSolves the exact specular path from each ray's origin to its receiver through the reflectors in options.expected_prim_ids (equivalent-path correction, EPC), then checks the visibility of every segment. No derivatives.
Source rays. The origin is the transmitter.
Receiver position per ray.
Slots per ray.
NoneExpected reflectors and surface-group tables.
TrueLane mask.
ReflEpcOptions#
| Field | Default | Meaning |
|---|---|---|
expected_prim_ids | [] | expected reflector per slot, ray_count * max_bounces entries |
surface_group_id | [] | surface-group id per triangle |
surface_group_size | [] | member count per group |
surface_group_members | [] | flattened member table, group_count * surface_max_group_size |
surface_max_group_size | 0 | width of the member table |
visibility_ignore_mode | "primitive" | ignore the reflector itself ("primitive") or its whole group ("surface_group") in visibility checks |
plane_tolerance | 1e-5 | relative out-of-plane tolerance for a point to count as on the reflector |
final_ignore_group_ids | [] | groups ignored on the last segment to the receiver |
ReflEpc#
Per ray: valid (a corrected path exists), bounce_count, path_length, first_blocked_segment, first_blocked_prim, first_blocked_group (-1 when clear). Per slot: reflection_points, plane_normals, prim_ids, trace_prim_ids (primitive actually hit while tracing), resolved_prim_ids (after surface-group resolution), surface_group_ids. Also ray_count, max_bounces.
Scene.trace_refl_epc_field#
trace_refl_epc_field(source, receiver, max_bounces: int, options: ReflEpcFieldOptions | ReflEpcFieldOptionsAD, active=True) -> ReflEpcField | ReflEpcFieldADSolves the EPC path and evaluates the complex electric field at the receiver.
A ray (its first hit selects the reflector) or a transmitter position per lane (then options.expected_prim_ids is required).
Receiver position per lane.
Slots per lane.
Path, material, and output options. Use ReflEpcFieldOptionsAD with AD inputs.
TrueLane mask.
Raises RuntimeError when a position source is given without expected_prim_ids of width n_rays * max_bounces.
ReflEpcFieldOptions#
All ReflEpcOptions fields, plus:
| Field | Default | Meaning |
|---|---|---|
slot_plane_point, slot_plane_normal | zeros | reflecting plane per slot; set the normal, a zero normal gives invalid paths |
slot_eta_r | 1 | relative permittivity per slot |
slot_mu_r | 1 | relative permeability per slot |
slot_sigma | 0 | conductivity per slot |
slot_gain | 1 | extra gain per slot |
tx_polarization | (1, 0, 0) | transmitter polarization |
omega | 2 * pi * 299792458 | angular frequency in rad/s |
wavelength | 1 | wavelength in scene units |
return_geom | False | master switch for the per-slot geometry outputs |
return_endpoints | False | emit tx_pos, first_hit, last_hit |
return_hit_points, return_normals, return_resolved_prim_ids, return_surface_group_ids | True | per-slot outputs, when return_geom is set |
ReflEpcField#
Per ray: valid, bounce_count, path_length, and the field components field_x_re, field_x_im, field_y_re, field_y_im, field_z_re, field_z_im. Optional: tx_pos, first_hit, last_hit, and per-slot hit_points, normals, resolved_prim_ids, surface_group_ids. Also ray_count, max_bounces.
Scene.accumulate_reflections#
accumulate_reflections(
ray, tx_position, grid: AccumGrid, material, max_bounces: int,
options: AccumOptions = AccumOptions(), active=True,
tx_polarization=(1.0, 0.0, 0.0),
) -> AccumResult | AccumResultADLaunches ray from the transmitter, follows reflections, and sums field and power into the cells of grid.
Launch rays. Each ray represents options.solid_angle_per_ray steradians.
Transmitter position.
Receiver grid.
Material per scene-global primitive.
Maximum reflections per ray.
AccumOptions()Wave and sampling parameters.
TrueLane mask.
(1.0, 0.0, 0.0)Transmitter polarization.
AccumGrid#
An axis-aligned plane of resolution0 * resolution1 cells.
| Field | Default | Meaning |
|---|---|---|
axis | 2 | plane normal axis (0 = x, 1 = y, 2 = z) |
position | 0 | plane offset along axis |
coord0_min, coord0_max | 0 | extent along the first in-plane axis |
coord1_min, coord1_max | 0 | extent along the second in-plane axis |
resolution0, resolution1 | 0 | cell counts |
AccumOptions#
| Field | Default | Meaning |
|---|---|---|
wavelength | 1 | wavelength in scene units |
k | 0 | wavenumber, 2 * pi / wavelength (set it yourself) |
solid_angle_per_ray | 1 | solid angle each ray represents |
cell_area | 1 | area of one cell |
seed | 0 | random seed |
rr_depth | 0 | bounce depth where Russian roulette starts |
rr_prob | 1 | survival probability per roulette test |
stop_threshold | 0 | stop a path when its contribution falls below this |
collect_wedges | False | record diffraction-wedge events |
collect_wedge_prefixes | False | also record the reflection prefix of each wedge event |
wedge_capacity | 0 | maximum stored wedge events |
wedge_sample_stride | 1 | prefix wedge event sampling stride |
Material, MaterialAD#
Per-primitive electromagnetic parameters, each an array with one entry per scene-global primitive.
| Field | Default | Meaning |
|---|---|---|
eta_r | 1 | relative permittivity |
sigma | 0 | conductivity |
mu_r | 1 | relative permeability |
gain | 1 | extra gain factor |
valid | False | the entry holds a real material |
AccumResult#
| Field | Meaning |
|---|---|
ray_count, max_bounces, grid_cell_count | sizes |
reflection_power | accumulated power per cell |
reflection_field_x, _y, _z | accumulated complex field per cell |
reflection_count | total contributions accumulated |
wedge_events | WedgeEvents, when collect_wedges is set |
WedgeEvents#
capacity, count, and per event: ray_index, hit_points (wedge location), normals, prim_id, directions (incident direction), source_points (virtual source before the event), src_power, initial_directions (primary ray direction), bounce_depth.