From 4974ed93ef50437084e6d3b03530fffdc58ea834 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 8 Oct 2015 21:14:14 +0500 Subject: Cycles: Fix issues with quick inverse of degenerate matrix This fixes part of the issues reported in T46322. Still need to solve issue with wrong intersection distance scaling. --- intern/cycles/util/util_transform.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'intern/cycles/util') diff --git a/intern/cycles/util/util_transform.h b/intern/cycles/util/util_transform.h index ba8d04b5c16..44502737ec6 100644 --- a/intern/cycles/util/util_transform.h +++ b/intern/cycles/util/util_transform.h @@ -347,7 +347,12 @@ ccl_device_inline Transform transform_quick_inverse(Transform M) * scale can be inverted but what about shearing? */ Transform R; float det = M.x.x*(M.z.z*M.y.y - M.z.y*M.y.z) - M.y.x*(M.z.z*M.x.y - M.z.y*M.x.z) + M.z.x*(M.y.z*M.x.y - M.y.y*M.x.z); - + if(det == 0.0f) { + M[0][0] += 1e-8f; + M[1][1] += 1e-8f; + M[2][2] += 1e-8f; + det = M.x.x*(M.z.z*M.y.y - M.z.y*M.y.z) - M.y.x*(M.z.z*M.x.y - M.z.y*M.x.z) + M.z.x*(M.y.z*M.x.y - M.y.y*M.x.z); + } det = (det != 0.0f)? 1.0f/det: 0.0f; float3 Rx = det*make_float3(M.z.z*M.y.y - M.z.y*M.y.z, M.z.y*M.x.z - M.z.z*M.x.y, M.y.z*M.x.y - M.y.y*M.x.z); -- cgit v1.2.3