From a16879a5f05594faaf2c392fb0fee1d5b2317cd3 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Tue, 10 Dec 2024 21:56:04 +0100 Subject: [PATCH] Fix #131240: Cycles: Negative integration range in Huang Hair The cause is numerical issues with `fast_sinf()`. While fixing `fast_sinf()` would ultimately fix the problem, it involves more complications in other code paths, and it is safer to clamp the integration range anyway. Pull Request: https://projects.blender.org/blender/blender/pulls/131689 --- intern/cycles/kernel/closure/bsdf_principled_hair_huang.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h b/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h index 4dbe44dfafa..4076218257e 100644 --- a/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h +++ b/intern/cycles/kernel/closure/bsdf_principled_hair_huang.h @@ -856,6 +856,14 @@ ccl_device Spectrum bsdf_hair_huang_eval(KernelGlobals kg, bsdf->extra->gamma_m_min = gamma_m_min; bsdf->extra->gamma_m_max = gamma_m_max; + /* FIXME(weizhen): There is a problem of `fast_sinf(-1.57085085f)` returning 0 instead of + * expected -1, causing the range to be incorrect. As that seems an uncommon case, it feels safer + * to cover this case first, and look into solving the problem in `fast_sinf()` later. */ + kernel_assert(bsdf->extra->gamma_m_min < bsdf->extra->gamma_m_max); + if (!(bsdf->extra->gamma_m_min < bsdf->extra->gamma_m_max)) { + return zero_spectrum(); + } + const float projected_area = cos_theta(local_I) * dh; return (bsdf_hair_huang_eval_r(kg, sc, local_I, local_O) +