commit 0e4d2f2ddf6fd4801bca635c0e9d5cefe6a803a0
parent 0ca3fa94134299c2a3ab5dae27c3ac1c1f8210ef
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 9 Sep 2016 10:57:08 +0200
Test the Fresnel Dielectric
Diffstat:
3 files changed, 104 insertions(+), 5 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -92,6 +92,7 @@ if(NOT NO_TEST)
new_test(test_ssf_bsdf)
new_test(test_ssf_bxdf)
new_test(test_ssf_fresnel)
+ new_test(test_ssf_fresnel_dielectric)
new_test(test_ssf_fresnel_no_op)
new_test(test_ssf_specular_reflection)
endif()
diff --git a/src/test_ssf_fresnel_dielectric.c b/src/test_ssf_fresnel_dielectric.c
@@ -0,0 +1,60 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * 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 "ssf.h"
+#include "test_ssf_utils.h"
+
+#include <rsys/math.h>
+
+int
+main(int argc, char** argv)
+{
+ const size_t nsteps = 100;
+ const double step = (PI/2.0) / (double)nsteps;
+ size_t i;
+ struct mem_allocator allocator;
+ struct ssf_fresnel* fresnel;
+ struct ssf_fresnel* dummy;
+ double val;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+ CHECK(ssf_fresnel_create(&allocator, &fresnel_dummy, &dummy), RES_OK);
+ CHECK(ssf_fresnel_create
+ (&allocator, &ssf_fresnel_dielectric, &fresnel), RES_OK);
+
+ CHECK(ssf_fresnel_dielectric_setup(NULL, -1.0, -1.0), RES_BAD_ARG);
+ CHECK(ssf_fresnel_dielectric_setup(fresnel, -1.0, -1.0), RES_OK);
+ CHECK(ssf_fresnel_dielectric_setup(dummy, -1.0, -1.0), RES_BAD_ARG);
+ CHECK(ssf_fresnel_dielectric_setup(fresnel, 1.000277, 1.5), RES_OK);
+
+ CHECK(ssf_fresnel_eval(fresnel, 1, &val), RES_OK);
+ CHECK(eq_eps(val, 0.04, 1.e-4), 1);
+
+ FOR_EACH(i, 0, nsteps+1) {
+ const double theta_i = MMIN((double)i*step, PI/2);
+ const double cos_theta_i = cos(theta_i);
+ CHECK(ssf_fresnel_eval(fresnel, cos_theta_i, &val), RES_OK);
+ printf("%g %g\n", theta_i, val);
+ }
+
+ CHECK(ssf_fresnel_ref_put(fresnel), RES_OK);
+ CHECK(ssf_fresnel_ref_put(dummy), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}
diff --git a/src/test_ssf_utils.h b/src/test_ssf_utils.h
@@ -19,20 +19,23 @@
#include <rsys/mem_allocator.h>
#include <stdio.h>
-static INLINE res_T
+/*******************************************************************************
+ * Dummy BxDF type
+ ******************************************************************************/
+static res_T
bxdf_dummy_init(struct mem_allocator* allocator, void* bxdf)
{
(void)allocator, (void)bxdf;
return RES_OK;
}
-static INLINE void
+static void
bxdf_dummy_release(void* bxdf)
{
(void)bxdf;
}
-static INLINE double
+static double
bxdf_dummy_sample
(void* bxdf,
const double u,
@@ -40,9 +43,9 @@ bxdf_dummy_sample
const double w[3],
const double N[3],
double dir[4])
-{
+{
(void)bxdf, (void)u, (void)v, (void)w, (void)N, (void)dir;
- return 0.0;
+ return 0.0;
}
static const struct ssf_bxdf_type bxdf_dummy = {
@@ -52,6 +55,41 @@ static const struct ssf_bxdf_type bxdf_dummy = {
0, 1
};
+/*******************************************************************************
+ * Dummy Fresnel type
+ ******************************************************************************/
+static res_T
+fresnel_dummy_init(struct mem_allocator* allocator, void* fresnel)
+{
+ (void)allocator, (void)fresnel;
+ return RES_OK;
+}
+
+static void
+fresnel_dummy_release(void* fresnel)
+{
+ (void)fresnel;
+}
+
+static double
+fresnel_dummy_eval
+ (void* fresnel,
+ const double cos_theta_i)
+{
+ (void)fresnel, (void)cos_theta_i;
+ return 0.0;
+}
+
+static const struct ssf_fresnel_type fresnel_dummy = {
+ fresnel_dummy_init,
+ fresnel_dummy_release,
+ fresnel_dummy_eval,
+ 0, 1
+};
+
+/*******************************************************************************
+ * Miscellaneous functions
+ ******************************************************************************/
static INLINE void
check_memory_allocator(struct mem_allocator* allocator)
{