From b62149c08f835068215b48110df876ae8d481969 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Wed, 23 May 2012 13:09:50 -0400 Subject: Diffuse reflection is lambertian, not isotropic. --- chroma/cuda/photon.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chroma/cuda/photon.h b/chroma/cuda/photon.h index 310f09d..00aee95 100644 --- a/chroma/cuda/photon.h +++ b/chroma/cuda/photon.h @@ -356,10 +356,15 @@ propagate_at_specular_reflector(Photon &p, State &s) __device__ int propagate_at_diffuse_reflector(Photon &p, State &s, curandState &rng) { - p.direction = uniform_sphere(&rng); - - if (dot(p.direction, s.surface_normal) < 0.0f) - p.direction = -p.direction; + float ndotv; + do { + p.direction = uniform_sphere(&rng); + ndotv = dot(p.direction, s.surface_normal); + if (ndotv < 0.0f) { + p.direction = -p.direction; + ndotv = -ndotv; + } + } while (! (curand_uniform(&rng) < ndotv) ); p.polarization = cross(uniform_sphere(&rng), p.direction); p.polarization /= norm(p.polarization); -- cgit