diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index ef925f7..671db6c 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -290,8 +290,10 @@ struct FbxTraditionalMaterialInfo : FbxMaterialInfo { // the normal map can only ever be a map, ignore everything else std::tie(std::ignore, res->texNormal) = getSurfaceVector(FbxSurfaceMaterial::sNormalMap); - // shininess can be a map or a factor - std::tie(res->shininess, res->texShininess) = getSurfaceScalar(FbxSurfaceMaterial::sShininess); + // shininess can be a map or a factor; afaict the map is always 'ShininessExponent' and the + // value is always found in 'Shininess' but only sometimes in 'ShininessExponent'. + std::tie(std::ignore, res->texShininess) = getSurfaceScalar("ShininessExponent"); + std::tie(res->shininess, std::ignore) = getSurfaceScalar("Shininess"); // for transparency we just want a constant vector value; FbxVector4 transparency; diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index e9de177..b27ec90 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -695,7 +695,7 @@ ModelData *Raw2Gltf( aoMetRoughTex = merge3Tex("ao_met_rough", RAW_TEXTURE_USAGE_OCCLUSION, RAW_TEXTURE_USAGE_METALLIC, RAW_TEXTURE_USAGE_ROUGHNESS, [&](const std::vector pixels) -> pixel { - return { (*pixels[0])[0], (*pixels[2])[0], (*pixels[1])[0], 0 }; + return { (*pixels[0])[0], (*pixels[2])[0], (*pixels[1])[0], 1 }; }, false); baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO); @@ -723,19 +723,22 @@ ModelData *Raw2Gltf( // blinn/phong hardcoded to 0.4 metallic metallic = 0.4f; - // fairly arbitrary formula chosen such that + // fairly arbitrary conversion equation, with properties: // shininess 0 -> roughness 1 - // shininess 5 -> roughness 0.5 + // shininess 2 -> roughness ~0.7 + // shininess 6 -> roughness 0.5 + // shininess 16 -> roughness ~0.33 + // as shininess ==> oo, roughness ==> 0 auto getRoughness = [&](float shininess) { - return 1.0f / (1.0f + shininess/5); + return sqrtf(2.0f / (2.0f + shininess)); }; aoMetRoughTex = merge1Tex("ao_met_rough", RAW_TEXTURE_USAGE_SHININESS, [&](const std::vector pixels) -> pixel { // do not multiply with props->shininess; that doesn't work like the other factors. - float shininess = (*pixels[0])[0]; - return { 0, getRoughness(shininess), metallic, 0 }; + float shininess = props->shininess * (*pixels[0])[0]; + return { 0, getRoughness(shininess), metallic, 1 }; }, false); if (aoMetRoughTex != nullptr) {