From 80cf245b683f9f4cca9f66eac5200077180e9a26 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 4 Aug 2014 14:32:28 +0200 Subject: [PATCH] microfacet.h: roughness clamping --- include/mitsuba/core/math.h | 2 +- src/bsdfs/microfacet.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/mitsuba/core/math.h b/include/mitsuba/core/math.h index cf887b38..539a4214 100644 --- a/include/mitsuba/core/math.h +++ b/include/mitsuba/core/math.h @@ -114,7 +114,7 @@ inline int roundToInt(float value) { /// Integer round function (double precision) inline int roundToInt(double value) { #if defined(__MSVC__) - return (int) (value < 0.0f ? std::ceil(value - 0.5f) : std::floor(value + 0.5f)); + return (int) (value < 0.0 ? std::ceil(value - 0.5) : std::floor(value + 0.5)); #else return (int) ::round(value); #endif diff --git a/src/bsdfs/microfacet.h b/src/bsdfs/microfacet.h index 2c8dc419..9bc6af36 100644 --- a/src/bsdfs/microfacet.h +++ b/src/bsdfs/microfacet.h @@ -67,6 +67,8 @@ public: inline MicrofacetDistribution(EType type, Float alpha, bool sampleVisible = true) : m_type(type), m_alphaU(alpha), m_alphaV(alpha), m_sampleVisible(sampleVisible), m_exponentU(0.0f), m_exponentV(0.0f) { + m_alphaU = std::max(m_alphaU, (Float) 1e-4f); + m_alphaV = std::max(m_alphaV, (Float) 1e-4f); if (m_type == EPhong) computePhongExponent(); } @@ -84,6 +86,8 @@ public: inline MicrofacetDistribution(EType type, Float alphaU, Float alphaV, bool sampleVisible = true) : m_type(type), m_alphaU(alphaU), m_alphaV(alphaV), m_sampleVisible(sampleVisible), m_exponentU(0.0f), m_exponentV(0.0f) { + m_alphaU = std::max(m_alphaU, (Float) 1e-4f); + m_alphaV = std::max(m_alphaV, (Float) 1e-4f); if (m_type == EPhong) computePhongExponent(); } @@ -123,6 +127,14 @@ public: m_alphaV = props.getFloat("alphaV"); } + if (m_alphaU == 0 || m_alphaV == 0) { + SLog(EWarn, "Cannot create a microfacet distribution with alphaU/alphaV=0 (clamped to 0.0001)." + "Please use the corresponding smooth reflectance model to get zero roughness."); + } + + m_alphaU = std::max(m_alphaU, (Float) 1e-4f); + m_alphaV = std::max(m_alphaV, (Float) 1e-4f); + m_sampleVisible = props.getBoolean("sampleVisible", sampleVisible); /* Visible normal sampling is not supported for the Phong / Ashikhmin-Shirley distribution */