commit 8f3648209f3944484179bd1cefe2395efb958da3
parent d622392b5b6253692c1c3868b657804f33ea8c9d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 3 Oct 2016 16:53:09 +0200
Check the energy conservation on the Microfacet reflection test
Diffstat:
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/src/test_ssf_microfacet_reflection.c b/src/test_ssf_microfacet_reflection.c
@@ -28,6 +28,9 @@ main(int argc, char** argv)
struct ssf_fresnel* F;
struct ssf_microfacet_distribution* D;
struct ssp_rng* rng;
+ double N[4]; /* xyz, pdf */
+ double wo[4]; /* xyz, pdf */
+ size_t i, NSTEPS=100000;
(void)argc, (void)argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
@@ -49,33 +52,14 @@ main(int argc, char** argv)
CHECK(ssf_microfacet_reflection_setup(NULL, F, D), RES_BAD_ARG);
CHECK(ssf_microfacet_reflection_setup(bxdf, F, D), RES_OK);
- /* Numerically evaluate rho */
-#if 0
- {
- double N[3];
- double wo[3];
- double wi[3];
- double pdf;
- double sum, sum_sqr;
- double E, SE, V;
- size_t i, NSTEPS=1000;
-
- d3(N, 0, 1, 0);
- sum = sum_sqr = 0;
- ran_hemisphere_cos(N, wo, NULL);
- FOR_EACH(i, 0, NSTEPS) {
- double R;
- R = ssf_bxdf_sample(bxdf, rng, wo, N, wi, &pdf);
- sum += R;
- sum_sqr += R*R;
- }
-
- E = sum / (double)NSTEPS;
- V = sum_sqr / (double)NSTEPS - E*E;
- SE = sqrt(V/(double)NSTEPS);
- printf("%g +/- %g\n", E, SE);
+ /* Check energy conservation */
+ ssp_ran_sphere_uniform(rng, N);
+ ssp_ran_hemisphere_cos(rng, N, wo);
+ FOR_EACH(i, 0, NSTEPS) {
+ double wi[3], pdf;
+ CHECK(ssf_bxdf_sample(bxdf, rng, wo, N, wi, &pdf), 1);
+ CHECK(d3_dot(wi, N) > 0, 1);
}
-#endif
CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
CHECK(ssf_bxdf_ref_put(dummy), RES_OK);