Handle 'inverse roughness' flag.

This commit is contained in:
Par Winzell 2019-01-25 14:33:53 -08:00
parent d0883136d3
commit ce2a9f8d85
5 changed files with 22 additions and 7 deletions

View File

@ -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<FbxTraditionalMaterialInfo*>(fbxMaterial.get());

View File

@ -65,9 +65,6 @@ std::unique_ptr<FbxRoughMetMaterialInfo> 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<FbxRoughMetMaterialInfo> 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<FbxRoughMetMaterialInfo> Fbx3dsMaxPhysicalMaterialResolver::reso
res->texMetallic = metalnessMap;
res->texRoughness = roughnessMap;
res->invertRoughnessMap = invertRoughness;
res->emissive = emissiveColor;
res->emissiveIntensity = emissiveWeight;

View File

@ -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;

View File

@ -276,7 +276,13 @@ ModelData* Raw2Gltf(
},
"ao_met_rough",
[&](const std::vector<const TextureBuilder::pixel*> 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);

View File

@ -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)) {