Skip to content

Commit

Permalink
make scaled_principal_point_offset an opaque instance variable to pre…
Browse files Browse the repository at this point in the history
…vent new drjit kernel from being generated on every iteration when film parameters are changed; fix mitsuba-renderer#908
  • Loading branch information
KoykL committed Sep 19, 2023
1 parent 5016304 commit 8da2a0a
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/sensors/perspective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
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<Ray3f, Spectrum> sample_ray(Float time, Float wavelength_sample,
Expand All @@ -209,13 +209,10 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
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.
Expand Down Expand Up @@ -246,13 +243,10 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
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.
Expand Down Expand Up @@ -290,12 +284,9 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
if (dr::none_or<false>(active))
return { ds, dr::zeros<Spectrum>() };

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<false>(active))
Expand Down Expand Up @@ -409,6 +400,7 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
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)
Expand Down

0 comments on commit 8da2a0a

Please sign in to comment.