Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-10-22 20:06:25 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-29 13:10:14 +0300
commit673bc6d65ae672cd6986f3e6c9cd62f885054896 (patch)
tree5360b4f06d6f096e095b78cf576afcf262b55644
parentce268f6005a6317b0f4fdd8b901dada2ba549919 (diff)
Cycles: Fix for watertight intersection
It was possible to miss some intersection caused by wrong barycentric coordinates sign. Cases when one of the coordinate is zero and other are negative was not handled correct.
-rw-r--r--intern/cycles/kernel/geom/geom_triangle_intersect.h13
1 files changed, 5 insertions, 8 deletions
diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h
index ba309a1dc53..1ce4eea48f4 100644
--- a/intern/cycles/kernel/geom/geom_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h
@@ -142,12 +142,8 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg,
float U = Cx * By - Cy * Bx;
float V = Ax * Cy - Ay * Cx;
float W = Bx * Ay - By * Ax;
- const int sign_mask = (__float_as_int(U) & 0x80000000);
- /* TODO(sergey): Check if multiplication plus sign check is faster
- * or at least same speed (but robust for endian types).
- */
- if(sign_mask != (__float_as_int(V) & 0x80000000) ||
- sign_mask != (__float_as_int(W) & 0x80000000))
+ if ((U < 0.0f || V < 0.0f || W < 0.0f) &&
+ (U > 0.0f || V > 0.0f || W > 0.0f))
{
return false;
}
@@ -162,9 +158,10 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg,
* the hit distance.
*/
const float T = (U * A_kz + V * B_kz + W * C_kz) * Sz;
- const float sign_T = xor_signmask(T, sign_mask);
+ const int sign_det = (__float_as_int(det) & 0x80000000);
+ const float sign_T = xor_signmask(T, sign_det);
if((sign_T < 0.0f) ||
- (sign_T > isect->t * xor_signmask(det, sign_mask)))
+ (sign_T > isect->t * xor_signmask(det, sign_det)))
{
return false;
}