2017-01-16 15:04:19 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* material_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2017-01-16 15:04:19 +08:00
|
|
|
/*************************************************************************/
|
2021-01-02 03:13:46 +08:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-01-16 15:04:19 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2017-08-26 23:46:49 +08:00
|
|
|
|
2016-05-24 04:10:26 +08:00
|
|
|
#include "material_editor_plugin.h"
|
|
|
|
|
2019-12-24 15:17:23 +08:00
|
|
|
#include "editor/editor_scale.h"
|
2020-04-02 02:28:09 +08:00
|
|
|
#include "scene/gui/subviewport_container.h"
|
2018-09-04 17:30:04 +08:00
|
|
|
#include "scene/resources/particles_material.h"
|
2020-03-20 08:32:19 +08:00
|
|
|
#include "scene/resources/sky_material.h"
|
2017-09-22 20:20:28 +08:00
|
|
|
|
2019-03-05 02:52:39 +08:00
|
|
|
void MaterialEditor::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_READY) {
|
|
|
|
//get_scene()->connect("node_removed",this,"_node_removed");
|
|
|
|
|
|
|
|
if (first_enter) {
|
|
|
|
//it's in propertyeditor so.. could be moved around
|
|
|
|
|
2021-07-18 05:22:52 +08:00
|
|
|
light_1_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons")));
|
|
|
|
light_1_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons")));
|
|
|
|
light_2_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons")));
|
|
|
|
light_2_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons")));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2021-07-18 05:22:52 +08:00
|
|
|
sphere_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewSphereOff"), SNAME("EditorIcons")));
|
|
|
|
sphere_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons")));
|
|
|
|
box_switch->set_normal_texture(get_theme_icon(SNAME("MaterialPreviewCubeOff"), SNAME("EditorIcons")));
|
|
|
|
box_switch->set_pressed_texture(get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons")));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
first_enter = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2021-07-18 05:22:52 +08:00
|
|
|
Ref<Texture2D> checkerboard = get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons"));
|
2019-03-05 02:52:39 +08:00
|
|
|
Size2 size = get_size();
|
|
|
|
|
|
|
|
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) {
|
|
|
|
material = p_material;
|
|
|
|
camera->set_environment(p_env);
|
|
|
|
if (!material.is_null()) {
|
|
|
|
sphere_instance->set_material_override(material);
|
|
|
|
box_instance->set_material_override(material);
|
|
|
|
} else {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialEditor::_button_pressed(Node *p_button) {
|
|
|
|
if (p_button == light_1_switch) {
|
|
|
|
light1->set_visible(!light_1_switch->is_pressed());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_button == light_2_switch) {
|
|
|
|
light2->set_visible(!light_2_switch->is_pressed());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_button == box_switch) {
|
|
|
|
box_instance->show();
|
|
|
|
sphere_instance->hide();
|
|
|
|
box_switch->set_pressed(true);
|
|
|
|
sphere_switch->set_pressed(false);
|
2020-04-02 04:50:06 +08:00
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", false);
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_button == sphere_switch) {
|
|
|
|
box_instance->hide();
|
|
|
|
sphere_instance->show();
|
|
|
|
box_switch->set_pressed(false);
|
|
|
|
sphere_switch->set_pressed(true);
|
2020-04-02 04:50:06 +08:00
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", true);
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialEditor::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
MaterialEditor::MaterialEditor() {
|
2020-04-02 02:28:09 +08:00
|
|
|
vc = memnew(SubViewportContainer);
|
2019-03-05 02:52:39 +08:00
|
|
|
vc->set_stretch(true);
|
|
|
|
add_child(vc);
|
2020-12-23 00:24:29 +08:00
|
|
|
vc->set_anchors_and_offsets_preset(PRESET_WIDE);
|
2020-03-04 09:51:12 +08:00
|
|
|
viewport = memnew(SubViewport);
|
2020-04-18 17:00:51 +08:00
|
|
|
Ref<World3D> world_3d;
|
2021-06-18 06:03:09 +08:00
|
|
|
world_3d.instantiate();
|
2020-04-18 17:00:51 +08:00
|
|
|
viewport->set_world_3d(world_3d); //use own world
|
2019-03-05 02:52:39 +08:00
|
|
|
vc->add_child(viewport);
|
|
|
|
viewport->set_disable_input(true);
|
|
|
|
viewport->set_transparent_background(true);
|
|
|
|
viewport->set_msaa(Viewport::MSAA_4X);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
camera = memnew(Camera3D);
|
2020-10-17 13:08:21 +08:00
|
|
|
camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 3)));
|
2019-03-05 02:52:39 +08:00
|
|
|
camera->set_perspective(45, 0.1, 10);
|
|
|
|
camera->make_current();
|
|
|
|
viewport->add_child(camera);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
light1 = memnew(DirectionalLight3D);
|
2020-10-17 13:08:21 +08:00
|
|
|
light1->set_transform(Transform3D().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
|
2019-03-05 02:52:39 +08:00
|
|
|
viewport->add_child(light1);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
light2 = memnew(DirectionalLight3D);
|
2020-10-17 13:08:21 +08:00
|
|
|
light2->set_transform(Transform3D().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
|
2019-03-05 02:52:39 +08:00
|
|
|
light2->set_color(Color(0.7, 0.7, 0.7));
|
|
|
|
viewport->add_child(light2);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
sphere_instance = memnew(MeshInstance3D);
|
2019-03-05 02:52:39 +08:00
|
|
|
viewport->add_child(sphere_instance);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
box_instance = memnew(MeshInstance3D);
|
2019-03-05 02:52:39 +08:00
|
|
|
viewport->add_child(box_instance);
|
|
|
|
|
2020-10-17 13:08:21 +08:00
|
|
|
Transform3D box_xform;
|
2019-03-05 02:52:39 +08:00
|
|
|
box_xform.basis.rotate(Vector3(1, 0, 0), Math::deg2rad(25.0));
|
|
|
|
box_xform.basis = box_xform.basis * Basis().rotated(Vector3(0, 1, 0), Math::deg2rad(-25.0));
|
|
|
|
box_xform.basis.scale(Vector3(0.8, 0.8, 0.8));
|
|
|
|
box_xform.origin.y = 0.2;
|
|
|
|
box_instance->set_transform(box_xform);
|
|
|
|
|
2021-06-18 06:03:09 +08:00
|
|
|
sphere_mesh.instantiate();
|
2019-03-05 02:52:39 +08:00
|
|
|
sphere_instance->set_mesh(sphere_mesh);
|
2021-06-18 06:03:09 +08:00
|
|
|
box_mesh.instantiate();
|
2019-03-05 02:52:39 +08:00
|
|
|
box_instance->set_mesh(box_mesh);
|
|
|
|
|
|
|
|
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
|
|
|
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
|
|
add_child(hb);
|
2020-12-23 00:24:29 +08:00
|
|
|
hb->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 2);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
VBoxContainer *vb_shape = memnew(VBoxContainer);
|
|
|
|
hb->add_child(vb_shape);
|
|
|
|
|
|
|
|
sphere_switch = memnew(TextureButton);
|
|
|
|
sphere_switch->set_toggle_mode(true);
|
|
|
|
sphere_switch->set_pressed(true);
|
|
|
|
vb_shape->add_child(sphere_switch);
|
2020-02-22 01:28:45 +08:00
|
|
|
sphere_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(sphere_switch));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
box_switch = memnew(TextureButton);
|
|
|
|
box_switch->set_toggle_mode(true);
|
|
|
|
box_switch->set_pressed(false);
|
|
|
|
vb_shape->add_child(box_switch);
|
2020-02-22 01:28:45 +08:00
|
|
|
box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(box_switch));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
hb->add_spacer();
|
|
|
|
|
|
|
|
VBoxContainer *vb_light = memnew(VBoxContainer);
|
|
|
|
hb->add_child(vb_light);
|
|
|
|
|
|
|
|
light_1_switch = memnew(TextureButton);
|
|
|
|
light_1_switch->set_toggle_mode(true);
|
|
|
|
vb_light->add_child(light_1_switch);
|
2020-02-22 01:28:45 +08:00
|
|
|
light_1_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(light_1_switch));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
light_2_switch = memnew(TextureButton);
|
|
|
|
light_2_switch->set_toggle_mode(true);
|
|
|
|
vb_light->add_child(light_2_switch);
|
2020-02-22 01:28:45 +08:00
|
|
|
light_2_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed), varray(light_2_switch));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
first_enter = true;
|
2020-04-02 04:50:06 +08:00
|
|
|
|
|
|
|
if (EditorSettings::get_singleton()->get_project_metadata("inspector_options", "material_preview_on_sphere", true)) {
|
|
|
|
box_instance->hide();
|
|
|
|
} else {
|
|
|
|
box_instance->show();
|
|
|
|
sphere_instance->hide();
|
|
|
|
box_switch->set_pressed(true);
|
|
|
|
sphere_switch->set_pressed(false);
|
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
bool EditorInspectorPluginMaterial::can_handle(Object *p_object) {
|
|
|
|
Material *material = Object::cast_to<Material>(p_object);
|
2020-05-14 22:41:43 +08:00
|
|
|
if (!material) {
|
2019-03-05 02:52:39 +08:00
|
|
|
return false;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
return material->get_shader_mode() == Shader::MODE_SPATIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorInspectorPluginMaterial::parse_begin(Object *p_object) {
|
|
|
|
Material *material = Object::cast_to<Material>(p_object);
|
|
|
|
if (!material) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ref<Material> m(material);
|
|
|
|
|
|
|
|
MaterialEditor *editor = memnew(MaterialEditor);
|
|
|
|
editor->edit(m, env);
|
|
|
|
add_custom_control(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() {
|
2021-06-18 06:03:09 +08:00
|
|
|
env.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
Ref<Sky> sky = memnew(Sky());
|
|
|
|
env->set_sky(sky);
|
2019-08-27 04:43:58 +08:00
|
|
|
env->set_background(Environment::BG_COLOR);
|
|
|
|
env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
|
|
|
|
env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) {
|
|
|
|
Ref<EditorInspectorPluginMaterial> plugin;
|
2021-06-18 06:03:09 +08:00
|
|
|
plugin.instantiate();
|
2019-03-05 02:52:39 +08:00
|
|
|
add_inspector_plugin(plugin);
|
|
|
|
}
|
|
|
|
|
2019-09-15 12:01:52 +08:00
|
|
|
String StandardMaterial3DConversionPlugin::converts_to() const {
|
2017-09-22 20:20:28 +08:00
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-09-15 12:01:52 +08:00
|
|
|
bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<StandardMaterial3D> mat = p_resource;
|
2017-09-22 20:20:28 +08:00
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-09-15 12:01:52 +08:00
|
|
|
Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<StandardMaterial3D> mat = p_resource;
|
2017-09-22 20:20:28 +08:00
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2017-09-22 20:20:28 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2017-09-22 20:20:28 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2017-09-22 20:20:28 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2017-09-22 20:20:28 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2019-09-15 12:01:52 +08:00
|
|
|
// Texture parameter has to be treated specially since StandardMaterial3D saved it
|
2017-10-16 17:14:39 +08:00
|
|
|
// as RID but ShaderMaterial needs Texture itself
|
2021-07-16 11:45:57 +08:00
|
|
|
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
2017-10-16 17:14:39 +08:00
|
|
|
if (texture.is_valid()) {
|
2021-07-16 11:45:57 +08:00
|
|
|
smat->set_shader_param(E.name, texture);
|
2017-10-16 17:14:39 +08:00
|
|
|
} else {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2017-10-16 17:14:39 +08:00
|
|
|
}
|
2017-09-22 20:20:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2017-09-22 20:20:28 +08:00
|
|
|
return smat;
|
|
|
|
}
|
2017-10-12 19:12:50 +08:00
|
|
|
|
|
|
|
String ParticlesMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-10-12 19:12:50 +08:00
|
|
|
bool ParticlesMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ParticlesMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-26 18:25:41 +08:00
|
|
|
Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
2017-10-12 19:12:50 +08:00
|
|
|
Ref<ParticlesMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2017-10-12 19:12:50 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2017-10-12 19:12:50 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2017-10-12 19:12:50 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2017-10-12 19:12:50 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2017-10-12 19:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2017-10-12 19:12:50 +08:00
|
|
|
return smat;
|
|
|
|
}
|
2017-11-15 02:44:51 +08:00
|
|
|
|
|
|
|
String CanvasItemMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-11-15 02:44:51 +08:00
|
|
|
bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<CanvasItemMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-26 18:25:41 +08:00
|
|
|
Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
2017-11-15 02:44:51 +08:00
|
|
|
Ref<CanvasItemMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2017-11-15 02:44:51 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2017-11-15 02:44:51 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2017-11-15 02:44:51 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2017-11-15 02:44:51 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2017-11-15 02:44:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2017-11-15 02:44:51 +08:00
|
|
|
return smat;
|
|
|
|
}
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
String ProceduralSkyMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ProceduralSkyMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ProceduralSkyMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2020-03-20 08:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2020-03-20 08:32:19 +08:00
|
|
|
return smat;
|
|
|
|
}
|
|
|
|
|
|
|
|
String PanoramaSkyMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<PanoramaSkyMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<PanoramaSkyMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2020-03-20 08:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2020-03-20 08:32:19 +08:00
|
|
|
return smat;
|
|
|
|
}
|
|
|
|
|
|
|
|
String PhysicalSkyMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<PhysicalSkyMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<PhysicalSkyMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
2021-06-18 06:03:09 +08:00
|
|
|
smat.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
Ref<Shader> shader;
|
2021-06-18 06:03:09 +08:00
|
|
|
shader.instantiate();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms);
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2021-07-24 21:46:25 +08:00
|
|
|
for (const PropertyInfo &E : params) {
|
2021-07-16 11:45:57 +08:00
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
|
|
|
smat->set_shader_param(E.name, value);
|
2020-03-20 08:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
2021-09-16 07:45:07 +08:00
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
2020-03-20 08:32:19 +08:00
|
|
|
return smat;
|
|
|
|
}
|