From 8b73ec7541e89e870140efa49e829fee5a32b9a0 Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Thu, 26 Oct 2017 11:33:33 -0400 Subject: [PATCH] Fix shininess to roughness conversion; Add comments Was accidentally flipping to value (1 - x) twice, thus negating the effect. --- code/glTF2Exporter.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 9e64155..d8cff89 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -446,15 +446,15 @@ void glTF2Exporter::ExportMaterials() ) { // convert specular color to luminance float specularIntensity = specularColor[0] * 0.2125 + specularColor[1] * 0.7154 + specularColor[2] * 0.0721; - float roughnessFactor = 1 - std::sqrt(shininess / 1000); - - roughnessFactor = std::pow(roughnessFactor, 2); - roughnessFactor = std::min(std::max(roughnessFactor, 0.0f), 1.0f); + //normalize shininess (assuming max is 1000) with an inverse exponentional curve + float normalizedShininess = std::sqrt(shininess / 1000); + //clamp the shininess value between 0 and 1 + normalizedShininess = std::min(std::max(normalizedShininess, 0.0f), 1.0f); // low specular intensity values should produce a rough material even if shininess is high. - roughnessFactor = 1 - (roughnessFactor * specularIntensity); + normalizedShininess = normalizedShininess * specularIntensity; - m->pbrMetallicRoughness.roughnessFactor = roughnessFactor; + m->pbrMetallicRoughness.roughnessFactor = 1 - normalizedShininess; } } -- 2.7.4