commit 03d119e65f2a5e4eed65374bffe1066b45abba19
parent 32bddcd0f6386444d79c04c31d70507a2ddf2667
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Sep 2016 11:33:48 +0200
Implement the ssf_specular_reflection BRDF API
Diffstat:
3 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -43,10 +43,12 @@ set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-set(SSF_FILES_SRC ssf_bxdf.c)
+set(SSF_FILES_DOC COPYING README.md)
set(SSF_FILES_INC_API ssf.h)
set(SSF_FILES_INC ssf_bxdf_c.h)
-set(SSF_FILES_DOC COPYING README.md)
+set(SSF_FILES_SRC
+ ssf_bxdf.c
+ ssf_specular_reflection.c)
rcmake_prepend_path(SSF_FILES_SRC ${SSF_SOURCE_DIR})
rcmake_prepend_path(SSF_FILES_INC ${SSF_SOURCE_DIR})
rcmake_prepend_path(SSF_FILES_INC_API ${SSF_SOURCE_DIR})
diff --git a/src/ssf.h b/src/ssf.h
@@ -101,7 +101,7 @@ ssf_specular_reflection_create
struct ssf_bxdf** bxdf);
SSF_API res_T
-ssf_specular_reflection
+ssf_specular_reflection_setup
(struct ssf_bxdf* brdf,
const double reflectivity);
diff --git a/src/ssf_specular_reflection.c b/src/ssf_specular_reflection.c
@@ -0,0 +1,90 @@
+/* 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 "ssf_bxdf_c.h"
+
+#include <rsys/double3.h>
+
+struct specular_reflection {
+ double reflectivity; /* W . sr^-1 . m^-2 */
+};
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static double
+specular_reflection_sample
+ (void* data,
+ const double u,
+ const double v,
+ const double w[3],
+ const double N[3],
+ double dir[4])
+{
+ struct specular_reflection* brdf = data;
+ double cosi;
+ ASSERT(u >= 0 && u < 1 && v >= 0 && v < 1 && w && N && dir);
+ (void)u, (void)v;
+
+ /* Reflection the incoming direction w[3] with respect to the normal */
+ cosi = -d3_dot(w, N);
+ d3_muld(dir, N, 2*cosi);
+ d3_add(dir, dir, w);
+ dir[3] = 1; /* pdf */
+ return brdf->reflectivity;
+}
+
+/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+ssf_specular_reflection_create
+ (struct mem_allocator* allocator, struct ssf_bxdf** out_bxdf)
+{
+ struct ssf_bxdf* bxdf = NULL;
+ res_T res = RES_OK;
+
+ if(!out_bxdf) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ res = bxdf_create(allocator, sizeof(struct specular_reflection),
+ ALIGNOF(struct specular_reflection), &bxdf);
+ if(res != RES_OK) goto error;
+
+ bxdf->sample = specular_reflection_sample;
+ ((struct specular_reflection*)bxdf->data)->reflectivity = 1.0;
+
+exit:
+ *out_bxdf = bxdf;
+ return res;
+error:
+ if(bxdf) {
+ SSF(bxdf_ref_put(bxdf));
+ bxdf = NULL;
+ }
+ goto exit;
+}
+
+res_T
+ssf_specular_reflection_setup(struct ssf_bxdf* bxdf, const double reflectivity)
+{
+ if(!bxdf || reflectivity < 0) return RES_BAD_ARG;
+ ((struct specular_reflection*)bxdf->data)->reflectivity = reflectivity;
+ return RES_OK;
+}
+