Skip to content

Commit

Permalink
Fix NAN bug when MLT propose a path with 0 radiance
Browse files Browse the repository at this point in the history
  • Loading branch information
w3ntao committed Jan 9, 2025
1 parent 88645ff commit 6595221
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/pbrt/cpu/integrators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,12 +2679,33 @@ void MLTIntegrator::Render() {
// Compute acceptance probability for proposed sample
Float cProposed = c(LProposed, lambdaProposed);
Float cCurrent = c(LCurrent, lambdaCurrent);
Float accept = std::min<Float>(1, cProposed / cCurrent);

// Splat both current and proposed samples to _film_
if (accept > 0)
film.AddSplat(pProposed, LProposed * accept / cProposed, lambdaProposed);
film.AddSplat(pCurrent, LCurrent * (1 - accept) / cCurrent, lambdaCurrent);
Float accept = NAN;
if (cProposed == 0 && cCurrent == 0) {
// neither current path or the proposed found a light source
accept = 0.5;

} else if (cProposed == 0) {
// current path found a light source but the proposed didn't
accept = 0;
film.AddSplat(pCurrent, LCurrent / cCurrent, lambdaCurrent);

} else if (cCurrent == 0) {
// current path didn't find a light source but the proposed did
accept = 1;
film.AddSplat(pProposed, LProposed / cProposed, lambdaProposed);

} else {
// both paths found a light source
accept = std::min<Float>(1, cProposed / cCurrent);
// Splat both current and proposed samples to _film_
if (accept > 0) {
film.AddSplat(pProposed, LProposed * accept / cProposed, lambdaProposed);
}
if (accept < 1) {
film.AddSplat(pCurrent, LCurrent * (1 - accept) / cCurrent, lambdaCurrent);
}
}

// Accept or reject the proposal
if (rng.Uniform<Float>() < accept) {
Expand Down

0 comments on commit 6595221

Please sign in to comment.