Fix #125750: NaN on Glossy materials with low roughness

Fix a NaN when rendering glossy materials that can appear due to a
division by zero in bsdf_D when rendering materials with low roughness.

Thank you to Weizhen for the fix after my incorrect
first attempt.

Pull Request: https://projects.blender.org/blender/blender/pulls/125756
This commit is contained in:
Alaska
2024-08-02 16:28:42 +02:00
committed by Weizhen Huang
parent 09390858ab
commit 5b61a01c19

View File

@@ -508,7 +508,7 @@ ccl_device_inline float bsdf_G(float alpha2, float cos_NI, float cos_NO)
/* Normal distribution function. */
template<MicrofacetType m_type> ccl_device_inline float bsdf_D(float alpha2, float cos_NH)
{
const float cos_NH2 = sqr(cos_NH);
const float cos_NH2 = min(sqr(cos_NH), 1.0f);
if (m_type == MicrofacetType::BECKMANN) {
return expf((1.0f - 1.0f / cos_NH2) / alpha2) / (M_PI_F * alpha2 * sqr(cos_NH2));