commit fa78684b06aee101ad963ec853247796d1b42963
parent bf2b8481c5923d693b4569d6e02f5dd68478e5c7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 13 Oct 2016 09:18:47 +0200
Plug the atmosphere attenuation into the refactored solver
Diffstat:
3 files changed, 56 insertions(+), 44 deletions(-)
diff --git a/src/ssol_atmosphere.c b/src/ssol_atmosphere.c
@@ -1,17 +1,17 @@
/* Copyright (C) CNRS 2016
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "ssol.h"
#include "ssol_atmosphere_c.h"
@@ -23,8 +23,8 @@
#include <rsys/ref_count.h>
/*******************************************************************************
-* Helper functions
-******************************************************************************/
+ * Helper functions
+ ******************************************************************************/
static void
atmosphere_release(ref_T* ref)
{
@@ -34,41 +34,19 @@ atmosphere_release(ref_T* ref)
dev = atmosphere->dev;
ASSERT(dev && dev->allocator);
switch (atmosphere->type) {
- case ATMOS_UNIFORM:
- if (atmosphere->data.uniform.spectrum)
- SSOL(spectrum_ref_put(atmosphere->data.uniform.spectrum));
- break;
- default: FATAL("Unreachable code\n"); break;
+ case ATMOS_UNIFORM:
+ if (atmosphere->data.uniform.spectrum)
+ SSOL(spectrum_ref_put(atmosphere->data.uniform.spectrum));
+ break;
+ default: FATAL("Unreachable code\n"); break;
}
MEM_RM(dev->allocator, atmosphere);
SSOL(device_ref_put(dev));
}
/*******************************************************************************
-* Exported ssol_atmosphere functions
+ * Exported ssol_atmosphere functions
******************************************************************************/
-double
-compute_atmosphere_attenuation
- (const struct ssol_atmosphere* atmosphere,
- const double distance,
- const double wavelength)
-{
- double ka;
- const struct ssol_spectrum* spectrum;
- if (!atmosphere)
- return 1;
-
- ASSERT(distance >= 0 && wavelength >= 0);
- switch (atmosphere->type) {
- case ATMOS_UNIFORM:
- spectrum = atmosphere->data.uniform.spectrum;
- ka = spectrum_interpolate(spectrum, wavelength);
- break;
- default: FATAL("Unreachable code\n"); break;
- }
- return exp(-ka * distance);
-}
-
res_T
ssol_atmosphere_create_uniform
(struct ssol_device* dev,
@@ -140,3 +118,29 @@ ssol_atmosphere_set_uniform_absorption
uni->spectrum = spectrum;
return RES_OK;
}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
+double
+compute_atmosphere_attenuation
+ (const struct ssol_atmosphere* atmosphere,
+ const double distance,
+ const double wavelength)
+{
+ double ka;
+ const struct ssol_spectrum* spectrum;
+ if (!atmosphere)
+ return 1;
+
+ ASSERT(distance >= 0 && wavelength >= 0);
+ switch (atmosphere->type) {
+ case ATMOS_UNIFORM:
+ spectrum = atmosphere->data.uniform.spectrum;
+ ka = spectrum_interpolate(spectrum, wavelength);
+ break;
+ default: FATAL("Unreachable code\n"); break;
+ }
+ return exp(-ka * distance);
+}
+
diff --git a/src/ssol_atmosphere_c.h b/src/ssol_atmosphere_c.h
@@ -41,7 +41,7 @@ struct ssol_atmosphere {
ref_T ref;
};
-double
+extern LOCAL_SYM double
compute_atmosphere_attenuation
(const struct ssol_atmosphere* atmosphere,
const double distance,
diff --git a/src/ssol_solver.c b/src/ssol_solver.c
@@ -44,6 +44,7 @@
/*******************************************************************************
* Helper functions
******************************************************************************/
+#if 0
static FINLINE void
solstice_trace_ray(struct realisation* rs)
{
@@ -66,6 +67,7 @@ cmp_candidates(const void* _c1, const void* _c2)
const double d2 = c2->hit_distance;
return (d1 > d2) - (d1 < d2);
}
+#endif
static FINLINE res_T
check_scene(const struct ssol_scene* scene, const char* caller)
@@ -1031,6 +1033,12 @@ ssol_solve
++depth;
+ /* Take into account the atomosphere attenuation along the new ray */
+ if(scn->atmosphere) {
+ weight *= compute_atmosphere_attenuation
+ (scn->atmosphere, hit.distance, wl);
+ }
+
/* Retrieve the hit instance and shaded shape */
inst = *htable_instance_find(&scn->instances_rt, &hit.prim.inst_id);
id = *htable_shaded_shape_find(&inst->object->shaded_shapes_rt, &hit.prim.geom_id);