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:
parent
ca12a38afe
commit
e992aac1d9
|
@ -751,7 +751,8 @@ ModelData *Raw2Gltf(
|
|||
|
||||
std::shared_ptr<MaterialData> 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;
|
||||
}
|
||||
|
|
|
@ -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<KHRCmnUnlitMaterial> const khrCmnConstantMaterial,
|
||||
std::shared_ptr<PBRMetallicRoughness> 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) {
|
||||
|
|
|
@ -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<KHRCmnUnlitMaterial> const khrCmnConstantMaterial,
|
||||
std::shared_ptr<PBRMetallicRoughness> 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<const Tex> normalTexture;
|
||||
const std::unique_ptr<const Tex> occlusionTexture;
|
||||
|
|
Loading…
Reference in New Issue