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:
    "<unknown>"
    "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.
This commit is contained in:
Par Winzell 2018-03-27 19:31:01 -07:00
parent ca12a38afe
commit e992aac1d9
3 changed files with 15 additions and 6 deletions

View File

@ -751,7 +751,8 @@ ModelData *Raw2Gltf(
std::shared_ptr<MaterialData> mData = gltf->materials.hold( std::shared_ptr<MaterialData> mData = gltf->materials.hold(
new MaterialData( new MaterialData(
material.name, isTransparent, normalTexture, occlusionTexture, emissiveTexture, material.name, isTransparent, material.info->shadingModel,
normalTexture, occlusionTexture, emissiveTexture,
emissiveFactor * emissiveIntensity, khrCmnUnlitMat, pbrMetRough)); emissiveFactor * emissiveIntensity, khrCmnUnlitMat, pbrMetRough));
materialsByName[materialHash(material)] = mData; materialsByName[materialHash(material)] = mData;
} }

View File

@ -79,13 +79,14 @@ void to_json(json &j, const PBRMetallicRoughness &d)
} }
MaterialData::MaterialData( MaterialData::MaterialData(
std::string name, bool isTransparent, const TextureData *normalTexture, std::string name, bool isTransparent, const RawShadingModel shadingModel,
const TextureData *occlusionTexture, const TextureData *normalTexture, const TextureData *occlusionTexture,
const TextureData *emissiveTexture, const Vec3f & emissiveFactor, const TextureData *emissiveTexture, const Vec3f & emissiveFactor,
std::shared_ptr<KHRCmnUnlitMaterial> const khrCmnConstantMaterial, std::shared_ptr<KHRCmnUnlitMaterial> const khrCmnConstantMaterial,
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness) std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness)
: Holdable(), : Holdable(),
name(std::move(name)), name(std::move(name)),
shadingModel(shadingModel),
isTransparent(isTransparent), isTransparent(isTransparent),
normalTexture(Tex::ref(normalTexture)), normalTexture(Tex::ref(normalTexture)),
occlusionTexture(Tex::ref(occlusionTexture)), occlusionTexture(Tex::ref(occlusionTexture)),
@ -98,7 +99,13 @@ json MaterialData::serialize() const
{ {
json result = { json result = {
{ "name", name }, { "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) { if (normalTexture != nullptr) {

View File

@ -44,8 +44,8 @@ struct PBRMetallicRoughness
struct MaterialData : Holdable struct MaterialData : Holdable
{ {
MaterialData( MaterialData(
std::string name, bool isTransparent, const TextureData *normalTexture, std::string name, bool isTransparent, RawShadingModel shadingModel,
const TextureData *occlusionTexture, const TextureData *normalTexture, const TextureData *occlusionTexture,
const TextureData *emissiveTexture, const Vec3f &emissiveFactor, const TextureData *emissiveTexture, const Vec3f &emissiveFactor,
std::shared_ptr<KHRCmnUnlitMaterial> const khrCmnConstantMaterial, std::shared_ptr<KHRCmnUnlitMaterial> const khrCmnConstantMaterial,
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness); std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness);
@ -53,6 +53,7 @@ struct MaterialData : Holdable
json serialize() const override; json serialize() const override;
const std::string name; const std::string name;
const RawShadingModel shadingModel;
const bool isTransparent; const bool isTransparent;
const std::unique_ptr<const Tex> normalTexture; const std::unique_ptr<const Tex> normalTexture;
const std::unique_ptr<const Tex> occlusionTexture; const std::unique_ptr<const Tex> occlusionTexture;