Skip to content

Commit 58aad07

Browse files
authored
Fix numeric error
1 parent 5bb3bd1 commit 58aad07

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

RadeonRays/src/kernels/CL/common.cl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,17 @@ float2 triangle_calculate_barycentrics(float3 p, float3 v1, float3 v2, float3 v3
243243
float const d20 = dot(e, e1);
244244
float const d21 = dot(e, e2);
245245

246+
float denom = (d00 * d11 - d01 * d01);
247+
248+
if (denom == 0.f)
249+
{
250+
return make_float2(0.f, 0.f);
251+
}
252+
246253
#ifdef USE_SAFE_MATH
247-
float const invdenom = 1.f / (d00 * d11 - d01 * d01);
254+
float const invdenom = 1.f / denom;
248255
#else
249-
float const invdenom = native_recip(d00 * d11 - d01 * d01);
256+
float const invdenom = native_recip(denom);
250257
#endif
251258

252259
float const b1 = (d11 * d20 - d01 * d21) * invdenom;

0 commit comments

Comments
 (0)