ccl_device_forceinline bool point_intersect_test(const float4 point, const float3 P, const float3 dir, float *t) { const float3 center = float4_to_float3(point); const float radius = point.w; const float rd2 = 1.0f / dot(dir, dir); const float3 c0 = center - P; const float projC0 = dot(c0, dir) * rd2; const float3 perp = c0 - projC0 * dir; const float l2 = dot(perp, perp); const float r2 = radius * radius; if (!(l2 <= r2)) { return false; } const float td = sqrt((r2 - l2) * rd2); const float t_front = projC0 - td; const float t_back = projC0 + td; const bool valid_front = (0.0f <= t_front) & (t_front <= *t); const bool valid_back = (0.0f <= t_back) & (t_back <= *t); /* check if there is a first hit */ const bool valid_first = valid_front | valid_back; if (!valid_first) { return false; } *t = (valid_front) ? t_front : t_back; return true; }