@@ -100,6 +100,9 @@ struct Interaction {
100100 // / Position of the interaction in world coordinates
101101 Point3f p;
102102
103+ // / (Optional) offset to be used to spawn rays from this interaction
104+ Vector3f ray_offset;
105+
103106 // / Geometric normal (only valid for \c SurfaceInteraction)
104107 Normal3f n;
105108
@@ -113,7 +116,7 @@ struct Interaction {
113116 // / Constructor
114117 Interaction (Float t, Float time, const Wavelength &wavelengths,
115118 const Point3f &p, const Normal3f &n = 0 .f )
116- : t (t), time (time), wavelengths (wavelengths), p (p), n (n) { }
119+ : t (t), time (time), wavelengths (wavelengths), p (p), ray_offset ( 0 . f ), n (n) { }
117120
118121 // / Virtual destructor
119122 virtual ~Interaction () = default ;
@@ -124,11 +127,12 @@ struct Interaction {
124127 * field should be set to an infinite value to mark invalid intersection records.
125128 */
126129 virtual void zero_ (size_t size = 1 ) {
127- t = dr::full<Float>(dr::Infinity<Float>, size);
128- time = dr::zeros<Float>(size);
129- wavelengths = dr::zeros<Wavelength>(size);
130- p = dr::zeros<Point3f>(size);
131- n = dr::zeros<Normal3f>(size);
130+ t = dr::full<Float>(dr::Infinity<Float>, size);
131+ time = dr::zeros<Float>(size);
132+ wavelengths = dr::zeros<Wavelength>(size);
133+ p = dr::zeros<Point3f>(size);
134+ ray_offset = dr::zeros<Vector3f>(size);
135+ n = dr::zeros<Normal3f>(size);
132136 }
133137
134138 // / Is the current interaction valid?
@@ -154,7 +158,7 @@ struct Interaction {
154158 // ! @}
155159 // =============================================================
156160
157- DRJIT_STRUCT (Interaction, t, time, wavelengths, p, n);
161+ DRJIT_STRUCT (Interaction, t, time, wavelengths, p, ray_offset, n);
158162
159163private:
160164 /* *
@@ -165,7 +169,7 @@ struct Interaction {
165169 Point3f offset_p (const Vector3f &d) const {
166170 Float mag = (1 .f + dr::max (dr::abs (p))) * math::RayEpsilon<Float>;
167171 mag = dr::detach (dr::mulsign (mag, dr::dot (n, d)));
168- return dr::fmadd (mag, dr::detach (n), p);
172+ return dr::fmadd (mag, dr::detach (n), p + dr::detach (ray_offset) );
169173 }
170174};
171175
@@ -186,7 +190,7 @@ struct SurfaceInteraction : Interaction<Float_, Spectrum_> {
186190 using Spectrum = Spectrum_;
187191
188192 // Make parent fields/functions visible
189- MI_IMPORT_BASE (Interaction, t, time, wavelengths, p, n, is_valid)
193+ MI_IMPORT_BASE (Interaction, t, time, wavelengths, p, ray_offset, n, is_valid)
190194
191195 MI_IMPORT_RENDER_BASIC_TYPES ()
192196 MI_IMPORT_OBJECT_TYPES ()
@@ -524,8 +528,8 @@ struct SurfaceInteraction : Interaction<Float_, Spectrum_> {
524528 // ! @}
525529 // =============================================================
526530
527- DRJIT_STRUCT (SurfaceInteraction, t, time, wavelengths, p, n, shape, uv ,
528- sh_frame, dp_du, dp_dv, dn_du, dn_dv, duv_dx,
531+ DRJIT_STRUCT (SurfaceInteraction, t, time, wavelengths, p, ray_offset, n ,
532+ shape, uv, sh_frame, dp_du, dp_dv, dn_du, dn_dv, duv_dx,
529533 duv_dy, wi, prim_index, instance)
530534};
531535
@@ -545,7 +549,7 @@ struct MediumInteraction : Interaction<Float_, Spectrum_> {
545549 using Index = typename CoreAliases::UInt32;
546550
547551 // Make parent fields/functions visible
548- MI_IMPORT_BASE (Interaction, t, time, wavelengths, p, n, is_valid)
552+ MI_IMPORT_BASE (Interaction, t, time, wavelengths, p, ray_offset, n, is_valid)
549553 // ! @}
550554 // =============================================================
551555
@@ -609,7 +613,7 @@ struct MediumInteraction : Interaction<Float_, Spectrum_> {
609613 // ! @}
610614 // =============================================================
611615
612- DRJIT_STRUCT (MediumInteraction, t, time, wavelengths, p, n, medium,
616+ DRJIT_STRUCT (MediumInteraction, t, time, wavelengths, p, ray_offset, n, medium,
613617 sh_frame, wi, sigma_s, sigma_n, sigma_t ,
614618 combined_extinction, mint)
615619};
@@ -755,7 +759,9 @@ std::ostream &operator<<(std::ostream &os, const Interaction<Float, Spectrum> &i
755759 << " t = " << it.t << " ," << std::endl
756760 << " time = " << it.time << " ," << std::endl
757761 << " wavelengths = " << it.wavelengths << " ," << std::endl
758- << " p = " << string::indent (it.p , 6 ) << std::endl
762+ << " p = " << string::indent (it.p , 6 ) << " ," << std::endl
763+ << " ray_offset = " << string::indent (it.ray_offset , 15 ) << " ," << std::endl
764+ << " n = " << string::indent (it.n , 6 ) << std::endl
759765 << " ]" ;
760766 }
761767 return os;
0 commit comments