From aac668b094b96a62a7ac83664558c2b166bddb45 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 1 Dec 2022 11:43:10 +0100 Subject: [PATCH] Beckmann distribution changed. It's working now, but maybe too good?? --- shader/cooktorranceshader.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/shader/cooktorranceshader.cpp b/shader/cooktorranceshader.cpp index 5d019c5..8f0c78a 100644 --- a/shader/cooktorranceshader.cpp +++ b/shader/cooktorranceshader.cpp @@ -38,21 +38,15 @@ Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const { } float CookTorranceShader::D(float NdotH) const { - float divisor = 4.0f * m * m * std::pow(cos(NdotH), 4); - float exponent = std::pow(tan(NdotH) / m, 2); - return 1 / divisor * std::exp(- 1.0f * exponent); + float divisor = 4.0f * m * m * std::pow(NdotH, 4.0f); + float exponent = (NdotH * NdotH - 1.0f) / (m * m * NdotH * NdotH); + return 1 / divisor * std::exp(exponent); } float CookTorranceShader::F(float VdotH) const { - return F0 + (1 - F0) * std::pow(1 - VdotH, 5); + return F0 + (1.0f - F0) * std::pow(1.0f - VdotH, 5.0f); } float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const { - if (std::abs(NdotL) < 0.1f) { return std::min(1.0f, std::min(2 * NdotH * NdotV / VdotH, 2 * NdotH * NdotL / VdotH)); - } else if (std::abs(NdotV) < 0.1f) { - return 2 * NdotH * NdotL / VdotH; - } else { - return 1; - } }