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
This commit is contained in:
Antonis Ryakiotakis 2020-05-23 14:21:49 +02:00
parent 86fa8dc7f7
commit 08c1f5bf33
1 changed files with 12 additions and 4 deletions

View File

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