star-phor

Radiative transfer solver for photoreactors.
git clone https://www.edstar.cnrs.fr/git/star-phor.git
Log | Files | Refs | README | LICENSE

commit 59b76e8ff5019cafa97baf2eeb4c65c604cb3712
parent adffac8b7f4ab05a33187a784bb8580e404975c7
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Mon,  8 Sep 2025 10:26:02 +0200

Fix: Sample direction using source primitive

In compute_mvrea, the source direction was being sampled using a
primitive retrieved from the global scene view. This was problematic, as
it bypassed all the geometrical preprocessing applied to the sources
during sampling.

In particular, issues arose whenever a source emitted from its back
side, since the normal was reversed in those cases.

The fix consists of sampling the direction using the primitive from the
source scene view instead, thus benefiting from all the preprocessing
performed on these primitives.

Diffstat:
Msrc/sphor_compute_mvrea.c | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/sphor_compute_mvrea.c b/src/sphor_compute_mvrea.c @@ -67,6 +67,7 @@ compute_MVREA_realization struct s3d_attrib attrib; struct s3d_hit hit = S3D_HIT_NULL; struct s3d_primitive prim = S3D_PRIMITIVE_NULL; + struct s3d_primitive src_prim = S3D_PRIMITIVE_NULL; struct source_view* source_view = NULL; struct sphin_brdf* brdf = NULL; struct sphin_sensor_volume* sensor_volume = NULL; @@ -79,10 +80,10 @@ compute_MVREA_realization ASSERT(NULL != rng); /* Sample a random position from a source in the whole scene */ - res = sample_source_position(sphor, rng, &source_view, &prim, st); + res = sample_source_position(sphor, rng, &source_view, &src_prim, st); if (RES_OK != res){ goto error; } - scn_prim_id = darray_size_t_data_get(&source_view->src2scn)[prim.prim_id]; + scn_prim_id = darray_size_t_data_get(&source_view->src2scn)[src_prim.prim_id]; res = s3d_scene_view_get_primitive (sphor->scene_view, (unsigned)scn_prim_id, &prim); @@ -92,10 +93,6 @@ compute_MVREA_realization if (RES_OK != res){ goto error; } d3_set_f3(pos, attrib.value); - /* Retrieve geometry normal of the sampled primitive */ - res = s3d_primitive_get_attrib (&prim, S3D_GEOMETRY_NORMAL, st, &attrib); - if (RES_OK != res){ goto error; } - d3_normalize(normal, d3_minus(normal, d3_set_f3(normal, attrib.value))); /* TODO Sample a wavelength when spectral information available in sphin */ @@ -106,8 +103,13 @@ compute_MVREA_realization if (RES_OK != res){ goto error; } if (NULL == source){ res = RES_BAD_ARG; goto error; } + /* Retrieve geometry normal of the sampled primitive */ + res = s3d_primitive_get_attrib (&src_prim, S3D_GEOMETRY_NORMAL, st, &attrib); + if (RES_OK != res){ goto error; } + d3_normalize(normal, d3_minus(normal, d3_set_f3(normal, attrib.value))); + /* Sample a direction according to the source direction distribution */ - res = source_surface_sample_direction(source, rng, &prim, dir); + res = source_surface_sample_direction(source, rng, &src_prim, dir); if (RES_OK != res){ goto error; } /* While no absorption takes place and an interface is found */