Fix #110255: Cover up CPU/GPU differences with small suns in light tree

This pull request covers up a subtle difference between the CPU and GPU
when rendering with a light tree. Specifically a case where the user
has a sun light with a small angle.

The difference was caused by the dot() function being different between
CPU and GPU backends, with the GPU showing more meaningful
floating-point precision losses when working with small suns.

Pull Request: https://projects.blender.org/blender/blender/pulls/110307
This commit is contained in:
Alaska 2023-08-07 07:29:14 +02:00 committed by Weizhen Huang
parent 58e4a7ae2b
commit 52ed6a216f
1 changed files with 12 additions and 2 deletions

View File

@ -174,9 +174,19 @@ ccl_device void light_tree_importance(const float3 N_or_D,
cos_max_incidence_angle = fmaxf(cos_theta_i * cos_theta_u - sin_theta_i * sin_theta_u, 0.0f);
}
float cos_theta, sin_theta;
if (isequal(bcone.axis, -point_to_centroid)) {
/* When `bcone.axis == -point_to_centroid`, dot(bcone.axis, -point_to_centroid) doesn't always
* return 1 due to floating point precision issues. We account for that case here. */
cos_theta = 1.0f;
sin_theta = 0.0f;
}
else {
cos_theta = dot(bcone.axis, -point_to_centroid);
sin_theta = sin_from_cos(cos_theta);
}
/* cos(theta - theta_u) */
const float cos_theta = dot(bcone.axis, -point_to_centroid);
const float sin_theta = sin_from_cos(cos_theta);
const float cos_theta_minus_theta_u = cos_theta * cos_theta_u + sin_theta * sin_theta_u;
float cos_theta_o, sin_theta_o;