From ce2a9f8d85b4226f805668dc8baddf9c29209d18 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Fri, 25 Jan 2019 14:33:53 -0800 Subject: [PATCH] Handle 'inverse roughness' flag. --- src/fbx/Fbx2Raw.cpp | 3 ++- src/fbx/materials/3dsMaxPhysicalMaterial.cpp | 10 +++++++--- src/fbx/materials/RoughnessMetallicMaterials.hpp | 1 + src/gltf/Raw2Gltf.cpp | 8 +++++++- src/raw/RawModel.hpp | 7 +++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/fbx/Fbx2Raw.cpp b/src/fbx/Fbx2Raw.cpp index 5695dbc..3b31cc7 100644 --- a/src/fbx/Fbx2Raw.cpp +++ b/src/fbx/Fbx2Raw.cpp @@ -249,7 +249,8 @@ static void ReadMesh( toVec3f(fbxMatInfo->emissive), fbxMatInfo->emissiveIntensity, fbxMatInfo->metallic, - fbxMatInfo->roughness)); + fbxMatInfo->roughness, + fbxMatInfo->invertRoughnessMap)); } else { FbxTraditionalMaterialInfo* fbxMatInfo = static_cast(fbxMaterial.get()); diff --git a/src/fbx/materials/3dsMaxPhysicalMaterial.cpp b/src/fbx/materials/3dsMaxPhysicalMaterial.cpp index 5f52239..aa619cd 100644 --- a/src/fbx/materials/3dsMaxPhysicalMaterial.cpp +++ b/src/fbx/materials/3dsMaxPhysicalMaterial.cpp @@ -65,9 +65,6 @@ std::unique_ptr Fbx3dsMaxPhysicalMaterialResolver::reso roughness = 1.0f - roughness; } - // TODO: turn this into a normal map through simple numerial differentiation - const auto* bumpMap = getTex("bump"); - std::string unsupported; const auto addUnsupported = [&](const std::string bit) { if (!unsupported.empty()) { @@ -76,6 +73,12 @@ std::unique_ptr Fbx3dsMaxPhysicalMaterialResolver::reso unsupported += bit; }; + // TODO: turn this into a normal map through simple numerial differentiation + const auto* bumpMap = getTex("bump"); + if (bumpMap != nullptr) { + addUnsupported("bump map"); + } + // TODO: bake transparency > 0.0f into the alpha of baseColor? double transparency = getValue(props, "transparency", 0.0); const auto* transparencyMap = getTex("transparency"); @@ -157,6 +160,7 @@ std::unique_ptr Fbx3dsMaxPhysicalMaterialResolver::reso res->texMetallic = metalnessMap; res->texRoughness = roughnessMap; + res->invertRoughnessMap = invertRoughness; res->emissive = emissiveColor; res->emissiveIntensity = emissiveWeight; diff --git a/src/fbx/materials/RoughnessMetallicMaterials.hpp b/src/fbx/materials/RoughnessMetallicMaterials.hpp index f994e3a..9123e28 100644 --- a/src/fbx/materials/RoughnessMetallicMaterials.hpp +++ b/src/fbx/materials/RoughnessMetallicMaterials.hpp @@ -35,6 +35,7 @@ struct FbxRoughMetMaterialInfo : FbxMaterialInfo { const FbxDouble metallic; const FbxDouble roughness; + FbxBool invertRoughnessMap = false; FbxDouble baseWeight = 1; FbxVector4 emissive = FbxVector4(0, 0, 0, 1); FbxDouble emissiveIntensity = 1; diff --git a/src/gltf/Raw2Gltf.cpp b/src/gltf/Raw2Gltf.cpp index d14c725..6542641 100644 --- a/src/gltf/Raw2Gltf.cpp +++ b/src/gltf/Raw2Gltf.cpp @@ -276,7 +276,13 @@ ModelData* Raw2Gltf( }, "ao_met_rough", [&](const std::vector pixels) -> TextureBuilder::pixel { - return {{(*pixels[0])[0], (*pixels[2])[0], (*pixels[1])[0], 1}}; + const float occlusion = (*pixels[0])[0]; + const float metallic = (*pixels[1])[0]; + const float roughness = (*pixels[2])[0]; + return {{occlusion, + props->invertRoughnessMap ? 1.0f - roughness : roughness, + metallic, + 1}}; }, false); diff --git a/src/raw/RawModel.hpp b/src/raw/RawModel.hpp index df134fa..0b81903 100644 --- a/src/raw/RawModel.hpp +++ b/src/raw/RawModel.hpp @@ -234,18 +234,21 @@ struct RawMetRoughMatProps : RawMatProps { const Vec3f&& emissiveFactor, float emissiveIntensity, float metallic, - float roughness) + float roughness, + bool invertRoughnessMap) : RawMatProps(shadingModel), diffuseFactor(diffuseFactor), emissiveFactor(emissiveFactor), emissiveIntensity(emissiveIntensity), metallic(metallic), - roughness(roughness) {} + roughness(roughness), + invertRoughnessMap(invertRoughnessMap) {} const Vec4f diffuseFactor; const Vec3f emissiveFactor; const float emissiveIntensity; const float metallic; const float roughness; + const bool invertRoughnessMap; bool operator==(const RawMatProps& other) const override { if (RawMatProps::operator==(other)) {