Merge pull request #1516 from Matter-and-Form/gltf2-export-roughness-from-shininess-fix

[gltf2 export] Fix shininess to roughness conversion
pull/1519/head
Kim Kulling 2017-10-27 20:14:23 +02:00 committed by GitHub
commit 89d198399c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -446,15 +446,15 @@ void glTF2Exporter::ExportMaterials()
) { ) {
// convert specular color to luminance // convert specular color to luminance
float specularIntensity = specularColor[0] * 0.2125 + specularColor[1] * 0.7154 + specularColor[2] * 0.0721; float specularIntensity = specularColor[0] * 0.2125 + specularColor[1] * 0.7154 + specularColor[2] * 0.0721;
float roughnessFactor = 1 - std::sqrt(shininess / 1000); //normalize shininess (assuming max is 1000) with an inverse exponentional curve
float normalizedShininess = std::sqrt(shininess / 1000);
roughnessFactor = std::pow(roughnessFactor, 2);
roughnessFactor = std::min(std::max(roughnessFactor, 0.0f), 1.0f);
//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. // 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;
} }
} }