From e992aac1d93fdea60ad2534c3285686f54da1a13 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Tue, 27 Mar 2018 19:31:01 -0700 Subject: [PATCH] Mark glTF materials with FBX origins. Because we make a best-effort attempt to convert materials on the old form -- like :ambert and Phong -- to PBR materials, it can be beneficial to the consumer of the asset to know if the asset was intentionally authored as PBR, or if it was a conversion. The precise details of this information is specific to the intersection of FBX and glTF, so we're not going to bother proposing extensions; we just drop something into the extras field, e.g. "materials": [ { "name": "Troll_Water", "alphaMode": "OPAQUE", "extras": { "fromFBX": { "shadingModel": "Metallic/Roughness", "isTruePBR": true } }, // ... and so on. The possible values for shadingModel are: "" "Constant" "Lambert" "Blinn" "Phong" "Metallic/Roughness" Currently isTruePBR is true for the final entry, false for the other. However, we may well add more PBR shading models in the future, so if you intend to use this feature to look for true PBR, use the derived property. --- src/Raw2Gltf.cpp | 3 ++- src/glTF/MaterialData.cpp | 13 ++++++++++--- src/glTF/MaterialData.h | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index 919803e..40739d4 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -751,7 +751,8 @@ ModelData *Raw2Gltf( std::shared_ptr mData = gltf->materials.hold( new MaterialData( - material.name, isTransparent, normalTexture, occlusionTexture, emissiveTexture, + material.name, isTransparent, material.info->shadingModel, + normalTexture, occlusionTexture, emissiveTexture, emissiveFactor * emissiveIntensity, khrCmnUnlitMat, pbrMetRough)); materialsByName[materialHash(material)] = mData; } diff --git a/src/glTF/MaterialData.cpp b/src/glTF/MaterialData.cpp index 3fbad6e..4a28d26 100644 --- a/src/glTF/MaterialData.cpp +++ b/src/glTF/MaterialData.cpp @@ -79,13 +79,14 @@ void to_json(json &j, const PBRMetallicRoughness &d) } MaterialData::MaterialData( - std::string name, bool isTransparent, const TextureData *normalTexture, - const TextureData *occlusionTexture, + std::string name, bool isTransparent, const RawShadingModel shadingModel, + const TextureData *normalTexture, const TextureData *occlusionTexture, const TextureData *emissiveTexture, const Vec3f & emissiveFactor, std::shared_ptr const khrCmnConstantMaterial, std::shared_ptr const pbrMetallicRoughness) : Holdable(), name(std::move(name)), + shadingModel(shadingModel), isTransparent(isTransparent), normalTexture(Tex::ref(normalTexture)), occlusionTexture(Tex::ref(occlusionTexture)), @@ -98,7 +99,13 @@ json MaterialData::serialize() const { json result = { { "name", name }, - { "alphaMode", isTransparent ? "BLEND" : "OPAQUE" } + { "alphaMode", isTransparent ? "BLEND" : "OPAQUE" }, + { "extras", { + { "fromFBX", { + { "shadingModel", Describe(shadingModel) }, + { "isTruePBR", shadingModel == RAW_SHADING_MODEL_PBR_MET_ROUGH } + }} + }} }; if (normalTexture != nullptr) { diff --git a/src/glTF/MaterialData.h b/src/glTF/MaterialData.h index 4ff4f1a..170c093 100644 --- a/src/glTF/MaterialData.h +++ b/src/glTF/MaterialData.h @@ -44,8 +44,8 @@ struct PBRMetallicRoughness struct MaterialData : Holdable { MaterialData( - std::string name, bool isTransparent, const TextureData *normalTexture, - const TextureData *occlusionTexture, + std::string name, bool isTransparent, RawShadingModel shadingModel, + const TextureData *normalTexture, const TextureData *occlusionTexture, const TextureData *emissiveTexture, const Vec3f &emissiveFactor, std::shared_ptr const khrCmnConstantMaterial, std::shared_ptr const pbrMetallicRoughness); @@ -53,6 +53,7 @@ struct MaterialData : Holdable json serialize() const override; const std::string name; + const RawShadingModel shadingModel; const bool isTransparent; const std::unique_ptr normalTexture; const std::unique_ptr occlusionTexture;