From fedeaab30f81e908e63fd6890b242a61efb9a140 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Wed, 6 Sep 2023 16:16:34 +0200 Subject: [PATCH] Fix #112005: increase `ray_sphere_intersect()` precision by doing the subtraction first and then take the dot product. This offers higher precision than taking the dot product first and then subtract the result, especially in the cases where the ray origin is very far away from the sphere center. --- intern/cycles/util/math_intersect.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/cycles/util/math_intersect.h b/intern/cycles/util/math_intersect.h index c7277f38f25..b5eb209ec82 100644 --- a/intern/cycles/util/math_intersect.h +++ b/intern/cycles/util/math_intersect.h @@ -28,7 +28,7 @@ ccl_device bool ray_sphere_intersect(float3 ray_P, return false; } - const float d_sin_theta_sq = d_sq - d_cos_theta * d_cos_theta; + const float d_sin_theta_sq = len_squared(d_vec - d_cos_theta * ray_D); if (d_sin_theta_sq > r_sq) { /* Closest point on ray outside sphere. */