commit 8005d7cc672004954559d2ffd7b10ee9fe29ca92
parent f79f49c63fa5ae0194e82f13a797a766499b0c40
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 8 Sep 2016 14:33:13 +0200
Add the test_ssf_bxdf test
Diffstat:
4 files changed, 185 insertions(+), 17 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -85,6 +85,7 @@ if(NOT NO_TEST)
endfunction()
new_test(test_ssf_bsdf)
+ new_test(test_ssf_bxdf)
new_test(test_ssf_specular_reflection)
endif()
diff --git a/src/ssf_bxdf_c.h b/src/ssf_bxdf_c.h
@@ -21,7 +21,6 @@
struct mem_allocator;
-/* Generic Bidirectional <Reflec|Transmit>tance Distirbution Function */
struct ssf_bxdf {
struct ssf_bxdf_type type;
void* data; /* Specific internal data of the BxDF */
diff --git a/src/test_ssf_bxdf.c b/src/test_ssf_bxdf.c
@@ -0,0 +1,184 @@
+/* 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/double3.h>
+#include <rsys/double4.h>
+
+static int bxdf_is_init = 0;
+
+struct ALIGN(64) bxdf {
+ uint32_t id;
+ double u;
+ double v;
+ double w[3];
+ double N[3];
+ double radiance;
+};
+
+static res_T
+bxdf_init(struct mem_allocator* allocator, void* bxdf)
+{
+ NCHECK(allocator, NULL);
+ NCHECK(bxdf, NULL);
+ CHECK(IS_ALIGNED(bxdf, 64), 1);
+ ((struct bxdf*)bxdf)->id = 0xDECAFBAD;
+ bxdf_is_init = 1;
+ return RES_OK;
+}
+
+static void
+bxdf_release(void* bxdf)
+{
+ NCHECK(bxdf, NULL);
+ CHECK(((struct bxdf*)bxdf)->id, 0xDECAFBAD);
+ bxdf_is_init = 0;
+}
+
+static double
+bxdf_sample
+ (void* bxdf,
+ const double u,
+ const double v,
+ const double w[3],
+ const double N[3],
+ double dir[4])
+{
+ struct bxdf* BxDF = bxdf;
+ CHECK(BxDF->u, u);
+ CHECK(BxDF->v, v);
+ CHECK(d3_eq(BxDF->w, w), 1);
+ CHECK(d3_eq(BxDF->N, N), 1);
+ d4(dir, 1.0, 2.0, 3.0, 4.0);
+ return BxDF->radiance;
+}
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct bxdf* data;
+ struct ssf_bxdf* bxdf;
+ struct ssf_bxdf_type type;
+ double w[3];
+ double N[3];
+ double dir[4];
+ double rad;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ type.init = bxdf_init;
+ type.release = bxdf_release;
+ type.sample = bxdf_sample;
+ type.sizeof_bxdf = sizeof(struct bxdf);
+ type.alignof_bxdf = ALIGNOF(struct bxdf);
+
+ CHECK(ssf_bxdf_create(NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_create(&allocator, NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_create(NULL, &type, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_create(&allocator, &type, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_create(NULL, NULL, &bxdf), RES_BAD_ARG);
+ CHECK(ssf_bxdf_create(&allocator, NULL, &bxdf), RES_BAD_ARG);
+
+ CHECK(bxdf_is_init, 0);
+ CHECK(ssf_bxdf_create(NULL, &type, &bxdf), RES_OK);
+ CHECK(bxdf_is_init, 1);
+
+ CHECK(ssf_bxdf_ref_get(NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_ref_get(bxdf), RES_OK);
+ CHECK(ssf_bxdf_ref_put(NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
+ CHECK(bxdf_is_init, 1);
+ CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
+ CHECK(bxdf_is_init, 0);
+
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_OK);
+ CHECK(bxdf_is_init, 1);
+ CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
+ CHECK(bxdf_is_init, 0);
+
+ type.init = NULL;
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_BAD_ARG);
+ CHECK(bxdf_is_init, 0);
+ type.init = bxdf_init;
+ type.release = NULL;
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_BAD_ARG);
+ CHECK(bxdf_is_init, 0);
+ type.release = bxdf_release;
+ type.sample = NULL;
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_BAD_ARG);
+ CHECK(bxdf_is_init, 0);
+ type.sample = bxdf_sample;
+ type.alignof_bxdf = 3;
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_BAD_ARG);
+ CHECK(bxdf_is_init, 0);
+ type.alignof_bxdf = ALIGNOF(struct bxdf);
+ CHECK(ssf_bxdf_create(&allocator, &type, &bxdf), RES_OK);
+ CHECK(bxdf_is_init, 1);
+
+ CHECK(ssf_bxdf_get_data(NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_get_data(bxdf, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_get_data(NULL, (void**)&data), RES_BAD_ARG);
+ CHECK(ssf_bxdf_get_data(bxdf, (void**)&data), RES_OK);
+
+ CHECK(data->id, 0xDECAFBAD);
+
+ d3_normalize(w, d3(w, -1, -1, 0));
+ d3(N, 0.0, 1.0, 0.0);
+ d3_set(data->w, w);
+ d3_set(data->N, N);
+ data->u = 0.0;
+ data->v = 0.0;
+ data->radiance = 1.234;
+
+ CHECK(ssf_bxdf_sample(NULL, 0, 0, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, -1, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 1, 0, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, 0, NULL, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, 0, w, NULL, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, 0, w, N, NULL, &rad), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, 0, w, N, dir, NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_sample(bxdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.234);
+ data->u = 0.5;
+ data->v = 0.5;
+ CHECK(ssf_bxdf_sample(bxdf, 0.5, 0.5, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.234);
+
+ d3(w, -1, -1, 0);
+ CHECK(ssf_bxdf_sample(bxdf, 0.5, 0.5, w, N, dir, &rad), RES_BAD_ARG);
+ d3_normalize(w, w);
+ d3(N, 0.0, 2.0, 1.0);
+ CHECK(ssf_bxdf_sample(bxdf, 0.5, 0.5, w, N, dir, &rad), RES_BAD_ARG);
+ d3_normalize(N, N);
+ d3_set(data->w, w);
+ d3_set(data->N, N);
+ data->radiance = 3.14;
+ CHECK(ssf_bxdf_sample(bxdf, 0.5, 0.5, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 3.14);
+
+ CHECK(bxdf_is_init, 1);
+ CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
+ CHECK(bxdf_is_init, 0);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}
+
diff --git a/src/test_ssf_specular_reflection.c b/src/test_ssf_specular_reflection.c
@@ -30,21 +30,6 @@ main(int argc, char** argv)
(void)argc, (void)argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(ssf_bxdf_create(NULL, NULL, NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(&allocator, NULL, NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(NULL, &ssf_specular_reflection, NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(&allocator, &ssf_specular_reflection, NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(NULL, NULL, &brdf), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(&allocator, NULL, &brdf), RES_BAD_ARG);
- CHECK(ssf_bxdf_create(NULL, &ssf_specular_reflection, &brdf), RES_OK);
-
- CHECK(ssf_bxdf_ref_get(NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_ref_get(brdf), RES_OK);
- CHECK(ssf_bxdf_ref_put(NULL), RES_BAD_ARG);
- CHECK(ssf_bxdf_ref_put(brdf), RES_OK);
- CHECK(ssf_bxdf_ref_put(brdf), RES_OK);
-
CHECK(ssf_bxdf_create(&allocator, &ssf_specular_reflection, &brdf), RES_OK);
CHECK(ssf_specular_reflection_setup(NULL, -1.0), RES_BAD_ARG);
@@ -90,6 +75,5 @@ main(int argc, char** argv)
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
CHECK(mem_allocated_size(), 0);
-
return 0;
}