From b855242450844d3076d0d695ef9682b820e1d3d4 Mon Sep 17 00:00:00 2001 From: Michael Hitchens Date: Fri, 27 Feb 2026 14:57:54 -0500 Subject: [PATCH] [glTF] Support materials without pbrMetallicRoughness The spec 5.19 says that the defaults should be applied if not present. Do this instead of using the error material. Fixes #471 --- src/ppx/scene/scene_gltf_loader.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ppx/scene/scene_gltf_loader.cpp b/src/ppx/scene/scene_gltf_loader.cpp index cae41664c..8db9c650b 100644 --- a/src/ppx/scene/scene_gltf_loader.cpp +++ b/src/ppx/scene/scene_gltf_loader.cpp @@ -458,17 +458,11 @@ GltfMaterialSelector::~GltfMaterialSelector() std::string GltfMaterialSelector::DetermineMaterial(const cgltf_material* pGltfMaterial) const { - std::string ident = PPX_MATERIAL_IDENT_ERROR; - // Determine material type if (pGltfMaterial->unlit) { - ident = PPX_MATERIAL_IDENT_UNLIT; - } - else if (pGltfMaterial->has_pbr_metallic_roughness) { - ident = PPX_MATERIAL_IDENT_STANDARD; + return PPX_MATERIAL_IDENT_UNLIT; } - - return ident; + return PPX_MATERIAL_IDENT_STANDARD; } // ------------------------------------------------------------------------------------------------- @@ -1156,6 +1150,16 @@ ppx::Result GltfLoader::LoadPbrMetallicRoughnessMaterialInternal( PPX_ASSERT_NULL_ARG(pGltfMaterial); PPX_ASSERT_NULL_ARG(pTargetMaterial); + pTargetMaterial->SetEmissiveFactor(*(reinterpret_cast(pGltfMaterial->emissive_factor))); + + // pbrMetallicRoughness is not required. 5.19 says "When undefined, all the default values of pbrMetallicRoughness MUST apply" + if (!pGltfMaterial->has_pbr_metallic_roughness) { + pTargetMaterial->SetBaseColorFactor(glm::float4(1.F, 1.F, 1.F, 1.F)); + pTargetMaterial->SetMetallicFactor(1.F); + pTargetMaterial->SetRoughnessFactor(1.F); + return ppx::SUCCESS; + } + // pbrMetallicRoughness textures if (!IsNull(pGltfMaterial->pbr_metallic_roughness.base_color_texture.texture)) { auto ppxres = LoadTextureViewInternal( @@ -1212,7 +1216,6 @@ ppx::Result GltfLoader::LoadPbrMetallicRoughnessMaterialInternal( pTargetMaterial->SetBaseColorFactor(*(reinterpret_cast(pGltfMaterial->pbr_metallic_roughness.base_color_factor))); pTargetMaterial->SetMetallicFactor(pGltfMaterial->pbr_metallic_roughness.metallic_factor); pTargetMaterial->SetRoughnessFactor(pGltfMaterial->pbr_metallic_roughness.roughness_factor); - pTargetMaterial->SetEmissiveFactor(*(reinterpret_cast(pGltfMaterial->emissive_factor))); if (pGltfMaterial->has_emissive_strength) { pTargetMaterial->SetEmissiveStrength(pGltfMaterial->emissive_strength.emissive_strength);