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 7f0b067f6de086788467e4058d81138a8b1e5a24
parent 75f142d18acf46f581f469379025b3e8021d3764
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 28 Sep 2022 17:13:43 +0200

Start testing the discrete phase function

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/test_ssf_phase_discrete.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -165,6 +165,7 @@ if(NOT NO_TEST) new_test(test_ssf_microfacet_distribution) new_test(test_ssf_microfacet_reflection) new_test(test_ssf_phase) + new_test(test_ssf_phase_discrete) new_test(test_ssf_phase_hg) new_test(test_ssf_phase_rayleigh) new_test(test_ssf_specular_dielectric_dielectric_reflection) diff --git a/src/test_ssf_phase_discrete.c b/src/test_ssf_phase_discrete.c @@ -0,0 +1,87 @@ +/* Copyright (C) 2016-2018, 2021 |Meso|Star> (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" + +static struct ssf_discrete_item g_items[] = { + {0.0000000000000000, 68.603348420512177}, + {1.7453292519943295e-2, 50.735150232030207}, + {3.4906585039886591e-2, 24.908999683188814}, + {5.2359877559829883e-2, 11.936459532538100}, + {6.9813170079773182e-2, 6.5845291580807999}, + {8.7266462599716474e-2, 4.1115681738409000}, + {0.10471975511965977, 2.7971255874985190}, + {0.12217304763960307, 2.0200365258652173}, + {0.13962634015954636, 1.5241311066143122}, + {0.15707963267948966, 1.1891144970876193}, + {0.17453292519943295, 0.95259719392666198}, + {0.26179938779914941, 0.40729722471207858}, + {0.34906585039886590, 0.22439173045102234}, + {0.52359877559829882, 9.8911118269091880e-2}, + {0.87266462599716477, 3.8428151500227763e-2}, + {1.2217304763960306, 2.3435147759515759e-2}, + {1.5707963267948966, 1.8554414090107985e-2}, + {1.9198621771937625, 1.7273221501888446e-2}, + {2.2689280275926285, 1.7471501307208134e-2}, + {2.6179938779914944, 1.8089219162242556e-2}, + {2.8797932657906435, 1.8455274187448138e-2}, + {2.9845130209103035, 1.8546787943749535e-2}, + {3.0194196059501901, 1.8562040236466435e-2}, + {3.0543261909900763, 1.8584918675541785e-2}, + {3.0892327760299634, 1.9156879652425504e-2}, + {3.1241393610698500, 2.8323507575281980e-2}, + {3.1415926535897931, 3.2632280267806027e-2} +}; +const size_t nitems = sizeof(g_items) / sizeof(*g_items); + +static void +get_item(const size_t id, struct ssf_discrete_item* item, void* ctx) +{ + CHK(ctx == g_items); + CHK(id < nitems); + *item = g_items[id]; +} + +int +main(int argc, char** argv) +{ + struct mem_allocator* allocator = &mem_default_allocator; + struct ssf_discrete_setup_args args = SSF_DISCRETE_SETUP_ARGS_NULL; + struct ssf_phase* discrete = NULL; + struct ssf_phase* dummy = NULL; + (void)argc, (void)argv; + + CHK(ssf_phase_create(allocator, &ssf_phase_discrete, &discrete) == RES_OK); + CHK(ssf_phase_create(allocator, &phase_dummy, &dummy) == RES_OK); + + args.get_item = get_item; + args.context = g_items; + args.nitems = nitems; + + CHK(ssf_phase_discrete_setup(NULL, &args) == RES_BAD_ARG); + CHK(ssf_phase_discrete_setup(discrete, NULL) == RES_BAD_ARG); + CHK(ssf_phase_discrete_setup(discrete, &args) == RES_OK); + + CHK(ssf_phase_discrete_setup(dummy, &args) == RES_BAD_ARG); + + args.nitems = 2; + CHK(ssf_phase_discrete_setup(discrete, &args) == RES_BAD_ARG); + + CHK(ssf_phase_ref_put(discrete) == RES_OK); + CHK(ssf_phase_ref_put(dummy) == RES_OK); + return 0; +} +