htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

commit 6c6617d3a78ab6c7e2ed05ef50267db790377434
parent 6a423707c21a860af0cce9ab1e2edeaaa5dc7c35
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  7 Mar 2019 15:22:59 +0100

Fix the russian roulette at surface scattering

Diffstat:
Msrc/htrdr_compute_radiance_sw.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/htrdr_compute_radiance_sw.c b/src/htrdr_compute_radiance_sw.c @@ -325,6 +325,7 @@ htrdr_compute_radiance_sw /* Radiative random walk */ for(;;) { struct scattering_context scattering_ctx = SCATTERING_CONTEXT_NULL; + double bounce_reflectivity = 0; /* Find the first intersection with a surface */ d2(range, 0, DBL_MAX); @@ -388,16 +389,14 @@ htrdr_compute_radiance_sw /* Scattering at a surface */ if(SVX_HIT_NONE(&svx_hit)) { - double reflectivity; double N[3]; int type; d3_normalize(N, d3_set_f3(N, s3d_hit.normal)); if(d3_dot(N, wo) < 0) d3_minus(N, N); - reflectivity = ssf_bsdf_sample - (bsdf, rng, wo, N, dir_next, &type, &pdf); - if(ssp_rng_canonical(rng) > reflectivity) break; /* Russian roulette */ + bounce_reflectivity = ssf_bsdf_sample + (bsdf, rng, wo, N, dir_next, &type, &pdf); if(d3_dot(N, sun_dir) < 0) { /* Below the ground */ R = 0; } else { @@ -432,6 +431,9 @@ htrdr_compute_radiance_sw ksi *= Tr_abs; w += ksi * L_sun * sun_solid_angle * Tr * R; + /* Russian roulette */ + if(ssp_rng_canonical(rng) >= bounce_reflectivity) break; + /* Setup the next random walk state */ d3_set(pos, pos_next); d3_set(dir, dir_next);