star-sf

Set of surface and volume scattering functions
git clone git://git.meso-star.fr/star-sf.git
Log | Files | Refs | README | LICENSE

commit e2517cae8e52cefc810118f775d4d2e03ad30f85
parent 5f422f862ad802eb9f0495b0a64ddb291a3852d9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  8 Sep 2016 15:52:12 +0200

Implement and test the no operation fresnel term

Diffstat:
Mcmake/CMakeLists.txt | 2++
Asrc/ssf_fresnel_no_op.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/ssf_specular_reflection.c | 6+++---
Asrc/test_ssf_fresnel_no_op.c | 43+++++++++++++++++++++++++++++++++++++++++++
4 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -52,6 +52,7 @@ set(SSF_FILES_SRC ssf_bsdf.c ssf_bxdf.c ssf_fresnel.c + ssf_fresnel_no_op.c ssf_specular_reflection.c) rcmake_prepend_path(SSF_FILES_SRC ${SSF_SOURCE_DIR}) rcmake_prepend_path(SSF_FILES_INC ${SSF_SOURCE_DIR}) @@ -90,6 +91,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_no_op) new_test(test_ssf_specular_reflection) endif() diff --git a/src/ssf_fresnel_no_op.c b/src/ssf_fresnel_no_op.c @@ -0,0 +1,50 @@ +/* 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" + +/******************************************************************************* + * Private functions + ******************************************************************************/ +static res_T +fresnel_no_op_init(struct mem_allocator* allocator, void* fresnel) +{ + (void)allocator, (void)fresnel; + return RES_OK; +} + +static void +fresnel_no_op_release(void* fresnel) +{ + (void)fresnel; +} + +static double +fresnel_no_op_eval(void* fresnel, const double cos_theta) +{ + (void)fresnel, (void)cos_theta; + return 1.0; +} + +/******************************************************************************* + * Exported symbol + ******************************************************************************/ +const struct ssf_fresnel_type ssf_fresnel_no_op = { + fresnel_no_op_init, + fresnel_no_op_release, + fresnel_no_op_eval, + 0, 1 +}; + diff --git a/src/ssf_specular_reflection.c b/src/ssf_specular_reflection.c @@ -23,12 +23,12 @@ struct specular_reflection { }; /******************************************************************************* - * Helper functions + * Private functions ******************************************************************************/ static res_T specular_reflection_init(struct mem_allocator* allocator, void* bxdf) { - ASSERT(allocator && bxdf); + ASSERT(bxdf); (void)allocator; ((struct specular_reflection*)bxdf)->reflectivity = 0.0; return RES_OK; @@ -61,7 +61,7 @@ specular_reflection_sample } /******************************************************************************* - * Exported functions + * Exported symbols ******************************************************************************/ const struct ssf_bxdf_type ssf_specular_reflection = { specular_reflection_init, diff --git a/src/test_ssf_fresnel_no_op.c b/src/test_ssf_fresnel_no_op.c @@ -0,0 +1,43 @@ +/* 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" + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + double val; + struct ssf_fresnel* fresnel; + (void)argc, (void)argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + CHECK(ssf_fresnel_create(&allocator, &ssf_fresnel_no_op, &fresnel), RES_OK); + + CHECK(ssf_fresnel_eval(fresnel, 0, &val), RES_OK); + CHECK(val, 1.0); + CHECK(ssf_fresnel_eval(fresnel, 1, &val), RES_OK); + CHECK(val, 1.0); + CHECK(ssf_fresnel_eval(fresnel, 0.48, &val), RES_OK); + CHECK(val, 1.0); + + CHECK(ssf_fresnel_ref_put(fresnel), RES_OK); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +}