ssf_fresnel_constant.c (2166B)
1 /* Copyright (C) 2016-2018, 2021-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "ssf.h" 17 #include "ssf_fresnel_c.h" 18 19 struct fresnel_constant { 20 double k; /* in [0, 1] */ 21 }; 22 23 /******************************************************************************* 24 * Private functions 25 ******************************************************************************/ 26 static res_T 27 fresnel_constant_init(struct mem_allocator* allocator, void* fresnel) 28 { 29 struct fresnel_constant* f = fresnel; 30 (void)allocator; 31 ASSERT(fresnel); 32 f->k = 1; /* <=> No op */ 33 return RES_OK; 34 } 35 36 static void 37 fresnel_constant_release(void* fresnel) 38 { 39 (void)fresnel; 40 } 41 42 static double 43 fresnel_constant_eval(void* fresnel, const double cos_theta_i) 44 { 45 struct fresnel_constant* f = fresnel; 46 (void)cos_theta_i; 47 return f->k; 48 } 49 50 /******************************************************************************* 51 * Exported symbols 52 ******************************************************************************/ 53 const struct ssf_fresnel_type ssf_fresnel_constant = { 54 fresnel_constant_init, 55 fresnel_constant_release, 56 fresnel_constant_eval, 57 sizeof(struct fresnel_constant), 58 ALIGNOF(struct fresnel_constant) 59 }; 60 61 res_T 62 ssf_fresnel_constant_setup(struct ssf_fresnel* fresnel, const double value) 63 { 64 struct fresnel_constant* f; 65 if(!fresnel || !FRESNEL_TYPE_EQ(&fresnel->type, &ssf_fresnel_constant)) 66 return RES_BAD_ARG; 67 if(value < 0 || value > 1) 68 return RES_BAD_ARG; 69 f = fresnel->data; 70 f->k = value; 71 return RES_OK; 72 } 73