htrdr

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

commit aad22b4ed34c01c7ef751c8446cc1a33773a513b
parent 3b41b51414d6c35391566df8b2473fbd83b7bd25
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 14 Oct 2020 13:26:55 +0200

Small upd of the reject sampling on the rectangle sensor

Diffstat:
Msrc/htrdr_sensor.c | 39+++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/htrdr_sensor.c b/src/htrdr_sensor.c @@ -62,7 +62,6 @@ sample_rectangle_ray { struct s3d_hit hit = S3D_HIT_NULL; double pix_samp[2]; - double up_dir[3] = {0, 0, 1}; const double range[2] = {0, INF}; double normal[3]; ASSERT(rect && ground && ipix && pix_sz && rng && ray_org && ray_dir); @@ -74,33 +73,37 @@ sample_rectangle_ray /* Retrieve the world space position of pix_samp */ htrdr_rectangle_sample_pos(rect, pix_samp, ray_org); - /* Check that `ray_org' is not included into a geometry. Right now, use a - * naïve "up" intersection. */ - HTRDR(ground_trace_ray(ground, ray_org, up_dir, range, NULL, &hit)); + /* Sample a ray direction */ + htrdr_rectangle_get_normal(rect, normal); + ssp_ran_hemisphere_cos(rng, normal, ray_dir, NULL); - /* Up direction is occluded, check if the sample must be recjected */ + /* Check that `ray_org' is not included into a geometry */ + HTRDR(ground_trace_ray(ground, ray_org, ray_dir, range, NULL, &hit)); + + /* Up direction is occluded. Check if the sample must be rejected, i.e. does it + * lies inside a geometry? */ if(!S3D_HIT_NONE(&hit)) { struct htrdr_interface interf = HTRDR_INTERFACE_NULL; const struct mrumtl* mat = NULL; + float N[3]; /* Normalized normal of the hit */ float wi[3]; - float N[3]; - - /* Fetch the interface of the hit */ - htrdr_ground_get_interface(ground, &hit, &interf); + float cos_wi_N; - /* Retrieve the material on the side of the incident direction */ - f3_set_d3(wi, up_dir); + /* Compute the cosine between the incident ray direction and the hit normal */ + f3_set_d3(wi, ray_dir); f3_normalize(N, hit.normal); - mat = f3_dot(wi, N) < 0 ? interf.mtl_front : interf.mtl_back; + cos_wi_N = f3_dot(wi, N); - /* Mat is NULL only for the external air. Reject the sample if the material - * is not null, i.e. the incident direction travels into the geometry */ + /* Fetch the hit interface and retrieve the material into which the ray was + * traced */ + htrdr_ground_get_interface(ground, &hit, &interf); + mat = cos_wi_N ? interf.mtl_front : interf.mtl_back; + + /* Reject the sample if the material is not null, i.e. the incident + * direction do not travel into the external air and thus the challenged + * position is not outside */ if(mat != NULL) return RES_BAD_OP; } - - /* Sample a ray direction */ - htrdr_rectangle_get_normal(rect, normal); - ssp_ran_hemisphere_cos(rng, normal, ray_dir, NULL); return RES_OK; }