[Bf-blender-cvs] [08c1f5bf335] master: Cycles: Improve sampling of area lights

Antony Ryakiotakis noreply at git.blender.org
Sat May 23 14:31:49 CEST 2020


Commit: 08c1f5bf335992ff797e9543f50b1b90f96e8369
Author: Antony Ryakiotakis
Date:   Sat May 23 14:21:49 2020 +0200
Branches: master
https://developer.blender.org/rB08c1f5bf335992ff797e9543f50b1b90f96e8369

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

===================================================================

M	intern/cycles/kernel/kernel_light.h

===================================================================

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 */



More information about the Bf-blender-cvs mailing list