summaryrefslogtreecommitdiffstats
path: root/modules/gltf/gltf_document.cpp
diff options
context:
space:
mode:
authorHakim <hakim.rouatbi@gmail.com>2023-03-03 12:10:42 +0100
committerHakim <hakim.rouatbi@gmail.com>2023-03-05 22:34:04 +0100
commite14fa5532bd87addc8c019e2b3770758b36d0c09 (patch)
tree8c07a3dbc7dbcc6af0db4dcb5bec91f0f360c60e /modules/gltf/gltf_document.cpp
parent5dccc940e73d39a1ac4f3d64ccc92373e6609add (diff)
downloadredot-engine-e14fa5532bd87addc8c019e2b3770758b36d0c09.tar.gz
Get the unlit / unshaded extension when importing GLTF and set it when exporting
Diffstat (limited to 'modules/gltf/gltf_document.cpp')
-rw-r--r--modules/gltf/gltf_document.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index e3ba290eb2..d93485a800 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -3748,6 +3748,14 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> p_state) {
d["alphaMode"] = "BLEND";
}
+ Dictionary extensions;
+ if (base_material->get_shading_mode() == BaseMaterial3D::SHADING_MODE_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()) {
@@ -3780,6 +3788,11 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> p_state) {
if (d.has("extensions")) {
pbr_spec_gloss_extensions = d["extensions"];
}
+
+ if (pbr_spec_gloss_extensions.has("KHR_materials_unlit")) {
+ material->set_shading_mode(BaseMaterial3D::SHADING_MODE_UNSHADED);
+ }
+
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"];
@@ -7440,6 +7453,7 @@ Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> 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 (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
Vector<String> ext_supported_extensions = ext->get_supported_extensions();