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 fa4d4d70e6a09d152f4d4d18b80cb05eb022e86c
parent b230ebbce26e91418b39693d22985641316fda39
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 19 Jul 2018 16:19:01 +0200

Make optional The pdf argument of the BSDF/microfacet/phase sample

Diffstat:
Msrc/ssf.h | 10+++++-----
Msrc/ssf_bsdf.c | 9++++++---
Msrc/ssf_microfacet_distribution.c | 8+++++---
Msrc/ssf_phase.c | 10++++++----
Msrc/ssf_phase_hg.c | 4+---
Msrc/test_ssf_bsdf.c | 2+-
Msrc/test_ssf_microfacet_distribution.c | 1+
Msrc/test_ssf_phase.c | 7+++----
Msrc/test_ssf_utils.h | 3+--
9 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/ssf.h b/src/ssf.h @@ -75,7 +75,7 @@ struct ssf_bsdf_type { const double N[3], /* Normalized surface normal */ double wi[3], /* Sampled normalized incoming direction */ int* type, /* Type of the sampled component. Combination of ssf_bxdf_flag */ - double* pdf); /* PDF to sample wi wrt wo */ + double* pdf); /* PDF to sample wi wrt wo. Can be NULL */ /* Evaluate the BxDF wrt `wo' and `wi' */ double @@ -127,7 +127,7 @@ struct ssf_microfacet_distribution_type { struct ssp_rng* rng, /* Random number generator */ const double N[3], /* Normalized Z-direction of the distribution */ double wh[3], /* Sampled normalized half vector */ - double* pdf); /* PDF to sample wh */ + double* pdf); /* PDF to sample wh. Can be NULL */ double (*eval) @@ -157,13 +157,13 @@ struct ssf_phase_type { void (*release)(void* bsdf); /* Can be NULL */ /* Sample a direction `wi' wrt `wo'. TODO comment the PDF */ - double /* FIXME */ + void (*sample) (void* phase, struct ssp_rng* rng, /* Random number generator */ const double wo[3], /* Normalized outgoing direction */ double wi[3], /* Sampled normalized incoming direction */ - double* pdf); /* PDF to sample wi wrt wo */ + double* pdf); /* PDF to sample wi wrt wo. Can be NULL */ /* Evaluate the phase function wrt `wo' and `wi' */ double @@ -409,7 +409,7 @@ SSF_API res_T ssf_phase_ref_put (struct ssf_phase* phase); -SSF_API double +SSF_API void ssf_phase_sample (struct ssf_phase* phase, struct ssp_rng* rng, /* Random number generator */ diff --git a/src/ssf_bsdf.c b/src/ssf_bsdf.c @@ -123,11 +123,14 @@ ssf_bsdf_sample const double N[3], double wi[3], int* type, - double* pdf) + double* out_pdf) { - ASSERT(bsdf && rng && wo && N && wi && type && pdf); + double R, pdf; + ASSERT(bsdf && rng && wo && N && wi && type); ASSERT(d3_is_normalized(wo) && d3_is_normalized(N)); - return bsdf->type.sample(bsdf->data, rng, wo, N, wi, type, pdf); + R = bsdf->type.sample(bsdf->data, rng, wo, N, wi, type, &pdf); + if(out_pdf) *out_pdf = pdf; + return R; } double diff --git a/src/ssf_microfacet_distribution.c b/src/ssf_microfacet_distribution.c @@ -126,11 +126,13 @@ ssf_microfacet_distribution_sample struct ssp_rng* rng, const double N[3], double wh[3], - double* pdf) + double* out_pdf) { - ASSERT(distrib && rng && N && wh && pdf); + double pdf; + ASSERT(distrib && rng && N && wh); ASSERT(d3_is_normalized(N)); - distrib->type.sample(distrib->data, rng, N, wh, pdf); + distrib->type.sample(distrib->data, rng, N, wh, &pdf); + if(out_pdf) *out_pdf = pdf; } double diff --git a/src/ssf_phase.c b/src/ssf_phase.c @@ -115,17 +115,19 @@ ssf_phase_ref_put(struct ssf_phase* phase) return RES_OK; } -double +void ssf_phase_sample (struct ssf_phase* phase, struct ssp_rng* rng, const double wo[3], double wi[3], - double* pdf) + double* out_pdf) { - ASSERT(phase && rng && wo && wi && pdf); + double pdf; + ASSERT(phase && rng && wo && wi); ASSERT(d3_is_normalized(wo)); - return phase->type.sample(phase->data, rng, wo, wi, pdf); + phase->type.sample(phase->data, rng, wo, wi, &pdf); + if(out_pdf) *out_pdf = pdf; } double diff --git a/src/ssf_phase_hg.c b/src/ssf_phase_hg.c @@ -61,7 +61,7 @@ hg_eval(void* data, const double wo[3], const double wi[3]) return 1.0/(4.0*PI) * (1 - g*g) / (denom*sqrt(denom)); } -static double +static void hg_sample (void* data, struct ssp_rng* rng, @@ -72,10 +72,8 @@ hg_sample const struct hg* hg = data; double sample[3]; ASSERT(data && wo && wi); - ssp_ran_sphere_hg(rng, wo, hg->g, sample, pdf); d3_set(wi, sample); - return NaN; /* FIXME define return value */ } static double diff --git a/src/test_ssf_bsdf.c b/src/test_ssf_bsdf.c @@ -190,7 +190,7 @@ main(int argc, char** argv) data->rng = rng; data->reflectivity = 0.1234; - CHK(ssf_bsdf_sample(bsdf, rng, wo, N, wi, &i, &pdf) == 0.1234); + CHK(ssf_bsdf_sample(bsdf, rng, wo, N, wi, &i, NULL) == 0.1234); CHK(ssf_bsdf_sample(bsdf, rng, wo, N, wi, &i, &pdf) == 0.1234); CHK(i == 314); CHK(pdf == 4); diff --git a/src/test_ssf_microfacet_distribution.c b/src/test_ssf_microfacet_distribution.c @@ -182,6 +182,7 @@ main(int argc, char** argv) data->pdf = 0.1234; data->value = 0.43; + ssf_microfacet_distribution_sample(distrib, rng, N, wh, NULL); ssf_microfacet_distribution_sample(distrib, rng, N, wh, &pdf); CHK(d3_eq(wh, data->wh) == 1); CHK(pdf == data->pdf); diff --git a/src/test_ssf_phase.c b/src/test_ssf_phase.c @@ -46,7 +46,7 @@ phase_release(void* phase) phase_is_init = 0; } -static double +static void phase_sample (void* data, struct ssp_rng* rng, @@ -60,7 +60,6 @@ phase_sample CHK(d3_eq(phase->wo, wo) == 1); d3(wi, 1.0, 2.0, 3.0); *pdf = phase->pdf; - return phase->value; } static double @@ -167,8 +166,8 @@ main(int argc, char** argv) data->value = 0.1234; data->pdf = 4; - CHK(ssf_phase_sample(phase, rng, data->wo, wi, &pdf) == 0.1234); - CHK(ssf_phase_sample(phase, rng, data->wo, wi, &pdf) == 0.1234); + ssf_phase_sample(phase, rng, data->wo, wi, NULL); + ssf_phase_sample(phase, rng, data->wo, wi, &pdf); CHK(pdf == 4); d3_normalize(data->wi, wi); diff --git a/src/test_ssf_utils.h b/src/test_ssf_utils.h @@ -193,7 +193,7 @@ phase_dummy_release(void* phase) (void)phase; } -static double +static void phase_dummy_sample (void* phase, struct ssp_rng* rng, @@ -202,7 +202,6 @@ phase_dummy_sample double* pdf) { (void)phase, (void)rng, (void)w, (void)dir, (void)pdf; - return 0.0; } static double