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.
This commit is contained in:
Weizhen Huang
2023-09-06 16:16:34 +02:00
parent 00a36cbf24
commit fedeaab30f

View File

@@ -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. */