From 00f1096e87594c992f51d92e06ee1319ea5345f6 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 --- editor_modules/gltf/gltf_document.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/editor_modules/gltf/gltf_document.cpp b/editor_modules/gltf/gltf_document.cpp index 51efc3c67..3fc3606bd 100644 --- a/editor_modules/gltf/gltf_document.cpp +++ b/editor_modules/gltf/gltf_document.cpp @@ -3658,6 +3658,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()) { @@ -3691,6 +3700,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"]; @@ -7037,6 +7051,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();