Finalized ability to convert from CanvasItem/Spatial/Particles materials to ShaderMaterial, closes #10242
This commit is contained in:
parent
bd2b1a62d9
commit
04edfc090b
@ -5533,6 +5533,10 @@ EditorNode::EditorNode() {
|
|||||||
spatial_mat_convert.instance();
|
spatial_mat_convert.instance();
|
||||||
resource_conversion_plugins.push_back(spatial_mat_convert);
|
resource_conversion_plugins.push_back(spatial_mat_convert);
|
||||||
|
|
||||||
|
Ref<CanvasItemMaterialConversionPlugin> canvas_item_mat_convert;
|
||||||
|
canvas_item_mat_convert.instance();
|
||||||
|
resource_conversion_plugins.push_back(canvas_item_mat_convert);
|
||||||
|
|
||||||
Ref<ParticlesMaterialConversionPlugin> particles_mat_convert;
|
Ref<ParticlesMaterialConversionPlugin> particles_mat_convert;
|
||||||
particles_mat_convert.instance();
|
particles_mat_convert.instance();
|
||||||
resource_conversion_plugins.push_back(particles_mat_convert);
|
resource_conversion_plugins.push_back(particles_mat_convert);
|
||||||
|
@ -503,3 +503,41 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_
|
|||||||
smat->set_render_priority(mat->get_render_priority());
|
smat->set_render_priority(mat->get_render_priority());
|
||||||
return smat;
|
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(), ¶ms);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -119,4 +119,12 @@ public:
|
|||||||
virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
|
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
|
#endif // MATERIAL_EDITOR_PLUGIN_H
|
||||||
|
@ -178,6 +178,12 @@ CanvasItemMaterial::LightMode CanvasItemMaterial::get_light_mode() const {
|
|||||||
void CanvasItemMaterial::_validate_property(PropertyInfo &property) const {
|
void CanvasItemMaterial::_validate_property(PropertyInfo &property) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RID CanvasItemMaterial::get_shader_rid() const {
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
|
||||||
|
return shader_map[current_key].shader;
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasItemMaterial::_bind_methods() {
|
void CanvasItemMaterial::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
|
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
|
||||||
|
@ -121,6 +121,8 @@ public:
|
|||||||
static void finish_shaders();
|
static void finish_shaders();
|
||||||
static void flush_changes();
|
static void flush_changes();
|
||||||
|
|
||||||
|
RID get_shader_rid() const;
|
||||||
|
|
||||||
CanvasItemMaterial();
|
CanvasItemMaterial();
|
||||||
virtual ~CanvasItemMaterial();
|
virtual ~CanvasItemMaterial();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user