Fix division-by-zero in null-scattering PDF computation for participating media#535
Open
DeepReinforce wants to merge 1 commit intommp:masterfrom
Open
Fix division-by-zero in null-scattering PDF computation for participating media#535DeepReinforce wants to merge 1 commit intommp:masterfrom
DeepReinforce wants to merge 1 commit intommp:masterfrom
Conversation
When the null-scattering PDF evaluates to zero during medium sampling, the original code performs division before (or without) checking for zero, producing NaN/Inf that corrupts path throughput and MIS weights. Move the zero-check before the division in all affected code paths (VolPathIntegrator::Li, RandomWalk, WavefrontPathIntegrator:: SampleMediumInteraction, and TraceTransmittance) and return false early to terminate the path cleanly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix division-by-zero bugs in the null-scattering path of participating media sampling. When the null-scattering PDF (
T_maj[0] * sigma_n[0]orT_maj[0] * sigma_maj[0]) evaluates to zero, the original code performs division before checking the zero condition, producing NaN/Inf values that propagate throughbeta,r_u,r_l, andT_ray, corrupting the entire path contribution and potentially causing rendering artifacts.This PR moves the zero-check before the division and immediately returns
falseto terminate the path, avoiding any undefined arithmetic.Changes
CPU integrators (
src/pbrt/cpu/integrators.cpp)VolPathIntegrator::Li(null-scattering callback): Checkpdf == 0before dividingbeta,r_u,r_lbypdf. Setbetato zero and returnfalseearly.RandomWalk(null-scattering callback): Same fix — checkpdf == 0first, setbetato zero and returnfalseinstead of conditionally skipping only thebetaupdate.Wavefront media sampling (
src/pbrt/wavefront/media.cpp)WavefrontPathIntegrator::SampleMediumInteraction(null-scattering callback): Checkpr == 0before dividingbeta,r_u,r_lbypr. Setbetato zero and returnfalseearly.Wavefront transmittance (
src/pbrt/wavefront/intersect.h)TraceTransmittance(ratio-tracking null-scattering): Addpr == 0guard before dividingT_ray,r_l,r_ubypr. SetT_rayto zero and returnfalseearly.Motivation
In scenes with participating media, it is possible for the null-scattering probability
T_maj * sigma_n(orT_maj * sigma_maj) to evaluate to exactly zero. The original code either:Both cases lead to NaN/Inf propagation, which can cause visible fireflies, black pixels, or assertion failures depending on the scene configuration and medium parameters.