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 f79f49c63fa5ae0194e82f13a797a766499b0c40
parent 41fe49d5b9a46a9a9027ade386e9f8496f4b6fe7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  8 Sep 2016 14:31:36 +0200

Add the ssf_bxdf_get_data function + fixes

Fix issues on the check of the BxDF creation parameters

Diffstat:
Msrc/ssf.h | 11+++++++++--
Msrc/ssf_bxdf.c | 24+++++++++++++++++++++---
2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/ssf.h b/src/ssf.h @@ -56,7 +56,7 @@ struct ssf_bxdf_type { const double N[3], /* Normalized normal */ double dir[4]); /* Sampled direction. The PDF is stored in dir[3] */ - size_t sizeof_bxdf; /* In bytes */ + size_t sizeof_bxdf; /* In Bytes */ size_t alignof_bxdf; /* In Bytes */ }; @@ -131,9 +131,16 @@ ssf_bxdf_sample SSF_API res_T ssf_specular_reflection_setup - (struct ssf_bxdf* brdf, + (struct ssf_bxdf* bxdf, const double reflectivity); +/* Retrieve the internal data of the BxDF. Usefull for user defined BxDF on + * which the caller has to retrieve them to setup the its parameters */ +SSF_API res_T +ssf_bxdf_get_data + (struct ssf_bxdf* bxdf, + void** data); + END_DECLS #endif /* SSF_H */ diff --git a/src/ssf_bxdf.c b/src/ssf_bxdf.c @@ -25,6 +25,16 @@ /******************************************************************************* * Helper functions ******************************************************************************/ +static INLINE int +check_bxdf_type(const struct ssf_bxdf_type* type) +{ + return type + && type->init + && type->release + && type->sample + && IS_POW2(type->alignof_bxdf); +} + static void bxdf_release(ref_T* ref) { @@ -50,7 +60,7 @@ ssf_bxdf_create struct ssf_bxdf* bxdf = NULL; res_T res = RES_OK; - if(!out_bxdf || !type) { + if(!out_bxdf || !check_bxdf_type(type)) { res = RES_BAD_ARG; goto error; } @@ -72,7 +82,7 @@ ssf_bxdf_create } memset(bxdf->data, 0, bxdf->type.sizeof_bxdf); res = bxdf->type.init(mem_allocator, bxdf->data); - if(res != RES_OK) goto exit; + if(res != RES_OK) goto error; exit: if(out_bxdf) *out_bxdf = bxdf; @@ -111,7 +121,7 @@ ssf_bxdf_sample double dir[4], double* radiance) { - if(!bxdf || u<0 || u>=1 || v<0 || v>=1 || !w || !dir || !radiance) + if(!bxdf || u<0 || u>=1 || v<0 || v>=1 || !w || !N || !dir || !radiance) return RES_BAD_ARG; if(!d3_is_normalized(w) || !d3_is_normalized(N)) return RES_BAD_ARG; @@ -119,3 +129,11 @@ ssf_bxdf_sample return RES_OK; } +res_T +ssf_bxdf_get_data(struct ssf_bxdf* bxdf, void** data) +{ + if(!bxdf || !data) return RES_BAD_ARG; + *data = bxdf->data; + return RES_OK; +} +