diff options
author | Antony Ryakiotakis <kalast@gmail.com> | 2020-05-23 15:21:49 +0300 |
---|---|---|
committer | Antony Ryakiotakis <kalast@gmail.com> | 2020-05-23 15:21:49 +0300 |
commit | 08c1f5bf335992ff797e9543f50b1b90f96e8369 (patch) | |
tree | 6cba6411b99c0104353be2ab3ee87e0d86eec685 /intern/cycles | |
parent | 86fa8dc7f73a38404c276351710a2226d0fc4510 (diff) |
Cycles: Improve sampling of area lights
This patch uses the sampling method described in "A Low Distortion Map Between Triangle and Square" by Eric Heitz.
The benefit is avoiding sqrt in the calculation, which could be cheaper on some architectures, and the result is
more even sampling across the triangle surface.
Based on ideas from
https://pharr.org/matt/blog/2019/02/27/triangle-sampling-1.html
https://pharr.org/matt/blog/2019/03/13/triangle-sampling-1.5.html
Reviewed By: Brecht Van Lommel
Differential Revision: https://developer.blender.org/D6566
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/kernel_light.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h index ce908ce0fe2..d918abed381 100644 --- a/intern/cycles/kernel/kernel_light.h +++ b/intern/cycles/kernel/kernel_light.h @@ -1041,11 +1041,19 @@ ccl_device_forceinline void triangle_light_sample(KernelGlobals *kg, } } else { - /* compute random point in triangle */ - randu = sqrtf(randu); + /* compute random point in triangle. From Eric Heitz's "A Low-Distortion Map Between Triangle + * and Square" */ + float u = randu; + float v = randv; + if (v > u) { + u *= 0.5f; + v -= u; + } + else { + v *= 0.5f; + u -= v; + } - const float u = 1.0f - randu; - const float v = randv * randu; const float t = 1.0f - u - v; ls->P = u * V[0] + v * V[1] + t * V[2]; /* compute incoming direction, distance and pdf */ |