htrdr

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

commit 847f47e029726facc6e9df77e2c06094f011dd5a
parent 182060d6dd367fa225f0a987e07ef2165bef3bfa
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sat, 21 Nov 2020 19:12:14 +0100

Fix a self-intersection issue in htrdr_compute_radiance_sw

The previous hit was not set correctly when the hit surface do not look
toward the sun regarding its normal.

Diffstat:
Msrc/htrdr_compute_radiance_sw.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/htrdr_compute_radiance_sw.c b/src/htrdr_compute_radiance_sw.c @@ -308,9 +308,9 @@ htrdr_compute_radiance_sw d3_set(pos, pos_in); d3_set(dir, dir_in); - if((cpnt_mask & HTRDR_RADIANCE_DIRECT) /* Handle direct contribuation */ + if((cpnt_mask & HTRDR_RADIANCE_DIRECT) /* Handle direct contribation */ && htrdr_sun_is_dir_in_solar_cone(htrdr->sun, dir)) { - /* Check that the ray is not occlude along the submitted range */ + /* Check that the ray is not occluded along the submitted range */ d2(range, 0, FLT_MAX); HTRDR(ground_trace_ray(htrdr->ground, pos, dir, range, NULL, &s3d_hit_tmp)); if(!S3D_HIT_NONE(&s3d_hit_tmp)) { @@ -366,11 +366,17 @@ htrdr_compute_radiance_sw /* Negate the incoming dir to match the convention of the SSF library */ d3_minus(wo, dir); + /* Define if the scattering occurs at a surface */ + surface_scattering = SVX_HIT_NONE(&svx_hit); + /* Compute the new position */ pos_next[0] = pos[0] + dir[0]*scattering_ctx.traversal_dst; pos_next[1] = pos[1] + dir[1]*scattering_ctx.traversal_dst; pos_next[2] = pos[2] + dir[2]*scattering_ctx.traversal_dst; + /* Define the previous hit surface used to avoid self hit */ + s3d_hit_prev = surface_scattering ? s3d_hit : S3D_HIT_NULL; + /* Define the absorption transmissivity from the current position to the * next position */ d2(range, 0, scattering_ctx.traversal_dst); @@ -378,8 +384,6 @@ htrdr_compute_radiance_sw (htrdr, rng, HTSKY_Ka, iband, iquad, pos, dir, range); if(Tr_abs <= 0) break; - surface_scattering = SVX_HIT_NONE(&svx_hit); - /* Sample the scattering direction */ if(surface_scattering) { /* Scattering at a surface */ struct htrdr_interface interf = HTRDR_INTERFACE_NULL; @@ -453,7 +457,6 @@ htrdr_compute_radiance_sw } else { /* Check that the sun is visible from the new position */ d2(range, 0, FLT_MAX); - s3d_hit_prev = SVX_HIT_NONE(&svx_hit) ? s3d_hit : S3D_HIT_NULL; HTRDR(ground_trace_ray (htrdr->ground, pos_next, sun_dir, range, &s3d_hit_prev, &s3d_hit_tmp));