From c3c496668a9b7d1ed20c8252418a0f0cf135d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Boy=C3=A9?= Date: Fri, 9 Feb 2024 11:57:50 +0100 Subject: [PATCH] Fix invalid output resulting from precision issues --- include/nori/dpdf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nori/dpdf.h b/include/nori/dpdf.h index f471706a..bcddc0ab 100644 --- a/include/nori/dpdf.h +++ b/include/nori/dpdf.h @@ -140,6 +140,7 @@ struct DiscretePDF { size_t index = sample(sampleValue); sampleValue = (sampleValue - m_cdf[index]) / (m_cdf[index + 1] - m_cdf[index]); + sampleValue = std::clamp(sampleValue, 0.0f, 1.0f); return index; } @@ -159,6 +160,7 @@ struct DiscretePDF { size_t index = sample(sampleValue, pdf); sampleValue = (sampleValue - m_cdf[index]) / (m_cdf[index + 1] - m_cdf[index]); + sampleValue = std::clamp(sampleValue, 0.0f, 1.0f); return index; }