From 6d7bc801f643e6b1693b4350900d4fc41b1d4d3f Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 15 Mar 2023 17:26:06 +0800 Subject: [PATCH] Set the unlit / unshaded extension when importing / exporting GLTF Co-authored-by: Hakim --- modules/gltf/gltf_document.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 6a45a436723..dc0f4b5c0c8 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3640,6 +3640,15 @@ Error GLTFDocument::_serialize_materials(Ref p_state) { d["alphaMode"] = "BLEND"; } } + + Dictionary extensions; + if (material->get_flag(SpatialMaterial::FLAG_UNSHADED)) { + Dictionary mat_unlit; + extensions["KHR_materials_unlit"] = mat_unlit; + p_state->add_used_extension("KHR_materials_unlit"); + } + d["extensions"] = extensions; + materials.push_back(d); } if (!materials.size()) { @@ -3673,6 +3682,11 @@ Error GLTFDocument::_parse_materials(Ref p_state) { if (d.has("extensions")) { pbr_spec_gloss_extensions = d["extensions"]; } + + if (pbr_spec_gloss_extensions.has("KHR_materials_unlit")) { + material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + } + if (pbr_spec_gloss_extensions.has("KHR_materials_pbrSpecularGlossiness")) { WARN_PRINT("Material uses a specular and glossiness workflow. Textures will be converted to roughness and metallic workflow, which may not be 100% accurate."); Dictionary sgm = pbr_spec_gloss_extensions["KHR_materials_pbrSpecularGlossiness"]; @@ -6951,6 +6965,7 @@ Error GLTFDocument::_parse_gltf_extensions(Ref p_state) { supported_extensions.insert("KHR_lights_punctual"); supported_extensions.insert("KHR_materials_pbrSpecularGlossiness"); supported_extensions.insert("KHR_texture_transform"); + supported_extensions.insert("KHR_materials_unlit"); for (int ext_i = 0; ext_i < document_extensions.size(); ext_i++) { Ref ext = document_extensions[ext_i]; Vector ext_supported_extensions = ext->get_supported_extensions();