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 b695e6b6ce02976610a0532c485ed9aa9d72a1f0
parent d7de821f5287bd8cba8392849c5251ed27efa118
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 19 Jul 2018 15:10:17 +0200

Fix the evaluation of the HG phase function

Diffstat:
Msrc/ssf_phase_hg.c | 8+++++++-
Msrc/test_ssf_phase_hg.c | 9+++++----
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/ssf_phase_hg.c b/src/ssf_phase_hg.c @@ -43,13 +43,19 @@ static double hg_eval(void* data, const double wo[3], const double wi[3]) { const struct hg* hg = data; + double w[3]; double g; double cos_theta; double denom; ASSERT(data && wo && wi); ASSERT(d3_is_normalized(wo) && d3_is_normalized(wi)); + g = hg->g; - cos_theta = d3_dot(wi, wo); + /* By convention wo point outward the scattering point. Revert it to point + * inward the scattering point in order to compute the cosine of the + * scattering angle */ + d3_minus(w, wo); + cos_theta = d3_dot(w, wi); denom = 1 + g*g - 2*g*cos_theta; ASSERT(denom != 0); return 1.0/(4.0*PI) * (1 - g*g) / (denom*sqrt(denom)); diff --git a/src/test_ssf_phase_hg.c b/src/test_ssf_phase_hg.c @@ -63,13 +63,14 @@ main(int argc, char** argv) ssf_phase_sample(phase, rng, wo, wi, &pdf); CHK(d3_is_normalized(wi)); CHK(eq_eps(ssf_phase_pdf(phase, wo, wi), pdf, 1.e-6)); - r = ssf_phase_eval(phase, wo, wi); - /* HG(theta) = 1/(4*PI) * (1 - g^2) / (1 + g^2 - 2*g*cos(theta))^3/2 */ - ref = 1/(4*PI) * (1-g*g) / pow(1+g*g-2*g*d3_dot(wi,wo), 1.5); - CHK(eq_eps(r, ref, 1.e-6)); w = d3_dot(wo, wi); sum_cos += w; sum_cos_sqr += w*w; + + /* HG(theta) = 1/(4*PI) * (1 - g^2) / (1 + g^2 - 2*g*cos(theta))^3/2 */ + r = ssf_phase_eval(phase, wo, wi); + ref = 1/(4*PI) * (1-g*g) / pow(1+g*g-2*g*d3_dot(wi,d3_minus(wo,wo)), 1.5); + CHK(eq_eps(r, ref, 1.e-6)); } /* On average cos(wo, wi) should be g */ E = sum_cos / NSAMPS;