commit 770463352b8229482fd4768274babd449d95f8be
parent ee2302d0ec7b350dda4f9280f2d68d4167aed35f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 10 Nov 2022 15:37:17 +0100
htrdr-planeto: upd the calculation of the direct contribution
Previously, extinction transmissivity was calculated assuming an
infinite distance between the source and the position to be considered.
This commit adds the htrdr_planeto_source_distance_to function that
calculates the distance between the surface of the source and a given
position. The extinction transmissivity now uses this distance.
Diffstat:
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/planeto/htrdr_planeto_compute_radiance.c b/src/planeto/htrdr_planeto_compute_radiance.c
@@ -262,6 +262,7 @@ direct_contribution
struct s3d_hit hit;
double Tr;
double Ld;
+ double src_dst;
ASSERT(cmd && args && pos && dir);
/* Is the source hidden? */
@@ -271,7 +272,11 @@ direct_contribution
RNGRD(trace_ray(cmd->ground, &rt, &hit));
if(!S3D_HIT_NONE(&hit)) return 0;
- Tr = transmissivity(cmd, args, RNATM_RADCOEF_Kext, pos, dir, INF);
+ /* Calculate the distance between the source and `pos' */
+ src_dst = htrdr_planeto_source_distance_to(cmd->source, pos);
+ ASSERT(src_dst >= 0);
+
+ Tr = transmissivity(cmd, args, RNATM_RADCOEF_Kext, pos, dir, src_dst);
Ld = htrdr_planeto_source_get_radiance(cmd->source, args->wlen);
return Ld * Tr;
}
@@ -498,7 +503,7 @@ planeto_compute_radiance
double dir[3];
double L = 0; /* Radiance in W/m²/sr/m */
double Tr_abs = 1; /* Absorption transmissivity */
- size_t nsc = 0; /* For debug */
+ size_t nsc = 0; /* Number of scatterings (for debug) */
ASSERT(cmd && check_planeto_compute_radiance_args(cmd, args) == RES_OK);
d3_set(pos, args->path_org);
diff --git a/src/planeto/htrdr_planeto_source.c b/src/planeto/htrdr_planeto_source.c
@@ -152,6 +152,20 @@ htrdr_planeto_source_get_radiance
(wlen*1e-9/*From nm to m*/, source->temperature);
}
+double
+htrdr_planeto_source_distance_to
+ (const struct htrdr_planeto_source* source,
+ const double pos[3])
+{
+ double vec[3];
+ double dst;
+ ASSERT(source && pos);
+
+ d3_sub(vec, source->position, pos);
+ dst = d3_len(vec);
+ return dst - source->radius;
+}
+
int
htrdr_planeto_source_is_targeted
(const struct htrdr_planeto_source* source,
diff --git a/src/planeto/htrdr_planeto_source.h b/src/planeto/htrdr_planeto_source.h
@@ -53,6 +53,13 @@ htrdr_planeto_source_get_radiance
(const struct htrdr_planeto_source* source,
const double wlen); /* In nanometers */
+/* Return the distance between the source surface and the input position. Can
+ * be negative if the position is in the source */
+extern LOCAL_SYM double /* In m */
+htrdr_planeto_source_distance_to
+ (const struct htrdr_planeto_source* source,
+ const double pos[3]);
+
/* Return 1 if the source is targeted by the submitted ray and 0 otherwise */
extern LOCAL_SYM int
htrdr_planeto_source_is_targeted