@@ -67,7 +67,7 @@ ccl_device_inline float area_light_rect_sample(const float3 P,
6767 * the extra +pi that would remain in the expression for au can be removed by flipping the sign
6868 * of cos(au) and sin(au), which also cancels if we flip the sign of b1 in the fu term. */
6969 const float au = rand.x * S + g2 + g3;
70- const float fu = (cosf (au) * b0 + b1) / sinf (au);
70+ const float fu = safe_divide (cosf (au) * b0 + b1, sinf (au) );
7171 float cu = copysignf (1 .0f / sqrtf (fu * fu + b0sq), fu);
7272 cu = clamp (cu, -1 .0f , 1 .0f );
7373 /* Compute xu. */
@@ -96,7 +96,7 @@ ccl_device_inline float area_light_rect_sample(const float3 P,
9696 * needed for the case where the light is viewed from grazing angles, see e.g. #98930.
9797 */
9898 const float t = len (dir);
99- return -t * t * t / (z0 * len_u * len_v);
99+ return safe_divide ( -t * t * t, (z0 * len_u * len_v) );
100100 }
101101 return 1 .0f / S;
102102}
@@ -306,7 +306,7 @@ ccl_device_inline bool area_light_eval(const ccl_global KernelLight *klight,
306306
307307 if (sample_coord) {
308308 *light_P = light_P_new;
309- ls->D = normalize_len (*light_P - ray_P, &ls->t );
309+ ls->D = safe_normalize_len (*light_P - ray_P, &ls->t );
310310 }
311311
312312 /* Convert radiant flux to radiance. */
@@ -384,7 +384,7 @@ ccl_device_forceinline void area_light_mnee_sample_update(const ccl_global Kerne
384384 area_light_eval<false >(klight, P, &ls->P , ls, zero_float2 (), true );
385385 }
386386 else {
387- ls->D = normalize_len (ls->P - P, &ls->t );
387+ ls->D = safe_normalize_len (ls->P - P, &ls->t );
388388 area_light_eval<false >(klight, P, &ls->P , ls, zero_float2 (), false );
389389 /* Convert pdf to be in area measure. */
390390 ls->pdf /= light_pdf_area_to_solid_angle (ls->Ng , -ls->D , ls->t );
0 commit comments