-
Dear Mitsuba Community, I am looking for a solution for several weeks now, but cannot find the source of my problem. I implemented a new light, which basically captures the radiant intensity distribution in form of a set of points which define the falloff curve, obtained by linear interpolation between them. It can be found here. Float falloff_curve(const Vector3f &d, Mask /*active*/) const {
using Index = dr::uint32_array_t<Float>;
Vector3f local_dir = dr::normalize(d);
Float theta = dr::acos(local_dir.z());
/*
// find interval in ordered set
UInt32 i = math::find_interval<UInt32>(
(uint32_t) m_tab_angles.size(),
[&](UInt32 idx) DRJIT_INLINE_LAMBDA {
return dr::gather<Float>(m_tab_angles, idx) <= theta;
});
*/
Index i = math::find_interval<Index>(
(uint32_t) m_tab_angles.size(),
[&](Index idx) DRJIT_INLINE_LAMBDA {
return dr::gather<Float>(m_tab_angles, idx) <= theta;
});
// linerarly interpolate RID
Float weight = (theta - dr::gather<Float>(m_tab_angles, i)) / (dr::gather<Float>(m_tab_angles, i+1) - dr::gather<Float>(m_tab_angles, i));
Float falloff = dr::lerp(dr::gather<Float>(m_tab_values, i), dr::gather<Float>(m_tab_values, i+1), weight);
//std::cout << "min falloff " << dr::min(falloff) << " ++ max falloff " << dr::max(falloff) << std::endl;
return dr::select(theta <= m_cutoff_angle, falloff, 0.f);
} In addition, I would like to optimize the pose of the light in an SO3XR3 optimization scheme. To this end, I do a latent optimization of the translation and the x,y-components of the log-rotation. I only optimize two components as the z-component is meaningless wrt an isotropic light. After the update by Adam, I use a SO3XR3 exponential map to write the 4X4 Transform4f back into the to_world parameters of the light. If I do this with a spotlight, everything works fine. However, if I combine the pose optimization with the tablight, I can only use 1 spp. If I use a higher SPP, the gradients of the latent pose parameters become NAN eventually. Unfortunately, I cannot find the reason for that. Anybody has an idea? E.g., is the vectorization in find_interval problematic? Please find code, which reproduces the problem in a minimum working example here. To make the MWE work, the whole repository has to be cloned and Mitsuba has to be recompiled, as the tablight is written in c++. Thank you very much for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @dnakath Just to confirm, without doing the SO3XR3 scheme on your tablight, do you get NaNs too ? Right before getting the NaNs in your foward rendering, I imagine that the gradient value of your latent variables are NaNs too, right? You can check this by printing If your gradients on the latent variables are NaNs, the next step would be to call |
Beta Was this translation helpful? Give feedback.
One faster thing you could try first is to walk through the implementation of your new plugin and check for any potentially "unsafe" math, e.g.:
sqrt(-1)
,acos(1.01)
,exp(very_large)
, etc.By replacing each of those calls with a safe version (e.g. clamping the argument to a safe range), you might already find the source of your NaN gradients.