2017-01-16 15:04:19 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* material_editor_plugin.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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"
|
|
|
|
|
2022-08-01 07:20:24 +08:00
|
|
|
#include "core/config/project_settings.h"
|
2022-02-12 09:46:22 +08:00
|
|
|
#include "editor/editor_node.h"
|
2022-08-01 02:14:15 +08:00
|
|
|
#include "editor/editor_settings.h"
|
2024-07-11 21:20:25 +08:00
|
|
|
#include "editor/editor_string_names.h"
|
2022-03-26 01:06:46 +08:00
|
|
|
#include "editor/editor_undo_redo_manager.h"
|
2024-01-15 20:14:55 +08:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2023-04-08 00:59:49 +08:00
|
|
|
#include "scene/3d/camera_3d.h"
|
|
|
|
#include "scene/3d/light_3d.h"
|
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
|
|
|
#include "scene/gui/box_container.h"
|
2023-06-29 19:48:53 +08:00
|
|
|
#include "scene/gui/button.h"
|
2023-04-08 00:59:49 +08:00
|
|
|
#include "scene/gui/color_rect.h"
|
2024-07-11 21:20:25 +08:00
|
|
|
#include "scene/gui/label.h"
|
2020-04-02 02:28:09 +08:00
|
|
|
#include "scene/gui/subviewport_container.h"
|
2023-04-13 03:02:28 +08:00
|
|
|
#include "scene/main/viewport.h"
|
2021-08-14 00:42:45 +08:00
|
|
|
#include "scene/resources/3d/fog_material.h"
|
|
|
|
#include "scene/resources/3d/sky_material.h"
|
2022-08-18 17:09:22 +08:00
|
|
|
#include "scene/resources/particle_process_material.h"
|
2017-09-22 20:20:28 +08:00
|
|
|
|
2022-09-07 13:17:57 +08:00
|
|
|
void MaterialEditor::gui_input(const Ref<InputEvent> &p_event) {
|
|
|
|
ERR_FAIL_COND(p_event.is_null());
|
|
|
|
|
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
2023-01-08 07:55:54 +08:00
|
|
|
if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
|
2022-09-07 13:17:57 +08:00
|
|
|
rot.x -= mm->get_relative().y * 0.01;
|
|
|
|
rot.y -= mm->get_relative().x * 0.01;
|
2024-09-15 10:38:17 +08:00
|
|
|
if (quad_instance->is_visible()) {
|
|
|
|
// Clamp rotation so the quad is always visible.
|
|
|
|
const real_t limit = Math::deg_to_rad(80.0);
|
|
|
|
rot = rot.clampf(-limit, limit);
|
|
|
|
} else {
|
|
|
|
rot.x = CLAMP(rot.x, -Math_PI / 2, Math_PI / 2);
|
|
|
|
}
|
2022-09-07 13:17:57 +08:00
|
|
|
_update_rotation();
|
2024-09-15 10:38:17 +08:00
|
|
|
_store_rotation_metadata();
|
2022-09-07 13:17:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 23:52:49 +08:00
|
|
|
void MaterialEditor::_update_theme_item_cache() {
|
|
|
|
Control::_update_theme_item_cache();
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-08-13 08:33:39 +08:00
|
|
|
theme_cache.light_1_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight1"));
|
|
|
|
theme_cache.light_2_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight2"));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-08-13 08:33:39 +08:00
|
|
|
theme_cache.sphere_icon = get_editor_theme_icon(SNAME("MaterialPreviewSphere"));
|
|
|
|
theme_cache.box_icon = get_editor_theme_icon(SNAME("MaterialPreviewCube"));
|
2024-09-15 10:38:17 +08:00
|
|
|
theme_cache.quad_icon = get_editor_theme_icon(SNAME("MaterialPreviewQuad"));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-08-13 08:33:39 +08:00
|
|
|
theme_cache.checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
|
2022-09-01 23:52:49 +08:00
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2022-09-01 23:52:49 +08:00
|
|
|
void MaterialEditor::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2024-10-10 06:21:47 +08:00
|
|
|
light_1_switch->set_button_icon(theme_cache.light_1_icon);
|
|
|
|
light_2_switch->set_button_icon(theme_cache.light_2_icon);
|
2023-06-29 19:48:53 +08:00
|
|
|
|
2024-10-10 06:21:47 +08:00
|
|
|
sphere_switch->set_button_icon(theme_cache.sphere_icon);
|
|
|
|
box_switch->set_button_icon(theme_cache.box_icon);
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_switch->set_button_icon(theme_cache.quad_icon);
|
2024-07-11 21:20:25 +08:00
|
|
|
|
|
|
|
error_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
|
2022-02-16 10:44:22 +08:00
|
|
|
} break;
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2022-02-16 10:44:22 +08:00
|
|
|
case NOTIFICATION_DRAW: {
|
2024-07-11 21:20:25 +08:00
|
|
|
if (!is_unsupported_shader_mode) {
|
|
|
|
Size2 size = get_size();
|
|
|
|
draw_texture_rect(theme_cache.checkerboard, Rect2(Point2(), size), true);
|
|
|
|
}
|
2022-02-16 10:44:22 +08:00
|
|
|
} break;
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-15 10:38:17 +08:00
|
|
|
void MaterialEditor::_set_rotation(real_t p_x_degrees, real_t p_y_degrees) {
|
|
|
|
rot.x = Math::deg_to_rad(p_x_degrees);
|
|
|
|
rot.y = Math::deg_to_rad(p_y_degrees);
|
|
|
|
_update_rotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the rotation so it can persist when switching between materials.
|
|
|
|
void MaterialEditor::_store_rotation_metadata() {
|
|
|
|
Vector2 rotation_degrees = Vector2(Math::rad_to_deg(rot.x), Math::rad_to_deg(rot.y));
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_rotation", rotation_degrees);
|
|
|
|
}
|
|
|
|
|
2022-09-07 13:17:57 +08:00
|
|
|
void MaterialEditor::_update_rotation() {
|
|
|
|
Transform3D t;
|
|
|
|
t.basis.rotate(Vector3(0, 1, 0), -rot.y);
|
|
|
|
t.basis.rotate(Vector3(1, 0, 0), -rot.x);
|
|
|
|
rotation->set_transform(t);
|
|
|
|
}
|
|
|
|
|
2019-03-05 02:52:39 +08:00
|
|
|
void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) {
|
|
|
|
material = p_material;
|
|
|
|
camera->set_environment(p_env);
|
2024-07-11 21:20:25 +08:00
|
|
|
|
|
|
|
is_unsupported_shader_mode = false;
|
2019-03-05 02:52:39 +08:00
|
|
|
if (!material.is_null()) {
|
2021-12-07 22:16:41 +08:00
|
|
|
Shader::Mode mode = p_material->get_shader_mode();
|
|
|
|
switch (mode) {
|
|
|
|
case Shader::MODE_CANVAS_ITEM:
|
2024-07-11 21:20:25 +08:00
|
|
|
layout_error->hide();
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_3d->hide();
|
|
|
|
layout_2d->show();
|
|
|
|
vc->hide();
|
|
|
|
rect_instance->set_material(material);
|
|
|
|
break;
|
|
|
|
case Shader::MODE_SPATIAL:
|
2024-07-11 21:20:25 +08:00
|
|
|
layout_error->hide();
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_2d->hide();
|
|
|
|
layout_3d->show();
|
|
|
|
vc->show();
|
|
|
|
sphere_instance->set_material_override(material);
|
|
|
|
box_instance->set_material_override(material);
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_instance->set_material_override(material);
|
2021-12-07 22:16:41 +08:00
|
|
|
break;
|
|
|
|
default:
|
2024-07-11 21:20:25 +08:00
|
|
|
layout_error->show();
|
|
|
|
layout_2d->hide();
|
|
|
|
layout_3d->hide();
|
|
|
|
vc->hide();
|
|
|
|
is_unsupported_shader_mode = true;
|
2021-12-07 22:16:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
} else {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
void MaterialEditor::_on_light_1_switch_pressed() {
|
|
|
|
light1->set_visible(light_1_switch->is_pressed());
|
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
void MaterialEditor::_on_light_2_switch_pressed() {
|
|
|
|
light2->set_visible(light_2_switch->is_pressed());
|
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
void MaterialEditor::_on_sphere_switch_pressed() {
|
|
|
|
sphere_instance->show();
|
2024-09-15 10:38:17 +08:00
|
|
|
box_instance->hide();
|
|
|
|
quad_instance->hide();
|
2023-06-29 19:48:53 +08:00
|
|
|
box_switch->set_pressed(false);
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_switch->set_pressed(false);
|
|
|
|
_set_rotation(-15.0, 30.0);
|
|
|
|
_store_rotation_metadata();
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_mesh", "sphere");
|
2023-06-29 19:48:53 +08:00
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
void MaterialEditor::_on_box_switch_pressed() {
|
2024-09-15 10:38:17 +08:00
|
|
|
sphere_instance->hide();
|
2023-06-29 19:48:53 +08:00
|
|
|
box_instance->show();
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_instance->hide();
|
|
|
|
sphere_switch->set_pressed(false);
|
|
|
|
quad_switch->set_pressed(false);
|
|
|
|
_set_rotation(-15.0, 30.0);
|
|
|
|
_store_rotation_metadata();
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_mesh", "box");
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialEditor::_on_quad_switch_pressed() {
|
2023-06-29 19:48:53 +08:00
|
|
|
sphere_instance->hide();
|
2024-09-15 10:38:17 +08:00
|
|
|
box_instance->hide();
|
|
|
|
quad_instance->show();
|
2023-06-29 19:48:53 +08:00
|
|
|
sphere_switch->set_pressed(false);
|
2024-09-15 10:38:17 +08:00
|
|
|
box_switch->set_pressed(false);
|
|
|
|
_set_rotation(0.0, 0.0);
|
|
|
|
_store_rotation_metadata();
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_mesh", "quad");
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MaterialEditor::MaterialEditor() {
|
2023-06-29 19:48:53 +08:00
|
|
|
// Canvas item
|
2021-12-07 22:16:41 +08:00
|
|
|
|
2023-04-29 02:10:04 +08:00
|
|
|
vc_2d = memnew(SubViewportContainer);
|
|
|
|
vc_2d->set_stretch(true);
|
|
|
|
add_child(vc_2d);
|
|
|
|
vc_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
|
|
|
|
|
|
|
viewport_2d = memnew(SubViewport);
|
|
|
|
vc_2d->add_child(viewport_2d);
|
|
|
|
viewport_2d->set_disable_input(true);
|
|
|
|
viewport_2d->set_transparent_background(true);
|
|
|
|
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_2d = memnew(HBoxContainer);
|
2021-12-09 18:40:46 +08:00
|
|
|
layout_2d->set_alignment(BoxContainer::ALIGNMENT_CENTER);
|
2023-04-29 02:10:04 +08:00
|
|
|
viewport_2d->add_child(layout_2d);
|
2022-03-19 08:02:57 +08:00
|
|
|
layout_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
2021-12-07 22:16:41 +08:00
|
|
|
|
|
|
|
rect_instance = memnew(ColorRect);
|
|
|
|
layout_2d->add_child(rect_instance);
|
|
|
|
rect_instance->set_custom_minimum_size(Size2(150, 150) * EDSCALE);
|
|
|
|
|
|
|
|
layout_2d->set_visible(false);
|
|
|
|
|
2024-07-11 21:20:25 +08:00
|
|
|
layout_error = memnew(VBoxContainer);
|
|
|
|
layout_error->set_alignment(BoxContainer::ALIGNMENT_CENTER);
|
|
|
|
layout_error->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
|
|
|
|
|
|
|
error_label = memnew(Label);
|
|
|
|
error_label->set_text(TTR("Preview is not available for this shader mode."));
|
|
|
|
error_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
|
|
|
error_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
|
|
|
error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
|
|
|
|
|
|
|
|
layout_error->add_child(error_label);
|
|
|
|
layout_error->hide();
|
|
|
|
add_child(layout_error);
|
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
// Spatial
|
2021-12-07 22:16:41 +08:00
|
|
|
|
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);
|
2022-03-19 08:02:57 +08:00
|
|
|
vc->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
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();
|
2024-09-15 10:38:17 +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);
|
2022-08-13 07:02:32 +08:00
|
|
|
viewport->set_msaa_3d(Viewport::MSAA_4X);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
camera = memnew(Camera3D);
|
2022-09-07 13:17:57 +08:00
|
|
|
camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 1.1)));
|
2024-09-15 10:38:17 +08:00
|
|
|
// Use low field of view so the sphere/box/quad is fully encompassed within the preview,
|
2022-07-11 00:47:09 +08:00
|
|
|
// without much distortion.
|
|
|
|
camera->set_perspective(20, 0.1, 10);
|
2019-03-05 02:52:39 +08:00
|
|
|
camera->make_current();
|
2022-08-01 07:20:24 +08:00
|
|
|
if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
|
|
|
|
camera_attributes.instantiate();
|
|
|
|
camera->set_attributes(camera_attributes);
|
|
|
|
}
|
2019-03-05 02:52:39 +08:00
|
|
|
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);
|
|
|
|
|
2022-09-07 13:17:57 +08:00
|
|
|
rotation = memnew(Node3D);
|
|
|
|
viewport->add_child(rotation);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
sphere_instance = memnew(MeshInstance3D);
|
2022-09-07 13:17:57 +08:00
|
|
|
rotation->add_child(sphere_instance);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
box_instance = memnew(MeshInstance3D);
|
2022-09-07 13:17:57 +08:00
|
|
|
rotation->add_child(box_instance);
|
|
|
|
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_instance = memnew(MeshInstance3D);
|
|
|
|
rotation->add_child(quad_instance);
|
|
|
|
|
2022-09-07 13:17:57 +08:00
|
|
|
sphere_instance->set_transform(Transform3D() * 0.375);
|
2024-09-15 10:38:17 +08:00
|
|
|
box_instance->set_transform(Transform3D() * 0.25);
|
|
|
|
quad_instance->set_transform(Transform3D() * 0.375);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
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);
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_mesh.instantiate();
|
|
|
|
quad_instance->set_mesh(quad_mesh);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
|
|
|
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_3d = memnew(HBoxContainer);
|
|
|
|
add_child(layout_3d);
|
2022-03-19 08:02:57 +08:00
|
|
|
layout_3d->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
VBoxContainer *vb_shape = memnew(VBoxContainer);
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_3d->add_child(vb_shape);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
sphere_switch = memnew(Button);
|
|
|
|
sphere_switch->set_theme_type_variation("PreviewLightButton");
|
2019-03-05 02:52:39 +08:00
|
|
|
sphere_switch->set_toggle_mode(true);
|
|
|
|
vb_shape->add_child(sphere_switch);
|
2024-05-14 15:40:21 +08:00
|
|
|
sphere_switch->connect(SceneStringName(pressed), callable_mp(this, &MaterialEditor::_on_sphere_switch_pressed));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
box_switch = memnew(Button);
|
|
|
|
box_switch->set_theme_type_variation("PreviewLightButton");
|
2019-03-05 02:52:39 +08:00
|
|
|
box_switch->set_toggle_mode(true);
|
|
|
|
vb_shape->add_child(box_switch);
|
2024-05-14 15:40:21 +08:00
|
|
|
box_switch->connect(SceneStringName(pressed), callable_mp(this, &MaterialEditor::_on_box_switch_pressed));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_switch = memnew(Button);
|
|
|
|
quad_switch->set_theme_type_variation("PreviewLightButton");
|
|
|
|
quad_switch->set_toggle_mode(true);
|
|
|
|
vb_shape->add_child(quad_switch);
|
|
|
|
quad_switch->connect(SceneStringName(pressed), callable_mp(this, &MaterialEditor::_on_quad_switch_pressed));
|
|
|
|
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_3d->add_spacer();
|
2019-03-05 02:52:39 +08:00
|
|
|
|
|
|
|
VBoxContainer *vb_light = memnew(VBoxContainer);
|
2021-12-07 22:16:41 +08:00
|
|
|
layout_3d->add_child(vb_light);
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
light_1_switch = memnew(Button);
|
|
|
|
light_1_switch->set_theme_type_variation("PreviewLightButton");
|
2019-03-05 02:52:39 +08:00
|
|
|
light_1_switch->set_toggle_mode(true);
|
2023-06-29 19:48:53 +08:00
|
|
|
light_1_switch->set_pressed(true);
|
2019-03-05 02:52:39 +08:00
|
|
|
vb_light->add_child(light_1_switch);
|
2024-05-14 15:40:21 +08:00
|
|
|
light_1_switch->connect(SceneStringName(pressed), callable_mp(this, &MaterialEditor::_on_light_1_switch_pressed));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2023-06-29 19:48:53 +08:00
|
|
|
light_2_switch = memnew(Button);
|
|
|
|
light_2_switch->set_theme_type_variation("PreviewLightButton");
|
2019-03-05 02:52:39 +08:00
|
|
|
light_2_switch->set_toggle_mode(true);
|
2023-06-29 19:48:53 +08:00
|
|
|
light_2_switch->set_pressed(true);
|
2019-03-05 02:52:39 +08:00
|
|
|
vb_light->add_child(light_2_switch);
|
2024-05-14 15:40:21 +08:00
|
|
|
light_2_switch->connect(SceneStringName(pressed), callable_mp(this, &MaterialEditor::_on_light_2_switch_pressed));
|
2019-03-05 02:52:39 +08:00
|
|
|
|
2024-09-15 10:38:17 +08:00
|
|
|
String shape = EditorSettings::get_singleton()->get_project_metadata("inspector_options", "material_preview_mesh", "sphere");
|
|
|
|
if (shape == "sphere") {
|
2020-04-02 04:50:06 +08:00
|
|
|
box_instance->hide();
|
2024-09-15 10:38:17 +08:00
|
|
|
quad_instance->hide();
|
|
|
|
sphere_switch->set_pressed_no_signal(true);
|
|
|
|
} else if (shape == "box") {
|
|
|
|
sphere_instance->hide();
|
|
|
|
quad_instance->hide();
|
|
|
|
box_switch->set_pressed_no_signal(true);
|
2020-04-02 04:50:06 +08:00
|
|
|
} else {
|
|
|
|
sphere_instance->hide();
|
2024-09-15 10:38:17 +08:00
|
|
|
box_instance->hide();
|
|
|
|
quad_switch->set_pressed_no_signal(true);
|
2020-04-02 04:50:06 +08:00
|
|
|
}
|
2024-09-15 10:38:17 +08:00
|
|
|
|
|
|
|
Vector2 stored_rot = EditorSettings::get_singleton()->get_project_metadata("inspector_options", "material_preview_rotation", Vector2());
|
|
|
|
_set_rotation(stored_rot.x, stored_rot.y);
|
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
|
|
|
}
|
2021-12-07 22:16:41 +08:00
|
|
|
Shader::Mode mode = material->get_shader_mode();
|
|
|
|
return mode == Shader::MODE_SPATIAL || mode == Shader::MODE_CANVAS_ITEM;
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-02-16 00:25:58 +08:00
|
|
|
void EditorInspectorPluginMaterial::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value) {
|
2022-12-24 06:53:16 +08:00
|
|
|
EditorUndoRedoManager *undo_redo = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
|
|
|
|
ERR_FAIL_NULL(undo_redo);
|
2021-12-22 06:19:00 +08:00
|
|
|
|
|
|
|
// For BaseMaterial3D, if a roughness or metallic textures is being assigned to an empty slot,
|
2022-01-07 07:08:56 +08:00
|
|
|
// set the respective metallic or roughness factor to 1.0 as a convenience feature
|
2021-12-22 06:19:00 +08:00
|
|
|
BaseMaterial3D *base_material = Object::cast_to<StandardMaterial3D>(p_edited);
|
|
|
|
if (base_material) {
|
|
|
|
Texture2D *texture = Object::cast_to<Texture2D>(p_new_value);
|
|
|
|
if (texture) {
|
|
|
|
if (p_property == "roughness_texture") {
|
2022-04-05 18:40:26 +08:00
|
|
|
if (base_material->get_texture(StandardMaterial3D::TEXTURE_ROUGHNESS).is_null()) {
|
2021-12-22 06:19:00 +08:00
|
|
|
undo_redo->add_do_property(p_edited, "roughness", 1.0);
|
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
Variant value = p_edited->get("roughness", &valid);
|
|
|
|
if (valid) {
|
|
|
|
undo_redo->add_undo_property(p_edited, "roughness", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (p_property == "metallic_texture") {
|
2022-04-05 18:40:26 +08:00
|
|
|
if (base_material->get_texture(StandardMaterial3D::TEXTURE_METALLIC).is_null()) {
|
2021-12-22 06:19:00 +08:00
|
|
|
undo_redo->add_do_property(p_edited, "metallic", 1.0);
|
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
Variant value = p_edited->get("metallic", &valid);
|
|
|
|
if (valid) {
|
|
|
|
undo_redo->add_undo_property(p_edited, "metallic", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 02:52:39 +08:00
|
|
|
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);
|
2021-12-22 06:19:00 +08:00
|
|
|
|
2023-08-11 21:55:47 +08:00
|
|
|
EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &EditorInspectorPluginMaterial::_undo_redo_inspector_callback));
|
2019-03-05 02:52:39 +08:00
|
|
|
}
|
|
|
|
|
2022-01-27 17:36:51 +08:00
|
|
|
MaterialEditorPlugin::MaterialEditorPlugin() {
|
2019-03-05 02:52:39 +08:00
|
|
|
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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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()) {
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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
|
|
|
|
2021-10-29 22:49:12 +08:00
|
|
|
String ORMMaterial3DConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ORMMaterial3D> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ORMMaterial3D> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
|
|
|
smat.instantiate();
|
|
|
|
|
|
|
|
Ref<Shader> shader;
|
|
|
|
shader.instantiate();
|
|
|
|
|
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
2021-10-29 22:49:12 +08:00
|
|
|
|
|
|
|
for (const PropertyInfo &E : params) {
|
|
|
|
// Texture parameter has to be treated specially since ORMMaterial3D saved it
|
|
|
|
// as RID but ShaderMaterial needs Texture itself
|
|
|
|
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
|
|
|
|
if (texture.is_valid()) {
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(E.name, texture);
|
2021-10-29 22:49:12 +08:00
|
|
|
} else {
|
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(E.name, value);
|
2021-10-29 22:49:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
|
|
|
smat->set_local_to_scene(mat->is_local_to_scene());
|
|
|
|
smat->set_name(mat->get_name());
|
|
|
|
return smat;
|
|
|
|
}
|
|
|
|
|
2022-08-18 17:09:22 +08:00
|
|
|
String ParticleProcessMaterialConversionPlugin::converts_to() const {
|
2017-10-12 19:12:50 +08:00
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2022-08-18 17:09:22 +08:00
|
|
|
bool ParticleProcessMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ParticleProcessMaterial> mat = p_resource;
|
2017-10-12 19:12:50 +08:00
|
|
|
return mat.is_valid();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2022-08-18 17:09:22 +08:00
|
|
|
Ref<Resource> ParticleProcessMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<ParticleProcessMaterial> mat = p_resource;
|
2017-10-12 19:12:50 +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-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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_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);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(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;
|
|
|
|
}
|
2021-10-03 19:28:55 +08:00
|
|
|
|
|
|
|
String FogMaterialConversionPlugin::converts_to() const {
|
|
|
|
return "ShaderMaterial";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<FogMaterial> mat = p_resource;
|
|
|
|
return mat.is_valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
|
|
|
|
Ref<FogMaterial> mat = p_resource;
|
|
|
|
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
|
|
|
|
|
|
|
|
Ref<ShaderMaterial> smat;
|
|
|
|
smat.instantiate();
|
|
|
|
|
|
|
|
Ref<Shader> shader;
|
|
|
|
shader.instantiate();
|
|
|
|
|
|
|
|
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
|
|
|
|
|
|
|
|
shader->set_code(code);
|
|
|
|
|
|
|
|
smat->set_shader(shader);
|
|
|
|
|
|
|
|
List<PropertyInfo> params;
|
2022-08-27 17:22:43 +08:00
|
|
|
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);
|
2021-10-03 19:28:55 +08:00
|
|
|
|
|
|
|
for (const PropertyInfo &E : params) {
|
|
|
|
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
|
2022-08-27 17:22:43 +08:00
|
|
|
smat->set_shader_parameter(E.name, value);
|
2021-10-03 19:28:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smat->set_render_priority(mat->get_render_priority());
|
|
|
|
return smat;
|
|
|
|
}
|