123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- /*************************************************************************/
- /* material_editor_plugin.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* https://godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
- /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
- /* */
- /* 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. */
- /*************************************************************************/
- #include "material_editor_plugin.h"
- #include "core/config/project_settings.h"
- #include "editor/editor_node.h"
- #include "editor/editor_scale.h"
- #include "editor/editor_settings.h"
- #include "editor/editor_undo_redo_manager.h"
- #include "scene/gui/subviewport_container.h"
- #include "scene/resources/fog_material.h"
- #include "scene/resources/particle_process_material.h"
- #include "scene/resources/sky_material.h"
- void MaterialEditor::_update_theme_item_cache() {
- Control::_update_theme_item_cache();
- theme_cache.light_1_on = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
- theme_cache.light_1_off = get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"));
- theme_cache.light_2_on = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
- theme_cache.light_2_off = get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"));
- theme_cache.sphere_on = get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons"));
- theme_cache.sphere_off = get_theme_icon(SNAME("MaterialPreviewSphereOff"), SNAME("EditorIcons"));
- theme_cache.box_on = get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons"));
- theme_cache.box_off = get_theme_icon(SNAME("MaterialPreviewCubeOff"), SNAME("EditorIcons"));
- theme_cache.checkerboard = get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons"));
- }
- void MaterialEditor::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_THEME_CHANGED: {
- light_1_switch->set_normal_texture(theme_cache.light_1_on);
- light_1_switch->set_pressed_texture(theme_cache.light_1_off);
- light_2_switch->set_normal_texture(theme_cache.light_2_on);
- light_2_switch->set_pressed_texture(theme_cache.light_2_off);
- sphere_switch->set_normal_texture(theme_cache.sphere_off);
- sphere_switch->set_pressed_texture(theme_cache.sphere_on);
- box_switch->set_normal_texture(theme_cache.box_off);
- box_switch->set_pressed_texture(theme_cache.box_on);
- } break;
- case NOTIFICATION_DRAW: {
- Size2 size = get_size();
- draw_texture_rect(theme_cache.checkerboard, Rect2(Point2(), size), true);
- } break;
- }
- }
- void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) {
- material = p_material;
- camera->set_environment(p_env);
- if (!material.is_null()) {
- Shader::Mode mode = p_material->get_shader_mode();
- switch (mode) {
- case Shader::MODE_CANVAS_ITEM:
- layout_3d->hide();
- layout_2d->show();
- vc->hide();
- rect_instance->set_material(material);
- break;
- case Shader::MODE_SPATIAL:
- layout_2d->hide();
- layout_3d->show();
- vc->show();
- sphere_instance->set_material_override(material);
- box_instance->set_material_override(material);
- break;
- default:
- break;
- }
- } 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);
- EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", false);
- }
- if (p_button == sphere_switch) {
- box_instance->hide();
- sphere_instance->show();
- box_switch->set_pressed(false);
- sphere_switch->set_pressed(true);
- EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", true);
- }
- }
- void MaterialEditor::_bind_methods() {
- }
- MaterialEditor::MaterialEditor() {
- // canvas item
- layout_2d = memnew(HBoxContainer);
- layout_2d->set_alignment(BoxContainer::ALIGNMENT_CENTER);
- add_child(layout_2d);
- layout_2d->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
- 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);
- // spatial
- vc = memnew(SubViewportContainer);
- vc->set_stretch(true);
- add_child(vc);
- vc->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
- viewport = memnew(SubViewport);
- Ref<World3D> world_3d;
- world_3d.instantiate();
- viewport->set_world_3d(world_3d); //use own world
- vc->add_child(viewport);
- viewport->set_disable_input(true);
- viewport->set_transparent_background(true);
- viewport->set_msaa_3d(Viewport::MSAA_4X);
- camera = memnew(Camera3D);
- camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 3)));
- // Use low field of view so the sphere/box is fully encompassed within the preview,
- // without much distortion.
- camera->set_perspective(20, 0.1, 10);
- camera->make_current();
- if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
- camera_attributes.instantiate();
- camera->set_attributes(camera_attributes);
- }
- viewport->add_child(camera);
- light1 = memnew(DirectionalLight3D);
- light1->set_transform(Transform3D().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
- viewport->add_child(light1);
- light2 = memnew(DirectionalLight3D);
- light2->set_transform(Transform3D().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
- light2->set_color(Color(0.7, 0.7, 0.7));
- viewport->add_child(light2);
- sphere_instance = memnew(MeshInstance3D);
- viewport->add_child(sphere_instance);
- box_instance = memnew(MeshInstance3D);
- viewport->add_child(box_instance);
- Transform3D box_xform;
- box_xform.basis.rotate(Vector3(1, 0, 0), Math::deg_to_rad(25.0));
- box_xform.basis = box_xform.basis * Basis().rotated(Vector3(0, 1, 0), Math::deg_to_rad(-25.0));
- box_xform.basis.scale(Vector3(0.7, 0.7, 0.7));
- box_xform.origin.y = 0.05;
- box_instance->set_transform(box_xform);
- sphere_mesh.instantiate();
- sphere_instance->set_mesh(sphere_mesh);
- box_mesh.instantiate();
- box_instance->set_mesh(box_mesh);
- set_custom_minimum_size(Size2(1, 150) * EDSCALE);
- layout_3d = memnew(HBoxContainer);
- add_child(layout_3d);
- layout_3d->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
- VBoxContainer *vb_shape = memnew(VBoxContainer);
- layout_3d->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);
- sphere_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(sphere_switch));
- box_switch = memnew(TextureButton);
- box_switch->set_toggle_mode(true);
- box_switch->set_pressed(false);
- vb_shape->add_child(box_switch);
- box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(box_switch));
- layout_3d->add_spacer();
- VBoxContainer *vb_light = memnew(VBoxContainer);
- layout_3d->add_child(vb_light);
- light_1_switch = memnew(TextureButton);
- light_1_switch->set_toggle_mode(true);
- vb_light->add_child(light_1_switch);
- light_1_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(light_1_switch));
- light_2_switch = memnew(TextureButton);
- light_2_switch->set_toggle_mode(true);
- vb_light->add_child(light_2_switch);
- light_2_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(light_2_switch));
- 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);
- }
- }
- ///////////////////////
- bool EditorInspectorPluginMaterial::can_handle(Object *p_object) {
- Material *material = Object::cast_to<Material>(p_object);
- if (!material) {
- return false;
- }
- Shader::Mode mode = material->get_shader_mode();
- return mode == Shader::MODE_SPATIAL || mode == Shader::MODE_CANVAS_ITEM;
- }
- 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);
- }
- void EditorInspectorPluginMaterial::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value) {
- Ref<EditorUndoRedoManager> undo_redo = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
- ERR_FAIL_COND(!undo_redo.is_valid());
- // For BaseMaterial3D, if a roughness or metallic textures is being assigned to an empty slot,
- // set the respective metallic or roughness factor to 1.0 as a convenience feature
- 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") {
- if (base_material->get_texture(StandardMaterial3D::TEXTURE_ROUGHNESS).is_null()) {
- 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") {
- if (base_material->get_texture(StandardMaterial3D::TEXTURE_METALLIC).is_null()) {
- 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);
- }
- }
- }
- }
- }
- }
- EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() {
- env.instantiate();
- Ref<Sky> sky = memnew(Sky());
- env->set_sky(sky);
- env->set_background(Environment::BG_COLOR);
- env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
- env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
- EditorNode::get_singleton()->get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &EditorInspectorPluginMaterial::_undo_redo_inspector_callback));
- }
- MaterialEditorPlugin::MaterialEditorPlugin() {
- Ref<EditorInspectorPluginMaterial> plugin;
- plugin.instantiate();
- add_inspector_plugin(plugin);
- }
- String StandardMaterial3DConversionPlugin::converts_to() const {
- return "ShaderMaterial";
- }
- bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- Ref<StandardMaterial3D> mat = p_resource;
- return mat.is_valid();
- }
- Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
- Ref<StandardMaterial3D> 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- // Texture parameter has to be treated specially since StandardMaterial3D saved it
- // as RID but ShaderMaterial needs Texture itself
- Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
- if (texture.is_valid()) {
- smat->set_shader_uniform(E.name, texture);
- } else {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- }
- 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;
- }
- 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- 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()) {
- smat->set_shader_uniform(E.name, texture);
- } else {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- }
- 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;
- }
- String ParticleProcessMaterialConversionPlugin::converts_to() const {
- return "ShaderMaterial";
- }
- bool ParticleProcessMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- Ref<ParticleProcessMaterial> mat = p_resource;
- return mat.is_valid();
- }
- Ref<Resource> ParticleProcessMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
- Ref<ParticleProcessMaterial> 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- 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;
- }
- 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) const {
- Ref<CanvasItemMaterial> 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- 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;
- }
- String ProceduralSkyMaterialConversionPlugin::converts_to() const {
- return "ShaderMaterial";
- }
- bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- Ref<ProceduralSkyMaterial> mat = p_resource;
- return mat.is_valid();
- }
- 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;
- 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- 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;
- }
- String PanoramaSkyMaterialConversionPlugin::converts_to() const {
- return "ShaderMaterial";
- }
- bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- Ref<PanoramaSkyMaterial> mat = p_resource;
- return mat.is_valid();
- }
- 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;
- 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- 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;
- }
- String PhysicalSkyMaterialConversionPlugin::converts_to() const {
- return "ShaderMaterial";
- }
- bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- Ref<PhysicalSkyMaterial> mat = p_resource;
- return mat.is_valid();
- }
- 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;
- 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- 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;
- }
- 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;
- RS::get_singleton()->shader_get_shader_uniform_list(mat->get_shader_rid(), ¶ms);
- for (const PropertyInfo &E : params) {
- Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
- smat->set_shader_uniform(E.name, value);
- }
- smat->set_render_priority(mat->get_render_priority());
- return smat;
- }
|