mitsuba2
mitsuba2 copied to clipboard
[🐛 bug report] warp::square_to_von_mises_fisher([0.5, 0.5], ...) returns nan.
Summary
warp::square_to_von_mises_fisher
returns nan, when the sample is exactly [0.5, 0.5].
System configuration
- Platform: openSUSE Tumbleweed (same issue on Ubuntu 20.04)
- Compiler: GCC 10.2.1
- Python version: 3.8.5
- Mitsuba 2 version: 2.2.1 (
b87c11ace78e110b094b23b83ac5902a4773202d
) - Compiled variants:
-
scalar_rgb
-
spectral_rgb
-
Description
For the sample [0.5, 0.5], p
will be exactly at the origin.
Therefore, r2
will be 0 and dividing 0/0 produces nan in p *= safe_sqrt((1.f - sqr(cos_theta)) / r2);
.
Instead, masked(p, r2 > 0.0f) *= safe_sqrt((1.f - sqr(cos_theta)) / r2);
works fine, but there may be more elegant alternatives.
Neat trick though to use the concentric disc sampling for vMFs :+1: .
Steps to reproduce
import mitsuba
mitsuba.set_variant('scalar_rgb')
mitsuba.core.warp.square_to_von_mises_fisher([0.5, 0.5], 1.0)
returns [-nan, -nan, 1]
for any kappa != 0.0
.