aboutsummaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorJuan Linietsky2017-11-14 15:44:51 -0300
committerJuan Linietsky2017-11-14 15:45:30 -0300
commit04edfc090b0e78f4f820977da8cb4eb2d015c5f7 (patch)
tree85e317bfbe1fe765dae11a433d1a7943e098c90a /editor/plugins
parentbd2b1a62d9d6f97ebfa7457ab3e84ae839531bdb (diff)
downloadgodot-04edfc090b0e78f4f820977da8cb4eb2d015c5f7.tar.gz
godot-04edfc090b0e78f4f820977da8cb4eb2d015c5f7.tar.zst
godot-04edfc090b0e78f4f820977da8cb4eb2d015c5f7.zip
Finalized ability to convert from CanvasItem/Spatial/Particles materials to ShaderMaterial, closes #10242
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/material_editor_plugin.cpp38
-rw-r--r--editor/plugins/material_editor_plugin.h8
2 files changed, 46 insertions, 0 deletions
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index bd4891ccb..1fc112896 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -503,3 +503,41 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_
smat->set_render_priority(mat->get_render_priority());
return smat;
}
+
+String CanvasItemMaterialConversionPlugin::converts_to() const {
+
+ return "ShaderMaterial";
+}
+bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
+
+ Ref<CanvasItemMaterial> mat = p_resource;
+ return mat.is_valid();
+}
+Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) {
+
+ Ref<CanvasItemMaterial> mat = p_resource;
+ ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
+
+ Ref<ShaderMaterial> smat;
+ smat.instance();
+
+ Ref<Shader> shader;
+ shader.instance();
+
+ String code = VS::get_singleton()->shader_get_code(mat->get_shader_rid());
+
+ shader->set_code(code);
+
+ smat->set_shader(shader);
+
+ List<PropertyInfo> params;
+ VS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), &params);
+
+ for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) {
+ Variant value = VS::get_singleton()->material_get_param(mat->get_rid(), E->get().name);
+ smat->set_shader_param(E->get().name, value);
+ }
+
+ smat->set_render_priority(mat->get_render_priority());
+ return smat;
+}
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index 52c73cb7d..2cc24be33 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -119,4 +119,12 @@ public:
virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
};
+class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
+ GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin)
+public:
+ virtual String converts_to() const;
+ virtual bool handles(const Ref<Resource> &p_resource) const;
+ virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
+};
+
#endif // MATERIAL_EDITOR_PLUGIN_H