Skip to content

Commit 1369044

Browse files
committed
Fix issue with non-finite values in volpathmis.
1 parent e193855 commit 1369044

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/integrators/volpathmis.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ class VolpathMisIntegratorImpl final : public MonteCarloIntegrator<Float, Spectr
637637
UnpolarizedSpectrum ratio = p / f.entry(i);
638638
ratio = dr::select(dr::isfinite(ratio), ratio, 0.f);
639639
ratio *= p_over_f[i];
640-
dr::masked(p_over_f[i], active) = dr::select(dr::isnan(ratio), 0.f, ratio);
640+
dr::masked(p_over_f[i], active) = dr::select(dr::isfinite(ratio), ratio, 0.f);
641641
}
642642
} else {
643643
// If we don't do spectral MIS: We need to use a specific channel of the spectrum "p" as the PDF
@@ -653,12 +653,14 @@ class VolpathMisIntegratorImpl final : public MonteCarloIntegrator<Float, Spectr
653653
UnpolarizedSpectrum weight(0.0f);
654654
for (size_t i = 0; i < n; ++i) {
655655
Float sum = dr::sum(p_over_f[i]);
656-
weight[i] = dr::select(sum == 0.f, 0.0f, n / sum);
656+
auto inv_sum = dr::rcp(sum);
657+
weight[i] = dr::select(dr::isfinite(inv_sum), n * inv_sum, 0.0f);
657658
}
658659
return weight;
659660
} else {
660-
Mask invalid = (min(dr::abs(p_over_f)) == 0.f);
661-
return dr::select(invalid, 0.f, 1.f / p_over_f);
661+
auto inv_p_over_f = dr::rcp(p_over_f);
662+
Mask valid = dr::all(dr::isfinite(inv_p_over_f));
663+
return dr::select(valid, inv_p_over_f, 0.0f);
662664
}
663665
}
664666

@@ -670,11 +672,13 @@ class VolpathMisIntegratorImpl final : public MonteCarloIntegrator<Float, Spectr
670672
auto sum_matrix = p_over_f1 + p_over_f2;
671673
for (size_t i = 0; i < n; ++i) {
672674
Float sum = dr::sum(sum_matrix[i]);
673-
weight[i] = dr::select(sum == 0.f, 0.0f, n / sum);
675+
auto inv_sum = dr::rcp(sum);
676+
weight[i] = dr::select(dr::isfinite(inv_sum), n * inv_sum, 0.0f);
674677
}
675678
} else {
676679
auto sum = p_over_f1 + p_over_f2;
677-
weight = dr::select(min(dr::abs(sum)) == 0.f, 0.0f, 1.f / sum);
680+
auto inv_sum = dr::rcp(sum);
681+
weight = dr::select(dr::all(dr::isfinite(inv_sum)) == 0.f, inv_sum, 0.0f);
678682
}
679683
return weight;
680684
}

0 commit comments

Comments
 (0)