From 8da2a0aee512a41cf78618be71172991a3850477 Mon Sep 17 00:00:00 2001 From: KoykL Date: Mon, 18 Sep 2023 22:04:24 -0400 Subject: [PATCH] make scaled_principal_point_offset an opaque instance variable to prevent new drjit kernel from being generated on every iteration when film parameters are changed; fix #908 --- src/sensors/perspective.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/sensors/perspective.cpp b/src/sensors/perspective.cpp index 641bd0af7..dd4f46b74 100644 --- a/src/sensors/perspective.cpp +++ b/src/sensors/perspective.cpp @@ -190,9 +190,9 @@ class PerspectiveCamera final : public ProjectiveCamera { m_image_rect.expand(Point2f(pmax.x(), pmax.y()) / pmax.z()); m_normalization = 1.f / m_image_rect.volume(); m_needs_sample_3 = false; - + m_scaled_principal_point_offset = m_film->size() * m_principal_point_offset / m_film->crop_size(); dr::make_opaque(m_camera_to_sample, m_sample_to_camera, m_dx, m_dy, m_x_fov, - m_image_rect, m_normalization, m_principal_point_offset); + m_image_rect, m_normalization, m_principal_point_offset, m_scaled_principal_point_offset); } std::pair sample_ray(Float time, Float wavelength_sample, @@ -209,13 +209,10 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + scaled_principal_point_offset.x(), - position_sample.y() + scaled_principal_point_offset.y(), + Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), + position_sample.y() + m_scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -246,13 +243,10 @@ class PerspectiveCamera final : public ProjectiveCamera { ray.time = time; ray.wavelengths = wavelengths; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - // Compute the sample position on the near plane (local camera space). Point3f near_p = m_sample_to_camera * - Point3f(position_sample.x() + scaled_principal_point_offset.x(), - position_sample.y() + scaled_principal_point_offset.y(), + Point3f(position_sample.x() + m_scaled_principal_point_offset.x(), + position_sample.y() + m_scaled_principal_point_offset.y(), 0.f); // Convert into a normalized ray direction; adjust the ray interval accordingly. @@ -290,12 +284,9 @@ class PerspectiveCamera final : public ProjectiveCamera { if (dr::none_or(active)) return { ds, dr::zeros() }; - Vector2f scaled_principal_point_offset = - m_film->size() * m_principal_point_offset / m_film->crop_size(); - Point3f screen_sample = m_camera_to_sample * ref_p; - ds.uv = Point2f(screen_sample.x() - scaled_principal_point_offset.x(), - screen_sample.y() - scaled_principal_point_offset.y()); + ds.uv = Point2f(screen_sample.x() - m_scaled_principal_point_offset.x(), + screen_sample.y() - m_scaled_principal_point_offset.y()); active &= (ds.uv.x() >= 0) && (ds.uv.x() <= 1) && (ds.uv.y() >= 0) && (ds.uv.y() <= 1); if (dr::none_or(active)) @@ -409,6 +400,7 @@ class PerspectiveCamera final : public ProjectiveCamera { Float m_x_fov; Vector3f m_dx, m_dy; Vector2f m_principal_point_offset; + Vector2f m_scaled_principal_point_offset; }; MI_IMPLEMENT_CLASS_VARIANT(PerspectiveCamera, ProjectiveCamera)