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 3164f1eb3721ef4030f054e04bb68e4ed698e788
parent 61593b7e28cd7216348746b849a0ae4d60df63ba
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  7 Sep 2016 15:22:49 +0200

Ensure that the wi and N of ssf_bsdf_sample are normalized

Diffstat:
Msrc/ssf.h | 2+-
Msrc/ssf_bsdf.c | 11+++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/ssf.h b/src/ssf.h @@ -75,7 +75,7 @@ ssf_bsdf_sample (struct ssf_bsdf* bsdf, const double u, /* Canonical number */ const double v, /* Canonical number */ - const double w[3], /* Incoming direction */ + const double w[3], /* Normalized incoming direction */ const double N[3], /* Normalized normal */ double dir[4], /* Sampled direction. The PDF is stored in dir[3] */ double* radiance); /* Sampled radiance */ diff --git a/src/ssf_bsdf.c b/src/ssf_bsdf.c @@ -16,6 +16,7 @@ #include "ssf.h" #include "ssf_bxdf_c.h" +#include <rsys/double3.h> #include <rsys/double4.h> #include <rsys/mem_allocator.h> #include <rsys/ref_count.h> @@ -117,6 +118,8 @@ ssf_bsdf_clear(struct ssf_bsdf* bsdf) return RES_OK; } +/* TODO fix the use of the u & v canonical random number. Currently u is used 2 + * times */ res_T ssf_bsdf_sample (struct ssf_bsdf* bsdf, @@ -140,6 +143,10 @@ ssf_bsdf_sample res = RES_BAD_ARG; goto error; } + if(!d3_is_normalized(w) || !d3_is_normalized(N)) { + res = RES_BAD_ARG; + goto error; + } /* Build the probability distribution by sampling each BRDF */ n = 0; @@ -178,8 +185,8 @@ ssf_bsdf_sample exit: return res; error: - d4_splat(dir, -DBL_MAX); - *radiance = -DBL_MAX; + if(dir) d4_splat(dir, -DBL_MAX); + if(radiance) *radiance = -DBL_MAX; goto exit; }