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.

rayRay | RayADrequired

Rays to trace. A RayAD returns AD records.

max_bouncesintrequired

Maximum reflections per ray.

optionsReflectionTraceOptions

Deduplication and export settings. Alternatively pass deduplicate, canonical_prim_table, and image_source_tolerance as keywords.

activeBooldefault True

Lane mask.

symbolicbooldefault True

Selects 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#

FieldDefaultMeaning
deduplicateFalsemerge rays that share the same reflector sequence
canonical_prim_table[]map from global primitive id to a canonical id used for deduplication
image_source_tolerance1e-5distance under which two image sources are treated as equal
export_modeREFLECTION_EXPORT_FULLresult payload: full, minimal, or counts only
return_trailingTruetrace and export the segment after the last reflection

ReflectionTrace#

FieldMeaning
ray_count, max_bouncesinput size and slot capacity
bounce_countvalid reflections per ray
discovery_countnumber of rays merged into each path by deduplication
representative_ray_indexray chosen to represent a merged group
dedup_keep_maskrays that survived deduplication
deduplicate_requested, deduplicate_appliedwhether deduplication was asked for and ran
bounceslist 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) -> ReflEpc

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

rayRayrequired

Source rays. The origin is the transmitter.

receiverArray3frequired

Receiver position per ray.

max_bouncesintrequired

Slots per ray.

optionsReflEpcOptions | Nonedefault None

Expected reflectors and surface-group tables.

activeBooldefault True

Lane mask.

ReflEpcOptions#

FieldDefaultMeaning
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_size0width of the member table
visibility_ignore_mode"primitive"ignore the reflector itself ("primitive") or its whole group ("surface_group") in visibility checks
plane_tolerance1e-5relative 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 | ReflEpcFieldAD

Solves the EPC path and evaluates the complex electric field at the receiver.

sourceRay | RayAD | Array3frequired

A ray (its first hit selects the reflector) or a transmitter position per lane (then options.expected_prim_ids is required).

receiverArray3frequired

Receiver position per lane.

max_bouncesintrequired

Slots per lane.

optionsReflEpcFieldOptionsrequired

Path, material, and output options. Use ReflEpcFieldOptionsAD with AD inputs.

activeBooldefault True

Lane mask.

Raises RuntimeError when a position source is given without expected_prim_ids of width n_rays * max_bounces.

ReflEpcFieldOptions#

All ReflEpcOptions fields, plus:

FieldDefaultMeaning
slot_plane_point, slot_plane_normalzerosreflecting plane per slot; set the normal, a zero normal gives invalid paths
slot_eta_r1relative permittivity per slot
slot_mu_r1relative permeability per slot
slot_sigma0conductivity per slot
slot_gain1extra gain per slot
tx_polarization(1, 0, 0)transmitter polarization
omega2 * pi * 299792458angular frequency in rad/s
wavelength1wavelength in scene units
return_geomFalsemaster switch for the per-slot geometry outputs
return_endpointsFalseemit tx_pos, first_hit, last_hit
return_hit_points, return_normals, return_resolved_prim_ids, return_surface_group_idsTrueper-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 | AccumResultAD

Launches ray from the transmitter, follows reflections, and sums field and power into the cells of grid.

rayRay | RayADrequired

Launch rays. Each ray represents options.solid_angle_per_ray steradians.

tx_positionArray3frequired

Transmitter position.

gridAccumGridrequired

Receiver grid.

materialMaterial | MaterialADrequired

Material per scene-global primitive.

max_bouncesintrequired

Maximum reflections per ray.

optionsAccumOptionsdefault AccumOptions()

Wave and sampling parameters.

activeBooldefault True

Lane mask.

tx_polarizationArray3f | tupledefault (1.0, 0.0, 0.0)

Transmitter polarization.

AccumGrid#

An axis-aligned plane of resolution0 * resolution1 cells.

FieldDefaultMeaning
axis2plane normal axis (0 = x, 1 = y, 2 = z)
position0plane offset along axis
coord0_min, coord0_max0extent along the first in-plane axis
coord1_min, coord1_max0extent along the second in-plane axis
resolution0, resolution10cell counts

AccumOptions#

FieldDefaultMeaning
wavelength1wavelength in scene units
k0wavenumber, 2 * pi / wavelength (set it yourself)
solid_angle_per_ray1solid angle each ray represents
cell_area1area of one cell
seed0random seed
rr_depth0bounce depth where Russian roulette starts
rr_prob1survival probability per roulette test
stop_threshold0stop a path when its contribution falls below this
collect_wedgesFalserecord diffraction-wedge events
collect_wedge_prefixesFalsealso record the reflection prefix of each wedge event
wedge_capacity0maximum stored wedge events
wedge_sample_stride1prefix wedge event sampling stride

Material, MaterialAD#

Per-primitive electromagnetic parameters, each an array with one entry per scene-global primitive.

FieldDefaultMeaning
eta_r1relative permittivity
sigma0conductivity
mu_r1relative permeability
gain1extra gain factor
validFalsethe entry holds a real material

AccumResult#

FieldMeaning
ray_count, max_bounces, grid_cell_countsizes
reflection_poweraccumulated power per cell
reflection_field_x, _y, _zaccumulated complex field per cell
reflection_counttotal contributions accumulated
wedge_eventsWedgeEvents, 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.