@@ -264,7 +264,8 @@ inline __host__ __device__ Ray pixel_to_ray(
264264 const ECameraMode camera_mode = ECameraMode::Perspective,
265265 const CameraDistortion& camera_distortion = {},
266266 const float * __restrict__ distortion_data = nullptr ,
267- const Eigen::Vector2i distortion_resolution = Eigen::Vector2i::Zero()
267+ const Eigen::Vector2i distortion_resolution = Eigen::Vector2i::Zero(),
268+ const float dataset_scale = 1.f
268269) {
269270 Eigen::Vector2f offset = ld_random_pixel_offset (snap_to_pixel_centers ? 0 : spp);
270271 Eigen::Vector2f uv = (pixel.cast <float >() + offset).cwiseQuotient (resolution.cast <float >());
@@ -273,12 +274,16 @@ inline __host__ __device__ Ray pixel_to_ray(
273274 Eigen::Vector3f dir;
274275 Eigen::Vector3f head_pos;
275276 if (camera_mode == ECameraMode::Orthographic){
277+ // 'dataset_scale' argument is only required by the orthographic camera.
278+ // The focal length of Environment and Perspective cameras isn't affected by the change of dataset_scale,
279+ // because all rays originate from the same point
276280 dir = {0 .f , 0 .f , 1 .f }; // Camera forward
277281 head_pos = {
278282 (uv.x () - screen_center.x ()) * (float )resolution.x () / focal_length.x (),
279283 (uv.y () - screen_center.y ()) * (float )resolution.y () / focal_length.y (),
280284 0 .0f
281285 };
286+ head_pos *= dataset_scale;
282287 head_pos += shift;
283288 dir -= shift / parallax_shift.z (); // we could use focus_z here in the denominator. for now, we pack m_scale in here.
284289 }
@@ -342,7 +347,8 @@ inline __host__ __device__ Eigen::Vector2f pos_to_pixel(
342347 const Eigen::Vector2f& screen_center,
343348 const Eigen::Vector3f& parallax_shift,
344349 const ECameraMode camera_mode,
345- const CameraDistortion& camera_distortion = {}
350+ const CameraDistortion& camera_distortion = {},
351+ const float dataset_scale = 1 .f
346352) {
347353 // We get 'pos' as an input. We have pos = origin + alpha*dir, with unknown alpha
348354 // tmp_dir = R^-1*(pos-t)
@@ -356,7 +362,8 @@ inline __host__ __device__ Eigen::Vector2f pos_to_pixel(
356362 // origin = R*(head_pos+shift) + t
357363 tmp_dir -= shift;
358364 const Eigen::Vector3f head_dir_minus_shift = Eigen::Vector3f (0 .f , 0 .f , 1 .f ) - shift/parallax_shift.z ();
359- const Eigen::Vector3f head_pos = tmp_dir - tmp_dir.z () * head_dir_minus_shift; // Gives head_pos.z=0 since head_dir_minus_shift.z=1
365+ Eigen::Vector3f head_pos = tmp_dir - tmp_dir.z () * head_dir_minus_shift; // Gives head_pos.z=0 since head_dir_minus_shift.z=1
366+ head_pos /= dataset_scale;
360367 return {
361368 head_pos.x () * focal_length.x () + screen_center.x () * resolution.x (),
362369 head_pos.y () * focal_length.y () + screen_center.y () * resolution.y (),
@@ -412,7 +419,8 @@ inline __host__ __device__ Eigen::Vector2f motion_vector_3d(
412419 const bool snap_to_pixel_centers,
413420 const float depth,
414421 const ECameraMode camera_mode,
415- const CameraDistortion& camera_distortion = {}
422+ const CameraDistortion& camera_distortion = {},
423+ const float dataset_scale = 1 .f
416424) {
417425 Ray ray = pixel_to_ray (
418426 sample_index,
@@ -428,7 +436,8 @@ inline __host__ __device__ Eigen::Vector2f motion_vector_3d(
428436 camera_mode,
429437 camera_distortion,
430438 nullptr ,
431- Eigen::Vector2i::Zero ()
439+ Eigen::Vector2i::Zero (),
440+ dataset_scale
432441 );
433442
434443 Eigen::Vector2f prev_pixel = pos_to_pixel (
@@ -439,7 +448,8 @@ inline __host__ __device__ Eigen::Vector2f motion_vector_3d(
439448 screen_center,
440449 parallax_shift,
441450 camera_mode,
442- camera_distortion
451+ camera_distortion,
452+ dataset_scale
443453 );
444454
445455 return prev_pixel - (pixel.cast <float >() + ld_random_pixel_offset (sample_index));
0 commit comments