diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h index 5e8c4c02650bfbd42686d7aca579513e77a6a3ca..f9b89e869a25c2077facc3f26a5f582d95fa250f 100644 --- a/intern/cycles/kernel/closure/bsdf_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_microfacet.h @@ -509,13 +509,14 @@ ccl_device_inline float bsdf_G(float alpha2, float cos_NI, float cos_NO) template<MicrofacetType m_type> ccl_device_inline float bsdf_D(float alpha2, float cos_NH) { const float cos_NH2 = min(sqr(cos_NH), 1.0f); + const float one_minus_cos_NH2 = 1.0f - cos_NH2; if (m_type == MicrofacetType::BECKMANN) { - return expf((cos_NH2 - 1.0f) / (cos_NH2 * alpha2)) / (M_PI_F * alpha2 * sqr(cos_NH2)); + return 1.0f / (expf(one_minus_cos_NH2 / (cos_NH2 * alpha2)) * M_PI_F * alpha2 * sqr(cos_NH2)); } else { kernel_assert(m_type == MicrofacetType::GGX); - return alpha2 / (M_PI_F * sqr((1.0f - cos_NH2) + alpha2 * cos_NH2)); + return alpha2 / (M_PI_F * sqr(one_minus_cos_NH2 + alpha2 * cos_NH2)); } }