| 1 | /**************************************************************************/ |
| 2 | /* visual_shader_editor_plugin.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "visual_shader_editor_plugin.h" |
| 32 | |
| 33 | #include "core/config/project_settings.h" |
| 34 | #include "core/io/resource_loader.h" |
| 35 | #include "core/math/math_defs.h" |
| 36 | #include "core/os/keyboard.h" |
| 37 | #include "core/version_generated.gen.h" |
| 38 | #include "editor/docks/filesystem_dock.h" |
| 39 | #include "editor/docks/inspector_dock.h" |
| 40 | #include "editor/editor_node.h" |
| 41 | #include "editor/editor_string_names.h" |
| 42 | #include "editor/editor_undo_redo_manager.h" |
| 43 | #include "editor/file_system/editor_paths.h" |
| 44 | #include "editor/gui/editor_toaster.h" |
| 45 | #include "editor/inspector/editor_properties.h" |
| 46 | #include "editor/inspector/editor_properties_vector.h" |
| 47 | #include "editor/scene/curve_editor_plugin.h" |
| 48 | #include "editor/scene/material_editor_plugin.h" |
| 49 | #include "editor/settings/editor_settings.h" |
| 50 | #include "editor/shader/shader_editor_plugin.h" |
| 51 | #include "editor/themes/editor_scale.h" |
| 52 | #include "editor/themes/editor_theme_manager.h" |
| 53 | #include "scene/animation/tween.h" |
| 54 | #include "scene/gui/button.h" |
| 55 | #include "scene/gui/check_box.h" |
| 56 | #include "scene/gui/code_edit.h" |
| 57 | #include "scene/gui/color_picker.h" |
| 58 | #include "scene/gui/flow_container.h" |
| 59 | #include "scene/gui/graph_edit.h" |
| 60 | #include "scene/gui/menu_button.h" |
| 61 | #include "scene/gui/option_button.h" |
| 62 | #include "scene/gui/popup.h" |
| 63 | #include "scene/gui/rich_text_label.h" |
| 64 | #include "scene/gui/separator.h" |
| 65 | #include "scene/gui/split_container.h" |
| 66 | #include "scene/gui/texture_rect.h" |
| 67 | #include "scene/gui/tree.h" |
| 68 | #include "scene/gui/view_panner.h" |
| 69 | #include "scene/main/window.h" |
| 70 | #include "scene/resources/curve_texture.h" |
| 71 | #include "scene/resources/style_box_flat.h" |
| 72 | #include "scene/resources/visual_shader_nodes.h" |
| 73 | #include "scene/resources/visual_shader_particle_nodes.h" |
| 74 | #include "servers/display/display_server.h" |
| 75 | #include "servers/rendering/shader_preprocessor.h" |
| 76 | #include "servers/rendering/shader_types.h" |
| 77 | |
| 78 | struct FloatConstantDef { |
| 79 | String name; |
| 80 | float value = 0; |
| 81 | const char *desc_key; |
| 82 | }; |
| 83 | |
| 84 | static FloatConstantDef float_constant_defs[] = { |
| 85 | { "E", Math::E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") }, |
| 86 | { "Epsilon", CMP_EPSILON, TTRC("Epsilon constant (0.00001). Smallest possible scalar number.") }, |
| 87 | { "Phi", 1.618034f, TTRC("Phi constant (1.618034). Golden ratio.") }, |
| 88 | { "Pi/4", Math::PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") }, |
| 89 | { "Pi/2", Math::PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") }, |
| 90 | { "Pi", Math::PI, TTRC("Pi constant (3.141593) or 180 degrees.") }, |
| 91 | { "Tau", Math::TAU, TTRC("Tau constant (6.283185) or 360 degrees.") }, |
| 92 | { "Sqrt2", Math::SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") } |
| 93 | }; |
| 94 | |
| 95 | constexpr int MAX_FLOAT_CONST_DEFS = std_size(float_constant_defs); |
| 96 | |
| 97 | /////////////////// |
| 98 | |
| 99 | void VisualShaderNodePlugin::set_editor(VisualShaderEditor *p_editor) { |
| 100 | vseditor = p_editor; |
| 101 | } |
| 102 | |
| 103 | Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { |
| 104 | Object *ret = nullptr; |
| 105 | GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret); |
| 106 | return Object::cast_to<Control>(ret); |
| 107 | } |
| 108 | |
| 109 | void VisualShaderNodePlugin::_bind_methods() { |
| 110 | GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node"); |
| 111 | } |
| 112 | |
| 113 | /////////////////// |
| 114 | |
| 115 | void VSGraphNode::_draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color) { |
| 116 | Ref<Texture2D> port_icon = p_left ? get_slot_custom_icon_left(p_slot_index) : get_slot_custom_icon_right(p_slot_index); |
| 117 | |
| 118 | Point2 icon_offset; |
| 119 | if (port_icon.is_null()) { |
| 120 | port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode")); |
| 121 | } |
| 122 | |
| 123 | icon_offset = -port_icon->get_size() * 0.5; |
| 124 | |
| 125 | // Draw "shadow"/outline in the connection rim color. |
| 126 | draw_texture_rect(port_icon, Rect2(p_pos + (icon_offset - Size2(2, 2)) * EDSCALE, (port_icon->get_size() + Size2(4, 4)) * EDSCALE), false, p_rim_color); |
| 127 | draw_texture_rect(port_icon, Rect2(p_pos + icon_offset * EDSCALE, port_icon->get_size() * EDSCALE), false, p_color); |
| 128 | } |
| 129 | |
| 130 | void VSGraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) { |
| 131 | Color rim_color = get_theme_color(SNAME("connection_rim_color"), SNAME("GraphEdit")); |
| 132 | _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color); |
| 133 | } |
| 134 | |
| 135 | /////////////////// |
| 136 | |
| 137 | void VSRerouteNode::_notification(int p_what) { |
| 138 | switch (p_what) { |
| 139 | case NOTIFICATION_READY: { |
| 140 | connect(SceneStringName(mouse_entered), callable_mp(this, &VSRerouteNode::_on_mouse_entered)); |
| 141 | connect(SceneStringName(mouse_exited), callable_mp(this, &VSRerouteNode::_on_mouse_exited)); |
| 142 | } break; |
| 143 | case NOTIFICATION_DRAW: { |
| 144 | Vector2 offset = Vector2(0, -16 * EDSCALE); |
| 145 | Color drag_bg_color = get_theme_color(SNAME("drag_background"), SNAME("VSRerouteNode")); |
| 146 | draw_circle(get_size() * 0.5 + offset, 16 * EDSCALE, Color(drag_bg_color, selected ? 1 : icon_opacity), true, -1, true); |
| 147 | |
| 148 | Ref<Texture2D> icon = get_editor_theme_icon(SNAME("ToolMove")); |
| 149 | Point2 icon_offset = -icon->get_size() * 0.5 + get_size() * 0.5 + offset; |
| 150 | draw_texture(icon, icon_offset, Color(1, 1, 1, selected ? 1 : icon_opacity)); |
| 151 | } break; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void VSRerouteNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) { |
| 156 | Color rim_color = selected ? get_theme_color("selected_rim_color", "VSRerouteNode") : get_theme_color("connection_rim_color", "GraphEdit"); |
| 157 | _draw_port(p_slot_index, p_pos, p_left, p_color, rim_color); |
| 158 | } |
| 159 | |
| 160 | VSRerouteNode::VSRerouteNode() { |
| 161 | Label *title_lbl = Object::cast_to<Label>(get_titlebar_hbox()->get_child(0)); |
| 162 | title_lbl->hide(); |
| 163 | |
| 164 | const Size2 size = Size2(32, 32) * EDSCALE; |
| 165 | |
| 166 | Control *slot_area = memnew(Control); |
| 167 | slot_area->set_custom_minimum_size(size); |
| 168 | slot_area->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); |
| 169 | add_child(slot_area); |
| 170 | |
| 171 | // Lay the input and output ports on top of each other to create the illusion of a single port. |
| 172 | add_theme_constant_override("port_h_offset", size.width / 2); |
| 173 | } |
| 174 | |
| 175 | void VSRerouteNode::set_icon_opacity(float p_opacity) { |
| 176 | icon_opacity = p_opacity; |
| 177 | queue_redraw(); |
| 178 | } |
| 179 | |
| 180 | void VSRerouteNode::_on_mouse_entered() { |
| 181 | Ref<Tween> tween = create_tween(); |
| 182 | tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 0.0, 1.0, FADE_ANIMATION_LENGTH_SEC); |
| 183 | } |
| 184 | |
| 185 | void VSRerouteNode::_on_mouse_exited() { |
| 186 | Ref<Tween> tween = create_tween(); |
| 187 | tween->tween_method(callable_mp(this, &VSRerouteNode::set_icon_opacity), 1.0, 0.0, FADE_ANIMATION_LENGTH_SEC); |
| 188 | } |
| 189 | |
| 190 | /////////////////// |
| 191 | |
| 192 | VisualShaderGraphPlugin::VisualShaderGraphPlugin() { |
| 193 | vs_msdf_fonts_theme.instantiate(); |
| 194 | } |
| 195 | |
| 196 | void VisualShaderGraphPlugin::_bind_methods() { |
| 197 | ClassDB::bind_method("add_node", &VisualShaderGraphPlugin::add_node); |
| 198 | ClassDB::bind_method("remove_node", &VisualShaderGraphPlugin::remove_node); |
| 199 | ClassDB::bind_method("connect_nodes", &VisualShaderGraphPlugin::connect_nodes); |
| 200 | ClassDB::bind_method("disconnect_nodes", &VisualShaderGraphPlugin::disconnect_nodes); |
| 201 | ClassDB::bind_method("set_node_position", &VisualShaderGraphPlugin::set_node_position); |
| 202 | ClassDB::bind_method("update_node", &VisualShaderGraphPlugin::update_node); |
| 203 | ClassDB::bind_method("update_node_deferred", &VisualShaderGraphPlugin::update_node_deferred); |
| 204 | ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value); |
| 205 | ClassDB::bind_method("set_parameter_name", &VisualShaderGraphPlugin::set_parameter_name); |
| 206 | ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression); |
| 207 | ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve); |
| 208 | ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz); |
| 209 | ClassDB::bind_method(D_METHOD("attach_node_to_frame", "type", "id", "frame"), &VisualShaderGraphPlugin::attach_node_to_frame); |
| 210 | ClassDB::bind_method(D_METHOD("detach_node_from_frame", "type", "id"), &VisualShaderGraphPlugin::detach_node_from_frame); |
| 211 | ClassDB::bind_method(D_METHOD("set_frame_color_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_color_enabled); |
| 212 | ClassDB::bind_method(D_METHOD("set_frame_color", "type", "id", "color"), &VisualShaderGraphPlugin::set_frame_color); |
| 213 | ClassDB::bind_method(D_METHOD("set_frame_autoshrink_enabled", "type", "id", "enabled"), &VisualShaderGraphPlugin::set_frame_autoshrink_enabled); |
| 214 | } |
| 215 | |
| 216 | void VisualShaderGraphPlugin::set_editor(VisualShaderEditor *p_editor) { |
| 217 | editor = p_editor; |
| 218 | } |
| 219 | |
| 220 | void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) { |
| 221 | visual_shader = Ref<VisualShader>(p_shader); |
| 222 | } |
| 223 | |
| 224 | void VisualShaderGraphPlugin::set_connections(const List<VisualShader::Connection> &p_connections) { |
| 225 | connections = p_connections; |
| 226 | } |
| 227 | |
| 228 | void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid) { |
| 229 | if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].output_ports.has(p_port_id)) { |
| 230 | Link &link = links[p_node_id]; |
| 231 | |
| 232 | for (const KeyValue<int, Port> &E : link.output_ports) { |
| 233 | if (E.value.preview_button != nullptr) { |
| 234 | E.value.preview_button->set_pressed(false); |
| 235 | } |
| 236 | } |
| 237 | bool is_dirty = link.preview_pos < 0; |
| 238 | |
| 239 | if (!is_dirty && link.preview_visible && link.preview_box != nullptr) { |
| 240 | link.graph_element->remove_child(link.preview_box); |
| 241 | memdelete(link.preview_box); |
| 242 | link.preview_box = nullptr; |
| 243 | link.graph_element->reset_size(); |
| 244 | link.preview_visible = false; |
| 245 | } |
| 246 | |
| 247 | if (p_port_id != -1 && link.output_ports[p_port_id].preview_button != nullptr) { |
| 248 | if (is_dirty) { |
| 249 | link.preview_pos = link.graph_element->get_child_count(); |
| 250 | } |
| 251 | |
| 252 | VBoxContainer *vbox = memnew(VBoxContainer); |
| 253 | link.graph_element->add_child(vbox); |
| 254 | link.graph_element->move_child(vbox, link.preview_pos); |
| 255 | |
| 256 | GraphNode *graph_node = Object::cast_to<GraphNode>(link.graph_element); |
| 257 | if (graph_node) { |
| 258 | graph_node->set_slot_draw_stylebox(vbox->get_index(false), false); |
| 259 | } |
| 260 | |
| 261 | Control *offset = memnew(Control); |
| 262 | offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); |
| 263 | vbox->add_child(offset); |
| 264 | |
| 265 | VisualShaderNodePortPreview *port_preview = memnew(VisualShaderNodePortPreview); |
| 266 | port_preview->setup(visual_shader, editor->preview_material, editor->get_current_shader_type(), links[p_node_id].output_ports[p_port_id].type == VisualShaderNode::PORT_TYPE_VECTOR_4D, p_node_id, p_port_id, p_is_valid); |
| 267 | port_preview->set_h_size_flags(Control::SIZE_SHRINK_CENTER); |
| 268 | vbox->add_child(port_preview); |
| 269 | link.preview_visible = true; |
| 270 | link.preview_box = vbox; |
| 271 | link.output_ports[p_port_id].preview_button->set_pressed(true); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | void VisualShaderGraphPlugin::update_node_deferred(VisualShader::Type p_type, int p_node_id) { |
| 277 | callable_mp(this, &VisualShaderGraphPlugin::update_node).call_deferred(p_type, p_node_id); |
| 278 | } |
| 279 | |
| 280 | void VisualShaderGraphPlugin::update_node(VisualShader::Type p_type, int p_node_id) { |
| 281 | if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) { |
| 282 | return; |
| 283 | } |
| 284 | remove_node(p_type, p_node_id, true); |
| 285 | add_node(p_type, p_node_id, true, true); |
| 286 | |
| 287 | // TODO: Restore focus here? |
| 288 | } |
| 289 | |
| 290 | void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value) { |
| 291 | if (p_type != editor->get_current_shader_type() || !links.has(p_node_id)) { |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | Button *button = links[p_node_id].input_ports[p_port_id].default_input_button; |
| 296 | |
| 297 | switch (p_value.get_type()) { |
| 298 | case Variant::COLOR: { |
| 299 | button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); |
| 300 | |
| 301 | Callable ce = callable_mp(editor, &VisualShaderEditor::_draw_color_over_button); |
| 302 | if (!button->is_connected(SceneStringName(draw), ce)) { |
| 303 | button->connect(SceneStringName(draw), ce.bind(button, p_value)); |
| 304 | } |
| 305 | } break; |
| 306 | case Variant::BOOL: { |
| 307 | button->set_text(((bool)p_value) ? "true" : "false"); |
| 308 | } break; |
| 309 | case Variant::INT: |
| 310 | case Variant::FLOAT: { |
| 311 | button->set_text(String::num(p_value, 4)); |
| 312 | } break; |
| 313 | case Variant::VECTOR2: { |
| 314 | Vector2 v = p_value; |
| 315 | button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3)); |
| 316 | } break; |
| 317 | case Variant::VECTOR3: { |
| 318 | Vector3 v = p_value; |
| 319 | button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3)); |
| 320 | } break; |
| 321 | case Variant::VECTOR4: { |
| 322 | Vector4 v = p_value; |
| 323 | button->set_text(String::num(v.x, 3) + "," + String::num(v.y, 3) + "," + String::num(v.z, 3) + "," + String::num(v.w, 3)); |
| 324 | } break; |
| 325 | default: { |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | void VisualShaderGraphPlugin::set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name) { |
| 331 | if (editor->get_current_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].parameter_name != nullptr) { |
| 332 | links[p_node_id].parameter_name->set_text(p_name); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void VisualShaderGraphPlugin::update_curve(int p_node_id) { |
| 337 | if (links.has(p_node_id) && links[p_node_id].curve_editors[0]) { |
| 338 | Ref<VisualShaderNodeCurveTexture> tex = Object::cast_to<VisualShaderNodeCurveTexture>(links[p_node_id].visual_node); |
| 339 | ERR_FAIL_COND(tex.is_null()); |
| 340 | |
| 341 | if (tex->get_texture().is_valid()) { |
| 342 | links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve()); |
| 343 | } |
| 344 | tex->emit_changed(); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void VisualShaderGraphPlugin::update_curve_xyz(int p_node_id) { |
| 349 | if (links.has(p_node_id) && links[p_node_id].curve_editors[0] && links[p_node_id].curve_editors[1] && links[p_node_id].curve_editors[2]) { |
| 350 | Ref<VisualShaderNodeCurveXYZTexture> tex = Object::cast_to<VisualShaderNodeCurveXYZTexture>(links[p_node_id].visual_node); |
| 351 | ERR_FAIL_COND(tex.is_null()); |
| 352 | |
| 353 | if (tex->get_texture().is_valid()) { |
| 354 | links[p_node_id].curve_editors[0]->set_curve(tex->get_texture()->get_curve_x()); |
| 355 | links[p_node_id].curve_editors[1]->set_curve(tex->get_texture()->get_curve_y()); |
| 356 | links[p_node_id].curve_editors[2]->set_curve(tex->get_texture()->get_curve_z()); |
| 357 | } |
| 358 | tex->emit_changed(); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | int VisualShaderGraphPlugin::get_constant_index(float p_constant) const { |
| 363 | for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { |
| 364 | if (Math::is_equal_approx(p_constant, float_constant_defs[i].value)) { |
| 365 | return i + 1; |
| 366 | } |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) { |
| 372 | if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) { |
| 373 | return; |
| 374 | } |
| 375 | links[p_node_id].expression_edit->set_text(p_expression); |
| 376 | } |
| 377 | |
| 378 | void VisualShaderGraphPlugin::attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id) { |
| 379 | if (p_type != editor->get_current_shader_type() || !links.has(p_node_id) || !links.has(p_frame_id)) { |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | GraphEdit *graph = editor->graph; |
| 384 | if (!graph) { |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | // Get the hint label and hide it before attaching the node to prevent resizing issues with the frame. |
| 389 | GraphFrame *frame = Object::cast_to<GraphFrame>(links[p_frame_id].graph_element); |
| 390 | ERR_FAIL_COND_MSG(!frame, "VisualShader node to attach to is not a frame node."); |
| 391 | |
| 392 | Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false)); |
| 393 | if (frame_hint_label) { |
| 394 | frame_hint_label->hide(); |
| 395 | } |
| 396 | |
| 397 | graph->attach_graph_element_to_frame(itos(p_node_id), itos(p_frame_id)); |
| 398 | } |
| 399 | |
| 400 | void VisualShaderGraphPlugin::detach_node_from_frame(VisualShader::Type p_type, int p_node_id) { |
| 401 | GraphEdit *graph = editor->graph; |
| 402 | if (!graph) { |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | const StringName node_name = itos(p_node_id); |
| 407 | GraphFrame *frame = graph->get_element_frame(node_name); |
| 408 | if (!frame) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | graph->detach_graph_element_from_frame(node_name); |
| 413 | |
| 414 | bool no_more_frames_attached = graph->get_attached_nodes_of_frame(frame->get_name()).is_empty(); |
| 415 | |
| 416 | if (no_more_frames_attached) { |
| 417 | // Get the hint label and show it. |
| 418 | Label *frame_hint_label = Object::cast_to<Label>(frame->get_child(0, false)); |
| 419 | ERR_FAIL_COND_MSG(!frame_hint_label, "Frame node does not have a hint label."); |
| 420 | |
| 421 | frame_hint_label->show(); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | void VisualShaderGraphPlugin::set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) { |
| 426 | GraphEdit *graph = editor->graph; |
| 427 | ERR_FAIL_COND(!graph); |
| 428 | |
| 429 | const NodePath node_name = itos(p_node_id); |
| 430 | GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name)); |
| 431 | if (!frame) { |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | frame->set_tint_color_enabled(p_enable); |
| 436 | } |
| 437 | |
| 438 | void VisualShaderGraphPlugin::set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color) { |
| 439 | GraphEdit *graph = editor->graph; |
| 440 | ERR_FAIL_COND(!graph); |
| 441 | |
| 442 | const NodePath node_name = itos(p_node_id); |
| 443 | GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name)); |
| 444 | if (!frame) { |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | frame->set_tint_color(p_color); |
| 449 | } |
| 450 | |
| 451 | void VisualShaderGraphPlugin::set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable) { |
| 452 | GraphEdit *graph = editor->graph; |
| 453 | ERR_FAIL_COND(!graph); |
| 454 | |
| 455 | const NodePath node_name = itos(p_node_id); |
| 456 | GraphFrame *frame = Object::cast_to<GraphFrame>(graph->get_node_or_null(node_name)); |
| 457 | if (!frame) { |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | frame->set_autoshrink_enabled(p_enable); |
| 462 | } |
| 463 | |
| 464 | void VisualShaderGraphPlugin::update_reroute_nodes() { |
| 465 | for (const KeyValue<int, Link> &E : links) { |
| 466 | Ref<VisualShaderNodeReroute> reroute_node = Object::cast_to<VisualShaderNodeReroute>(E.value.visual_node); |
| 467 | if (reroute_node.is_valid()) { |
| 468 | update_node(editor->get_current_shader_type(), E.key); |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | Ref<Script> VisualShaderGraphPlugin::get_node_script(int p_node_id) const { |
| 474 | if (!links.has(p_node_id)) { |
| 475 | return Ref<Script>(); |
| 476 | } |
| 477 | |
| 478 | Ref<VisualShaderNodeCustom> custom = Ref<VisualShaderNodeCustom>(links[p_node_id].visual_node); |
| 479 | if (custom.is_valid()) { |
| 480 | return custom->get_script(); |
| 481 | } |
| 482 | |
| 483 | return Ref<Script>(); |
| 484 | } |
| 485 | |
| 486 | void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) { |
| 487 | links[p_node_id].input_ports.insert(p_port_id, { p_button }); |
| 488 | } |
| 489 | |
| 490 | void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) { |
| 491 | links[p_node_id].expression_edit = p_expression_edit; |
| 492 | } |
| 493 | |
| 494 | void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor) { |
| 495 | links[p_node_id].curve_editors[p_index] = p_curve_editor; |
| 496 | } |
| 497 | |
| 498 | void VisualShaderGraphPlugin::update_parameter_refs() { |
| 499 | for (KeyValue<int, Link> &E : links) { |
| 500 | VisualShaderNodeParameterRef *ref = Object::cast_to<VisualShaderNodeParameterRef>(E.value.visual_node); |
| 501 | if (ref) { |
| 502 | remove_node(E.value.type, E.key, true); |
| 503 | add_node(E.value.type, E.key, true, true); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // Only updates the linked frames of the given node, not the node itself (in case it's a frame node). |
| 509 | void VisualShaderGraphPlugin::update_frames(VisualShader::Type p_type, int p_node) { |
| 510 | GraphEdit *graph = editor->graph; |
| 511 | if (!graph) { |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_node); |
| 516 | if (vsnode.is_null()) { |
| 517 | WARN_PRINT("Update linked frames: Node not found."); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | int frame_vsnode_id = vsnode->get_frame(); |
| 522 | if (frame_vsnode_id == -1) { |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | Ref<VisualShaderNodeFrame> frame_node = visual_shader->get_node(p_type, frame_vsnode_id); |
| 527 | if (frame_node.is_null() || !links.has(frame_vsnode_id)) { |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | GraphFrame *frame = Object::cast_to<GraphFrame>(links[frame_vsnode_id].graph_element); |
| 532 | if (!frame) { |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | // Update the frame node recursively. |
| 537 | editor->graph->_update_graph_frame(frame); |
| 538 | } |
| 539 | |
| 540 | void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) { |
| 541 | if (editor->get_current_shader_type() == p_type && links.has(p_id)) { |
| 542 | links[p_id].graph_element->set_position_offset(p_position * editor->cached_theme_base_scale); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | bool VisualShaderGraphPlugin::is_preview_visible(int p_id) const { |
| 547 | return links[p_id].preview_visible; |
| 548 | } |
| 549 | |
| 550 | void VisualShaderGraphPlugin::clear_links() { |
| 551 | links.clear(); |
| 552 | } |
| 553 | |
| 554 | void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element) { |
| 555 | links.insert(p_id, { p_type, p_visual_node, p_graph_element, p_visual_node->get_output_port_for_preview() != -1, -1, HashMap<int, InputPort>(), HashMap<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); |
| 556 | } |
| 557 | |
| 558 | void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button) { |
| 559 | links[p_node_id].output_ports.insert(p_port, { p_port_type, p_button }); |
| 560 | } |
| 561 | |
| 562 | void VisualShaderGraphPlugin::register_parameter_name(int p_node_id, LineEdit *p_parameter_name) { |
| 563 | links[p_node_id].parameter_name = p_parameter_name; |
| 564 | } |
| 565 | |
| 566 | void VisualShaderGraphPlugin::update_theme() { |
| 567 | vector_expanded_color[0] = editor->get_theme_color(SNAME("axis_x_color"), EditorStringName(Editor)); // red |
| 568 | vector_expanded_color[1] = editor->get_theme_color(SNAME("axis_y_color"), EditorStringName(Editor)); // green |
| 569 | vector_expanded_color[2] = editor->get_theme_color(SNAME("axis_z_color"), EditorStringName(Editor)); // blue |
| 570 | vector_expanded_color[3] = editor->get_theme_color(SNAME("axis_w_color"), EditorStringName(Editor)); // alpha |
| 571 | |
| 572 | Ref<Font> label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", EditorStringName(EditorFonts)); |
| 573 | Ref<Font> label_bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_bold_msdf", EditorStringName(EditorFonts)); |
| 574 | vs_msdf_fonts_theme->set_font(SceneStringName(font), "Label", label_font); |
| 575 | vs_msdf_fonts_theme->set_font(SceneStringName(font), "GraphNodeTitleLabel", label_bold_font); |
| 576 | if (!EditorThemeManager::is_dark_icon_and_font()) { |
| 577 | // Override the color to white for light themes. |
| 578 | vs_msdf_fonts_theme->set_color(SceneStringName(font_color), "GraphNodeTitleLabel", Color(1, 1, 1)); |
| 579 | } |
| 580 | vs_msdf_fonts_theme->set_font(SceneStringName(font), "LineEdit", label_font); |
| 581 | vs_msdf_fonts_theme->set_font(SceneStringName(font), "Button", label_font); |
| 582 | } |
| 583 | |
| 584 | bool VisualShaderGraphPlugin::is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const { |
| 585 | bool result = false; |
| 586 | |
| 587 | Ref<VisualShaderNodeParameter> parameter_node = Object::cast_to<VisualShaderNodeParameter>(visual_shader->get_node_unchecked(p_type, p_node).ptr()); |
| 588 | if (parameter_node.is_valid()) { |
| 589 | if (parameter_node->get_qualifier() == VisualShaderNodeParameter::QUAL_INSTANCE) { |
| 590 | return true; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | const LocalVector<int> &prev_connected_nodes = visual_shader->get_prev_connected_nodes(p_type, p_node); |
| 595 | |
| 596 | for (const int &E : prev_connected_nodes) { |
| 597 | result = is_node_has_parameter_instances_relatively(p_type, E); |
| 598 | if (result) { |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | return result; |
| 604 | } |
| 605 | |
| 606 | void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames) { |
| 607 | if (visual_shader.is_null() || p_type != editor->get_current_shader_type()) { |
| 608 | return; |
| 609 | } |
| 610 | GraphEdit *graph = editor->graph; |
| 611 | if (!graph) { |
| 612 | return; |
| 613 | } |
| 614 | VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin(); |
| 615 | if (!graph_plugin) { |
| 616 | return; |
| 617 | } |
| 618 | Shader::Mode mode = visual_shader->get_mode(); |
| 619 | |
| 620 | Control *offset; |
| 621 | |
| 622 | const Color type_color[] = { |
| 623 | EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"), |
| 624 | EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"), |
| 625 | EDITOR_GET("editors/visual_editors/connection_colors/scalar_color"), |
| 626 | EDITOR_GET("editors/visual_editors/connection_colors/vector2_color"), |
| 627 | EDITOR_GET("editors/visual_editors/connection_colors/vector3_color"), |
| 628 | EDITOR_GET("editors/visual_editors/connection_colors/vector4_color"), |
| 629 | EDITOR_GET("editors/visual_editors/connection_colors/boolean_color"), |
| 630 | EDITOR_GET("editors/visual_editors/connection_colors/transform_color"), |
| 631 | EDITOR_GET("editors/visual_editors/connection_colors/sampler_color"), |
| 632 | }; |
| 633 | |
| 634 | // Keep in sync with VisualShaderNode::Category. |
| 635 | const Color category_color[VisualShaderNode::Category::CATEGORY_MAX] = { |
| 636 | Color(0.0, 0.0, 0.0), // None (default, not used) |
| 637 | EDITOR_GET("editors/visual_editors/category_colors/output_color"), |
| 638 | EDITOR_GET("editors/visual_editors/category_colors/color_color"), |
| 639 | EDITOR_GET("editors/visual_editors/category_colors/conditional_color"), |
| 640 | EDITOR_GET("editors/visual_editors/category_colors/input_color"), |
| 641 | EDITOR_GET("editors/visual_editors/category_colors/scalar_color"), |
| 642 | EDITOR_GET("editors/visual_editors/category_colors/textures_color"), |
| 643 | EDITOR_GET("editors/visual_editors/category_colors/transform_color"), |
| 644 | EDITOR_GET("editors/visual_editors/category_colors/utility_color"), |
| 645 | EDITOR_GET("editors/visual_editors/category_colors/vector_color"), |
| 646 | EDITOR_GET("editors/visual_editors/category_colors/special_color"), |
| 647 | EDITOR_GET("editors/visual_editors/category_colors/particle_color"), |
| 648 | }; |
| 649 | |
| 650 | static const String vector_expanded_name[4] = { "red", "green", "blue", "alpha" }; |
| 651 | |
| 652 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(p_type, p_id); |
| 653 | ERR_FAIL_COND(vsnode.is_null()); |
| 654 | |
| 655 | Ref<VisualShaderNodeResizableBase> resizable_node = vsnode; |
| 656 | bool is_resizable = resizable_node.is_valid(); |
| 657 | Size2 size = Size2(0, 0); |
| 658 | |
| 659 | Ref<VisualShaderNodeGroupBase> group_node = vsnode; |
| 660 | bool is_group = group_node.is_valid(); |
| 661 | |
| 662 | Ref<VisualShaderNodeFrame> frame_node = vsnode; |
| 663 | bool is_frame = frame_node.is_valid(); |
| 664 | |
| 665 | Ref<VisualShaderNodeExpression> expression_node = group_node; |
| 666 | bool is_expression = expression_node.is_valid(); |
| 667 | String expression = ""; |
| 668 | |
| 669 | Ref<VisualShaderNodeReroute> reroute_node = vsnode; |
| 670 | bool is_reroute = reroute_node.is_valid(); |
| 671 | |
| 672 | Ref<VisualShaderNodeCustom> custom_node = vsnode; |
| 673 | if (custom_node.is_valid()) { |
| 674 | custom_node->_set_initialized(true); |
| 675 | } |
| 676 | |
| 677 | GraphElement *node; |
| 678 | if (is_frame) { |
| 679 | GraphFrame *frame = memnew(GraphFrame); |
| 680 | frame->set_title(vsnode->get_caption()); |
| 681 | node = frame; |
| 682 | } else if (is_reroute) { |
| 683 | VSRerouteNode *reroute_gnode = memnew(VSRerouteNode); |
| 684 | reroute_gnode->set_ignore_invalid_connection_type(true); |
| 685 | node = reroute_gnode; |
| 686 | } else { |
| 687 | VSGraphNode *gnode = memnew(VSGraphNode); |
| 688 | gnode->set_title(vsnode->get_caption()); |
| 689 | node = gnode; |
| 690 | } |
| 691 | node->set_name(itos(p_id)); |
| 692 | |
| 693 | // All nodes are closable except the output node. |
| 694 | if (p_id >= 2) { |
| 695 | vsnode->set_deletable(true); |
| 696 | node->connect("delete_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED); |
| 697 | } |
| 698 | graph->add_child(node); |
| 699 | node->set_theme(vs_msdf_fonts_theme); |
| 700 | |
| 701 | // Set the node's titlebar color based on its category. |
| 702 | if (vsnode->get_category() != VisualShaderNode::CATEGORY_NONE && !is_frame && !is_reroute) { |
| 703 | Ref<StyleBoxFlat> sb_colored = editor->get_theme_stylebox("titlebar", "GraphNode")->duplicate(); |
| 704 | sb_colored->set_bg_color(category_color[vsnode->get_category()]); |
| 705 | node->add_theme_style_override("titlebar", sb_colored); |
| 706 | |
| 707 | Ref<StyleBoxFlat> sb_colored_selected = editor->get_theme_stylebox("titlebar_selected", "GraphNode")->duplicate(); |
| 708 | sb_colored_selected->set_bg_color(category_color[vsnode->get_category()].lightened(0.2)); |
| 709 | node->add_theme_style_override("titlebar_selected", sb_colored_selected); |
| 710 | } |
| 711 | |
| 712 | if (p_just_update) { |
| 713 | Link &link = links[p_id]; |
| 714 | |
| 715 | link.visual_node = vsnode.ptr(); |
| 716 | link.graph_element = node; |
| 717 | link.preview_box = nullptr; |
| 718 | link.preview_pos = -1; |
| 719 | link.output_ports.clear(); |
| 720 | link.input_ports.clear(); |
| 721 | } else { |
| 722 | register_link(p_type, p_id, vsnode.ptr(), node); |
| 723 | } |
| 724 | |
| 725 | if (is_resizable) { |
| 726 | size = resizable_node->get_size(); |
| 727 | |
| 728 | node->set_resizable(true); |
| 729 | node->connect("resize_end", callable_mp(editor, &VisualShaderEditor::_node_resized).bind((int)p_type, p_id)); |
| 730 | node->set_size(size); |
| 731 | // node->call_deferred(SNAME("set_size"), size); |
| 732 | // editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size); |
| 733 | } |
| 734 | |
| 735 | if (is_expression) { |
| 736 | expression = expression_node->get_expression(); |
| 737 | } |
| 738 | |
| 739 | node->set_position_offset(visual_shader->get_node_position(p_type, p_id) * editor->cached_theme_base_scale); |
| 740 | |
| 741 | node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id)); |
| 742 | |
| 743 | Control *custom_editor = nullptr; |
| 744 | int port_offset = 1; |
| 745 | |
| 746 | if (p_update_frames) { |
| 747 | if (vsnode->get_frame() > -1) { |
| 748 | graph->attach_graph_element_to_frame(itos(p_id), itos(vsnode->get_frame())); |
| 749 | } else { |
| 750 | graph->detach_graph_element_from_frame(itos(p_id)); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | if (is_frame) { |
| 755 | GraphFrame *graph_frame = Object::cast_to<GraphFrame>(node); |
| 756 | ERR_FAIL_NULL(graph_frame); |
| 757 | |
| 758 | graph_frame->set_tint_color_enabled(frame_node->is_tint_color_enabled()); |
| 759 | graph_frame->set_tint_color(frame_node->get_tint_color()); |
| 760 | |
| 761 | // Add hint label. |
| 762 | Label *frame_hint_label = memnew(Label); |
| 763 | frame_hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 764 | node->add_child(frame_hint_label); |
| 765 | frame_hint_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); |
| 766 | frame_hint_label->set_vertical_alignment(VerticalAlignment::VERTICAL_ALIGNMENT_CENTER); |
| 767 | frame_hint_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 768 | frame_hint_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 769 | frame_hint_label->set_text(TTR("Drag and drop nodes here to attach them.")); |
| 770 | frame_hint_label->set_modulate(Color(1.0, 1.0, 1.0, 0.3)); |
| 771 | graph_frame->set_autoshrink_enabled(frame_node->is_autoshrink_enabled()); |
| 772 | |
| 773 | if (frame_node->get_attached_nodes().is_empty()) { |
| 774 | frame_hint_label->show(); |
| 775 | } else { |
| 776 | frame_hint_label->hide(); |
| 777 | } |
| 778 | |
| 779 | // Attach all nodes. |
| 780 | if (p_update_frames && frame_node->get_attached_nodes().size() > 0) { |
| 781 | for (const int &id : frame_node->get_attached_nodes()) { |
| 782 | graph->attach_graph_element_to_frame(itos(id), node->get_name()); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | // We should be done here. |
| 787 | return; |
| 788 | } |
| 789 | |
| 790 | if (!is_reroute) { |
| 791 | Control *content_offset = memnew(Control); |
| 792 | content_offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); |
| 793 | node->add_child(content_offset); |
| 794 | } |
| 795 | |
| 796 | if (is_group) { |
| 797 | port_offset += 1; |
| 798 | } |
| 799 | |
| 800 | // Set the minimum width of a node based on the preview size to avoid a resize when toggling the preview. |
| 801 | Ref<StyleBoxFlat> graph_node_stylebox = graph->get_theme_stylebox(SceneStringName(panel), "GraphNode"); |
| 802 | int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size"); |
| 803 | if (!is_frame && !is_reroute) { |
| 804 | node->set_custom_minimum_size(Size2((Math::ceil(graph_node_stylebox->get_minimum_size().width) + port_preview_size) * EDSCALE, 0)); |
| 805 | } |
| 806 | |
| 807 | Ref<VisualShaderNodeParticleEmit> emit = vsnode; |
| 808 | if (emit.is_valid()) { |
| 809 | node->set_custom_minimum_size(Size2(200 * EDSCALE, 0)); |
| 810 | } |
| 811 | |
| 812 | Ref<VisualShaderNodeParameterRef> parameter_ref = vsnode; |
| 813 | if (parameter_ref.is_valid()) { |
| 814 | parameter_ref->set_shader_rid(visual_shader->get_rid()); |
| 815 | parameter_ref->update_parameter_type(); |
| 816 | } |
| 817 | |
| 818 | Ref<VisualShaderNodeVarying> varying = vsnode; |
| 819 | if (varying.is_valid()) { |
| 820 | varying->set_shader_rid(visual_shader->get_rid()); |
| 821 | } |
| 822 | |
| 823 | Ref<VisualShaderNodeParameter> parameter = vsnode; |
| 824 | HBoxContainer *hb = nullptr; |
| 825 | |
| 826 | if (parameter.is_valid()) { |
| 827 | LineEdit *parameter_name = memnew(LineEdit); |
| 828 | register_parameter_name(p_id, parameter_name); |
| 829 | parameter_name->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 830 | parameter_name->set_text(parameter->get_parameter_name()); |
| 831 | parameter_name->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_changed).bind(p_id)); |
| 832 | parameter_name->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_parameter_line_edit_focus_out).bind(parameter_name, p_id)); |
| 833 | |
| 834 | if (vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") { |
| 835 | hb = memnew(HBoxContainer); |
| 836 | hb->add_child(parameter_name); |
| 837 | node->add_child(hb); |
| 838 | } else { |
| 839 | node->add_child(parameter_name); |
| 840 | } |
| 841 | port_offset++; |
| 842 | } |
| 843 | |
| 844 | for (int i = 0; i < editor->plugins.size(); i++) { |
| 845 | vsnode->set_meta("id", p_id); |
| 846 | vsnode->set_meta("shader_type", (int)p_type); |
| 847 | custom_editor = editor->plugins.write[i]->create_editor(visual_shader, vsnode); |
| 848 | vsnode->remove_meta("id"); |
| 849 | vsnode->remove_meta("shader_type"); |
| 850 | if (custom_editor) { |
| 851 | if (vsnode->is_show_prop_names()) { |
| 852 | custom_editor->call_deferred(SNAME("_show_prop_names"), true); |
| 853 | } |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | if (custom_node.is_valid()) { |
| 859 | bool first = true; |
| 860 | VBoxContainer *vbox = nullptr; |
| 861 | |
| 862 | int i = 0; |
| 863 | for (List<VisualShaderNodeCustom::DropDownListProperty>::ConstIterator itr = custom_node->dp_props.begin(); itr != custom_node->dp_props.end(); ++itr, ++i) { |
| 864 | const VisualShaderNodeCustom::DropDownListProperty &dp = *itr; |
| 865 | |
| 866 | if (first) { |
| 867 | first = false; |
| 868 | vbox = memnew(VBoxContainer); |
| 869 | node->add_child(vbox); |
| 870 | port_offset++; |
| 871 | } |
| 872 | |
| 873 | HBoxContainer *hbox = memnew(HBoxContainer); |
| 874 | vbox->add_child(hbox); |
| 875 | hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 876 | |
| 877 | String prop_name = dp.name.strip_edges(); |
| 878 | if (!prop_name.is_empty()) { |
| 879 | Label *label = memnew(Label); |
| 880 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 881 | label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. |
| 882 | label->set_text(prop_name + ":"); |
| 883 | hbox->add_child(label); |
| 884 | } |
| 885 | |
| 886 | OptionButton *op = memnew(OptionButton); |
| 887 | hbox->add_child(op); |
| 888 | op->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 889 | op->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_set_custom_node_option).bind(p_id, i), CONNECT_DEFERRED); |
| 890 | |
| 891 | for (const String &s : dp.options) { |
| 892 | op->add_item(s); |
| 893 | } |
| 894 | if (custom_node->dp_selected_cache.has(i)) { |
| 895 | op->select(custom_node->dp_selected_cache[i]); |
| 896 | } else { |
| 897 | op->select(0); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | Ref<VisualShaderNodeCurveTexture> curve = vsnode; |
| 903 | Ref<VisualShaderNodeCurveXYZTexture> curve_xyz = vsnode; |
| 904 | |
| 905 | bool is_curve = curve.is_valid() || curve_xyz.is_valid(); |
| 906 | if (is_curve) { |
| 907 | hb = memnew(HBoxContainer); |
| 908 | node->add_child(hb); |
| 909 | } |
| 910 | |
| 911 | if (curve.is_valid()) { |
| 912 | custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 913 | |
| 914 | if (curve->get_texture().is_valid()) { |
| 915 | curve->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve).bind(p_id)); |
| 916 | } |
| 917 | |
| 918 | CurveEditor *curve_editor = memnew(CurveEditor); |
| 919 | node->add_child(curve_editor); |
| 920 | register_curve_editor(p_id, 0, curve_editor); |
| 921 | curve_editor->set_custom_minimum_size(Size2(300, 0)); |
| 922 | curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 923 | if (curve->get_texture().is_valid()) { |
| 924 | curve_editor->set_curve(curve->get_texture()->get_curve()); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | if (curve_xyz.is_valid()) { |
| 929 | custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 930 | |
| 931 | if (curve_xyz->get_texture().is_valid()) { |
| 932 | curve_xyz->get_texture()->connect_changed(callable_mp(graph_plugin, &VisualShaderGraphPlugin::update_curve_xyz).bind(p_id)); |
| 933 | } |
| 934 | |
| 935 | CurveEditor *curve_editor_x = memnew(CurveEditor); |
| 936 | node->add_child(curve_editor_x); |
| 937 | register_curve_editor(p_id, 0, curve_editor_x); |
| 938 | curve_editor_x->set_custom_minimum_size(Size2(300, 0)); |
| 939 | curve_editor_x->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 940 | if (curve_xyz->get_texture().is_valid()) { |
| 941 | curve_editor_x->set_curve(curve_xyz->get_texture()->get_curve_x()); |
| 942 | } |
| 943 | |
| 944 | CurveEditor *curve_editor_y = memnew(CurveEditor); |
| 945 | node->add_child(curve_editor_y); |
| 946 | register_curve_editor(p_id, 1, curve_editor_y); |
| 947 | curve_editor_y->set_custom_minimum_size(Size2(300, 0)); |
| 948 | curve_editor_y->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 949 | if (curve_xyz->get_texture().is_valid()) { |
| 950 | curve_editor_y->set_curve(curve_xyz->get_texture()->get_curve_y()); |
| 951 | } |
| 952 | |
| 953 | CurveEditor *curve_editor_z = memnew(CurveEditor); |
| 954 | node->add_child(curve_editor_z); |
| 955 | register_curve_editor(p_id, 2, curve_editor_z); |
| 956 | curve_editor_z->set_custom_minimum_size(Size2(300, 0)); |
| 957 | curve_editor_z->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 958 | if (curve_xyz->get_texture().is_valid()) { |
| 959 | curve_editor_z->set_curve(curve_xyz->get_texture()->get_curve_z()); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (custom_editor) { |
| 964 | if (is_curve || (hb == nullptr && !vsnode->is_use_prop_slots() && (vsnode->get_output_port_count() == 0 || vsnode->get_output_port_name(0) == "") && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == ""))) { |
| 965 | // Will be embedded in first port. |
| 966 | } else { |
| 967 | port_offset++; |
| 968 | node->add_child(custom_editor); |
| 969 | custom_editor = nullptr; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | if (is_group) { |
| 974 | if (group_node->is_editable()) { |
| 975 | HBoxContainer *hb2 = memnew(HBoxContainer); |
| 976 | |
| 977 | String input_port_name = "input" + itos(group_node->get_free_input_port_id()); |
| 978 | String output_port_name = "output" + itos(group_node->get_free_output_port_id()); |
| 979 | |
| 980 | for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) { |
| 981 | if (i < vsnode->get_input_port_count()) { |
| 982 | if (input_port_name == vsnode->get_input_port_name(i)) { |
| 983 | input_port_name = "_" + input_port_name; |
| 984 | } |
| 985 | } |
| 986 | if (i < vsnode->get_output_port_count()) { |
| 987 | if (output_port_name == vsnode->get_output_port_name(i)) { |
| 988 | output_port_name = "_" + output_port_name; |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | Button *add_input_btn = memnew(Button); |
| 994 | add_input_btn->set_text(TTR("Add Input")); |
| 995 | add_input_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_add_input_port).bind(p_id, group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR_3D, input_port_name), CONNECT_DEFERRED); |
| 996 | hb2->add_child(add_input_btn); |
| 997 | |
| 998 | hb2->add_spacer(); |
| 999 | |
| 1000 | Button *add_output_btn = memnew(Button); |
| 1001 | add_output_btn->set_text(TTR("Add Output")); |
| 1002 | add_output_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_add_output_port).bind(p_id, group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR_3D, output_port_name), CONNECT_DEFERRED); |
| 1003 | hb2->add_child(add_output_btn); |
| 1004 | |
| 1005 | node->add_child(hb2); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | int output_port_count = 0; |
| 1010 | for (int i = 0; i < vsnode->get_output_port_count(); i++) { |
| 1011 | if (vsnode->_is_output_port_expanded(i)) { |
| 1012 | switch (vsnode->get_output_port_type(i)) { |
| 1013 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: { |
| 1014 | output_port_count += 2; |
| 1015 | } break; |
| 1016 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: { |
| 1017 | output_port_count += 3; |
| 1018 | } break; |
| 1019 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: { |
| 1020 | output_port_count += 4; |
| 1021 | } break; |
| 1022 | default: |
| 1023 | break; |
| 1024 | } |
| 1025 | } |
| 1026 | output_port_count++; |
| 1027 | } |
| 1028 | int max_ports = MAX(vsnode->get_input_port_count(), output_port_count); |
| 1029 | VisualShaderNode::PortType expanded_type = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1030 | int expanded_port_counter = 0; |
| 1031 | |
| 1032 | for (int i = 0, j = 0; i < max_ports; i++, j++) { |
| 1033 | switch (expanded_type) { |
| 1034 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: { |
| 1035 | if (expanded_port_counter >= 2) { |
| 1036 | expanded_type = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1037 | expanded_port_counter = 0; |
| 1038 | i -= 2; |
| 1039 | } |
| 1040 | } break; |
| 1041 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: { |
| 1042 | if (expanded_port_counter >= 3) { |
| 1043 | expanded_type = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1044 | expanded_port_counter = 0; |
| 1045 | i -= 3; |
| 1046 | } |
| 1047 | } break; |
| 1048 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: { |
| 1049 | if (expanded_port_counter >= 4) { |
| 1050 | expanded_type = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1051 | expanded_port_counter = 0; |
| 1052 | i -= 4; |
| 1053 | } |
| 1054 | } break; |
| 1055 | default: |
| 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | if (vsnode->is_port_separator(i)) { |
| 1060 | HSeparator *separator = memnew(HSeparator); |
| 1061 | separator->add_theme_style_override("separator", editor->get_theme_stylebox("separator", "GraphNode")); |
| 1062 | node->add_child(separator); |
| 1063 | port_offset++; |
| 1064 | } |
| 1065 | |
| 1066 | bool valid_left = j < vsnode->get_input_port_count(); |
| 1067 | VisualShaderNode::PortType port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1068 | bool port_left_used = false; |
| 1069 | String name_left; |
| 1070 | if (valid_left) { |
| 1071 | name_left = vsnode->get_input_port_name(j); |
| 1072 | port_left = vsnode->get_input_port_type(j); |
| 1073 | for (const VisualShader::Connection &E : connections) { |
| 1074 | if (E.to_node == p_id && E.to_port == j) { |
| 1075 | port_left_used = true; |
| 1076 | break; |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | bool valid_right = true; |
| 1082 | VisualShaderNode::PortType port_right = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1083 | String name_right; |
| 1084 | |
| 1085 | if (expanded_type == VisualShaderNode::PORT_TYPE_SCALAR) { |
| 1086 | valid_right = i < vsnode->get_output_port_count(); |
| 1087 | if (valid_right) { |
| 1088 | name_right = vsnode->get_output_port_name(i); |
| 1089 | port_right = vsnode->get_output_port_type(i); |
| 1090 | } |
| 1091 | } else { |
| 1092 | name_right = vector_expanded_name[expanded_port_counter++]; |
| 1093 | } |
| 1094 | |
| 1095 | bool is_first_hbox = false; |
| 1096 | if (i == 0 && hb != nullptr) { |
| 1097 | is_first_hbox = true; |
| 1098 | } else { |
| 1099 | hb = memnew(HBoxContainer); |
| 1100 | } |
| 1101 | hb->add_theme_constant_override("separation", 7 * EDSCALE); |
| 1102 | |
| 1103 | // Default value button/property editor. |
| 1104 | Variant default_value; |
| 1105 | |
| 1106 | if (valid_left && !port_left_used) { |
| 1107 | default_value = vsnode->get_input_port_default_value(j); |
| 1108 | } |
| 1109 | |
| 1110 | Button *default_input_btn = memnew(Button); |
| 1111 | hb->add_child(default_input_btn); |
| 1112 | register_default_input_button(p_id, j, default_input_btn); |
| 1113 | default_input_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_edit_port_default_input).bind(default_input_btn, p_id, j)); |
| 1114 | if (default_value.get_type() != Variant::NIL) { // only a label |
| 1115 | set_input_port_default_value(p_type, p_id, j, default_value); |
| 1116 | } else { |
| 1117 | default_input_btn->hide(); |
| 1118 | } |
| 1119 | |
| 1120 | if (j == 0 && custom_editor) { |
| 1121 | hb->add_child(custom_editor); |
| 1122 | custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1123 | } else { |
| 1124 | if (valid_left) { |
| 1125 | if (is_group) { |
| 1126 | OptionButton *type_box = memnew(OptionButton); |
| 1127 | hb->add_child(type_box); |
| 1128 | type_box->add_item(TTR("Float")); |
| 1129 | type_box->add_item(TTR("Int")); |
| 1130 | type_box->add_item(TTR("UInt")); |
| 1131 | type_box->add_item(TTR("Vector2")); |
| 1132 | type_box->add_item(TTR("Vector3")); |
| 1133 | type_box->add_item(TTR("Vector4")); |
| 1134 | type_box->add_item(TTR("Boolean")); |
| 1135 | type_box->add_item(TTR("Transform")); |
| 1136 | type_box->add_item(TTR("Sampler")); |
| 1137 | type_box->select(group_node->get_input_port_type(j)); |
| 1138 | type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
| 1139 | type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_input_port_type).bind(p_id, j), CONNECT_DEFERRED); |
| 1140 | |
| 1141 | LineEdit *name_box = memnew(LineEdit); |
| 1142 | hb->add_child(name_box); |
| 1143 | name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0)); |
| 1144 | name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1145 | name_box->set_text(name_left); |
| 1146 | name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_input_port_name).bind(name_box, p_id, j), CONNECT_DEFERRED); |
| 1147 | name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, j, false), CONNECT_DEFERRED); |
| 1148 | |
| 1149 | Button *remove_btn = memnew(Button); |
| 1150 | remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons))); |
| 1151 | remove_btn->set_tooltip_text(TTR("Remove") + " " + name_left); |
| 1152 | remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_input_port).bind(p_id, j), CONNECT_DEFERRED); |
| 1153 | hb->add_child(remove_btn); |
| 1154 | } else { |
| 1155 | Label *label = memnew(Label); |
| 1156 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1157 | label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. |
| 1158 | label->set_text(name_left); |
| 1159 | label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); |
| 1160 | hb->add_child(label); |
| 1161 | |
| 1162 | if (vsnode->is_input_port_default(j, mode) && !port_left_used) { |
| 1163 | Label *hint_label = memnew(Label); |
| 1164 | hint_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1165 | hint_label->set_text(TTR("[default]")); |
| 1166 | hint_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit"))); |
| 1167 | hint_label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); |
| 1168 | hb->add_child(hint_label); |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | if (!is_group && !is_first_hbox) { |
| 1174 | hb->add_spacer(); |
| 1175 | } |
| 1176 | |
| 1177 | if (valid_right) { |
| 1178 | if (is_group) { |
| 1179 | Button *remove_btn = memnew(Button); |
| 1180 | remove_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Remove"), EditorStringName(EditorIcons))); |
| 1181 | remove_btn->set_tooltip_text(TTR("Remove") + " " + name_right); |
| 1182 | remove_btn->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_remove_output_port).bind(p_id, i), CONNECT_DEFERRED); |
| 1183 | hb->add_child(remove_btn); |
| 1184 | |
| 1185 | LineEdit *name_box = memnew(LineEdit); |
| 1186 | hb->add_child(name_box); |
| 1187 | name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0)); |
| 1188 | name_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1189 | name_box->set_text(name_right); |
| 1190 | name_box->connect(SceneStringName(text_submitted), callable_mp(editor, &VisualShaderEditor::_change_output_port_name).bind(name_box, p_id, i), CONNECT_DEFERRED); |
| 1191 | name_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_port_name_focus_out).bind(name_box, p_id, i, true), CONNECT_DEFERRED); |
| 1192 | |
| 1193 | OptionButton *type_box = memnew(OptionButton); |
| 1194 | hb->add_child(type_box); |
| 1195 | type_box->add_item(TTR("Float")); |
| 1196 | type_box->add_item(TTR("Int")); |
| 1197 | type_box->add_item(TTR("UInt")); |
| 1198 | type_box->add_item(TTR("Vector2")); |
| 1199 | type_box->add_item(TTR("Vector3")); |
| 1200 | type_box->add_item(TTR("Vector4")); |
| 1201 | type_box->add_item(TTR("Boolean")); |
| 1202 | type_box->add_item(TTR("Transform")); |
| 1203 | type_box->select(group_node->get_output_port_type(i)); |
| 1204 | type_box->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
| 1205 | type_box->connect(SceneStringName(item_selected), callable_mp(editor, &VisualShaderEditor::_change_output_port_type).bind(p_id, i), CONNECT_DEFERRED); |
| 1206 | } else { |
| 1207 | Label *label = memnew(Label); |
| 1208 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1209 | label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. |
| 1210 | label->set_text(name_right); |
| 1211 | label->add_theme_style_override(CoreStringName(normal), editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact |
| 1212 | hb->add_child(label); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (valid_right) { |
| 1218 | if (expanded_port_counter == 0 && vsnode->is_output_port_expandable(i)) { |
| 1219 | TextureButton *expand = memnew(TextureButton); |
| 1220 | expand->set_accessibility_name(TTRC("Expand output port")); |
| 1221 | expand->set_toggle_mode(true); |
| 1222 | expand->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiTreeArrowRight"))); |
| 1223 | expand->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiTreeArrowDown"))); |
| 1224 | expand->set_v_size_flags(Control::SIZE_SHRINK_CENTER); |
| 1225 | expand->set_pressed(vsnode->_is_output_port_expanded(i)); |
| 1226 | expand->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_expand_output_port).bind(p_id, i, !vsnode->_is_output_port_expanded(i)), CONNECT_DEFERRED); |
| 1227 | hb->add_child(expand); |
| 1228 | } |
| 1229 | if (vsnode->has_output_port_preview(i) && port_right != VisualShaderNode::PORT_TYPE_TRANSFORM && port_right != VisualShaderNode::PORT_TYPE_SAMPLER) { |
| 1230 | TextureButton *preview = memnew(TextureButton); |
| 1231 | preview->set_accessibility_name(TTRC("Select preview port")); |
| 1232 | preview->set_toggle_mode(true); |
| 1233 | preview->set_texture_normal(editor->get_editor_theme_icon(SNAME("GuiVisibilityHidden"))); |
| 1234 | preview->set_texture_pressed(editor->get_editor_theme_icon(SNAME("GuiVisibilityVisible"))); |
| 1235 | preview->set_v_size_flags(Control::SIZE_SHRINK_CENTER); |
| 1236 | |
| 1237 | register_output_port(p_id, j, port_right, preview); |
| 1238 | |
| 1239 | preview->connect(SceneStringName(pressed), callable_mp(editor, &VisualShaderEditor::_preview_select_port).bind(p_id, j), CONNECT_DEFERRED); |
| 1240 | hb->add_child(preview); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if (is_group) { |
| 1245 | offset = memnew(Control); |
| 1246 | offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); |
| 1247 | node->add_child(offset); |
| 1248 | port_offset++; |
| 1249 | } |
| 1250 | |
| 1251 | if (!is_first_hbox && !is_reroute) { |
| 1252 | node->add_child(hb); |
| 1253 | if (curve_xyz.is_valid()) { |
| 1254 | node->move_child(hb, 1 + expanded_port_counter); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | if (expanded_type != VisualShaderNode::PORT_TYPE_SCALAR) { |
| 1259 | continue; |
| 1260 | } |
| 1261 | |
| 1262 | int idx = is_first_hbox ? 1 : i + port_offset; |
| 1263 | if (is_reroute) { |
| 1264 | idx = 0; |
| 1265 | } |
| 1266 | if (!is_frame) { |
| 1267 | GraphNode *graph_node = Object::cast_to<GraphNode>(node); |
| 1268 | |
| 1269 | graph_node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]); |
| 1270 | |
| 1271 | if (vsnode->_is_output_port_expanded(i)) { |
| 1272 | switch (vsnode->get_output_port_type(i)) { |
| 1273 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: { |
| 1274 | port_offset++; |
| 1275 | valid_left = (i + 1) < vsnode->get_input_port_count(); |
| 1276 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1277 | if (valid_left) { |
| 1278 | port_left = vsnode->get_input_port_type(i + 1); |
| 1279 | } |
| 1280 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); |
| 1281 | port_offset++; |
| 1282 | |
| 1283 | valid_left = (i + 2) < vsnode->get_input_port_count(); |
| 1284 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1285 | if (valid_left) { |
| 1286 | port_left = vsnode->get_input_port_type(i + 2); |
| 1287 | } |
| 1288 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); |
| 1289 | |
| 1290 | expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D; |
| 1291 | } break; |
| 1292 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: { |
| 1293 | port_offset++; |
| 1294 | valid_left = (i + 1) < vsnode->get_input_port_count(); |
| 1295 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1296 | if (valid_left) { |
| 1297 | port_left = vsnode->get_input_port_type(i + 1); |
| 1298 | } |
| 1299 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); |
| 1300 | port_offset++; |
| 1301 | |
| 1302 | valid_left = (i + 2) < vsnode->get_input_port_count(); |
| 1303 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1304 | if (valid_left) { |
| 1305 | port_left = vsnode->get_input_port_type(i + 2); |
| 1306 | } |
| 1307 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); |
| 1308 | port_offset++; |
| 1309 | |
| 1310 | valid_left = (i + 3) < vsnode->get_input_port_count(); |
| 1311 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1312 | if (valid_left) { |
| 1313 | port_left = vsnode->get_input_port_type(i + 3); |
| 1314 | } |
| 1315 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); |
| 1316 | |
| 1317 | expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D; |
| 1318 | } break; |
| 1319 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: { |
| 1320 | port_offset++; |
| 1321 | valid_left = (i + 1) < vsnode->get_input_port_count(); |
| 1322 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1323 | if (valid_left) { |
| 1324 | port_left = vsnode->get_input_port_type(i + 1); |
| 1325 | } |
| 1326 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); |
| 1327 | port_offset++; |
| 1328 | |
| 1329 | valid_left = (i + 2) < vsnode->get_input_port_count(); |
| 1330 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1331 | if (valid_left) { |
| 1332 | port_left = vsnode->get_input_port_type(i + 2); |
| 1333 | } |
| 1334 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); |
| 1335 | port_offset++; |
| 1336 | |
| 1337 | valid_left = (i + 3) < vsnode->get_input_port_count(); |
| 1338 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1339 | if (valid_left) { |
| 1340 | port_left = vsnode->get_input_port_type(i + 3); |
| 1341 | } |
| 1342 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); |
| 1343 | port_offset++; |
| 1344 | |
| 1345 | valid_left = (i + 4) < vsnode->get_input_port_count(); |
| 1346 | port_left = VisualShaderNode::PORT_TYPE_SCALAR; |
| 1347 | if (valid_left) { |
| 1348 | port_left = vsnode->get_input_port_type(i + 4); |
| 1349 | } |
| 1350 | graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]); |
| 1351 | |
| 1352 | expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D; |
| 1353 | } break; |
| 1354 | default: |
| 1355 | break; |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | bool has_relative_parameter_instances = false; |
| 1362 | if (vsnode->get_output_port_for_preview() >= 0) { |
| 1363 | has_relative_parameter_instances = is_node_has_parameter_instances_relatively(p_type, p_id); |
| 1364 | show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview(), !has_relative_parameter_instances); |
| 1365 | } else if (!is_reroute) { |
| 1366 | offset = memnew(Control); |
| 1367 | offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE)); |
| 1368 | node->add_child(offset); |
| 1369 | } |
| 1370 | |
| 1371 | String error = vsnode->get_warning(mode, p_type); |
| 1372 | if (has_relative_parameter_instances) { |
| 1373 | error += "\n" + TTR("The 2D preview cannot correctly show the result retrieved from instance parameter."); |
| 1374 | } |
| 1375 | if (!error.is_empty()) { |
| 1376 | Label *error_label = memnew(Label); |
| 1377 | error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1378 | error_label->add_theme_color_override(SceneStringName(font_color), editor->get_theme_color(SNAME("error_color"), EditorStringName(Editor))); |
| 1379 | error_label->set_text(error); |
| 1380 | error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD); |
| 1381 | node->add_child(error_label); |
| 1382 | } |
| 1383 | |
| 1384 | if (is_expression) { |
| 1385 | CodeEdit *expression_box = memnew(CodeEdit); |
| 1386 | Ref<CodeHighlighter> expression_syntax_highlighter; |
| 1387 | expression_syntax_highlighter.instantiate(); |
| 1388 | expression_node->set_ctrl_pressed(expression_box, 0); |
| 1389 | expression_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1390 | node->add_child(expression_box); |
| 1391 | |
| 1392 | Control *offset2 = memnew(Control); |
| 1393 | offset2->set_custom_minimum_size(Vector2(0, 11 * EDSCALE)); |
| 1394 | node->add_child(offset2); |
| 1395 | |
| 1396 | register_expression_edit(p_id, expression_box); |
| 1397 | |
| 1398 | Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color"); |
| 1399 | Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); |
| 1400 | Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); |
| 1401 | Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); |
| 1402 | Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color"); |
| 1403 | Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color"); |
| 1404 | Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color"); |
| 1405 | Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); |
| 1406 | |
| 1407 | expression_box->set_syntax_highlighter(expression_syntax_highlighter); |
| 1408 | |
| 1409 | for (const String &E : editor->keyword_list) { |
| 1410 | if (ShaderLanguage::is_control_flow_keyword(E)) { |
| 1411 | expression_syntax_highlighter->add_keyword_color(E, control_flow_keyword_color); |
| 1412 | } else { |
| 1413 | expression_syntax_highlighter->add_keyword_color(E, keyword_color); |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | expression_box->begin_bulk_theme_override(); |
| 1418 | expression_box->add_theme_font_override(SceneStringName(font), editor->get_theme_font(SNAME("expression"), EditorStringName(EditorFonts))); |
| 1419 | expression_box->add_theme_font_size_override(SceneStringName(font_size), editor->get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts))); |
| 1420 | expression_box->add_theme_color_override(SceneStringName(font_color), text_color); |
| 1421 | expression_box->end_bulk_theme_override(); |
| 1422 | |
| 1423 | expression_syntax_highlighter->set_number_color(number_color); |
| 1424 | expression_syntax_highlighter->set_symbol_color(symbol_color); |
| 1425 | expression_syntax_highlighter->set_function_color(function_color); |
| 1426 | expression_syntax_highlighter->set_member_variable_color(members_color); |
| 1427 | expression_syntax_highlighter->add_color_region("/*", "*/", comment_color, false); |
| 1428 | expression_syntax_highlighter->add_color_region("//", "", comment_color, true); |
| 1429 | |
| 1430 | expression_box->clear_comment_delimiters(); |
| 1431 | expression_box->add_comment_delimiter("/*", "*/", false); |
| 1432 | expression_box->add_comment_delimiter("//", "", true); |
| 1433 | |
| 1434 | if (!expression_box->has_auto_brace_completion_open_key("/*")) { |
| 1435 | expression_box->add_auto_brace_completion_pair("/*", "*/"); |
| 1436 | } |
| 1437 | |
| 1438 | expression_box->set_text(expression); |
| 1439 | expression_box->set_context_menu_enabled(false); |
| 1440 | expression_box->set_draw_line_numbers(true); |
| 1441 | |
| 1442 | expression_box->connect(SceneStringName(focus_exited), callable_mp(editor, &VisualShaderEditor::_expression_focus_out).bind(expression_box, p_id)); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id, bool p_just_update) { |
| 1447 | if (editor->get_current_shader_type() == p_type && links.has(p_id)) { |
| 1448 | GraphEdit *graph_edit = editor->graph; |
| 1449 | if (!graph_edit) { |
| 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | graph_edit->remove_child(links[p_id].graph_element); |
| 1454 | memdelete(links[p_id].graph_element); |
| 1455 | if (!p_just_update) { |
| 1456 | links.erase(p_id); |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { |
| 1462 | GraphEdit *graph = editor->graph; |
| 1463 | if (!graph) { |
| 1464 | return; |
| 1465 | } |
| 1466 | |
| 1467 | if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) { |
| 1468 | // Update reroute nodes since their port type might have changed. |
| 1469 | Ref<VisualShaderNodeReroute> reroute_to = visual_shader->get_node(p_type, p_to_node); |
| 1470 | Ref<VisualShaderNodeReroute> reroute_from = visual_shader->get_node(p_type, p_from_node); |
| 1471 | if (reroute_to.is_valid() || reroute_from.is_valid()) { |
| 1472 | update_reroute_nodes(); |
| 1473 | } |
| 1474 | |
| 1475 | graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port); |
| 1476 | |
| 1477 | connections.push_back({ p_from_node, p_from_port, p_to_node, p_to_port }); |
| 1478 | if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) { |
| 1479 | links[p_to_node].input_ports[p_to_port].default_input_button->hide(); |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { |
| 1485 | GraphEdit *graph = editor->graph; |
| 1486 | if (!graph) { |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | if (visual_shader.is_valid() && editor->get_current_shader_type() == p_type) { |
| 1491 | graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port); |
| 1492 | |
| 1493 | for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { |
| 1494 | if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { |
| 1495 | connections.erase(E); |
| 1496 | break; |
| 1497 | } |
| 1498 | } |
| 1499 | if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr && links[p_to_node].visual_node->get_input_port_default_value(p_to_port).get_type() != Variant::NIL) { |
| 1500 | links[p_to_node].input_ports[p_to_port].default_input_button->show(); |
| 1501 | set_input_port_default_value(p_type, p_to_node, p_to_port, links[p_to_node].visual_node->get_input_port_default_value(p_to_port)); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | ///////////////// |
| 1507 | |
| 1508 | void VisualShaderEditedProperty::_bind_methods() { |
| 1509 | ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property); |
| 1510 | ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property); |
| 1511 | |
| 1512 | ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property"); |
| 1513 | } |
| 1514 | |
| 1515 | void VisualShaderEditedProperty::set_edited_property(const Variant &p_variant) { |
| 1516 | edited_property = p_variant; |
| 1517 | } |
| 1518 | |
| 1519 | Variant VisualShaderEditedProperty::get_edited_property() const { |
| 1520 | return edited_property; |
| 1521 | } |
| 1522 | |
| 1523 | ///////////////// |
| 1524 | |
| 1525 | Vector2 VisualShaderEditor::selection_center; |
| 1526 | List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer; |
| 1527 | List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer; |
| 1528 | |
| 1529 | void VisualShaderEditor::edit_shader(const Ref<Shader> &p_shader) { |
| 1530 | shader_fully_loaded = false; |
| 1531 | bool changed = false; |
| 1532 | VisualShader *visual_shader_ptr = Object::cast_to<VisualShader>(p_shader.ptr()); |
| 1533 | if (visual_shader_ptr) { |
| 1534 | if (visual_shader.is_null()) { |
| 1535 | changed = true; |
| 1536 | } else { |
| 1537 | if (visual_shader.ptr() != visual_shader_ptr) { |
| 1538 | changed = true; |
| 1539 | } |
| 1540 | } |
| 1541 | visual_shader = p_shader; |
| 1542 | graph_plugin->register_shader(visual_shader.ptr()); |
| 1543 | |
| 1544 | visual_shader->connect_changed(callable_mp(this, &VisualShaderEditor::_update_preview)); |
| 1545 | _set_mode(visual_shader->get_mode()); |
| 1546 | |
| 1547 | preview_material->set_shader(visual_shader); |
| 1548 | _update_nodes(); |
| 1549 | } else { |
| 1550 | if (visual_shader.is_valid()) { |
| 1551 | visual_shader->disconnect_changed(callable_mp(this, &VisualShaderEditor::_update_preview)); |
| 1552 | } |
| 1553 | visual_shader.unref(); |
| 1554 | } |
| 1555 | |
| 1556 | if (visual_shader.is_null()) { |
| 1557 | hide(); |
| 1558 | } else { |
| 1559 | if (changed) { // to avoid tree collapse |
| 1560 | _update_varying_tree(); |
| 1561 | _update_options_menu(); |
| 1562 | _update_preview(); |
| 1563 | _update_graph(); |
| 1564 | callable_mp(this, &VisualShaderEditor::_restore_editor_state).call_deferred(); |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | void VisualShaderEditor::use_menu_bar(MenuButton *p_file_menu) { |
| 1570 | p_file_menu->set_switch_on_hover(false); |
| 1571 | toolbar_hflow->add_child(p_file_menu); |
| 1572 | toolbar_hflow->move_child(p_file_menu, 2); // Toggle Files Panel button + separator. |
| 1573 | } |
| 1574 | |
| 1575 | void VisualShaderEditor::apply_shaders() { |
| 1576 | // Stub. TODO: Implement apply_shaders in visual shaders for parity with text shaders. |
| 1577 | } |
| 1578 | |
| 1579 | bool VisualShaderEditor::is_unsaved() const { |
| 1580 | // Stub. TODO: Implement is_unsaved in visual shaders for parity with text shaders. |
| 1581 | return false; |
| 1582 | } |
| 1583 | |
| 1584 | void VisualShaderEditor::save_external_data(const String &p_str) { |
| 1585 | ResourceSaver::save(visual_shader, visual_shader->get_path()); |
| 1586 | } |
| 1587 | |
| 1588 | void VisualShaderEditor::validate_script() { |
| 1589 | if (visual_shader.is_valid()) { |
| 1590 | _update_nodes(); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | void VisualShaderEditor::save_editor_layout() { |
| 1595 | const String id_string = _get_cache_id_string(); |
| 1596 | |
| 1597 | const String offset_cache_key = _get_cache_key("offset"); |
| 1598 | const String zoom_cache_key = _get_cache_key("zoom"); |
| 1599 | vs_editor_cache->set_value(id_string, offset_cache_key, graph->get_scroll_offset() / EDSCALE); |
| 1600 | vs_editor_cache->set_value(id_string, zoom_cache_key, graph->get_zoom()); |
| 1601 | vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg")); |
| 1602 | } |
| 1603 | |
| 1604 | void VisualShaderEditor::set_current_shader_type(VisualShader::Type p_type) { |
| 1605 | current_type = p_type; |
| 1606 | |
| 1607 | const String id_string = _get_cache_id_string(); |
| 1608 | |
| 1609 | vs_editor_cache->set_value(id_string, "edited_type", p_type); |
| 1610 | vs_editor_cache->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg")); |
| 1611 | |
| 1612 | const String offset_cache_key = _get_cache_key("offset"); |
| 1613 | const String zoom_cache_key = _get_cache_key("zoom"); |
| 1614 | const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2()); |
| 1615 | const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0); |
| 1616 | |
| 1617 | graph->set_scroll_offset(saved_scroll_offset); |
| 1618 | graph->set_zoom(saved_zoom); |
| 1619 | } |
| 1620 | |
| 1621 | VisualShader::Type VisualShaderEditor::get_current_shader_type() const { |
| 1622 | return current_type; |
| 1623 | } |
| 1624 | |
| 1625 | void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) { |
| 1626 | if (plugins.has(p_plugin)) { |
| 1627 | return; |
| 1628 | } |
| 1629 | plugins.push_back(p_plugin); |
| 1630 | } |
| 1631 | |
| 1632 | void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) { |
| 1633 | plugins.erase(p_plugin); |
| 1634 | } |
| 1635 | |
| 1636 | void VisualShaderEditor::clear_custom_types() { |
| 1637 | for (int i = 0; i < add_options.size(); i++) { |
| 1638 | if (add_options[i].is_custom) { |
| 1639 | add_options.remove_at(i); |
| 1640 | i--; |
| 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | void VisualShaderEditor::add_custom_type(const String &p_name, const String &p_type, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend) { |
| 1646 | ERR_FAIL_COND(!p_name.is_valid_ascii_identifier()); |
| 1647 | ERR_FAIL_COND(p_type.is_empty() && p_script.is_null()); |
| 1648 | |
| 1649 | for (int i = 0; i < add_options.size(); i++) { |
| 1650 | const AddOption &op = add_options[i]; |
| 1651 | |
| 1652 | if (op.is_custom) { |
| 1653 | if (!p_type.is_empty()) { |
| 1654 | if (op.type == p_type) { |
| 1655 | return; |
| 1656 | } |
| 1657 | } else if (op.script == p_script) { |
| 1658 | return; |
| 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | AddOption ao; |
| 1664 | ao.name = p_name; |
| 1665 | ao.type = p_type; |
| 1666 | ao.script = p_script; |
| 1667 | ao.return_type = p_return_icon_type; |
| 1668 | ao.description = p_description; |
| 1669 | ao.category = p_category; |
| 1670 | ao.highend = p_highend; |
| 1671 | ao.is_custom = true; |
| 1672 | ao.is_native = !p_type.is_empty(); |
| 1673 | |
| 1674 | bool begin = false; |
| 1675 | String root = p_category.get_slicec('/', 0); |
| 1676 | |
| 1677 | for (int i = 0; i < add_options.size(); i++) { |
| 1678 | if (add_options[i].is_custom) { |
| 1679 | if (add_options[i].category == root) { |
| 1680 | if (!begin) { |
| 1681 | begin = true; |
| 1682 | } |
| 1683 | } else { |
| 1684 | if (begin) { |
| 1685 | add_options.insert(i, ao); |
| 1686 | return; |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | add_options.push_back(ao); |
| 1692 | } |
| 1693 | |
| 1694 | Dictionary VisualShaderEditor::get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node) { |
| 1695 | Dictionary dict; |
| 1696 | dict["script"] = p_custom_node->get_script(); |
| 1697 | dict["name"] = p_custom_node->_get_name(); |
| 1698 | dict["description"] = p_custom_node->_get_description(); |
| 1699 | dict["return_icon_type"] = p_custom_node->_get_return_icon_type(); |
| 1700 | dict["highend"] = p_custom_node->_is_highend(); |
| 1701 | |
| 1702 | String category = p_custom_node->_get_category(); |
| 1703 | category = category.rstrip("/"); |
| 1704 | category = category.lstrip("/"); |
| 1705 | category = "Addons/" + category; |
| 1706 | if (p_custom_node->has_method("_get_subcategory")) { |
| 1707 | String subcategory = (String)p_custom_node->call("_get_subcategory"); |
| 1708 | if (!subcategory.is_empty()) { |
| 1709 | category += "/" + subcategory; |
| 1710 | } |
| 1711 | } |
| 1712 | dict["category"] = category; |
| 1713 | |
| 1714 | return dict; |
| 1715 | } |
| 1716 | |
| 1717 | void VisualShaderEditor::_get_current_mode_limits(int &r_begin_type, int &r_end_type) const { |
| 1718 | switch (visual_shader->get_mode()) { |
| 1719 | case Shader::MODE_CANVAS_ITEM: |
| 1720 | case Shader::MODE_SPATIAL: { |
| 1721 | r_begin_type = VisualShader::TYPE_VERTEX; |
| 1722 | r_end_type = VisualShader::TYPE_START; |
| 1723 | } break; |
| 1724 | case Shader::MODE_PARTICLES: { |
| 1725 | r_begin_type = VisualShader::TYPE_START; |
| 1726 | r_end_type = VisualShader::TYPE_SKY; |
| 1727 | } break; |
| 1728 | case Shader::MODE_SKY: { |
| 1729 | r_begin_type = VisualShader::TYPE_SKY; |
| 1730 | r_end_type = VisualShader::TYPE_FOG; |
| 1731 | } break; |
| 1732 | case Shader::MODE_FOG: { |
| 1733 | r_begin_type = VisualShader::TYPE_FOG; |
| 1734 | r_end_type = VisualShader::TYPE_MAX; |
| 1735 | } break; |
| 1736 | default: { |
| 1737 | } break; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | void VisualShaderEditor::_script_created(const Ref<Script> &p_script) { |
| 1742 | if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") { |
| 1743 | return; |
| 1744 | } |
| 1745 | Ref<VisualShaderNodeCustom> ref; |
| 1746 | ref.instantiate(); |
| 1747 | ref->set_script(p_script); |
| 1748 | |
| 1749 | Dictionary dict = get_custom_node_data(ref); |
| 1750 | add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]); |
| 1751 | |
| 1752 | _update_options_menu(); |
| 1753 | } |
| 1754 | |
| 1755 | void VisualShaderEditor::_update_custom_script(const Ref<Script> &p_script) { |
| 1756 | if (p_script.is_null() || p_script->get_instance_base_type() != "VisualShaderNodeCustom") { |
| 1757 | return; |
| 1758 | } |
| 1759 | |
| 1760 | Ref<VisualShaderNodeCustom> ref; |
| 1761 | ref.instantiate(); |
| 1762 | ref->set_script(p_script); |
| 1763 | if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) { |
| 1764 | for (int i = 0; i < add_options.size(); i++) { |
| 1765 | if (add_options[i].is_custom && add_options[i].script == p_script) { |
| 1766 | add_options.remove_at(i); |
| 1767 | _update_options_menu(); |
| 1768 | // TODO: Make indication for the existed custom nodes with that script on graph to be disabled. |
| 1769 | break; |
| 1770 | } |
| 1771 | } |
| 1772 | return; |
| 1773 | } |
| 1774 | Dictionary dict = get_custom_node_data(ref); |
| 1775 | |
| 1776 | bool found_type = false; |
| 1777 | bool need_rebuild = false; |
| 1778 | |
| 1779 | for (int i = custom_node_option_idx; i < add_options.size(); i++) { |
| 1780 | if (add_options[i].script == p_script) { |
| 1781 | found_type = true; |
| 1782 | |
| 1783 | add_options.write[i].name = dict["name"]; |
| 1784 | add_options.write[i].return_type = dict["return_icon_type"]; |
| 1785 | add_options.write[i].description = dict["description"]; |
| 1786 | add_options.write[i].category = dict["category"]; |
| 1787 | add_options.write[i].highend = dict["highend"]; |
| 1788 | |
| 1789 | int begin_type = 0; |
| 1790 | int end_type = 0; |
| 1791 | _get_current_mode_limits(begin_type, end_type); |
| 1792 | |
| 1793 | for (int t = begin_type; t < end_type; t++) { |
| 1794 | VisualShader::Type type = (VisualShader::Type)t; |
| 1795 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 1796 | |
| 1797 | List<VisualShader::Connection> node_connections; |
| 1798 | visual_shader->get_node_connections(type, &node_connections); |
| 1799 | |
| 1800 | List<VisualShader::Connection> custom_node_input_connections; |
| 1801 | List<VisualShader::Connection> custom_node_output_connections; |
| 1802 | |
| 1803 | for (const VisualShader::Connection &E : node_connections) { |
| 1804 | int from = E.from_node; |
| 1805 | int from_port = E.from_port; |
| 1806 | int to = E.to_node; |
| 1807 | int to_port = E.to_port; |
| 1808 | |
| 1809 | if (graph_plugin->get_node_script(from) == p_script) { |
| 1810 | custom_node_output_connections.push_back({ from, from_port, to, to_port }); |
| 1811 | } else if (graph_plugin->get_node_script(to) == p_script) { |
| 1812 | custom_node_input_connections.push_back({ from, from_port, to, to_port }); |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | for (int node_id : nodes) { |
| 1817 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); |
| 1818 | if (vsnode.is_null()) { |
| 1819 | continue; |
| 1820 | } |
| 1821 | Ref<VisualShaderNodeCustom> custom_node = vsnode; |
| 1822 | if (custom_node.is_null() || custom_node->get_script() != p_script) { |
| 1823 | continue; |
| 1824 | } |
| 1825 | need_rebuild = true; |
| 1826 | |
| 1827 | // Removes invalid connections. |
| 1828 | { |
| 1829 | int prev_input_port_count = custom_node->get_input_port_count(); |
| 1830 | int prev_output_port_count = custom_node->get_output_port_count(); |
| 1831 | |
| 1832 | custom_node->update_ports(); |
| 1833 | |
| 1834 | int input_port_count = custom_node->get_input_port_count(); |
| 1835 | int output_port_count = custom_node->get_output_port_count(); |
| 1836 | |
| 1837 | if (output_port_count != prev_output_port_count) { |
| 1838 | for (const VisualShader::Connection &E : custom_node_output_connections) { |
| 1839 | int from = E.from_node; |
| 1840 | int from_idx = E.from_port; |
| 1841 | int to = E.to_node; |
| 1842 | int to_idx = E.to_port; |
| 1843 | |
| 1844 | if (from_idx >= output_port_count) { |
| 1845 | visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx); |
| 1846 | graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx); |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | if (input_port_count != prev_input_port_count) { |
| 1851 | for (const VisualShader::Connection &E : custom_node_input_connections) { |
| 1852 | int from = E.from_node; |
| 1853 | int from_idx = E.from_port; |
| 1854 | int to = E.to_node; |
| 1855 | int to_idx = E.to_port; |
| 1856 | |
| 1857 | if (to_idx >= input_port_count) { |
| 1858 | visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx); |
| 1859 | graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx); |
| 1860 | } |
| 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | graph_plugin->update_node(type, node_id); |
| 1866 | } |
| 1867 | } |
| 1868 | break; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | if (!found_type) { |
| 1873 | add_custom_type(dict["name"], String(), dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]); |
| 1874 | } |
| 1875 | |
| 1876 | // To prevent updating options multiple times when multiple scripts are saved. |
| 1877 | if (!_block_update_options_menu) { |
| 1878 | _block_update_options_menu = true; |
| 1879 | |
| 1880 | callable_mp(this, &VisualShaderEditor::_update_options_menu_deferred); |
| 1881 | } |
| 1882 | |
| 1883 | // To prevent rebuilding the shader multiple times when multiple scripts are saved. |
| 1884 | if (need_rebuild && !_block_rebuild_shader) { |
| 1885 | _block_rebuild_shader = true; |
| 1886 | |
| 1887 | callable_mp(this, &VisualShaderEditor::_rebuild_shader_deferred); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | void VisualShaderEditor::_resource_saved(const Ref<Resource> &p_resource) { |
| 1892 | _update_custom_script(Ref<Script>(p_resource.ptr())); |
| 1893 | } |
| 1894 | |
| 1895 | void VisualShaderEditor::_resources_removed() { |
| 1896 | bool has_any_instance = false; |
| 1897 | |
| 1898 | for (const Ref<Script> &scr : custom_scripts_to_delete) { |
| 1899 | for (int i = custom_node_option_idx; i < add_options.size(); i++) { |
| 1900 | if (add_options[i].script == scr) { |
| 1901 | add_options.remove_at(i); |
| 1902 | |
| 1903 | // Removes all node instances using that script from the graph. |
| 1904 | { |
| 1905 | int begin_type = 0; |
| 1906 | int end_type = 0; |
| 1907 | _get_current_mode_limits(begin_type, end_type); |
| 1908 | |
| 1909 | for (int t = begin_type; t < end_type; t++) { |
| 1910 | VisualShader::Type type = (VisualShader::Type)t; |
| 1911 | |
| 1912 | List<VisualShader::Connection> node_connections; |
| 1913 | visual_shader->get_node_connections(type, &node_connections); |
| 1914 | |
| 1915 | for (const VisualShader::Connection &E : node_connections) { |
| 1916 | int from = E.from_node; |
| 1917 | int from_port = E.from_port; |
| 1918 | int to = E.to_node; |
| 1919 | int to_port = E.to_port; |
| 1920 | |
| 1921 | if (graph_plugin->get_node_script(from) == scr || graph_plugin->get_node_script(to) == scr) { |
| 1922 | visual_shader->disconnect_nodes(type, from, from_port, to, to_port); |
| 1923 | graph_plugin->disconnect_nodes(type, from, from_port, to, to_port); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 1928 | for (int node_id : nodes) { |
| 1929 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); |
| 1930 | if (vsnode.is_null()) { |
| 1931 | continue; |
| 1932 | } |
| 1933 | Ref<VisualShaderNodeCustom> custom_node = vsnode; |
| 1934 | if (custom_node.is_null() || custom_node->get_script() != scr) { |
| 1935 | continue; |
| 1936 | } |
| 1937 | visual_shader->remove_node(type, node_id); |
| 1938 | graph_plugin->remove_node(type, node_id, false); |
| 1939 | |
| 1940 | has_any_instance = true; |
| 1941 | } |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | break; |
| 1946 | } |
| 1947 | } |
| 1948 | } |
| 1949 | if (has_any_instance) { |
| 1950 | EditorUndoRedoManager::get_singleton()->clear_history(); // Need to clear undo history, otherwise it may lead to hard-detected errors and crashes (since the script was removed). |
| 1951 | ResourceSaver::save(visual_shader, visual_shader->get_path()); |
| 1952 | } |
| 1953 | _update_options_menu(); |
| 1954 | |
| 1955 | custom_scripts_to_delete.clear(); |
| 1956 | pending_custom_scripts_to_delete = false; |
| 1957 | } |
| 1958 | |
| 1959 | void VisualShaderEditor::_resource_removed(const Ref<Resource> &p_resource) { |
| 1960 | Ref<Script> scr = Ref<Script>(p_resource.ptr()); |
| 1961 | if (scr.is_null() || scr->get_instance_base_type() != "VisualShaderNodeCustom") { |
| 1962 | return; |
| 1963 | } |
| 1964 | |
| 1965 | custom_scripts_to_delete.push_back(scr); |
| 1966 | |
| 1967 | if (!pending_custom_scripts_to_delete) { |
| 1968 | pending_custom_scripts_to_delete = true; |
| 1969 | callable_mp(this, &VisualShaderEditor::_resources_removed).call_deferred(); |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | void VisualShaderEditor::_update_options_menu_deferred() { |
| 1974 | _update_options_menu(); |
| 1975 | |
| 1976 | _block_update_options_menu = false; |
| 1977 | } |
| 1978 | |
| 1979 | void VisualShaderEditor::_rebuild_shader_deferred() { |
| 1980 | if (visual_shader.is_valid()) { |
| 1981 | visual_shader->rebuild(); |
| 1982 | } |
| 1983 | |
| 1984 | _block_rebuild_shader = false; |
| 1985 | } |
| 1986 | |
| 1987 | bool VisualShaderEditor::_is_available(int p_mode) { |
| 1988 | int current_mode = edit_type->get_selected(); |
| 1989 | |
| 1990 | if (p_mode != -1) { |
| 1991 | switch (current_mode) { |
| 1992 | case 0: // Vertex / Emit |
| 1993 | current_mode = 1; |
| 1994 | break; |
| 1995 | case 1: // Fragment / Process |
| 1996 | current_mode = 2; |
| 1997 | break; |
| 1998 | case 2: // Light / Collide |
| 1999 | current_mode = 4; |
| 2000 | break; |
| 2001 | default: |
| 2002 | break; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | return (p_mode == -1 || (p_mode & current_mode) != 0); |
| 2007 | } |
| 2008 | |
| 2009 | bool VisualShaderEditor::_update_preview_parameter_tree() { |
| 2010 | bool found = false; |
| 2011 | bool use_filter = !param_filter_name.is_empty(); |
| 2012 | |
| 2013 | parameters->clear(); |
| 2014 | TreeItem *root = parameters->create_item(); |
| 2015 | |
| 2016 | for (const KeyValue<String, PropertyInfo> &prop : parameter_props) { |
| 2017 | String param_name = prop.value.name; |
| 2018 | if (use_filter && !param_name.containsn(param_filter_name)) { |
| 2019 | continue; |
| 2020 | } |
| 2021 | |
| 2022 | TreeItem *item = parameters->create_item(root); |
| 2023 | item->set_text(0, param_name); |
| 2024 | item->set_meta("id", param_name); |
| 2025 | |
| 2026 | if (param_name == selected_param_id) { |
| 2027 | parameters->set_selected(item); |
| 2028 | found = true; |
| 2029 | } |
| 2030 | |
| 2031 | if (prop.value.type == Variant::OBJECT) { |
| 2032 | item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture"))); |
| 2033 | } else { |
| 2034 | item->set_icon(0, get_editor_theme_icon(Variant::get_type_name(prop.value.type))); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | return found; |
| 2039 | } |
| 2040 | |
| 2041 | void VisualShaderEditor::_preview_tools_menu_option(int p_idx) { |
| 2042 | ShaderMaterial *src_mat = nullptr; |
| 2043 | |
| 2044 | if (p_idx == COPY_PARAMS_FROM_MATERIAL || p_idx == PASTE_PARAMS_TO_MATERIAL) { |
| 2045 | for (int i = EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() - 1; i >= 0; i--) { |
| 2046 | Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(i)); |
| 2047 | ShaderMaterial *src_mat2; |
| 2048 | if (!object) { |
| 2049 | continue; |
| 2050 | } |
| 2051 | if (object->has_method("get_material_override")) { // Trying to get material from MeshInstance. |
| 2052 | src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material_override")); |
| 2053 | } else if (object->has_method("get_material")) { // From CanvasItem/Node2D. |
| 2054 | src_mat2 = Object::cast_to<ShaderMaterial>(object->call("get_material")); |
| 2055 | } else { |
| 2056 | src_mat2 = Object::cast_to<ShaderMaterial>(object); |
| 2057 | } |
| 2058 | |
| 2059 | if (src_mat2 && src_mat2->get_shader().is_valid() && src_mat2->get_shader() == visual_shader) { |
| 2060 | src_mat = src_mat2; |
| 2061 | break; |
| 2062 | } |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | switch (p_idx) { |
| 2067 | case COPY_PARAMS_FROM_MATERIAL: |
| 2068 | if (src_mat) { |
| 2069 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2070 | undo_redo->create_action(TTR("Copy Preview Shader Parameters From Material")); |
| 2071 | |
| 2072 | List<PropertyInfo> params; |
| 2073 | preview_material->get_shader()->get_shader_uniform_list(¶ms); |
| 2074 | for (const PropertyInfo &E : params) { |
| 2075 | undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, src_mat->get_shader_parameter(E.name)); |
| 2076 | undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", E.name, preview_material->get_shader_parameter(E.name)); |
| 2077 | } |
| 2078 | |
| 2079 | undo_redo->commit_action(); |
| 2080 | } |
| 2081 | break; |
| 2082 | case PASTE_PARAMS_TO_MATERIAL: |
| 2083 | if (src_mat) { |
| 2084 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2085 | undo_redo->create_action(TTR("Paste Preview Shader Parameters To Material")); |
| 2086 | |
| 2087 | List<PropertyInfo> params; |
| 2088 | preview_material->get_shader()->get_shader_uniform_list(¶ms); |
| 2089 | for (const PropertyInfo &E : params) { |
| 2090 | undo_redo->add_do_method(src_mat, "set_shader_parameter", E.name, preview_material->get_shader_parameter(E.name)); |
| 2091 | undo_redo->add_undo_method(src_mat, "set_shader_parameter", E.name, src_mat->get_shader_parameter(E.name)); |
| 2092 | } |
| 2093 | |
| 2094 | undo_redo->commit_action(); |
| 2095 | } |
| 2096 | break; |
| 2097 | default: |
| 2098 | break; |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | void VisualShaderEditor::_clear_preview_param() { |
| 2103 | selected_param_id = ""; |
| 2104 | current_prop = nullptr; |
| 2105 | |
| 2106 | if (param_vbox2->get_child_count() > 0) { |
| 2107 | param_vbox2->remove_child(param_vbox2->get_child(0)); |
| 2108 | } |
| 2109 | |
| 2110 | param_vbox->hide(); |
| 2111 | } |
| 2112 | |
| 2113 | void VisualShaderEditor::_update_preview_parameter_list() { |
| 2114 | material_editor->edit(preview_material.ptr(), env); |
| 2115 | |
| 2116 | List<PropertyInfo> properties; |
| 2117 | RenderingServer::get_singleton()->get_shader_parameter_list(visual_shader->get_rid(), &properties); |
| 2118 | |
| 2119 | HashSet<String> params_to_remove; |
| 2120 | for (const KeyValue<String, PropertyInfo> &E : parameter_props) { |
| 2121 | params_to_remove.insert(E.key); |
| 2122 | } |
| 2123 | parameter_props.clear(); |
| 2124 | |
| 2125 | for (const PropertyInfo &prop : properties) { |
| 2126 | String param_name = prop.name; |
| 2127 | |
| 2128 | if (visual_shader->_has_preview_shader_parameter(param_name)) { |
| 2129 | preview_material->set_shader_parameter(param_name, visual_shader->_get_preview_shader_parameter(param_name)); |
| 2130 | } else { |
| 2131 | preview_material->set_shader_parameter(param_name, RenderingServer::get_singleton()->shader_get_parameter_default(visual_shader->get_rid(), param_name)); |
| 2132 | } |
| 2133 | |
| 2134 | parameter_props.insert(param_name, prop); |
| 2135 | params_to_remove.erase(param_name); |
| 2136 | |
| 2137 | if (param_name == selected_param_id) { |
| 2138 | current_prop->update_property(); |
| 2139 | current_prop->update_editor_property_status(); |
| 2140 | current_prop->update_cache(); |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | _update_preview_parameter_tree(); |
| 2145 | |
| 2146 | // Removes invalid parameters. |
| 2147 | for (const String ¶m_name : params_to_remove) { |
| 2148 | preview_material->set_shader_parameter(param_name, Variant()); |
| 2149 | |
| 2150 | if (visual_shader->_has_preview_shader_parameter(param_name)) { |
| 2151 | visual_shader->_set_preview_shader_parameter(param_name, Variant()); |
| 2152 | } |
| 2153 | |
| 2154 | if (param_name == selected_param_id) { |
| 2155 | _clear_preview_param(); |
| 2156 | } |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | void VisualShaderEditor::_update_nodes() { |
| 2161 | clear_custom_types(); |
| 2162 | Dictionary added; |
| 2163 | |
| 2164 | // Add GDScript classes. |
| 2165 | { |
| 2166 | LocalVector<StringName> class_list; |
| 2167 | ScriptServer::get_global_class_list(class_list); |
| 2168 | |
| 2169 | for (const StringName &class_name : class_list) { |
| 2170 | if (ScriptServer::get_global_class_native_base(class_name) == "VisualShaderNodeCustom") { |
| 2171 | String script_path = ScriptServer::get_global_class_path(class_name); |
| 2172 | Ref<Resource> res = ResourceLoader::load(script_path); |
| 2173 | ERR_CONTINUE(res.is_null()); |
| 2174 | ERR_CONTINUE(!res->is_class("Script")); |
| 2175 | Ref<Script> scr = Ref<Script>(res); |
| 2176 | |
| 2177 | Ref<VisualShaderNodeCustom> ref; |
| 2178 | ref.instantiate(); |
| 2179 | ref->set_script(scr); |
| 2180 | if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) { |
| 2181 | continue; |
| 2182 | } |
| 2183 | Dictionary dict = get_custom_node_data(ref); |
| 2184 | dict["type"] = String(); |
| 2185 | |
| 2186 | String key; |
| 2187 | key = String(dict["category"]) + "/" + String(dict["name"]); |
| 2188 | |
| 2189 | added[key] = dict; |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | // Add GDExtension classes. |
| 2195 | { |
| 2196 | LocalVector<StringName> class_list; |
| 2197 | ClassDB::get_class_list(class_list); |
| 2198 | |
| 2199 | for (const StringName &class_name : class_list) { |
| 2200 | if (ClassDB::get_parent_class(class_name) == "VisualShaderNodeCustom") { |
| 2201 | Object *instance = ClassDB::instantiate(class_name); |
| 2202 | Ref<VisualShaderNodeCustom> ref = Object::cast_to<VisualShaderNodeCustom>(instance); |
| 2203 | ERR_CONTINUE(ref.is_null()); |
| 2204 | if (!ref->is_available(visual_shader->get_mode(), get_current_shader_type())) { |
| 2205 | continue; |
| 2206 | } |
| 2207 | Dictionary dict = get_custom_node_data(ref); |
| 2208 | dict["type"] = class_name; |
| 2209 | dict["script"] = Ref<Script>(); |
| 2210 | |
| 2211 | String key; |
| 2212 | key = String(dict["category"]) + "/" + String(dict["name"]); |
| 2213 | |
| 2214 | added[key] = dict; |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | // Disables not-supported copied items. |
| 2220 | { |
| 2221 | for (CopyItem &item : copy_items_buffer) { |
| 2222 | Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(item.node.ptr()); |
| 2223 | |
| 2224 | if (custom.is_valid()) { |
| 2225 | if (!custom->is_available(visual_shader->get_mode(), get_current_shader_type())) { |
| 2226 | item.disabled = true; |
| 2227 | } else { |
| 2228 | item.disabled = false; |
| 2229 | } |
| 2230 | } else { |
| 2231 | for (int i = 0; i < add_options.size(); i++) { |
| 2232 | if (add_options[i].type == item.node->get_class_name()) { |
| 2233 | if ((add_options[i].func != visual_shader->get_mode() && add_options[i].func != -1) || !_is_available(add_options[i].mode)) { |
| 2234 | item.disabled = true; |
| 2235 | } else { |
| 2236 | item.disabled = false; |
| 2237 | } |
| 2238 | break; |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | LocalVector<Variant> keys = added.get_key_list(); |
| 2246 | keys.sort_custom<StringLikeVariantOrder>(); |
| 2247 | |
| 2248 | for (const Variant &key : keys) { |
| 2249 | const Dictionary &value = (Dictionary)added[key]; |
| 2250 | |
| 2251 | add_custom_type(value["name"], value["type"], value["script"], value["description"], value["return_icon_type"], value["category"], value["highend"]); |
| 2252 | } |
| 2253 | |
| 2254 | _update_options_menu(); |
| 2255 | } |
| 2256 | |
| 2257 | String VisualShaderEditor::_get_description(int p_idx) { |
| 2258 | return add_options[p_idx].description; |
| 2259 | } |
| 2260 | |
| 2261 | void VisualShaderEditor::_update_options_menu() { |
| 2262 | node_desc->set_text(""); |
| 2263 | highend_label->set_visible(false); |
| 2264 | members_dialog->get_ok_button()->set_disabled(true); |
| 2265 | |
| 2266 | members->clear(); |
| 2267 | TreeItem *root = members->create_item(); |
| 2268 | |
| 2269 | String filter = node_filter->get_text().strip_edges(); |
| 2270 | bool use_filter = !filter.is_empty(); |
| 2271 | |
| 2272 | bool is_first_item = true; |
| 2273 | |
| 2274 | Color unsupported_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor)); |
| 2275 | Color supported_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor)); |
| 2276 | |
| 2277 | static bool low_driver = GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility"; |
| 2278 | |
| 2279 | HashMap<String, TreeItem *> folders; |
| 2280 | |
| 2281 | int current_func = -1; |
| 2282 | |
| 2283 | if (visual_shader.is_valid()) { |
| 2284 | current_func = visual_shader->get_mode(); |
| 2285 | } |
| 2286 | |
| 2287 | Vector<AddOption> custom_options; |
| 2288 | Vector<AddOption> embedded_options; |
| 2289 | |
| 2290 | static Vector<String> type_filter_exceptions; |
| 2291 | if (type_filter_exceptions.is_empty()) { |
| 2292 | type_filter_exceptions.append("VisualShaderNodeExpression"); |
| 2293 | type_filter_exceptions.append("VisualShaderNodeReroute"); |
| 2294 | } |
| 2295 | |
| 2296 | for (int i = 0; i < add_options.size(); i++) { |
| 2297 | if (!use_filter || add_options[i].name.containsn(filter)) { |
| 2298 | // port type filtering |
| 2299 | if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { |
| 2300 | Ref<VisualShaderNode> vsn; |
| 2301 | int check_result = 0; |
| 2302 | |
| 2303 | if (!add_options[i].is_custom) { |
| 2304 | vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type))); |
| 2305 | if (vsn.is_null()) { |
| 2306 | continue; |
| 2307 | } |
| 2308 | |
| 2309 | if (type_filter_exceptions.has(add_options[i].type)) { |
| 2310 | check_result = 1; |
| 2311 | } |
| 2312 | |
| 2313 | Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr()); |
| 2314 | if (input.is_valid()) { |
| 2315 | input->set_shader_mode(visual_shader->get_mode()); |
| 2316 | input->set_shader_type(get_current_shader_type()); |
| 2317 | if (!add_options[i].ops.is_empty() && add_options[i].ops[0].is_string()) { |
| 2318 | input->set_input_name((String)add_options[i].ops[0]); |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr()); |
| 2323 | if (expression.is_valid()) { |
| 2324 | if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) { |
| 2325 | check_result = -1; // expressions creates a port with required type automatically (except for sampler output) |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | Ref<VisualShaderNodeParameterRef> parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn.ptr()); |
| 2330 | if (parameter_ref.is_valid() && parameter_ref->is_shader_valid()) { |
| 2331 | check_result = -1; |
| 2332 | |
| 2333 | if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { |
| 2334 | for (int j = 0; j < parameter_ref->get_parameters_count(); j++) { |
| 2335 | if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(j), members_input_port_type)) { |
| 2336 | check_result = 1; |
| 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | } else { |
| 2343 | check_result = 1; |
| 2344 | } |
| 2345 | |
| 2346 | if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) { |
| 2347 | if (check_result == 0) { |
| 2348 | for (int j = 0; j < vsn->get_input_port_count(); j++) { |
| 2349 | if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) { |
| 2350 | check_result = 1; |
| 2351 | break; |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | if (check_result != 1) { |
| 2357 | continue; |
| 2358 | } |
| 2359 | } |
| 2360 | if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { |
| 2361 | if (check_result == 0) { |
| 2362 | for (int j = 0; j < vsn->get_output_port_count(); j++) { |
| 2363 | if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) { |
| 2364 | check_result = 1; |
| 2365 | break; |
| 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | if (check_result != 1) { |
| 2371 | continue; |
| 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) { |
| 2376 | continue; |
| 2377 | } |
| 2378 | add_options[i].temp_idx = i; // save valid id |
| 2379 | if (add_options[i].is_custom) { |
| 2380 | custom_options.push_back(add_options[i]); |
| 2381 | } else { |
| 2382 | embedded_options.push_back(add_options[i]); |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | Vector<AddOption> options; |
| 2387 | SortArray<AddOption, _OptionComparator> sorter; |
| 2388 | sorter.sort(custom_options.ptrw(), custom_options.size()); |
| 2389 | |
| 2390 | options.append_array(custom_options); |
| 2391 | options.append_array(embedded_options); |
| 2392 | |
| 2393 | for (int i = 0; i < options.size(); i++) { |
| 2394 | String path = options[i].category; |
| 2395 | Vector<String> subfolders = path.split("/"); |
| 2396 | TreeItem *category = nullptr; |
| 2397 | |
| 2398 | if (!folders.has(path)) { |
| 2399 | category = root; |
| 2400 | String path_temp = ""; |
| 2401 | for (int j = 0; j < subfolders.size(); j++) { |
| 2402 | path_temp += subfolders[j]; |
| 2403 | if (!folders.has(path_temp)) { |
| 2404 | category = members->create_item(category); |
| 2405 | category->set_selectable(0, false); |
| 2406 | category->set_collapsed(!use_filter); |
| 2407 | category->set_text(0, subfolders[j]); |
| 2408 | folders.insert(path_temp, category); |
| 2409 | } else { |
| 2410 | category = folders[path_temp]; |
| 2411 | } |
| 2412 | } |
| 2413 | } else { |
| 2414 | category = folders[path]; |
| 2415 | } |
| 2416 | |
| 2417 | TreeItem *item = members->create_item(category); |
| 2418 | if (options[i].highend && low_driver) { |
| 2419 | item->set_custom_color(0, unsupported_color); |
| 2420 | } else if (options[i].highend) { |
| 2421 | item->set_custom_color(0, supported_color); |
| 2422 | } |
| 2423 | item->set_text(0, options[i].name); |
| 2424 | if (is_first_item && use_filter) { |
| 2425 | item->select(0); |
| 2426 | node_desc->set_text(options[i].description); |
| 2427 | is_first_item = false; |
| 2428 | |
| 2429 | members_dialog->get_ok_button()->set_disabled(false); |
| 2430 | } |
| 2431 | switch (options[i].return_type) { |
| 2432 | case VisualShaderNode::PORT_TYPE_SCALAR: |
| 2433 | item->set_icon(0, get_editor_theme_icon(SNAME("float"))); |
| 2434 | break; |
| 2435 | case VisualShaderNode::PORT_TYPE_SCALAR_INT: |
| 2436 | item->set_icon(0, get_editor_theme_icon(SNAME("int"))); |
| 2437 | break; |
| 2438 | case VisualShaderNode::PORT_TYPE_SCALAR_UINT: |
| 2439 | item->set_icon(0, get_editor_theme_icon(SNAME("uint"))); |
| 2440 | break; |
| 2441 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: |
| 2442 | item->set_icon(0, get_editor_theme_icon(SNAME("Vector2"))); |
| 2443 | break; |
| 2444 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: |
| 2445 | item->set_icon(0, get_editor_theme_icon(SNAME("Vector3"))); |
| 2446 | break; |
| 2447 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: |
| 2448 | item->set_icon(0, get_editor_theme_icon(SNAME("Vector4"))); |
| 2449 | break; |
| 2450 | case VisualShaderNode::PORT_TYPE_BOOLEAN: |
| 2451 | item->set_icon(0, get_editor_theme_icon(SNAME("bool"))); |
| 2452 | break; |
| 2453 | case VisualShaderNode::PORT_TYPE_TRANSFORM: |
| 2454 | item->set_icon(0, get_editor_theme_icon(SNAME("Transform3D"))); |
| 2455 | break; |
| 2456 | case VisualShaderNode::PORT_TYPE_SAMPLER: |
| 2457 | item->set_icon(0, get_editor_theme_icon(SNAME("ImageTexture"))); |
| 2458 | break; |
| 2459 | default: |
| 2460 | break; |
| 2461 | } |
| 2462 | item->set_meta("id", options[i].temp_idx); |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | void VisualShaderEditor::_set_mode(int p_which) { |
| 2467 | if (p_which == VisualShader::MODE_SKY) { |
| 2468 | edit_type_standard->set_visible(false); |
| 2469 | edit_type_particles->set_visible(false); |
| 2470 | edit_type_sky->set_visible(true); |
| 2471 | edit_type_fog->set_visible(false); |
| 2472 | edit_type = edit_type_sky; |
| 2473 | custom_mode_box->set_visible(false); |
| 2474 | varying_button->hide(); |
| 2475 | mode = MODE_FLAGS_SKY; |
| 2476 | } else if (p_which == VisualShader::MODE_FOG) { |
| 2477 | edit_type_standard->set_visible(false); |
| 2478 | edit_type_particles->set_visible(false); |
| 2479 | edit_type_sky->set_visible(false); |
| 2480 | edit_type_fog->set_visible(true); |
| 2481 | edit_type = edit_type_fog; |
| 2482 | custom_mode_box->set_visible(false); |
| 2483 | varying_button->hide(); |
| 2484 | mode = MODE_FLAGS_FOG; |
| 2485 | } else if (p_which == VisualShader::MODE_PARTICLES) { |
| 2486 | edit_type_standard->set_visible(false); |
| 2487 | edit_type_particles->set_visible(true); |
| 2488 | edit_type_sky->set_visible(false); |
| 2489 | edit_type_fog->set_visible(false); |
| 2490 | edit_type = edit_type_particles; |
| 2491 | if ((edit_type->get_selected() + 3) > VisualShader::TYPE_PROCESS) { |
| 2492 | custom_mode_box->set_visible(false); |
| 2493 | } else { |
| 2494 | custom_mode_box->set_visible(true); |
| 2495 | } |
| 2496 | varying_button->hide(); |
| 2497 | mode = MODE_FLAGS_PARTICLES; |
| 2498 | } else { |
| 2499 | edit_type_particles->set_visible(false); |
| 2500 | edit_type_standard->set_visible(true); |
| 2501 | edit_type_sky->set_visible(false); |
| 2502 | edit_type_fog->set_visible(false); |
| 2503 | edit_type = edit_type_standard; |
| 2504 | custom_mode_box->set_visible(false); |
| 2505 | varying_button->show(); |
| 2506 | mode = MODE_FLAGS_SPATIAL_CANVASITEM; |
| 2507 | } |
| 2508 | |
| 2509 | const String id_string = _get_cache_id_string(); |
| 2510 | |
| 2511 | int default_type = VisualShader::TYPE_VERTEX; |
| 2512 | int upper_type = VisualShader::TYPE_START; |
| 2513 | if (mode & MODE_FLAGS_PARTICLES) { |
| 2514 | default_type = VisualShader::TYPE_START; |
| 2515 | upper_type = VisualShader::TYPE_SKY; |
| 2516 | } else if (mode & MODE_FLAGS_SKY) { |
| 2517 | default_type = VisualShader::TYPE_SKY; |
| 2518 | upper_type = VisualShader::TYPE_FOG; |
| 2519 | } else if (mode & MODE_FLAGS_FOG) { |
| 2520 | default_type = VisualShader::TYPE_FOG; |
| 2521 | upper_type = VisualShader::TYPE_MAX; |
| 2522 | } |
| 2523 | |
| 2524 | int saved_type = vs_editor_cache->get_value(id_string, "edited_type", default_type); |
| 2525 | if (saved_type >= upper_type || saved_type < default_type) { |
| 2526 | saved_type = default_type; |
| 2527 | } |
| 2528 | |
| 2529 | if (mode & MODE_FLAGS_PARTICLES && saved_type - default_type >= 3) { |
| 2530 | edit_type->select(saved_type - default_type - 3); |
| 2531 | custom_mode_box->set_pressed(true); |
| 2532 | } else { |
| 2533 | edit_type->select(saved_type - default_type); |
| 2534 | } |
| 2535 | set_current_shader_type((VisualShader::Type)saved_type); |
| 2536 | } |
| 2537 | |
| 2538 | Size2 VisualShaderEditor::get_minimum_size() const { |
| 2539 | return Size2(10, 200); |
| 2540 | } |
| 2541 | |
| 2542 | void VisualShaderEditor::update_toggle_files_button() { |
| 2543 | ERR_FAIL_NULL(toggle_files_list); |
| 2544 | bool forward = toggle_files_list->is_visible() == is_layout_rtl(); |
| 2545 | toggle_files_button->set_button_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back"))); |
| 2546 | toggle_files_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Files Panel"), ED_GET_SHORTCUT("script_editor/toggle_files_panel")->get_as_text())); |
| 2547 | } |
| 2548 | |
| 2549 | void VisualShaderEditor::_draw_color_over_button(Object *p_obj, Color p_color) { |
| 2550 | Button *button = Object::cast_to<Button>(p_obj); |
| 2551 | if (!button) { |
| 2552 | return; |
| 2553 | } |
| 2554 | |
| 2555 | Ref<StyleBox> normal = get_theme_stylebox(CoreStringName(normal), SNAME("Button")); |
| 2556 | button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color); |
| 2557 | } |
| 2558 | |
| 2559 | void VisualShaderEditor::_update_parameters(bool p_update_refs) { |
| 2560 | VisualShaderNodeParameterRef::clear_parameters(visual_shader->get_rid()); |
| 2561 | |
| 2562 | for (int t = 0; t < VisualShader::TYPE_MAX; t++) { |
| 2563 | Vector<int> tnodes = visual_shader->get_node_list((VisualShader::Type)t); |
| 2564 | for (int i = 0; i < tnodes.size(); i++) { |
| 2565 | Ref<VisualShaderNode> vsnode = visual_shader->get_node((VisualShader::Type)t, tnodes[i]); |
| 2566 | Ref<VisualShaderNodeParameter> parameter = vsnode; |
| 2567 | |
| 2568 | if (parameter.is_valid()) { |
| 2569 | Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode; |
| 2570 | Ref<VisualShaderNodeIntParameter> int_parameter = vsnode; |
| 2571 | Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode; |
| 2572 | Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode; |
| 2573 | Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode; |
| 2574 | Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode; |
| 2575 | Ref<VisualShaderNodeColorParameter> color_parameter = vsnode; |
| 2576 | Ref<VisualShaderNodeBooleanParameter> boolean_parameter = vsnode; |
| 2577 | Ref<VisualShaderNodeTransformParameter> transform_parameter = vsnode; |
| 2578 | |
| 2579 | VisualShaderNodeParameterRef::ParameterType parameter_type; |
| 2580 | if (float_parameter.is_valid()) { |
| 2581 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT; |
| 2582 | } else if (int_parameter.is_valid()) { |
| 2583 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT; |
| 2584 | } else if (uint_parameter.is_valid()) { |
| 2585 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT; |
| 2586 | } else if (boolean_parameter.is_valid()) { |
| 2587 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN; |
| 2588 | } else if (vec2_parameter.is_valid()) { |
| 2589 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR2; |
| 2590 | } else if (vec3_parameter.is_valid()) { |
| 2591 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR3; |
| 2592 | } else if (vec4_parameter.is_valid()) { |
| 2593 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_VECTOR4; |
| 2594 | } else if (transform_parameter.is_valid()) { |
| 2595 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_TRANSFORM; |
| 2596 | } else if (color_parameter.is_valid()) { |
| 2597 | parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_COLOR; |
| 2598 | } else { |
| 2599 | parameter_type = VisualShaderNodeParameterRef::UNIFORM_TYPE_SAMPLER; |
| 2600 | } |
| 2601 | VisualShaderNodeParameterRef::add_parameter(visual_shader->get_rid(), parameter->get_parameter_name(), parameter_type); |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | if (p_update_refs) { |
| 2606 | graph_plugin->update_parameter_refs(); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | void VisualShaderEditor::_update_parameter_refs(HashSet<String> &p_deleted_names) { |
| 2611 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2612 | for (int i = 0; i < VisualShader::TYPE_MAX; i++) { |
| 2613 | VisualShader::Type type = VisualShader::Type(i); |
| 2614 | |
| 2615 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 2616 | for (int j = 0; j < nodes.size(); j++) { |
| 2617 | if (j > 0) { |
| 2618 | Ref<VisualShaderNodeParameterRef> ref = visual_shader->get_node(type, nodes[j]); |
| 2619 | if (ref.is_valid()) { |
| 2620 | if (p_deleted_names.has(ref->get_parameter_name())) { |
| 2621 | undo_redo->add_do_method(ref.ptr(), "set_parameter_name", "[None]"); |
| 2622 | undo_redo->add_undo_method(ref.ptr(), "set_parameter_name", ref->get_parameter_name()); |
| 2623 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]); |
| 2624 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", VisualShader::Type(i), nodes[j]); |
| 2625 | } |
| 2626 | } |
| 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | void VisualShaderEditor::_update_graph() { |
| 2633 | if (visual_shader.is_null()) { |
| 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | if (!is_inside_tree()) { |
| 2638 | return; |
| 2639 | } |
| 2640 | |
| 2641 | VisualShader::Type type = get_current_shader_type(); |
| 2642 | |
| 2643 | graph->clear_connections(); |
| 2644 | // Remove all nodes. |
| 2645 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 2646 | if (Object::cast_to<GraphElement>(graph->get_child(i))) { |
| 2647 | Node *node = graph->get_child(i); |
| 2648 | graph->remove_child(node); |
| 2649 | memdelete(node); |
| 2650 | i--; |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | List<VisualShader::Connection> node_connections; |
| 2655 | visual_shader->get_node_connections(type, &node_connections); |
| 2656 | graph_plugin->set_connections(node_connections); |
| 2657 | |
| 2658 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 2659 | |
| 2660 | _update_parameters(false); |
| 2661 | _update_varyings(); |
| 2662 | |
| 2663 | graph_plugin->clear_links(); |
| 2664 | graph_plugin->update_theme(); |
| 2665 | |
| 2666 | for (int n_i = 0; n_i < nodes.size(); n_i++) { |
| 2667 | // Update frame related stuff later since we need to have all nodes in the graph. |
| 2668 | graph_plugin->add_node(type, nodes[n_i], false, false); |
| 2669 | } |
| 2670 | |
| 2671 | for (const VisualShader::Connection &E : node_connections) { |
| 2672 | int from = E.from_node; |
| 2673 | int from_idx = E.from_port; |
| 2674 | int to = E.to_node; |
| 2675 | int to_idx = E.to_port; |
| 2676 | |
| 2677 | graph->connect_node(itos(from), from_idx, itos(to), to_idx); |
| 2678 | } |
| 2679 | |
| 2680 | // Attach nodes to frames. |
| 2681 | for (int node_id : nodes) { |
| 2682 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); |
| 2683 | ERR_CONTINUE_MSG(vsnode.is_null(), "Node is null."); |
| 2684 | |
| 2685 | if (vsnode->get_frame() != -1) { |
| 2686 | int frame_name = vsnode->get_frame(); |
| 2687 | graph->attach_graph_element_to_frame(itos(node_id), itos(frame_name)); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity"); |
| 2692 | graph->set_minimap_opacity(graph_minimap_opacity); |
| 2693 | float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature"); |
| 2694 | graph->set_connection_lines_curvature(graph_lines_curvature); |
| 2695 | } |
| 2696 | |
| 2697 | void VisualShaderEditor::_restore_editor_state() { |
| 2698 | const String id_string = _get_cache_id_string(); |
| 2699 | |
| 2700 | const String offset_cache_key = _get_cache_key("offset"); |
| 2701 | const String zoom_cache_key = _get_cache_key("zoom"); |
| 2702 | const Vector2 saved_scroll_offset = vs_editor_cache->get_value(id_string, offset_cache_key, Vector2()); |
| 2703 | const real_t saved_zoom = vs_editor_cache->get_value(id_string, zoom_cache_key, 1.0); |
| 2704 | |
| 2705 | // Setting the scroll offset needs to be further deferred because it requires min/max scroll offset to be final (as it gets clamped). |
| 2706 | callable_mp(graph, &GraphEdit::set_zoom).call_deferred(saved_zoom); |
| 2707 | callable_mp(graph, &GraphEdit::set_scroll_offset).call_deferred(saved_scroll_offset); |
| 2708 | |
| 2709 | shader_fully_loaded = true; |
| 2710 | } |
| 2711 | |
| 2712 | String VisualShaderEditor::_get_cache_id_string() const { |
| 2713 | String id_string = visual_shader->get_path(); |
| 2714 | const ResourceUID::ID uid = EditorFileSystem::get_singleton()->get_file_uid(id_string); |
| 2715 | if (uid != ResourceUID::INVALID_ID) { |
| 2716 | id_string = ResourceUID::get_singleton()->id_to_text(uid); |
| 2717 | } |
| 2718 | return id_string; |
| 2719 | } |
| 2720 | |
| 2721 | String VisualShaderEditor::_get_cache_key(const String &p_prop_name) const { |
| 2722 | const int type = get_current_shader_type(); |
| 2723 | return "type" + itos(type) + ":" + p_prop_name; |
| 2724 | } |
| 2725 | |
| 2726 | void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) { |
| 2727 | VisualShader::Type type = get_current_shader_type(); |
| 2728 | Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node); |
| 2729 | if (node.is_null()) { |
| 2730 | return; |
| 2731 | } |
| 2732 | |
| 2733 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2734 | undo_redo->create_action(TTR("Add Input Port")); |
| 2735 | undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name); |
| 2736 | undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port); |
| 2737 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2738 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2739 | undo_redo->commit_action(); |
| 2740 | } |
| 2741 | |
| 2742 | void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_type, const String &p_name) { |
| 2743 | VisualShader::Type type = get_current_shader_type(); |
| 2744 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); |
| 2745 | if (node.is_null()) { |
| 2746 | return; |
| 2747 | } |
| 2748 | |
| 2749 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2750 | undo_redo->create_action(TTR("Add Output Port")); |
| 2751 | undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name); |
| 2752 | undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port); |
| 2753 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2754 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2755 | undo_redo->commit_action(); |
| 2756 | } |
| 2757 | |
| 2758 | void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_port) { |
| 2759 | VisualShader::Type type = get_current_shader_type(); |
| 2760 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); |
| 2761 | if (node.is_null()) { |
| 2762 | return; |
| 2763 | } |
| 2764 | |
| 2765 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2766 | undo_redo->create_action(TTR("Change Input Port Type")); |
| 2767 | undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type); |
| 2768 | undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port)); |
| 2769 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2770 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2771 | undo_redo->commit_action(); |
| 2772 | } |
| 2773 | |
| 2774 | void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_port) { |
| 2775 | VisualShader::Type type = get_current_shader_type(); |
| 2776 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); |
| 2777 | if (node.is_null()) { |
| 2778 | return; |
| 2779 | } |
| 2780 | |
| 2781 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2782 | undo_redo->create_action(TTR("Change Output Port Type")); |
| 2783 | undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type); |
| 2784 | undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port)); |
| 2785 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2786 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2787 | undo_redo->commit_action(); |
| 2788 | } |
| 2789 | |
| 2790 | void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) { |
| 2791 | VisualShader::Type type = get_current_shader_type(); |
| 2792 | |
| 2793 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id); |
| 2794 | ERR_FAIL_COND(node.is_null()); |
| 2795 | |
| 2796 | String prev_name = node->get_input_port_name(p_port_id); |
| 2797 | if (prev_name == p_text) { |
| 2798 | return; |
| 2799 | } |
| 2800 | |
| 2801 | LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit); |
| 2802 | ERR_FAIL_NULL(line_edit); |
| 2803 | |
| 2804 | String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, false); |
| 2805 | if (validated_name.is_empty() || prev_name == validated_name) { |
| 2806 | line_edit->set_text(node->get_input_port_name(p_port_id)); |
| 2807 | return; |
| 2808 | } |
| 2809 | |
| 2810 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2811 | undo_redo->create_action(TTR("Change Input Port Name")); |
| 2812 | undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, validated_name); |
| 2813 | undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id)); |
| 2814 | undo_redo->commit_action(); |
| 2815 | } |
| 2816 | |
| 2817 | void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *p_line_edit, int p_node_id, int p_port_id) { |
| 2818 | VisualShader::Type type = get_current_shader_type(); |
| 2819 | |
| 2820 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id); |
| 2821 | ERR_FAIL_COND(node.is_null()); |
| 2822 | |
| 2823 | String prev_name = node->get_output_port_name(p_port_id); |
| 2824 | if (prev_name == p_text) { |
| 2825 | return; |
| 2826 | } |
| 2827 | |
| 2828 | LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit); |
| 2829 | ERR_FAIL_NULL(line_edit); |
| 2830 | |
| 2831 | String validated_name = visual_shader->validate_port_name(p_text, node.ptr(), p_port_id, true); |
| 2832 | if (validated_name.is_empty() || prev_name == validated_name) { |
| 2833 | line_edit->set_text(node->get_output_port_name(p_port_id)); |
| 2834 | return; |
| 2835 | } |
| 2836 | |
| 2837 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2838 | undo_redo->create_action(TTR("Change Output Port Name")); |
| 2839 | undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, validated_name); |
| 2840 | undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, prev_name); |
| 2841 | undo_redo->commit_action(); |
| 2842 | } |
| 2843 | |
| 2844 | void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expand) { |
| 2845 | VisualShader::Type type = get_current_shader_type(); |
| 2846 | |
| 2847 | Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node); |
| 2848 | ERR_FAIL_COND(node.is_null()); |
| 2849 | |
| 2850 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2851 | if (p_expand) { |
| 2852 | undo_redo->create_action(TTR("Expand Output Port")); |
| 2853 | } else { |
| 2854 | undo_redo->create_action(TTR("Shrink Output Port")); |
| 2855 | } |
| 2856 | |
| 2857 | undo_redo->add_do_method(node.ptr(), "_set_output_port_expanded", p_port, p_expand); |
| 2858 | undo_redo->add_undo_method(node.ptr(), "_set_output_port_expanded", p_port, !p_expand); |
| 2859 | |
| 2860 | int type_size = 0; |
| 2861 | switch (node->get_output_port_type(p_port)) { |
| 2862 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: { |
| 2863 | type_size = 2; |
| 2864 | } break; |
| 2865 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: { |
| 2866 | type_size = 3; |
| 2867 | } break; |
| 2868 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: { |
| 2869 | type_size = 4; |
| 2870 | } break; |
| 2871 | default: |
| 2872 | break; |
| 2873 | } |
| 2874 | |
| 2875 | List<VisualShader::Connection> conns; |
| 2876 | visual_shader->get_node_connections(type, &conns); |
| 2877 | |
| 2878 | for (const VisualShader::Connection &E : conns) { |
| 2879 | int cn_from_node = E.from_node; |
| 2880 | int cn_from_port = E.from_port; |
| 2881 | int cn_to_node = E.to_node; |
| 2882 | int cn_to_port = E.to_port; |
| 2883 | |
| 2884 | if (cn_from_node == p_node) { |
| 2885 | if (p_expand) { |
| 2886 | if (cn_from_port > p_port) { // reconnect ports after expanded ports |
| 2887 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2888 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2889 | |
| 2890 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2891 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2892 | |
| 2893 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port); |
| 2894 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port); |
| 2895 | |
| 2896 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port); |
| 2897 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port + type_size, cn_to_node, cn_to_port); |
| 2898 | } |
| 2899 | } else { |
| 2900 | if (cn_from_port > p_port + type_size) { // reconnect ports after expanded ports |
| 2901 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2902 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2903 | |
| 2904 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2905 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2906 | |
| 2907 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port); |
| 2908 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port); |
| 2909 | |
| 2910 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port); |
| 2911 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - type_size, cn_to_node, cn_to_port); |
| 2912 | } else if (cn_from_port > p_port) { // disconnect component ports |
| 2913 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2914 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2915 | |
| 2916 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2917 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2918 | } |
| 2919 | } |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | int preview_port = node->get_output_port_for_preview(); |
| 2924 | if (p_expand) { |
| 2925 | if (preview_port > p_port) { |
| 2926 | undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port + type_size); |
| 2927 | undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port); |
| 2928 | } |
| 2929 | } else { |
| 2930 | if (preview_port > p_port + type_size) { |
| 2931 | undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - type_size); |
| 2932 | undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2937 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2938 | undo_redo->commit_action(); |
| 2939 | } |
| 2940 | |
| 2941 | void VisualShaderEditor::_remove_input_port(int p_node, int p_port) { |
| 2942 | VisualShader::Type type = get_current_shader_type(); |
| 2943 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); |
| 2944 | if (node.is_null()) { |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2949 | undo_redo->create_action(TTR("Remove Input Port")); |
| 2950 | |
| 2951 | List<VisualShader::Connection> conns; |
| 2952 | visual_shader->get_node_connections(type, &conns); |
| 2953 | for (const VisualShader::Connection &E : conns) { |
| 2954 | int cn_from_node = E.from_node; |
| 2955 | int cn_from_port = E.from_port; |
| 2956 | int cn_to_node = E.to_node; |
| 2957 | int cn_to_port = E.to_port; |
| 2958 | |
| 2959 | if (cn_to_node == p_node) { |
| 2960 | if (cn_to_port == p_port) { |
| 2961 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2962 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2963 | |
| 2964 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2965 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2966 | } else if (cn_to_port > p_port) { |
| 2967 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2968 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2969 | |
| 2970 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2971 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 2972 | |
| 2973 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1); |
| 2974 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1); |
| 2975 | |
| 2976 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1); |
| 2977 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port - 1); |
| 2978 | } |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | undo_redo->add_do_method(node.ptr(), "remove_input_port", p_port); |
| 2983 | undo_redo->add_undo_method(node.ptr(), "add_input_port", p_port, (int)node->get_input_port_type(p_port), node->get_input_port_name(p_port)); |
| 2984 | |
| 2985 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2986 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 2987 | |
| 2988 | undo_redo->commit_action(); |
| 2989 | } |
| 2990 | |
| 2991 | void VisualShaderEditor::_remove_output_port(int p_node, int p_port) { |
| 2992 | VisualShader::Type type = get_current_shader_type(); |
| 2993 | Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node); |
| 2994 | if (node.is_null()) { |
| 2995 | return; |
| 2996 | } |
| 2997 | |
| 2998 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2999 | undo_redo->create_action(TTR("Remove Output Port")); |
| 3000 | |
| 3001 | List<VisualShader::Connection> conns; |
| 3002 | visual_shader->get_node_connections(type, &conns); |
| 3003 | for (const VisualShader::Connection &E : conns) { |
| 3004 | int cn_from_node = E.from_node; |
| 3005 | int cn_from_port = E.from_port; |
| 3006 | int cn_to_node = E.to_node; |
| 3007 | int cn_to_port = E.to_port; |
| 3008 | |
| 3009 | if (cn_from_node == p_node) { |
| 3010 | if (cn_from_port == p_port) { |
| 3011 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3012 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3013 | |
| 3014 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3015 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3016 | } else if (cn_from_port > p_port) { |
| 3017 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3018 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3019 | |
| 3020 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3021 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 3022 | |
| 3023 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port); |
| 3024 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port); |
| 3025 | |
| 3026 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port); |
| 3027 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port - 1, cn_to_node, cn_to_port); |
| 3028 | } |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | int preview_port = node->get_output_port_for_preview(); |
| 3033 | if (preview_port != -1) { |
| 3034 | if (preview_port == p_port) { |
| 3035 | undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1); |
| 3036 | undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port); |
| 3037 | } else if (preview_port > p_port) { |
| 3038 | undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1); |
| 3039 | undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port); |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port); |
| 3044 | undo_redo->add_undo_method(node.ptr(), "add_output_port", p_port, (int)node->get_output_port_type(p_port), node->get_output_port_name(p_port)); |
| 3045 | |
| 3046 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 3047 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 3048 | |
| 3049 | undo_redo->commit_action(); |
| 3050 | } |
| 3051 | |
| 3052 | void VisualShaderEditor::_expression_focus_out(Object *p_code_edit, int p_node) { |
| 3053 | VisualShader::Type type = get_current_shader_type(); |
| 3054 | Ref<VisualShaderNodeExpression> node = visual_shader->get_node(type, p_node); |
| 3055 | if (node.is_null()) { |
| 3056 | return; |
| 3057 | } |
| 3058 | |
| 3059 | CodeEdit *expression_box = Object::cast_to<CodeEdit>(p_code_edit); |
| 3060 | |
| 3061 | if (node->get_expression() == expression_box->get_text()) { |
| 3062 | return; |
| 3063 | } |
| 3064 | |
| 3065 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3066 | undo_redo->create_action(TTR("Set VisualShader Expression")); |
| 3067 | undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text()); |
| 3068 | undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression()); |
| 3069 | undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text()); |
| 3070 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression()); |
| 3071 | undo_redo->commit_action(); |
| 3072 | } |
| 3073 | |
| 3074 | void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) { |
| 3075 | VisualShader::Type type = VisualShader::Type(p_type); |
| 3076 | Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(type, p_node); |
| 3077 | if (node.is_null()) { |
| 3078 | return; |
| 3079 | } |
| 3080 | |
| 3081 | Size2 size = p_size; |
| 3082 | if (!node->is_allow_v_resize()) { |
| 3083 | size.y = 0; |
| 3084 | } |
| 3085 | |
| 3086 | node->set_size(size); |
| 3087 | |
| 3088 | if (get_current_shader_type() == type) { |
| 3089 | Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr()); |
| 3090 | Control *text_box = nullptr; |
| 3091 | if (expression_node.is_valid()) { |
| 3092 | text_box = expression_node->is_ctrl_pressed(0); |
| 3093 | if (text_box) { |
| 3094 | text_box->set_custom_minimum_size(Size2(0, 0)); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | GraphElement *graph_element = nullptr; |
| 3099 | Node *node2 = graph->get_node(itos(p_node)); |
| 3100 | graph_element = Object::cast_to<GraphElement>(node2); |
| 3101 | if (!graph_element) { |
| 3102 | return; |
| 3103 | } |
| 3104 | |
| 3105 | graph_element->set_size(size); |
| 3106 | } |
| 3107 | |
| 3108 | // Update all parent frames. |
| 3109 | graph_plugin->update_frames(type, p_node); |
| 3110 | } |
| 3111 | |
| 3112 | // Called once after the node was resized. |
| 3113 | void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) { |
| 3114 | Ref<VisualShaderNodeResizableBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node); |
| 3115 | if (node.is_null()) { |
| 3116 | return; |
| 3117 | } |
| 3118 | |
| 3119 | GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_node(itos(p_node))); |
| 3120 | if (!graph_element) { |
| 3121 | return; |
| 3122 | } |
| 3123 | |
| 3124 | Size2 size = graph_element->get_size(); |
| 3125 | |
| 3126 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3127 | undo_redo->create_action(TTR("Resize VisualShader Node")); |
| 3128 | undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, size); |
| 3129 | undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size()); |
| 3130 | undo_redo->commit_action(); |
| 3131 | } |
| 3132 | |
| 3133 | void VisualShaderEditor::_preview_select_port(int p_node, int p_port) { |
| 3134 | VisualShader::Type type = get_current_shader_type(); |
| 3135 | Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node); |
| 3136 | if (node.is_null()) { |
| 3137 | return; |
| 3138 | } |
| 3139 | int prev_port = node->get_output_port_for_preview(); |
| 3140 | if (node->get_output_port_for_preview() == p_port) { |
| 3141 | p_port = -1; //toggle it |
| 3142 | } |
| 3143 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3144 | undo_redo->create_action(p_port == -1 ? TTR("Hide Port Preview") : TTR("Show Port Preview")); |
| 3145 | undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", p_port); |
| 3146 | undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", prev_port); |
| 3147 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, p_node); |
| 3148 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, p_node); |
| 3149 | undo_redo->commit_action(); |
| 3150 | } |
| 3151 | |
| 3152 | void VisualShaderEditor::_frame_title_popup_show(const Point2 &p_position, int p_node_id) { |
| 3153 | VisualShader::Type type = get_current_shader_type(); |
| 3154 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id); |
| 3155 | if (node.is_null()) { |
| 3156 | return; |
| 3157 | } |
| 3158 | frame_title_change_edit->set_text(node->get_title()); |
| 3159 | frame_title_change_popup->set_meta("id", p_node_id); |
| 3160 | frame_title_change_popup->set_position(p_position); |
| 3161 | frame_title_change_popup->popup(); |
| 3162 | |
| 3163 | // Select current text. |
| 3164 | frame_title_change_edit->grab_focus(); |
| 3165 | } |
| 3166 | |
| 3167 | void VisualShaderEditor::_frame_title_text_changed(const String &p_new_text) { |
| 3168 | frame_title_change_edit->reset_size(); |
| 3169 | frame_title_change_popup->reset_size(); |
| 3170 | } |
| 3171 | |
| 3172 | void VisualShaderEditor::_frame_title_text_submitted(const String &p_new_text) { |
| 3173 | frame_title_change_popup->hide(); |
| 3174 | } |
| 3175 | |
| 3176 | void VisualShaderEditor::_frame_title_popup_focus_out() { |
| 3177 | frame_title_change_popup->hide(); |
| 3178 | } |
| 3179 | |
| 3180 | void VisualShaderEditor::_frame_title_popup_hide() { |
| 3181 | int node_id = (int)frame_title_change_popup->get_meta("id", -1); |
| 3182 | ERR_FAIL_COND(node_id == -1); |
| 3183 | |
| 3184 | VisualShader::Type type = get_current_shader_type(); |
| 3185 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id); |
| 3186 | |
| 3187 | ERR_FAIL_COND(node.is_null()); |
| 3188 | |
| 3189 | if (node->get_title() == frame_title_change_edit->get_text()) { |
| 3190 | return; // nothing changed - ignored |
| 3191 | } |
| 3192 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3193 | undo_redo->create_action(TTR("Set Frame Title")); |
| 3194 | undo_redo->add_do_method(node.ptr(), "set_title", frame_title_change_edit->get_text()); |
| 3195 | undo_redo->add_undo_method(node.ptr(), "set_title", node->get_title()); |
| 3196 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, node_id); |
| 3197 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, node_id); |
| 3198 | undo_redo->commit_action(); |
| 3199 | } |
| 3200 | |
| 3201 | void VisualShaderEditor::_frame_color_enabled_changed(int p_node_id) { |
| 3202 | int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR); |
| 3203 | |
| 3204 | // The new state. |
| 3205 | bool tint_color_enabled = !popup_menu->is_item_checked(item_index); |
| 3206 | |
| 3207 | popup_menu->set_item_checked(item_index, tint_color_enabled); |
| 3208 | int frame_color_item_idx = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR); |
| 3209 | if (tint_color_enabled && frame_color_item_idx == -1) { |
| 3210 | popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR); |
| 3211 | } else if (!tint_color_enabled && frame_color_item_idx != -1) { |
| 3212 | popup_menu->remove_item(frame_color_item_idx); |
| 3213 | } |
| 3214 | |
| 3215 | VisualShader::Type type = get_current_shader_type(); |
| 3216 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id); |
| 3217 | |
| 3218 | ERR_FAIL_COND(node.is_null()); |
| 3219 | |
| 3220 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3221 | undo_redo->create_action(TTR("Toggle Frame Color")); |
| 3222 | undo_redo->add_do_method(node.ptr(), "set_tint_color_enabled", tint_color_enabled); |
| 3223 | undo_redo->add_undo_method(node.ptr(), "set_tint_color_enabled", node->is_tint_color_enabled()); |
| 3224 | undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, tint_color_enabled); |
| 3225 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color_enabled", (int)type, p_node_id, node->is_tint_color_enabled()); |
| 3226 | undo_redo->commit_action(); |
| 3227 | } |
| 3228 | |
| 3229 | void VisualShaderEditor::_frame_color_popup_show(const Point2 &p_position, int p_node_id) { |
| 3230 | VisualShader::Type type = get_current_shader_type(); |
| 3231 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id); |
| 3232 | if (node.is_null()) { |
| 3233 | return; |
| 3234 | } |
| 3235 | frame_tint_color_picker->set_pick_color(node->get_tint_color()); |
| 3236 | frame_tint_color_pick_popup->set_meta("id", p_node_id); |
| 3237 | frame_tint_color_pick_popup->set_position(p_position); |
| 3238 | frame_tint_color_pick_popup->popup(); |
| 3239 | } |
| 3240 | |
| 3241 | void VisualShaderEditor::_frame_color_confirm() { |
| 3242 | frame_tint_color_pick_popup->hide(); |
| 3243 | } |
| 3244 | |
| 3245 | void VisualShaderEditor::_frame_color_changed(const Color &p_color) { |
| 3246 | ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id")); |
| 3247 | int node_id = (int)frame_tint_color_pick_popup->get_meta("id"); |
| 3248 | |
| 3249 | VisualShader::Type type = get_current_shader_type(); |
| 3250 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id); |
| 3251 | ERR_FAIL_COND(node.is_null()); |
| 3252 | node->set_tint_color(p_color); |
| 3253 | graph_plugin->set_frame_color(type, node_id, p_color); |
| 3254 | } |
| 3255 | |
| 3256 | void VisualShaderEditor::_frame_color_popup_hide() { |
| 3257 | ERR_FAIL_COND(!frame_tint_color_pick_popup->has_meta("id")); |
| 3258 | int node_id = (int)frame_tint_color_pick_popup->get_meta("id"); |
| 3259 | |
| 3260 | VisualShader::Type type = get_current_shader_type(); |
| 3261 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, node_id); |
| 3262 | ERR_FAIL_COND(node.is_null()); |
| 3263 | |
| 3264 | if (node->get_tint_color() == frame_tint_color_picker->get_pick_color()) { |
| 3265 | return; |
| 3266 | } |
| 3267 | |
| 3268 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3269 | undo_redo->create_action(TTR("Set Frame Color")); |
| 3270 | undo_redo->add_do_method(node.ptr(), "set_tint_color", frame_tint_color_picker->get_pick_color()); |
| 3271 | undo_redo->add_undo_method(node.ptr(), "set_tint_color", node->get_tint_color()); |
| 3272 | undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, frame_tint_color_picker->get_pick_color()); |
| 3273 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_color", (int)type, node_id, node->get_tint_color()); |
| 3274 | undo_redo->commit_action(); |
| 3275 | } |
| 3276 | |
| 3277 | void VisualShaderEditor::_frame_autoshrink_enabled_changed(int p_node_id) { |
| 3278 | int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK); |
| 3279 | |
| 3280 | bool autoshrink_enabled = popup_menu->is_item_checked(item_index); |
| 3281 | |
| 3282 | popup_menu->set_item_checked(item_index, !autoshrink_enabled); |
| 3283 | |
| 3284 | VisualShader::Type type = get_current_shader_type(); |
| 3285 | Ref<VisualShaderNodeFrame> node = visual_shader->get_node(type, p_node_id); |
| 3286 | |
| 3287 | ERR_FAIL_COND(node.is_null()); |
| 3288 | |
| 3289 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3290 | undo_redo->create_action(TTR("Toggle Auto Shrink")); |
| 3291 | undo_redo->add_do_method(node.ptr(), "set_autoshrink_enabled", !autoshrink_enabled); |
| 3292 | undo_redo->add_undo_method(node.ptr(), "set_autoshrink_enabled", autoshrink_enabled); |
| 3293 | undo_redo->add_do_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, !autoshrink_enabled); |
| 3294 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_frame_autoshrink_enabled", (int)type, p_node_id, autoshrink_enabled); |
| 3295 | undo_redo->commit_action(); |
| 3296 | |
| 3297 | popup_menu->hide(); |
| 3298 | } |
| 3299 | |
| 3300 | void VisualShaderEditor::_parameter_line_edit_changed(const String &p_text, int p_node_id) { |
| 3301 | VisualShader::Type type = get_current_shader_type(); |
| 3302 | |
| 3303 | Ref<VisualShaderNodeParameter> node = visual_shader->get_node(type, p_node_id); |
| 3304 | ERR_FAIL_COND(node.is_null()); |
| 3305 | |
| 3306 | String validated_name = visual_shader->validate_parameter_name(p_text, node); |
| 3307 | |
| 3308 | if (validated_name == node->get_parameter_name()) { |
| 3309 | return; |
| 3310 | } |
| 3311 | |
| 3312 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3313 | undo_redo->create_action(TTR("Set Parameter Name")); |
| 3314 | undo_redo->add_do_method(node.ptr(), "set_parameter_name", validated_name); |
| 3315 | undo_redo->add_undo_method(node.ptr(), "set_parameter_name", node->get_parameter_name()); |
| 3316 | undo_redo->add_do_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, validated_name); |
| 3317 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_parameter_name", type, p_node_id, node->get_parameter_name()); |
| 3318 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id); |
| 3319 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id); |
| 3320 | |
| 3321 | undo_redo->add_do_method(this, "_update_parameters", true); |
| 3322 | undo_redo->add_undo_method(this, "_update_parameters", true); |
| 3323 | |
| 3324 | HashSet<String> changed_names; |
| 3325 | changed_names.insert(node->get_parameter_name()); |
| 3326 | _update_parameter_refs(changed_names); |
| 3327 | |
| 3328 | undo_redo->commit_action(); |
| 3329 | } |
| 3330 | |
| 3331 | void VisualShaderEditor::_parameter_line_edit_focus_out(Object *line_edit, int p_node_id) { |
| 3332 | _parameter_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id); |
| 3333 | } |
| 3334 | |
| 3335 | void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) { |
| 3336 | if (!p_output) { |
| 3337 | _change_input_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id); |
| 3338 | } else { |
| 3339 | _change_output_port_name(Object::cast_to<LineEdit>(line_edit)->get_text(), line_edit, p_node_id, p_port_id); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { |
| 3344 | VisualShader::Type type = get_current_shader_type(); |
| 3345 | Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node); |
| 3346 | ERR_FAIL_COND(vsn.is_null()); |
| 3347 | |
| 3348 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3349 | undo_redo->create_action(TTR("Set Input Default Port")); |
| 3350 | |
| 3351 | Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr()); |
| 3352 | if (custom.is_valid()) { |
| 3353 | undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value); |
| 3354 | undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port)); |
| 3355 | } else { |
| 3356 | undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value); |
| 3357 | undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port)); |
| 3358 | } |
| 3359 | undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value); |
| 3360 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, vsn->get_input_port_default_value(editing_port)); |
| 3361 | undo_redo->commit_action(); |
| 3362 | } |
| 3363 | |
| 3364 | void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) { |
| 3365 | VisualShader::Type type = get_current_shader_type(); |
| 3366 | Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node); |
| 3367 | Variant value = vs_node->get_input_port_default_value(p_port); |
| 3368 | |
| 3369 | edited_property_holder->set_edited_property(value); |
| 3370 | editing_node = p_node; |
| 3371 | editing_port = p_port; |
| 3372 | |
| 3373 | if (property_editor) { |
| 3374 | property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited)); |
| 3375 | property_editor_popup->remove_child(property_editor); |
| 3376 | } |
| 3377 | |
| 3378 | // TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget. |
| 3379 | property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE, true); |
| 3380 | ERR_FAIL_NULL_MSG(property_editor, "Failed to create property editor for type: " + Variant::get_type_name(value.get_type())); |
| 3381 | |
| 3382 | // Determine the best size for the popup based on the property type. |
| 3383 | // This is done here, since the property editors are also used in the inspector where they have different layout requirements, so we can't just change their default minimum size. |
| 3384 | Size2 popup_pref_size; |
| 3385 | switch (value.get_type()) { |
| 3386 | case Variant::VECTOR3: |
| 3387 | case Variant::BASIS: |
| 3388 | popup_pref_size.width = 320; |
| 3389 | break; |
| 3390 | case Variant::VECTOR4: |
| 3391 | case Variant::PLANE: |
| 3392 | case Variant::TRANSFORM2D: |
| 3393 | case Variant::TRANSFORM3D: |
| 3394 | case Variant::PROJECTION: |
| 3395 | popup_pref_size.width = 480; |
| 3396 | break; |
| 3397 | default: |
| 3398 | popup_pref_size.width = 180; |
| 3399 | break; |
| 3400 | } |
| 3401 | property_editor_popup->set_min_size(popup_pref_size * EDSCALE); |
| 3402 | |
| 3403 | property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property"); |
| 3404 | property_editor->update_property(); |
| 3405 | property_editor->set_name_split_ratio(0); |
| 3406 | property_editor_popup->add_child(property_editor); |
| 3407 | |
| 3408 | property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited)); |
| 3409 | |
| 3410 | Button *button = Object::cast_to<Button>(p_button); |
| 3411 | if (button) { |
| 3412 | property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom()); |
| 3413 | } |
| 3414 | property_editor_popup->reset_size(); |
| 3415 | if (button) { |
| 3416 | property_editor_popup->popup(); |
| 3417 | } else { |
| 3418 | property_editor_popup->popup_centered_ratio(); |
| 3419 | } |
| 3420 | property_editor->select(0); // Focus the first focusable control. |
| 3421 | } |
| 3422 | |
| 3423 | void VisualShaderEditor::_set_custom_node_option(int p_index, int p_node, int p_op) { |
| 3424 | VisualShader::Type type = get_current_shader_type(); |
| 3425 | Ref<VisualShaderNodeCustom> node = visual_shader->get_node(type, p_node); |
| 3426 | if (node.is_null()) { |
| 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3431 | undo_redo->create_action(TTR("Set Custom Node Option")); |
| 3432 | undo_redo->add_do_method(node.ptr(), "_set_option_index", p_op, p_index); |
| 3433 | undo_redo->add_undo_method(node.ptr(), "_set_option_index", p_op, node->get_option_index(p_op)); |
| 3434 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 3435 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, p_node); |
| 3436 | undo_redo->commit_action(); |
| 3437 | } |
| 3438 | |
| 3439 | void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops) { |
| 3440 | // INPUT |
| 3441 | { |
| 3442 | VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(p_node); |
| 3443 | |
| 3444 | if (input) { |
| 3445 | ERR_FAIL_COND(!p_ops[0].is_string()); |
| 3446 | input->set_input_name((String)p_ops[0]); |
| 3447 | return; |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | // FLOAT_CONST |
| 3452 | { |
| 3453 | VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(p_node); |
| 3454 | |
| 3455 | if (float_const) { |
| 3456 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::FLOAT); |
| 3457 | float_const->set_constant((float)p_ops[0]); |
| 3458 | return; |
| 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | // FLOAT_OP |
| 3463 | { |
| 3464 | VisualShaderNodeFloatOp *float_op = Object::cast_to<VisualShaderNodeFloatOp>(p_node); |
| 3465 | |
| 3466 | if (float_op) { |
| 3467 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3468 | float_op->set_operator((VisualShaderNodeFloatOp::Operator)(int)p_ops[0]); |
| 3469 | return; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | // FLOAT_FUNC |
| 3474 | { |
| 3475 | VisualShaderNodeFloatFunc *float_func = Object::cast_to<VisualShaderNodeFloatFunc>(p_node); |
| 3476 | |
| 3477 | if (float_func) { |
| 3478 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3479 | float_func->set_function((VisualShaderNodeFloatFunc::Function)(int)p_ops[0]); |
| 3480 | return; |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | // VECTOR_OP |
| 3485 | { |
| 3486 | VisualShaderNodeVectorOp *vec_op = Object::cast_to<VisualShaderNodeVectorOp>(p_node); |
| 3487 | |
| 3488 | if (vec_op) { |
| 3489 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3490 | ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT); |
| 3491 | vec_op->set_operator((VisualShaderNodeVectorOp::Operator)(int)p_ops[0]); |
| 3492 | vec_op->set_op_type((VisualShaderNodeVectorOp::OpType)(int)p_ops[1]); |
| 3493 | return; |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | // VECTOR_FUNC |
| 3498 | { |
| 3499 | VisualShaderNodeVectorFunc *vec_func = Object::cast_to<VisualShaderNodeVectorFunc>(p_node); |
| 3500 | |
| 3501 | if (vec_func) { |
| 3502 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3503 | ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT); |
| 3504 | vec_func->set_function((VisualShaderNodeVectorFunc::Function)(int)p_ops[0]); |
| 3505 | vec_func->set_op_type((VisualShaderNodeVectorFunc::OpType)(int)p_ops[1]); |
| 3506 | return; |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | // COLOR_OP |
| 3511 | { |
| 3512 | VisualShaderNodeColorOp *color_op = Object::cast_to<VisualShaderNodeColorOp>(p_node); |
| 3513 | |
| 3514 | if (color_op) { |
| 3515 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3516 | color_op->set_operator((VisualShaderNodeColorOp::Operator)(int)p_ops[0]); |
| 3517 | return; |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | // COLOR_FUNC |
| 3522 | { |
| 3523 | VisualShaderNodeColorFunc *color_func = Object::cast_to<VisualShaderNodeColorFunc>(p_node); |
| 3524 | |
| 3525 | if (color_func) { |
| 3526 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3527 | color_func->set_function((VisualShaderNodeColorFunc::Function)(int)p_ops[0]); |
| 3528 | return; |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | // INT_OP |
| 3533 | { |
| 3534 | VisualShaderNodeIntOp *int_op = Object::cast_to<VisualShaderNodeIntOp>(p_node); |
| 3535 | |
| 3536 | if (int_op) { |
| 3537 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3538 | int_op->set_operator((VisualShaderNodeIntOp::Operator)(int)p_ops[0]); |
| 3539 | return; |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | // INT_FUNC |
| 3544 | { |
| 3545 | VisualShaderNodeIntFunc *int_func = Object::cast_to<VisualShaderNodeIntFunc>(p_node); |
| 3546 | |
| 3547 | if (int_func) { |
| 3548 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3549 | int_func->set_function((VisualShaderNodeIntFunc::Function)(int)p_ops[0]); |
| 3550 | return; |
| 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | // UINT_OP |
| 3555 | { |
| 3556 | VisualShaderNodeUIntOp *uint_op = Object::cast_to<VisualShaderNodeUIntOp>(p_node); |
| 3557 | |
| 3558 | if (uint_op) { |
| 3559 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3560 | uint_op->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]); |
| 3561 | return; |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | // UINT_FUNC |
| 3566 | { |
| 3567 | VisualShaderNodeUIntFunc *uint_func = Object::cast_to<VisualShaderNodeUIntFunc>(p_node); |
| 3568 | |
| 3569 | if (uint_func) { |
| 3570 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3571 | uint_func->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]); |
| 3572 | return; |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | // TRANSFORM_OP |
| 3577 | { |
| 3578 | VisualShaderNodeTransformOp *mat_op = Object::cast_to<VisualShaderNodeTransformOp>(p_node); |
| 3579 | |
| 3580 | if (mat_op) { |
| 3581 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3582 | mat_op->set_operator((VisualShaderNodeTransformOp::Operator)(int)p_ops[0]); |
| 3583 | return; |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | // TRANSFORM_FUNC |
| 3588 | { |
| 3589 | VisualShaderNodeTransformFunc *mat_func = Object::cast_to<VisualShaderNodeTransformFunc>(p_node); |
| 3590 | |
| 3591 | if (mat_func) { |
| 3592 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3593 | mat_func->set_function((VisualShaderNodeTransformFunc::Function)(int)p_ops[0]); |
| 3594 | return; |
| 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | // VECTOR_COMPOSE |
| 3599 | { |
| 3600 | VisualShaderNodeVectorCompose *vec_compose = Object::cast_to<VisualShaderNodeVectorCompose>(p_node); |
| 3601 | |
| 3602 | if (vec_compose) { |
| 3603 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3604 | vec_compose->set_op_type((VisualShaderNodeVectorCompose::OpType)(int)p_ops[0]); |
| 3605 | return; |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | // VECTOR_DECOMPOSE |
| 3610 | { |
| 3611 | VisualShaderNodeVectorDecompose *vec_decompose = Object::cast_to<VisualShaderNodeVectorDecompose>(p_node); |
| 3612 | |
| 3613 | if (vec_decompose) { |
| 3614 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3615 | vec_decompose->set_op_type((VisualShaderNodeVectorDecompose::OpType)(int)p_ops[0]); |
| 3616 | return; |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | // UV_FUNC |
| 3621 | { |
| 3622 | VisualShaderNodeUVFunc *uv_func = Object::cast_to<VisualShaderNodeUVFunc>(p_node); |
| 3623 | |
| 3624 | if (uv_func) { |
| 3625 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3626 | uv_func->set_function((VisualShaderNodeUVFunc::Function)(int)p_ops[0]); |
| 3627 | return; |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | // IS |
| 3632 | { |
| 3633 | VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node); |
| 3634 | |
| 3635 | if (is) { |
| 3636 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3637 | is->set_function((VisualShaderNodeIs::Function)(int)p_ops[0]); |
| 3638 | return; |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | // COMPARE |
| 3643 | { |
| 3644 | VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node); |
| 3645 | |
| 3646 | if (cmp) { |
| 3647 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3648 | cmp->set_function((VisualShaderNodeCompare::Function)(int)p_ops[0]); |
| 3649 | return; |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | // DISTANCE |
| 3654 | { |
| 3655 | VisualShaderNodeVectorDistance *dist = Object::cast_to<VisualShaderNodeVectorDistance>(p_node); |
| 3656 | |
| 3657 | if (dist) { |
| 3658 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3659 | dist->set_op_type((VisualShaderNodeVectorDistance::OpType)(int)p_ops[0]); |
| 3660 | return; |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | // DERIVATIVE |
| 3665 | { |
| 3666 | VisualShaderNodeDerivativeFunc *der_func = Object::cast_to<VisualShaderNodeDerivativeFunc>(p_node); |
| 3667 | |
| 3668 | if (der_func) { |
| 3669 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3670 | ERR_FAIL_COND(p_ops[1].get_type() != Variant::INT); |
| 3671 | der_func->set_function((VisualShaderNodeDerivativeFunc::Function)(int)p_ops[0]); |
| 3672 | der_func->set_op_type((VisualShaderNodeDerivativeFunc::OpType)(int)p_ops[1]); |
| 3673 | return; |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | // MIX |
| 3678 | { |
| 3679 | VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node); |
| 3680 | |
| 3681 | if (mix) { |
| 3682 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3683 | mix->set_op_type((VisualShaderNodeMix::OpType)(int)p_ops[0]); |
| 3684 | return; |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | // CLAMP |
| 3689 | { |
| 3690 | VisualShaderNodeClamp *clamp_func = Object::cast_to<VisualShaderNodeClamp>(p_node); |
| 3691 | |
| 3692 | if (clamp_func) { |
| 3693 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3694 | clamp_func->set_op_type((VisualShaderNodeClamp::OpType)(int)p_ops[0]); |
| 3695 | return; |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | // SWITCH |
| 3700 | { |
| 3701 | VisualShaderNodeSwitch *switch_func = Object::cast_to<VisualShaderNodeSwitch>(p_node); |
| 3702 | |
| 3703 | if (switch_func) { |
| 3704 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3705 | switch_func->set_op_type((VisualShaderNodeSwitch::OpType)(int)p_ops[0]); |
| 3706 | return; |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | // FACEFORWARD |
| 3711 | { |
| 3712 | VisualShaderNodeFaceForward *face_forward = Object::cast_to<VisualShaderNodeFaceForward>(p_node); |
| 3713 | if (face_forward) { |
| 3714 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3715 | face_forward->set_op_type((VisualShaderNodeFaceForward::OpType)(int)p_ops[0]); |
| 3716 | return; |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | // LENGTH |
| 3721 | { |
| 3722 | VisualShaderNodeVectorLen *length = Object::cast_to<VisualShaderNodeVectorLen>(p_node); |
| 3723 | if (length) { |
| 3724 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3725 | length->set_op_type((VisualShaderNodeVectorLen::OpType)(int)p_ops[0]); |
| 3726 | return; |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | // SMOOTHSTEP |
| 3731 | { |
| 3732 | VisualShaderNodeSmoothStep *smooth_step_func = Object::cast_to<VisualShaderNodeSmoothStep>(p_node); |
| 3733 | |
| 3734 | if (smooth_step_func) { |
| 3735 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3736 | smooth_step_func->set_op_type((VisualShaderNodeSmoothStep::OpType)(int)p_ops[0]); |
| 3737 | return; |
| 3738 | } |
| 3739 | } |
| 3740 | |
| 3741 | // STEP |
| 3742 | { |
| 3743 | VisualShaderNodeStep *step_func = Object::cast_to<VisualShaderNodeStep>(p_node); |
| 3744 | |
| 3745 | if (step_func) { |
| 3746 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3747 | step_func->set_op_type((VisualShaderNodeStep::OpType)(int)p_ops[0]); |
| 3748 | return; |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | // MULTIPLY_ADD |
| 3753 | { |
| 3754 | VisualShaderNodeMultiplyAdd *fma_func = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node); |
| 3755 | |
| 3756 | if (fma_func) { |
| 3757 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3758 | fma_func->set_op_type((VisualShaderNodeMultiplyAdd::OpType)(int)p_ops[0]); |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | // REMAP |
| 3763 | { |
| 3764 | VisualShaderNodeRemap *remap_func = Object::cast_to<VisualShaderNodeRemap>(p_node); |
| 3765 | |
| 3766 | if (remap_func) { |
| 3767 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3768 | remap_func->set_op_type((VisualShaderNodeRemap::OpType)(int)p_ops[0]); |
| 3769 | } |
| 3770 | } |
| 3771 | |
| 3772 | // REFRACT |
| 3773 | { |
| 3774 | VisualShaderNodeVectorRefract *refract = Object::cast_to<VisualShaderNodeVectorRefract>(p_node); |
| 3775 | |
| 3776 | if (refract) { |
| 3777 | ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); |
| 3778 | refract->set_op_type((VisualShaderNodeVectorRefract::OpType)(int)p_ops[0]); |
| 3779 | return; |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path, int p_node_idx) { |
| 3785 | ERR_FAIL_INDEX(p_idx, add_options.size()); |
| 3786 | |
| 3787 | VisualShader::Type type = get_current_shader_type(); |
| 3788 | |
| 3789 | Ref<VisualShaderNode> vsnode; |
| 3790 | |
| 3791 | bool is_custom = add_options[p_idx].is_custom; |
| 3792 | |
| 3793 | if (!is_custom && !add_options[p_idx].type.is_empty()) { |
| 3794 | VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type)); |
| 3795 | ERR_FAIL_NULL(vsn); |
| 3796 | if (!p_ops.is_empty()) { |
| 3797 | _setup_node(vsn, p_ops); |
| 3798 | } |
| 3799 | VisualShaderNodeParameterRef *parameter_ref = Object::cast_to<VisualShaderNodeParameterRef>(vsn); |
| 3800 | if (parameter_ref && to_node != -1 && to_slot != -1) { |
| 3801 | VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot); |
| 3802 | bool success = false; |
| 3803 | |
| 3804 | for (int i = 0; i < parameter_ref->get_parameters_count(); i++) { |
| 3805 | if (parameter_ref->get_port_type_by_index(i) == input_port_type) { |
| 3806 | parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i)); |
| 3807 | success = true; |
| 3808 | break; |
| 3809 | } |
| 3810 | } |
| 3811 | if (!success) { |
| 3812 | for (int i = 0; i < parameter_ref->get_parameters_count(); i++) { |
| 3813 | if (visual_shader->is_port_types_compatible(parameter_ref->get_port_type_by_index(i), input_port_type)) { |
| 3814 | parameter_ref->set_parameter_name(parameter_ref->get_parameter_name_by_index(i)); |
| 3815 | break; |
| 3816 | } |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | vsnode = Ref<VisualShaderNode>(vsn); |
| 3822 | } else { |
| 3823 | StringName base_type; |
| 3824 | bool is_native = add_options[p_idx].is_native; |
| 3825 | |
| 3826 | if (is_native) { |
| 3827 | base_type = add_options[p_idx].type; |
| 3828 | } else { |
| 3829 | ERR_FAIL_COND(add_options[p_idx].script.is_null()); |
| 3830 | base_type = add_options[p_idx].script->get_instance_base_type(); |
| 3831 | } |
| 3832 | VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type)); |
| 3833 | ERR_FAIL_NULL(vsn); |
| 3834 | vsnode = Ref<VisualShaderNode>(vsn); |
| 3835 | if (!is_native) { |
| 3836 | vsnode->set_script(add_options[p_idx].script); |
| 3837 | } |
| 3838 | VisualShaderNodeCustom *custom_node = Object::cast_to<VisualShaderNodeCustom>(vsn); |
| 3839 | ERR_FAIL_NULL(custom_node); |
| 3840 | custom_node->update_property_default_values(); |
| 3841 | custom_node->update_input_port_default_values(); |
| 3842 | custom_node->update_properties(); |
| 3843 | } |
| 3844 | |
| 3845 | bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr); |
| 3846 | bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr); |
| 3847 | bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr); |
| 3848 | bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr); |
| 3849 | bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr); |
| 3850 | bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr); |
| 3851 | bool is_parameter = (Object::cast_to<VisualShaderNodeParameter>(vsnode.ptr()) != nullptr); |
| 3852 | bool is_mesh_emitter = (Object::cast_to<VisualShaderNodeParticleMeshEmitter>(vsnode.ptr()) != nullptr); |
| 3853 | |
| 3854 | Point2 position = graph->get_scroll_offset(); |
| 3855 | |
| 3856 | if (saved_node_pos_dirty) { |
| 3857 | position += saved_node_pos; |
| 3858 | } else { |
| 3859 | position += graph->get_size() * 0.5; |
| 3860 | position /= EDSCALE; |
| 3861 | } |
| 3862 | position /= graph->get_zoom(); |
| 3863 | position /= cached_theme_base_scale; |
| 3864 | saved_node_pos_dirty = false; |
| 3865 | |
| 3866 | int id_to_use = visual_shader->get_valid_node_id(type); |
| 3867 | |
| 3868 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 3869 | if (p_resource_path.is_empty()) { |
| 3870 | undo_redo->create_action(TTR("Add Node to Visual Shader")); |
| 3871 | } else { |
| 3872 | id_to_use += p_node_idx; |
| 3873 | } |
| 3874 | undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, vsnode, position, id_to_use); |
| 3875 | undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_to_use); |
| 3876 | undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_to_use, false, true); |
| 3877 | undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_to_use, false); |
| 3878 | |
| 3879 | VisualShaderNodeExpression *expr = Object::cast_to<VisualShaderNodeExpression>(vsnode.ptr()); |
| 3880 | if (expr) { |
| 3881 | expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE)); |
| 3882 | } |
| 3883 | |
| 3884 | Ref<VisualShaderNodeFrame> frame = vsnode; |
| 3885 | if (frame.is_valid()) { |
| 3886 | frame->set_size(Size2(320 * EDSCALE, 180 * EDSCALE)); |
| 3887 | } |
| 3888 | |
| 3889 | Ref<VisualShaderNodeReroute> reroute = vsnode; |
| 3890 | |
| 3891 | bool created_expression_port = false; |
| 3892 | |
| 3893 | // A node is inserted in an already present connection. |
| 3894 | if (from_node != -1 && from_slot != -1 && to_node != -1 && to_slot != -1) { |
| 3895 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot); |
| 3896 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot); |
| 3897 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, to_node, to_slot); |
| 3898 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, to_node, to_slot); |
| 3899 | } |
| 3900 | |
| 3901 | // Create a connection from the output port of an existing node to the new one. |
| 3902 | if (from_node != -1 && from_slot != -1) { |
| 3903 | VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot); |
| 3904 | |
| 3905 | if (expr && expr->is_editable()) { |
| 3906 | expr->add_input_port(0, output_port_type, "input0"); |
| 3907 | created_expression_port = true; |
| 3908 | } |
| 3909 | |
| 3910 | if (vsnode->get_input_port_count() > 0 || created_expression_port) { |
| 3911 | int _to_node = id_to_use; |
| 3912 | |
| 3913 | if (created_expression_port) { |
| 3914 | int _to_slot = 0; |
| 3915 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3916 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3917 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3918 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3919 | } else { |
| 3920 | int _to_slot = -1; |
| 3921 | |
| 3922 | // Attempting to connect to the default input port or to the first correct port (if it's not found). |
| 3923 | for (int i = 0; i < vsnode->get_input_port_count(); i++) { |
| 3924 | if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i)) || reroute.is_valid()) { |
| 3925 | if (i == vsnode->get_default_input_port(output_port_type)) { |
| 3926 | _to_slot = i; |
| 3927 | break; |
| 3928 | } else if (_to_slot == -1) { |
| 3929 | _to_slot = i; |
| 3930 | } |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | if (_to_slot >= 0) { |
| 3935 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3936 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3937 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3938 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot); |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) { |
| 3943 | if (is_texture2d) { |
| 3944 | undo_redo->force_fixed_history(); // vsnode is freshly created and has no path, so history can't be correctly determined. |
| 3945 | undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT); |
| 3946 | } |
| 3947 | if (is_texture3d || is_texture2d_array) { |
| 3948 | undo_redo->force_fixed_history(); |
| 3949 | undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT); |
| 3950 | } |
| 3951 | if (is_cubemap) { |
| 3952 | undo_redo->force_fixed_history(); |
| 3953 | undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT); |
| 3954 | } |
| 3955 | } |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | // Create a connection from the new node to an input port of an existing one. |
| 3960 | if (to_node != -1 && to_slot != -1) { |
| 3961 | VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot); |
| 3962 | |
| 3963 | if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) { |
| 3964 | expr->add_output_port(0, input_port_type, "output0"); |
| 3965 | String initial_expression_code; |
| 3966 | |
| 3967 | switch (input_port_type) { |
| 3968 | case VisualShaderNode::PORT_TYPE_SCALAR: |
| 3969 | initial_expression_code = "output0 = 1.0;"; |
| 3970 | break; |
| 3971 | case VisualShaderNode::PORT_TYPE_SCALAR_INT: |
| 3972 | initial_expression_code = "output0 = 1;"; |
| 3973 | break; |
| 3974 | case VisualShaderNode::PORT_TYPE_SCALAR_UINT: |
| 3975 | initial_expression_code = "output0 = 1u;"; |
| 3976 | break; |
| 3977 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: |
| 3978 | initial_expression_code = "output0 = vec2(1.0, 1.0);"; |
| 3979 | break; |
| 3980 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: |
| 3981 | initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);"; |
| 3982 | break; |
| 3983 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: |
| 3984 | initial_expression_code = "output0 = vec4(1.0, 1.0, 1.0, 1.0);"; |
| 3985 | break; |
| 3986 | case VisualShaderNode::PORT_TYPE_BOOLEAN: |
| 3987 | initial_expression_code = "output0 = true;"; |
| 3988 | break; |
| 3989 | case VisualShaderNode::PORT_TYPE_TRANSFORM: |
| 3990 | initial_expression_code = "output0 = mat4(1.0);"; |
| 3991 | break; |
| 3992 | default: |
| 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | expr->set_expression(initial_expression_code); |
| 3997 | expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE)); |
| 3998 | created_expression_port = true; |
| 3999 | } |
| 4000 | if (vsnode->get_output_port_count() > 0 || created_expression_port) { |
| 4001 | int _from_node = id_to_use; |
| 4002 | |
| 4003 | if (created_expression_port) { |
| 4004 | int _from_slot = 0; |
| 4005 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot); |
| 4006 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot); |
| 4007 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot); |
| 4008 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot); |
| 4009 | } else { |
| 4010 | // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`. |
| 4011 | VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr()); |
| 4012 | if (input) { |
| 4013 | input->set_shader_mode(visual_shader->get_mode()); |
| 4014 | input->set_shader_type(get_current_shader_type()); |
| 4015 | } |
| 4016 | |
| 4017 | // Attempting to connect to the first correct port. |
| 4018 | for (int i = 0; i < vsnode->get_output_port_count(); i++) { |
| 4019 | if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type) || reroute.is_valid()) { |
| 4020 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot); |
| 4021 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot); |
| 4022 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot); |
| 4023 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot); |
| 4024 | break; |
| 4025 | } |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | _member_cancel(); |
| 4032 | |
| 4033 | if (is_parameter) { |
| 4034 | undo_redo->add_do_method(this, "_update_parameters", true); |
| 4035 | undo_redo->add_undo_method(this, "_update_parameters", true); |
| 4036 | } |
| 4037 | |
| 4038 | if (is_curve) { |
| 4039 | callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve).call_deferred(id_to_use); |
| 4040 | } |
| 4041 | |
| 4042 | if (is_curve_xyz) { |
| 4043 | callable_mp(graph_plugin.ptr(), &VisualShaderGraphPlugin::update_curve_xyz).call_deferred(id_to_use); |
| 4044 | } |
| 4045 | |
| 4046 | if (p_resource_path.is_empty()) { |
| 4047 | undo_redo->commit_action(); |
| 4048 | } else { |
| 4049 | //post-initialization |
| 4050 | |
| 4051 | if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) { |
| 4052 | undo_redo->force_fixed_history(); |
| 4053 | undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path)); |
| 4054 | return; |
| 4055 | } |
| 4056 | |
| 4057 | if (is_cubemap) { |
| 4058 | undo_redo->force_fixed_history(); |
| 4059 | undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path)); |
| 4060 | return; |
| 4061 | } |
| 4062 | |
| 4063 | if (is_texture2d_array) { |
| 4064 | undo_redo->force_fixed_history(); |
| 4065 | undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path)); |
| 4066 | return; |
| 4067 | } |
| 4068 | |
| 4069 | if (is_mesh_emitter) { |
| 4070 | undo_redo->add_do_method(vsnode.ptr(), "set_mesh", ResourceLoader::load(p_resource_path)); |
| 4071 | return; |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | void VisualShaderEditor::_add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type) { |
| 4077 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4078 | undo_redo->create_action(vformat(TTR("Add Varying to Visual Shader: %s"), p_name)); |
| 4079 | |
| 4080 | undo_redo->add_do_method(visual_shader.ptr(), "add_varying", p_name, p_mode, p_type); |
| 4081 | undo_redo->add_undo_method(visual_shader.ptr(), "remove_varying", p_name); |
| 4082 | |
| 4083 | undo_redo->add_do_method(this, "_update_varyings"); |
| 4084 | undo_redo->add_undo_method(this, "_update_varyings"); |
| 4085 | |
| 4086 | for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) { |
| 4087 | if (p_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) { |
| 4088 | continue; |
| 4089 | } |
| 4090 | |
| 4091 | VisualShader::Type type = VisualShader::Type(i); |
| 4092 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 4093 | |
| 4094 | for (int j = 0; j < nodes.size(); j++) { |
| 4095 | int node_id = nodes[j]; |
| 4096 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); |
| 4097 | Ref<VisualShaderNodeVarying> var = vsnode; |
| 4098 | |
| 4099 | if (var.is_valid()) { |
| 4100 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id); |
| 4101 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id); |
| 4102 | } |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | undo_redo->add_do_method(this, "_update_varying_tree"); |
| 4107 | undo_redo->add_undo_method(this, "_update_varying_tree"); |
| 4108 | undo_redo->commit_action(); |
| 4109 | } |
| 4110 | |
| 4111 | void VisualShaderEditor::_remove_varying(const String &p_name) { |
| 4112 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4113 | undo_redo->create_action(vformat(TTR("Remove Varying from Visual Shader: %s"), p_name)); |
| 4114 | |
| 4115 | VisualShader::VaryingMode var_mode = visual_shader->get_varying_mode(p_name); |
| 4116 | |
| 4117 | undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", p_name); |
| 4118 | undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", p_name, var_mode, visual_shader->get_varying_type(p_name)); |
| 4119 | |
| 4120 | undo_redo->add_do_method(this, "_update_varyings"); |
| 4121 | undo_redo->add_undo_method(this, "_update_varyings"); |
| 4122 | |
| 4123 | for (int i = 0; i <= VisualShader::TYPE_LIGHT; i++) { |
| 4124 | if (var_mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT && i == 0) { |
| 4125 | continue; |
| 4126 | } |
| 4127 | |
| 4128 | VisualShader::Type type = VisualShader::Type(i); |
| 4129 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 4130 | |
| 4131 | for (int j = 0; j < nodes.size(); j++) { |
| 4132 | int node_id = nodes[j]; |
| 4133 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); |
| 4134 | Ref<VisualShaderNodeVarying> var = vsnode; |
| 4135 | |
| 4136 | if (var.is_valid()) { |
| 4137 | String var_name = var->get_varying_name(); |
| 4138 | |
| 4139 | if (var_name == p_name) { |
| 4140 | undo_redo->add_do_method(var.ptr(), "set_varying_name", "[None]"); |
| 4141 | undo_redo->add_undo_method(var.ptr(), "set_varying_name", var_name); |
| 4142 | undo_redo->add_do_method(var.ptr(), "set_varying_type", VisualShader::VARYING_TYPE_FLOAT); |
| 4143 | undo_redo->add_undo_method(var.ptr(), "set_varying_type", var->get_varying_type()); |
| 4144 | } |
| 4145 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, node_id); |
| 4146 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type, node_id); |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | List<VisualShader::Connection> node_connections; |
| 4151 | visual_shader->get_node_connections(type, &node_connections); |
| 4152 | |
| 4153 | for (VisualShader::Connection &E : node_connections) { |
| 4154 | Ref<VisualShaderNodeVaryingGetter> var_getter = Object::cast_to<VisualShaderNodeVaryingGetter>(visual_shader->get_node(type, E.from_node).ptr()); |
| 4155 | if (var_getter.is_valid() && E.from_port > 0) { |
| 4156 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4157 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4158 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4159 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4160 | } |
| 4161 | Ref<VisualShaderNodeVaryingSetter> var_setter = Object::cast_to<VisualShaderNodeVaryingSetter>(visual_shader->get_node(type, E.to_node).ptr()); |
| 4162 | if (var_setter.is_valid() && E.to_port > 0) { |
| 4163 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4164 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4165 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4166 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4167 | } |
| 4168 | } |
| 4169 | } |
| 4170 | |
| 4171 | undo_redo->add_do_method(this, "_update_varying_tree"); |
| 4172 | undo_redo->add_undo_method(this, "_update_varying_tree"); |
| 4173 | undo_redo->commit_action(); |
| 4174 | } |
| 4175 | |
| 4176 | void VisualShaderEditor::_update_varyings() { |
| 4177 | VisualShaderNodeVarying::clear_varyings(visual_shader->get_rid()); |
| 4178 | |
| 4179 | for (int i = 0; i < visual_shader->get_varyings_count(); i++) { |
| 4180 | const VisualShader::Varying *var = visual_shader->get_varying_by_index(i); |
| 4181 | |
| 4182 | if (var != nullptr) { |
| 4183 | VisualShaderNodeVarying::add_varying(visual_shader->get_rid(), var->name, var->mode, var->type); |
| 4184 | } |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) { |
| 4189 | VisualShader::Type type = get_current_shader_type(); |
| 4190 | drag_buffer.push_back({ type, p_node, p_from / cached_theme_base_scale, p_to / cached_theme_base_scale }); |
| 4191 | if (!drag_dirty) { |
| 4192 | callable_mp(this, &VisualShaderEditor::_nodes_dragged).call_deferred(); |
| 4193 | } |
| 4194 | drag_dirty = true; |
| 4195 | } |
| 4196 | |
| 4197 | void VisualShaderEditor::_nodes_dragged() { |
| 4198 | drag_dirty = false; |
| 4199 | |
| 4200 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4201 | if (frame_node_id_to_link_to == -1) { |
| 4202 | undo_redo->create_action(TTR("Move VisualShader Node(s)")); |
| 4203 | } else { |
| 4204 | undo_redo->create_action(TTR("Move and Attach VisualShader Node(s) to parent frame")); |
| 4205 | } |
| 4206 | |
| 4207 | for (const DragOp &E : drag_buffer) { |
| 4208 | undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to); |
| 4209 | undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from); |
| 4210 | undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to); |
| 4211 | undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from); |
| 4212 | } |
| 4213 | |
| 4214 | for (const int node_id : nodes_link_to_frame_buffer) { |
| 4215 | VisualShader::Type type = get_current_shader_type(); |
| 4216 | Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, node_id); |
| 4217 | |
| 4218 | undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to); |
| 4219 | undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, frame_node_id_to_link_to); |
| 4220 | undo_redo->add_undo_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id); |
| 4221 | undo_redo->add_undo_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id); |
| 4222 | } |
| 4223 | |
| 4224 | undo_redo->commit_action(); |
| 4225 | |
| 4226 | _handle_node_drop_on_connection(); |
| 4227 | |
| 4228 | drag_buffer.clear(); |
| 4229 | nodes_link_to_frame_buffer.clear(); |
| 4230 | frame_node_id_to_link_to = -1; |
| 4231 | } |
| 4232 | |
| 4233 | void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { |
| 4234 | VisualShader::Type type = get_current_shader_type(); |
| 4235 | |
| 4236 | int from = p_from.to_int(); |
| 4237 | int to = p_to.to_int(); |
| 4238 | bool swap = last_to_node != -1 && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL); |
| 4239 | |
| 4240 | if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) { |
| 4241 | return; |
| 4242 | } |
| 4243 | |
| 4244 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4245 | undo_redo->create_action(TTR("Nodes Connected")); |
| 4246 | |
| 4247 | List<VisualShader::Connection> conns; |
| 4248 | visual_shader->get_node_connections(type, &conns); |
| 4249 | |
| 4250 | for (const VisualShader::Connection &E : conns) { |
| 4251 | if (E.to_node == to && E.to_port == p_to_index) { |
| 4252 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4253 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4254 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4255 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4256 | |
| 4257 | if (swap) { |
| 4258 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port); |
| 4259 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port); |
| 4260 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port); |
| 4261 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, last_to_node, last_to_port); |
| 4262 | } |
| 4263 | break; |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); |
| 4268 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); |
| 4269 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); |
| 4270 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); |
| 4271 | |
| 4272 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, from); |
| 4273 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, from); |
| 4274 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to); |
| 4275 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to); |
| 4276 | undo_redo->commit_action(); |
| 4277 | |
| 4278 | last_to_node = -1; |
| 4279 | last_to_port = -1; |
| 4280 | } |
| 4281 | |
| 4282 | void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { |
| 4283 | graph->disconnect_node(p_from, p_from_index, p_to, p_to_index); |
| 4284 | |
| 4285 | VisualShader::Type type = get_current_shader_type(); |
| 4286 | |
| 4287 | int from = p_from.to_int(); |
| 4288 | int to = p_to.to_int(); |
| 4289 | |
| 4290 | last_to_node = to; |
| 4291 | last_to_port = p_to_index; |
| 4292 | |
| 4293 | info_label->show(); |
| 4294 | |
| 4295 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4296 | undo_redo->create_action(TTR("Nodes Disconnected")); |
| 4297 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); |
| 4298 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); |
| 4299 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); |
| 4300 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); |
| 4301 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", (int)type, to); |
| 4302 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", (int)type, to); |
| 4303 | undo_redo->commit_action(); |
| 4304 | } |
| 4305 | |
| 4306 | void VisualShaderEditor::_connection_drag_ended() { |
| 4307 | info_label->hide(); |
| 4308 | } |
| 4309 | |
| 4310 | void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) { |
| 4311 | from_node = p_from.to_int(); |
| 4312 | from_slot = p_from_slot; |
| 4313 | VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 4314 | VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 4315 | Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node); |
| 4316 | if (node.is_valid()) { |
| 4317 | output_port_type = node->get_output_port_type(from_slot); |
| 4318 | } |
| 4319 | _show_members_dialog(true, input_port_type, output_port_type); |
| 4320 | } |
| 4321 | |
| 4322 | void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) { |
| 4323 | to_node = p_to.to_int(); |
| 4324 | to_slot = p_to_slot; |
| 4325 | VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 4326 | VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 4327 | Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node); |
| 4328 | if (node.is_valid()) { |
| 4329 | input_port_type = node->get_input_port_type(to_slot); |
| 4330 | } |
| 4331 | _show_members_dialog(true, input_port_type, output_port_type); |
| 4332 | } |
| 4333 | |
| 4334 | bool VisualShaderEditor::_check_node_drop_on_connection(const Vector2 &p_position, Ref<GraphEdit::Connection> *r_closest_connection, int *r_from_port, int *r_to_port) { |
| 4335 | VisualShader::Type shader_type = get_current_shader_type(); |
| 4336 | |
| 4337 | // Get selected graph node. |
| 4338 | Ref<VisualShaderNode> selected_vsnode; |
| 4339 | int selected_node_id = -1; |
| 4340 | int selected_node_count = 0; |
| 4341 | Rect2 selected_node_rect; |
| 4342 | |
| 4343 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 4344 | GraphNode *graph_node = Object::cast_to<GraphNode>(graph->get_child(i)); |
| 4345 | if (graph_node && graph_node->is_selected()) { |
| 4346 | selected_node_id = String(graph_node->get_name()).to_int(); |
| 4347 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(shader_type, selected_node_id); |
| 4348 | if (!vsnode->is_deletable()) { |
| 4349 | continue; |
| 4350 | } |
| 4351 | |
| 4352 | selected_node_count += 1; |
| 4353 | |
| 4354 | Ref<VisualShaderNode> node = visual_shader->get_node(shader_type, selected_node_id); |
| 4355 | selected_vsnode = node; |
| 4356 | selected_node_rect = graph_node->get_rect(); |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | // Only a single node - which has both input and output ports but is not connected yet - can be inserted. |
| 4361 | if (selected_node_count != 1 || selected_vsnode.is_null()) { |
| 4362 | return false; |
| 4363 | } |
| 4364 | |
| 4365 | // Check whether the dragged node was dropped over a connection. |
| 4366 | List<Ref<GraphEdit::Connection>> intersecting_connections = graph->get_connections_intersecting_with_rect(selected_node_rect); |
| 4367 | |
| 4368 | if (intersecting_connections.is_empty()) { |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | Ref<GraphEdit::Connection> intersecting_connection = intersecting_connections.front()->get(); |
| 4373 | |
| 4374 | if (selected_vsnode->is_any_port_connected() || selected_vsnode->get_input_port_count() == 0 || selected_vsnode->get_output_port_count() == 0) { |
| 4375 | return false; |
| 4376 | } |
| 4377 | |
| 4378 | VisualShaderNode::PortType original_port_type_from = visual_shader->get_node(shader_type, String(intersecting_connection->from_node).to_int())->get_output_port_type(intersecting_connection->from_port); |
| 4379 | VisualShaderNode::PortType original_port_type_to = visual_shader->get_node(shader_type, String(intersecting_connection->to_node).to_int())->get_input_port_type(intersecting_connection->to_port); |
| 4380 | |
| 4381 | Ref<VisualShaderNodeReroute> reroute_node = selected_vsnode; |
| 4382 | |
| 4383 | // Searching for the default port or the first compatible input port of the node to insert. |
| 4384 | int _to_port = -1; |
| 4385 | for (int i = 0; i < selected_vsnode->get_input_port_count(); i++) { |
| 4386 | if (visual_shader->is_port_types_compatible(original_port_type_from, selected_vsnode->get_input_port_type(i)) || reroute_node.is_valid()) { |
| 4387 | if (i == selected_vsnode->get_default_input_port(original_port_type_from)) { |
| 4388 | _to_port = i; |
| 4389 | break; |
| 4390 | } else if (_to_port == -1) { |
| 4391 | _to_port = i; |
| 4392 | } |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | // Searching for the first compatible output port of the node to insert. |
| 4397 | int _from_port = -1; |
| 4398 | for (int i = 0; i < selected_vsnode->get_output_port_count(); i++) { |
| 4399 | if (visual_shader->is_port_types_compatible(selected_vsnode->get_output_port_type(i), original_port_type_to) || reroute_node.is_valid()) { |
| 4400 | _from_port = i; |
| 4401 | break; |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | if (_to_port == -1 || _from_port == -1) { |
| 4406 | return false; |
| 4407 | } |
| 4408 | |
| 4409 | if (r_closest_connection != nullptr) { |
| 4410 | *r_closest_connection = intersecting_connection; |
| 4411 | } |
| 4412 | if (r_from_port != nullptr) { |
| 4413 | *r_from_port = _from_port; |
| 4414 | } |
| 4415 | if (r_to_port != nullptr) { |
| 4416 | *r_to_port = _to_port; |
| 4417 | } |
| 4418 | |
| 4419 | return true; |
| 4420 | } |
| 4421 | |
| 4422 | void VisualShaderEditor::_handle_node_drop_on_connection() { |
| 4423 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4424 | undo_redo->create_action(TTR("Insert node")); |
| 4425 | |
| 4426 | // Check whether the dragged node was dropped over a connection. |
| 4427 | Ref<GraphEdit::Connection> closest_connection; |
| 4428 | int _from_port = -1; |
| 4429 | int _to_port = -1; |
| 4430 | |
| 4431 | if (!_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection, &_from_port, &_to_port)) { |
| 4432 | return; |
| 4433 | } |
| 4434 | |
| 4435 | int selected_node_id = drag_buffer.front()->get().node; |
| 4436 | VisualShader::Type shader_type = get_current_shader_type(); |
| 4437 | Ref<VisualShaderNode> selected_vsnode = visual_shader->get_node(shader_type, selected_node_id); |
| 4438 | |
| 4439 | // Delete the old connection. |
| 4440 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4441 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4442 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4443 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4444 | |
| 4445 | // Add the connection to the dropped node. |
| 4446 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port); |
| 4447 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port); |
| 4448 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port); |
| 4449 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, String(closest_connection->from_node).to_int(), closest_connection->from_port, selected_node_id, _to_port); |
| 4450 | |
| 4451 | // Add the connection from the dropped node. |
| 4452 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4453 | undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4454 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4455 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", shader_type, selected_node_id, _from_port, String(closest_connection->to_node).to_int(), closest_connection->to_port); |
| 4456 | |
| 4457 | undo_redo->commit_action(); |
| 4458 | |
| 4459 | call_deferred(SNAME("_update_graph")); |
| 4460 | } |
| 4461 | |
| 4462 | void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) { |
| 4463 | VisualShader::Type type = VisualShader::Type(p_type); |
| 4464 | List<VisualShader::Connection> conns; |
| 4465 | visual_shader->get_node_connections(type, &conns); |
| 4466 | |
| 4467 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4468 | for (const int &F : p_nodes) { |
| 4469 | for (const VisualShader::Connection &E : conns) { |
| 4470 | if (E.from_node == F || E.to_node == F) { |
| 4471 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4472 | } |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | // The VS nodes need to be added before attaching them to frames. |
| 4477 | for (const int &F : p_nodes) { |
| 4478 | Ref<VisualShaderNode> node = visual_shader->get_node(type, F); |
| 4479 | undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F); |
| 4480 | undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F, false, false); |
| 4481 | } |
| 4482 | |
| 4483 | // Update frame references. |
| 4484 | for (const int &node_id : p_nodes) { |
| 4485 | Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, node_id); |
| 4486 | if (frame.is_valid()) { |
| 4487 | for (const int &attached_node_id : frame->get_attached_nodes()) { |
| 4488 | undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, attached_node_id); |
| 4489 | undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, attached_node_id); |
| 4490 | undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, attached_node_id, node_id); |
| 4491 | undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, attached_node_id, node_id); |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | Ref<VisualShaderNode> node = visual_shader->get_node(type, node_id); |
| 4496 | if (node->get_frame() == -1) { |
| 4497 | continue; |
| 4498 | } |
| 4499 | |
| 4500 | undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", type, node_id); |
| 4501 | undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", type, node_id); |
| 4502 | undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", type, node_id, node->get_frame()); |
| 4503 | undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", type, node_id, node->get_frame()); |
| 4504 | } |
| 4505 | |
| 4506 | // Restore size of the frame nodes. |
| 4507 | for (const int &F : p_nodes) { |
| 4508 | Ref<VisualShaderNodeFrame> frame = visual_shader->get_node(type, F); |
| 4509 | if (frame.is_valid()) { |
| 4510 | undo_redo->add_undo_method(this, "_set_node_size", type, F, frame->get_size()); |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | HashSet<String> parameter_names; |
| 4515 | |
| 4516 | for (const int &F : p_nodes) { |
| 4517 | Ref<VisualShaderNode> node = visual_shader->get_node(type, F); |
| 4518 | |
| 4519 | undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F); |
| 4520 | |
| 4521 | VisualShaderNodeParameter *parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr()); |
| 4522 | if (parameter) { |
| 4523 | parameter_names.insert(parameter->get_parameter_name()); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | List<VisualShader::Connection> used_conns; |
| 4528 | for (const int &F : p_nodes) { |
| 4529 | for (const VisualShader::Connection &E : conns) { |
| 4530 | if (E.from_node == F || E.to_node == F) { |
| 4531 | bool cancel = false; |
| 4532 | for (const VisualShader::Connection &R : used_conns) { |
| 4533 | if (R.from_node == E.from_node && R.from_port == E.from_port && R.to_node == E.to_node && R.to_port == E.to_port) { |
| 4534 | cancel = true; // to avoid ERR_ALREADY_EXISTS warning |
| 4535 | break; |
| 4536 | } |
| 4537 | } |
| 4538 | if (!cancel) { |
| 4539 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4540 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 4541 | used_conns.push_back(E); |
| 4542 | } |
| 4543 | } |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | // Delete nodes from the graph. |
| 4548 | for (const int &F : p_nodes) { |
| 4549 | undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F, false); |
| 4550 | } |
| 4551 | |
| 4552 | // Update parameter refs if any parameter has been deleted. |
| 4553 | if (parameter_names.size() > 0) { |
| 4554 | undo_redo->add_do_method(this, "_update_parameters", true); |
| 4555 | undo_redo->add_undo_method(this, "_update_parameters", true); |
| 4556 | |
| 4557 | _update_parameter_refs(parameter_names); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) { |
| 4562 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4563 | undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to); |
| 4564 | undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from); |
| 4565 | } |
| 4566 | |
| 4567 | void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) { |
| 4568 | Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id); |
| 4569 | ERR_FAIL_COND(node.is_null()); |
| 4570 | ERR_FAIL_COND(!node->has_method("set_constant")); |
| 4571 | node->call("set_constant", p_var); |
| 4572 | if (p_preview_port != -1) { |
| 4573 | node->set_output_port_for_preview(p_preview_port); |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | void VisualShaderEditor::_update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port) { |
| 4578 | Ref<VisualShaderNodeParameter> parameter = visual_shader->get_node(p_type_id, p_node_id); |
| 4579 | ERR_FAIL_COND(parameter.is_null()); |
| 4580 | |
| 4581 | String valid_name = visual_shader->validate_parameter_name(parameter->get_parameter_name(), parameter); |
| 4582 | parameter->set_parameter_name(valid_name); |
| 4583 | graph_plugin->set_parameter_name(p_type_id, p_node_id, valid_name); |
| 4584 | |
| 4585 | if (parameter->has_method("set_default_value_enabled")) { |
| 4586 | parameter->call("set_default_value_enabled", true); |
| 4587 | parameter->call("set_default_value", p_var); |
| 4588 | } |
| 4589 | if (p_preview_port != -1) { |
| 4590 | parameter->set_output_port_for_preview(p_preview_port); |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) { |
| 4595 | VisualShader::Type type_id = get_current_shader_type(); |
| 4596 | |
| 4597 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4598 | if (!p_vice_versa) { |
| 4599 | undo_redo->create_action(TTR("Convert Constant Node(s) To Parameter(s)")); |
| 4600 | } else { |
| 4601 | undo_redo->create_action(TTR("Convert Parameter Node(s) To Constant(s)")); |
| 4602 | } |
| 4603 | |
| 4604 | const HashSet<int> ¤t_set = p_vice_versa ? selected_parameters : selected_constants; |
| 4605 | HashSet<String> deleted_names; |
| 4606 | |
| 4607 | for (const int &E : current_set) { |
| 4608 | int node_id = E; |
| 4609 | Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id); |
| 4610 | bool caught = false; |
| 4611 | Variant var; |
| 4612 | |
| 4613 | // float |
| 4614 | if (!p_vice_versa) { |
| 4615 | Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr()); |
| 4616 | if (float_const.is_valid()) { |
| 4617 | _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatParameter"); |
| 4618 | var = float_const->get_constant(); |
| 4619 | caught = true; |
| 4620 | } |
| 4621 | } else { |
| 4622 | Ref<VisualShaderNodeFloatParameter> float_parameter = Object::cast_to<VisualShaderNodeFloatParameter>(node.ptr()); |
| 4623 | if (float_parameter.is_valid()) { |
| 4624 | _replace_node(type_id, node_id, "VisualShaderNodeFloatParameter", "VisualShaderNodeFloatConstant"); |
| 4625 | var = float_parameter->get_default_value(); |
| 4626 | caught = true; |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | // int |
| 4631 | if (!caught) { |
| 4632 | if (!p_vice_versa) { |
| 4633 | Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr()); |
| 4634 | if (int_const.is_valid()) { |
| 4635 | _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntParameter"); |
| 4636 | var = int_const->get_constant(); |
| 4637 | caught = true; |
| 4638 | } |
| 4639 | } else { |
| 4640 | Ref<VisualShaderNodeIntParameter> int_parameter = Object::cast_to<VisualShaderNodeIntParameter>(node.ptr()); |
| 4641 | if (int_parameter.is_valid()) { |
| 4642 | _replace_node(type_id, node_id, "VisualShaderNodeIntParameter", "VisualShaderNodeIntConstant"); |
| 4643 | var = int_parameter->get_default_value(); |
| 4644 | caught = true; |
| 4645 | } |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | // boolean |
| 4650 | if (!caught) { |
| 4651 | if (!p_vice_versa) { |
| 4652 | Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr()); |
| 4653 | if (boolean_const.is_valid()) { |
| 4654 | _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanParameter"); |
| 4655 | var = boolean_const->get_constant(); |
| 4656 | caught = true; |
| 4657 | } |
| 4658 | } else { |
| 4659 | Ref<VisualShaderNodeBooleanParameter> boolean_parameter = Object::cast_to<VisualShaderNodeBooleanParameter>(node.ptr()); |
| 4660 | if (boolean_parameter.is_valid()) { |
| 4661 | _replace_node(type_id, node_id, "VisualShaderNodeBooleanParameter", "VisualShaderNodeBooleanConstant"); |
| 4662 | var = boolean_parameter->get_default_value(); |
| 4663 | caught = true; |
| 4664 | } |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | // vec2 |
| 4669 | if (!caught) { |
| 4670 | if (!p_vice_versa) { |
| 4671 | Ref<VisualShaderNodeVec2Constant> vec2_const = Object::cast_to<VisualShaderNodeVec2Constant>(node.ptr()); |
| 4672 | if (vec2_const.is_valid()) { |
| 4673 | _replace_node(type_id, node_id, "VisualShaderNodeVec2Constant", "VisualShaderNodeVec2Parameter"); |
| 4674 | var = vec2_const->get_constant(); |
| 4675 | caught = true; |
| 4676 | } |
| 4677 | } else { |
| 4678 | Ref<VisualShaderNodeVec2Parameter> vec2_parameter = Object::cast_to<VisualShaderNodeVec2Parameter>(node.ptr()); |
| 4679 | if (vec2_parameter.is_valid()) { |
| 4680 | _replace_node(type_id, node_id, "VisualShaderNodeVec2Parameter", "VisualShaderNodeVec2Constant"); |
| 4681 | var = vec2_parameter->get_default_value(); |
| 4682 | caught = true; |
| 4683 | } |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | // vec3 |
| 4688 | if (!caught) { |
| 4689 | if (!p_vice_versa) { |
| 4690 | Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr()); |
| 4691 | if (vec3_const.is_valid()) { |
| 4692 | _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Parameter"); |
| 4693 | var = vec3_const->get_constant(); |
| 4694 | caught = true; |
| 4695 | } |
| 4696 | } else { |
| 4697 | Ref<VisualShaderNodeVec3Parameter> vec3_parameter = Object::cast_to<VisualShaderNodeVec3Parameter>(node.ptr()); |
| 4698 | if (vec3_parameter.is_valid()) { |
| 4699 | _replace_node(type_id, node_id, "VisualShaderNodeVec3Parameter", "VisualShaderNodeVec3Constant"); |
| 4700 | var = vec3_parameter->get_default_value(); |
| 4701 | caught = true; |
| 4702 | } |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | // vec4 |
| 4707 | if (!caught) { |
| 4708 | if (!p_vice_versa) { |
| 4709 | Ref<VisualShaderNodeVec4Constant> vec4_const = Object::cast_to<VisualShaderNodeVec4Constant>(node.ptr()); |
| 4710 | if (vec4_const.is_valid()) { |
| 4711 | _replace_node(type_id, node_id, "VisualShaderNodeVec4Constant", "VisualShaderNodeVec4Parameter"); |
| 4712 | var = vec4_const->get_constant(); |
| 4713 | caught = true; |
| 4714 | } |
| 4715 | } else { |
| 4716 | Ref<VisualShaderNodeVec4Parameter> vec4_parameter = Object::cast_to<VisualShaderNodeVec4Parameter>(node.ptr()); |
| 4717 | if (vec4_parameter.is_valid()) { |
| 4718 | _replace_node(type_id, node_id, "VisualShaderNodeVec4Parameter", "VisualShaderNodeVec4Constant"); |
| 4719 | var = vec4_parameter->get_default_value(); |
| 4720 | caught = true; |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | // color |
| 4726 | if (!caught) { |
| 4727 | if (!p_vice_versa) { |
| 4728 | Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr()); |
| 4729 | if (color_const.is_valid()) { |
| 4730 | _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorParameter"); |
| 4731 | var = color_const->get_constant(); |
| 4732 | caught = true; |
| 4733 | } |
| 4734 | } else { |
| 4735 | Ref<VisualShaderNodeColorParameter> color_parameter = Object::cast_to<VisualShaderNodeColorParameter>(node.ptr()); |
| 4736 | if (color_parameter.is_valid()) { |
| 4737 | _replace_node(type_id, node_id, "VisualShaderNodeColorParameter", "VisualShaderNodeColorConstant"); |
| 4738 | var = color_parameter->get_default_value(); |
| 4739 | caught = true; |
| 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | // transform |
| 4745 | if (!caught) { |
| 4746 | if (!p_vice_versa) { |
| 4747 | Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr()); |
| 4748 | if (transform_const.is_valid()) { |
| 4749 | _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformParameter"); |
| 4750 | var = transform_const->get_constant(); |
| 4751 | caught = true; |
| 4752 | } |
| 4753 | } else { |
| 4754 | Ref<VisualShaderNodeTransformParameter> transform_parameter = Object::cast_to<VisualShaderNodeTransformParameter>(node.ptr()); |
| 4755 | if (transform_parameter.is_valid()) { |
| 4756 | _replace_node(type_id, node_id, "VisualShaderNodeTransformParameter", "VisualShaderNodeTransformConstant"); |
| 4757 | var = transform_parameter->get_default_value(); |
| 4758 | caught = true; |
| 4759 | } |
| 4760 | } |
| 4761 | } |
| 4762 | ERR_CONTINUE(!caught); |
| 4763 | int preview_port = node->get_output_port_for_preview(); |
| 4764 | |
| 4765 | if (!p_vice_versa) { |
| 4766 | undo_redo->add_do_method(this, "_update_parameter", type_id, node_id, var, preview_port); |
| 4767 | undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port); |
| 4768 | } else { |
| 4769 | undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port); |
| 4770 | undo_redo->add_undo_method(this, "_update_parameter", type_id, node_id, var, preview_port); |
| 4771 | |
| 4772 | Ref<VisualShaderNodeParameter> parameter = Object::cast_to<VisualShaderNodeParameter>(node.ptr()); |
| 4773 | ERR_CONTINUE(parameter.is_null()); |
| 4774 | |
| 4775 | deleted_names.insert(parameter->get_parameter_name()); |
| 4776 | } |
| 4777 | |
| 4778 | undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id); |
| 4779 | undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id); |
| 4780 | } |
| 4781 | |
| 4782 | undo_redo->add_do_method(this, "_update_parameters", true); |
| 4783 | undo_redo->add_undo_method(this, "_update_parameters", true); |
| 4784 | |
| 4785 | if (deleted_names.size() > 0) { |
| 4786 | _update_parameter_refs(deleted_names); |
| 4787 | } |
| 4788 | |
| 4789 | undo_redo->commit_action(); |
| 4790 | } |
| 4791 | |
| 4792 | void VisualShaderEditor::_detach_nodes_from_frame(int p_type, const List<int> &p_nodes) { |
| 4793 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4794 | for (int node_id : p_nodes) { |
| 4795 | Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, node_id); |
| 4796 | if (node.is_null()) { |
| 4797 | continue; |
| 4798 | } |
| 4799 | int frame_id = node->get_frame(); |
| 4800 | if (frame_id != -1) { |
| 4801 | undo_redo->add_do_method(graph_plugin.ptr(), "detach_node_from_frame", p_type, node_id); |
| 4802 | undo_redo->add_do_method(visual_shader.ptr(), "detach_node_from_frame", p_type, node_id); |
| 4803 | undo_redo->add_undo_method(visual_shader.ptr(), "attach_node_to_frame", p_type, node_id, frame_id); |
| 4804 | undo_redo->add_undo_method(graph_plugin.ptr(), "attach_node_to_frame", p_type, node_id, frame_id); |
| 4805 | } |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | void VisualShaderEditor::_detach_nodes_from_frame_request() { |
| 4810 | // Called from context menu. |
| 4811 | List<int> to_detach_node_ids; |
| 4812 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 4813 | GraphElement *gn = Object::cast_to<GraphElement>(graph->get_child(i)); |
| 4814 | if (gn) { |
| 4815 | int id = String(gn->get_name()).to_int(); |
| 4816 | if (gn->is_selected()) { |
| 4817 | to_detach_node_ids.push_back(id); |
| 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | if (to_detach_node_ids.is_empty()) { |
| 4822 | return; |
| 4823 | } |
| 4824 | |
| 4825 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4826 | undo_redo->create_action(TTR("Detach VisualShader Node(s) from Frame")); |
| 4827 | _detach_nodes_from_frame(get_current_shader_type(), to_detach_node_ids); |
| 4828 | undo_redo->commit_action(); |
| 4829 | } |
| 4830 | |
| 4831 | void VisualShaderEditor::_delete_node_request(int p_type, int p_node) { |
| 4832 | Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, p_node); |
| 4833 | if (!node->is_deletable()) { |
| 4834 | return; |
| 4835 | } |
| 4836 | |
| 4837 | List<int> to_erase; |
| 4838 | to_erase.push_back(p_node); |
| 4839 | |
| 4840 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4841 | undo_redo->create_action(TTR("Delete VisualShader Node")); |
| 4842 | _delete_nodes(p_type, to_erase); |
| 4843 | undo_redo->commit_action(); |
| 4844 | } |
| 4845 | |
| 4846 | void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) { |
| 4847 | List<int> to_erase; |
| 4848 | |
| 4849 | if (p_nodes.is_empty()) { |
| 4850 | // Called from context menu. |
| 4851 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 4852 | GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i)); |
| 4853 | if (!graph_element) { |
| 4854 | continue; |
| 4855 | } |
| 4856 | |
| 4857 | VisualShader::Type type = get_current_shader_type(); |
| 4858 | int id = String(graph_element->get_name()).to_int(); |
| 4859 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id); |
| 4860 | if (vsnode->is_deletable() && graph_element->is_selected()) { |
| 4861 | to_erase.push_back(graph_element->get_name().operator String().to_int()); |
| 4862 | } |
| 4863 | } |
| 4864 | } else { |
| 4865 | VisualShader::Type type = get_current_shader_type(); |
| 4866 | for (int i = 0; i < p_nodes.size(); i++) { |
| 4867 | int id = p_nodes[i].operator String().to_int(); |
| 4868 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id); |
| 4869 | if (vsnode->is_deletable()) { |
| 4870 | to_erase.push_back(id); |
| 4871 | } |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | if (to_erase.is_empty()) { |
| 4876 | return; |
| 4877 | } |
| 4878 | |
| 4879 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 4880 | undo_redo->create_action(TTR("Delete VisualShader Node(s)")); |
| 4881 | _delete_nodes(get_current_shader_type(), to_erase); |
| 4882 | undo_redo->commit_action(); |
| 4883 | } |
| 4884 | |
| 4885 | void VisualShaderEditor::_node_selected(Object *p_node) { |
| 4886 | VisualShader::Type type = get_current_shader_type(); |
| 4887 | |
| 4888 | GraphElement *graph_element = Object::cast_to<GraphElement>(p_node); |
| 4889 | ERR_FAIL_NULL(graph_element); |
| 4890 | |
| 4891 | int id = String(graph_element->get_name()).to_int(); |
| 4892 | |
| 4893 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id); |
| 4894 | ERR_FAIL_COND(vsnode.is_null()); |
| 4895 | } |
| 4896 | |
| 4897 | void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { |
| 4898 | Ref<InputEventMouseMotion> mm = p_event; |
| 4899 | Ref<InputEventMouseButton> mb = p_event; |
| 4900 | VisualShader::Type type = get_current_shader_type(); |
| 4901 | |
| 4902 | // Highlight valid connection on which a node can be dropped. |
| 4903 | if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) { |
| 4904 | Ref<GraphEdit::Connection> closest_connection; |
| 4905 | graph->reset_all_connection_activity(); |
| 4906 | if (_check_node_drop_on_connection(graph->get_local_mouse_position(), &closest_connection)) { |
| 4907 | graph->set_connection_activity(closest_connection->from_node, closest_connection->from_port, closest_connection->to_node, closest_connection->to_port, 1.0); |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | Ref<VisualShaderNode> selected_vsnode; |
| 4912 | // Right click actions. |
| 4913 | if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) { |
| 4914 | selected_constants.clear(); |
| 4915 | selected_parameters.clear(); |
| 4916 | selected_frame = -1; |
| 4917 | selected_float_constant = -1; |
| 4918 | |
| 4919 | List<int> selected_deletable_graph_elements; |
| 4920 | List<GraphElement *> selected_graph_elements; |
| 4921 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 4922 | GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i)); |
| 4923 | if (!graph_element) { |
| 4924 | continue; |
| 4925 | } |
| 4926 | int id = String(graph_element->get_name()).to_int(); |
| 4927 | Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, id); |
| 4928 | |
| 4929 | if (!graph_element->is_selected()) { |
| 4930 | continue; |
| 4931 | } |
| 4932 | |
| 4933 | selected_graph_elements.push_back(graph_element); |
| 4934 | |
| 4935 | if (!vsnode->is_deletable()) { |
| 4936 | continue; |
| 4937 | } |
| 4938 | |
| 4939 | selected_deletable_graph_elements.push_back(id); |
| 4940 | |
| 4941 | Ref<VisualShaderNode> node = visual_shader->get_node(type, id); |
| 4942 | selected_vsnode = node; |
| 4943 | |
| 4944 | VisualShaderNodeFrame *frame_node = Object::cast_to<VisualShaderNodeFrame>(node.ptr()); |
| 4945 | if (frame_node != nullptr) { |
| 4946 | selected_frame = id; |
| 4947 | } |
| 4948 | VisualShaderNodeConstant *constant_node = Object::cast_to<VisualShaderNodeConstant>(node.ptr()); |
| 4949 | if (constant_node != nullptr) { |
| 4950 | selected_constants.insert(id); |
| 4951 | } |
| 4952 | VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr()); |
| 4953 | if (float_constant_node != nullptr) { |
| 4954 | selected_float_constant = id; |
| 4955 | } |
| 4956 | VisualShaderNodeParameter *parameter_node = Object::cast_to<VisualShaderNodeParameter>(node.ptr()); |
| 4957 | if (parameter_node != nullptr && parameter_node->is_convertible_to_constant()) { |
| 4958 | selected_parameters.insert(id); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | if (selected_deletable_graph_elements.size() > 1) { |
| 4963 | selected_frame = -1; |
| 4964 | selected_float_constant = -1; |
| 4965 | } |
| 4966 | |
| 4967 | bool copy_buffer_empty = true; |
| 4968 | for (const CopyItem &item : copy_items_buffer) { |
| 4969 | if (!item.disabled) { |
| 4970 | copy_buffer_empty = false; |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
| 4974 | |
| 4975 | menu_point = graph->get_local_mouse_position(); |
| 4976 | Point2 gpos = get_screen_position() + get_local_mouse_position(); |
| 4977 | |
| 4978 | Ref<GraphEdit::Connection> closest_connection = graph->get_closest_connection_at_point(menu_point); |
| 4979 | if (closest_connection.is_valid()) { |
| 4980 | clicked_connection = closest_connection; |
| 4981 | saved_node_pos = graph->get_local_mouse_position(); |
| 4982 | saved_node_pos_dirty = true; |
| 4983 | connection_popup_menu->set_position(gpos); |
| 4984 | connection_popup_menu->reset_size(); |
| 4985 | connection_popup_menu->popup(); |
| 4986 | } else if (selected_graph_elements.is_empty() && copy_buffer_empty) { |
| 4987 | _show_members_dialog(true); |
| 4988 | } else { |
| 4989 | popup_menu->set_item_disabled(NodeMenuOptions::CUT, selected_deletable_graph_elements.is_empty()); |
| 4990 | popup_menu->set_item_disabled(NodeMenuOptions::COPY, selected_deletable_graph_elements.is_empty()); |
| 4991 | popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_buffer_empty); |
| 4992 | popup_menu->set_item_disabled(NodeMenuOptions::DELETE_, selected_deletable_graph_elements.is_empty()); |
| 4993 | popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, selected_deletable_graph_elements.is_empty()); |
| 4994 | popup_menu->set_item_disabled(NodeMenuOptions::CLEAR_COPY_BUFFER, copy_buffer_empty); |
| 4995 | |
| 4996 | int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2); |
| 4997 | if (temp != -1) { |
| 4998 | popup_menu->remove_item(temp); |
| 4999 | } |
| 5000 | temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS); |
| 5001 | if (temp != -1) { |
| 5002 | popup_menu->remove_item(temp); |
| 5003 | } |
| 5004 | temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS); |
| 5005 | if (temp != -1) { |
| 5006 | popup_menu->remove_item(temp); |
| 5007 | } |
| 5008 | temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS); |
| 5009 | if (temp != -1) { |
| 5010 | popup_menu->remove_item(temp); |
| 5011 | } |
| 5012 | temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR3); |
| 5013 | if (temp != -1) { |
| 5014 | popup_menu->remove_item(temp); |
| 5015 | } |
| 5016 | temp = popup_menu->get_item_index(NodeMenuOptions::UNLINK_FROM_PARENT_FRAME); |
| 5017 | if (temp != -1) { |
| 5018 | popup_menu->remove_item(temp); |
| 5019 | } |
| 5020 | temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_TITLE); |
| 5021 | if (temp != -1) { |
| 5022 | popup_menu->remove_item(temp); |
| 5023 | } |
| 5024 | temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR); |
| 5025 | if (temp != -1) { |
| 5026 | popup_menu->remove_item(temp); |
| 5027 | } |
| 5028 | temp = popup_menu->get_item_index(NodeMenuOptions::SET_FRAME_COLOR); |
| 5029 | if (temp != -1) { |
| 5030 | popup_menu->remove_item(temp); |
| 5031 | } |
| 5032 | temp = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK); |
| 5033 | if (temp != -1) { |
| 5034 | popup_menu->remove_item(temp); |
| 5035 | } |
| 5036 | |
| 5037 | if (selected_constants.size() > 0 || selected_parameters.size() > 0) { |
| 5038 | popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2); |
| 5039 | |
| 5040 | if (selected_float_constant != -1) { |
| 5041 | if (!constants_submenu) { |
| 5042 | constants_submenu = memnew(PopupMenu); |
| 5043 | |
| 5044 | for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { |
| 5045 | constants_submenu->add_item(float_constant_defs[i].name, i); |
| 5046 | } |
| 5047 | constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected)); |
| 5048 | } |
| 5049 | popup_menu->add_submenu_node_item(TTR("Float Constants"), constants_submenu, int(NodeMenuOptions::FLOAT_CONSTANTS)); |
| 5050 | } |
| 5051 | |
| 5052 | if (selected_constants.size() > 0) { |
| 5053 | popup_menu->add_item(TTR("Convert Constant(s) to Parameter(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS); |
| 5054 | } |
| 5055 | |
| 5056 | if (selected_parameters.size() > 0) { |
| 5057 | popup_menu->add_item(TTR("Convert Parameter(s) to Constant(s)"), NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS); |
| 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | // Check if any selected node is attached to a frame. |
| 5062 | bool is_attached_to_frame = false; |
| 5063 | for (GraphElement *graph_element : selected_graph_elements) { |
| 5064 | if (graph->get_element_frame(graph_element->get_name())) { |
| 5065 | is_attached_to_frame = true; |
| 5066 | break; |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | if (is_attached_to_frame) { |
| 5071 | popup_menu->add_item(TTR("Detach from Parent Frame"), NodeMenuOptions::UNLINK_FROM_PARENT_FRAME); |
| 5072 | } |
| 5073 | |
| 5074 | if (selected_frame != -1) { |
| 5075 | popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3); |
| 5076 | popup_menu->add_item(TTR("Set Frame Title"), NodeMenuOptions::SET_FRAME_TITLE); |
| 5077 | popup_menu->add_check_item(TTR("Enable Auto Shrink"), NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK); |
| 5078 | popup_menu->add_check_item(TTR("Enable Tint Color"), NodeMenuOptions::ENABLE_FRAME_COLOR); |
| 5079 | |
| 5080 | VisualShaderNodeFrame *frame_ref = Object::cast_to<VisualShaderNodeFrame>(selected_vsnode.ptr()); |
| 5081 | if (frame_ref) { |
| 5082 | int item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_COLOR); |
| 5083 | popup_menu->set_item_checked(item_index, frame_ref->is_tint_color_enabled()); |
| 5084 | if (frame_ref->is_tint_color_enabled()) { |
| 5085 | popup_menu->add_item(TTR("Set Tint Color"), NodeMenuOptions::SET_FRAME_COLOR); |
| 5086 | } |
| 5087 | |
| 5088 | item_index = popup_menu->get_item_index(NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK); |
| 5089 | popup_menu->set_item_checked(item_index, frame_ref->is_autoshrink_enabled()); |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | popup_menu->set_position(gpos); |
| 5094 | popup_menu->reset_size(); |
| 5095 | popup_menu->popup(); |
| 5096 | } |
| 5097 | } |
| 5098 | } |
| 5099 | |
| 5100 | void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) { |
| 5101 | if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) { |
| 5102 | members_input_port_type = p_input_port_type; |
| 5103 | members_output_port_type = p_output_port_type; |
| 5104 | _update_options_menu(); |
| 5105 | } |
| 5106 | |
| 5107 | if (at_mouse_pos) { |
| 5108 | saved_node_pos_dirty = true; |
| 5109 | saved_node_pos = graph->get_local_mouse_position(); |
| 5110 | |
| 5111 | Point2 gpos = get_screen_position() + get_local_mouse_position(); |
| 5112 | members_dialog->set_position(gpos); |
| 5113 | } else { |
| 5114 | saved_node_pos_dirty = false; |
| 5115 | members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); |
| 5116 | } |
| 5117 | |
| 5118 | if (members_dialog->is_visible()) { |
| 5119 | members_dialog->grab_focus(); |
| 5120 | return; |
| 5121 | } |
| 5122 | |
| 5123 | members_dialog->popup(); |
| 5124 | |
| 5125 | // Keep dialog within window bounds. |
| 5126 | Rect2 window_rect = Rect2(get_window()->get_position(), get_window()->get_size()); |
| 5127 | Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size()); |
| 5128 | Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0); |
| 5129 | members_dialog->set_position(members_dialog->get_position() - difference); |
| 5130 | |
| 5131 | node_filter->grab_focus(); |
| 5132 | node_filter->select_all(); |
| 5133 | } |
| 5134 | |
| 5135 | void VisualShaderEditor::_varying_menu_id_pressed(int p_idx) { |
| 5136 | switch (VaryingMenuOptions(p_idx)) { |
| 5137 | case VaryingMenuOptions::ADD: { |
| 5138 | _show_add_varying_dialog(); |
| 5139 | } break; |
| 5140 | case VaryingMenuOptions::REMOVE: { |
| 5141 | _show_remove_varying_dialog(); |
| 5142 | } break; |
| 5143 | default: |
| 5144 | break; |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | void VisualShaderEditor::_show_add_varying_dialog() { |
| 5149 | _varying_name_changed(varying_name->get_text()); |
| 5150 | |
| 5151 | add_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); |
| 5152 | add_varying_dialog->popup(); |
| 5153 | |
| 5154 | varying_name->grab_focus(); |
| 5155 | |
| 5156 | // Keep dialog within window bounds. |
| 5157 | Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size()); |
| 5158 | Rect2 dialog_rect = Rect2(add_varying_dialog->get_position(), add_varying_dialog->get_size()); |
| 5159 | Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0); |
| 5160 | add_varying_dialog->set_position(add_varying_dialog->get_position() - difference); |
| 5161 | } |
| 5162 | |
| 5163 | void VisualShaderEditor::_show_remove_varying_dialog() { |
| 5164 | remove_varying_dialog->set_position(graph->get_screen_position() + varying_button->get_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); |
| 5165 | remove_varying_dialog->popup(); |
| 5166 | |
| 5167 | varyings->grab_focus(); |
| 5168 | |
| 5169 | // Keep dialog within window bounds. |
| 5170 | Rect2 window_rect = Rect2(DisplayServer::get_singleton()->window_get_position(), DisplayServer::get_singleton()->window_get_size()); |
| 5171 | Rect2 dialog_rect = Rect2(remove_varying_dialog->get_position(), remove_varying_dialog->get_size()); |
| 5172 | Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0); |
| 5173 | remove_varying_dialog->set_position(remove_varying_dialog->get_position() - difference); |
| 5174 | } |
| 5175 | |
| 5176 | void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_event) { |
| 5177 | // Redirect navigational key events to the tree. |
| 5178 | Ref<InputEventKey> key = p_event; |
| 5179 | if (key.is_valid()) { |
| 5180 | if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) { |
| 5181 | members->gui_input(key); |
| 5182 | node_filter->accept_event(); |
| 5183 | } |
| 5184 | } |
| 5185 | } |
| 5186 | |
| 5187 | void VisualShaderEditor::_param_filter_changed(const String &p_text) { |
| 5188 | param_filter_name = p_text; |
| 5189 | |
| 5190 | if (!_update_preview_parameter_tree()) { |
| 5191 | _clear_preview_param(); |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | void VisualShaderEditor::_param_property_changed(const String &p_property, const Variant &p_value, const String &p_field, bool p_changing) { |
| 5196 | if (p_changing) { |
| 5197 | return; |
| 5198 | } |
| 5199 | String raw_prop_name = p_property.trim_prefix("shader_parameter/"); |
| 5200 | |
| 5201 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 5202 | |
| 5203 | undo_redo->create_action(vformat(TTR("Edit Preview Parameter: %s"), p_property)); |
| 5204 | undo_redo->add_do_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, p_value); |
| 5205 | undo_redo->add_undo_method(visual_shader.ptr(), "_set_preview_shader_parameter", raw_prop_name, preview_material->get(p_property)); |
| 5206 | undo_redo->add_do_method(this, "_update_current_param"); |
| 5207 | undo_redo->add_undo_method(this, "_update_current_param"); |
| 5208 | undo_redo->commit_action(); |
| 5209 | } |
| 5210 | |
| 5211 | void VisualShaderEditor::_update_current_param() { |
| 5212 | if (current_prop != nullptr) { |
| 5213 | String name = current_prop->get_meta("id"); |
| 5214 | if (visual_shader->_has_preview_shader_parameter(name)) { |
| 5215 | preview_material->set("shader_parameter/" + name, visual_shader->_get_preview_shader_parameter(name)); |
| 5216 | } else { |
| 5217 | preview_material->set("shader_parameter/" + name, Variant()); |
| 5218 | } |
| 5219 | current_prop->update_property(); |
| 5220 | current_prop->update_editor_property_status(); |
| 5221 | current_prop->update_cache(); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | void VisualShaderEditor::_param_selected() { |
| 5226 | _clear_preview_param(); |
| 5227 | |
| 5228 | TreeItem *item = parameters->get_selected(); |
| 5229 | selected_param_id = item->get_meta("id"); |
| 5230 | |
| 5231 | PropertyInfo pi = parameter_props.get(selected_param_id); |
| 5232 | EditorProperty *prop = EditorInspector::instantiate_property_editor(preview_material.ptr(), pi.type, pi.name, pi.hint, pi.hint_string, pi.usage); |
| 5233 | if (!prop) { |
| 5234 | return; |
| 5235 | } |
| 5236 | prop->connect("property_changed", callable_mp(this, &VisualShaderEditor::_param_property_changed)); |
| 5237 | prop->set_h_size_flags(SIZE_EXPAND_FILL); |
| 5238 | prop->set_object_and_property(preview_material.ptr(), "shader_parameter/" + pi.name); |
| 5239 | |
| 5240 | prop->set_label(TTR("Value:")); |
| 5241 | prop->update_property(); |
| 5242 | prop->update_editor_property_status(); |
| 5243 | prop->update_cache(); |
| 5244 | |
| 5245 | current_prop = prop; |
| 5246 | current_prop->set_meta("id", selected_param_id); |
| 5247 | |
| 5248 | param_vbox2->add_child(prop); |
| 5249 | param_vbox->show(); |
| 5250 | } |
| 5251 | |
| 5252 | void VisualShaderEditor::_param_unselected() { |
| 5253 | parameters->deselect_all(); |
| 5254 | |
| 5255 | _clear_preview_param(); |
| 5256 | } |
| 5257 | |
| 5258 | void VisualShaderEditor::_help_open() { |
| 5259 | OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/visual_shaders.html", GODOT_VERSION_DOCS_URL)); |
| 5260 | } |
| 5261 | |
| 5262 | void VisualShaderEditor::_notification(int p_what) { |
| 5263 | switch (p_what) { |
| 5264 | case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { |
| 5265 | if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) { |
| 5266 | graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); |
| 5267 | graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning")); |
| 5268 | } |
| 5269 | if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/visual_editors")) { |
| 5270 | graph->set_minimap_opacity(EDITOR_GET("editors/visual_editors/minimap_opacity")); |
| 5271 | graph->set_grid_pattern((GraphEdit::GridPattern) int(EDITOR_GET("editors/visual_editors/grid_pattern"))); |
| 5272 | graph->set_connection_lines_curvature(EDITOR_GET("editors/visual_editors/lines_curvature")); |
| 5273 | |
| 5274 | _update_graph(); |
| 5275 | } |
| 5276 | } break; |
| 5277 | |
| 5278 | case NOTIFICATION_ENTER_TREE: { |
| 5279 | node_filter->set_clear_button_enabled(true); |
| 5280 | |
| 5281 | // collapse tree by default |
| 5282 | |
| 5283 | TreeItem *category = members->get_root()->get_first_child(); |
| 5284 | while (category) { |
| 5285 | category->set_collapsed(true); |
| 5286 | TreeItem *sub_category = category->get_first_child(); |
| 5287 | while (sub_category) { |
| 5288 | sub_category->set_collapsed(true); |
| 5289 | sub_category = sub_category->get_next(); |
| 5290 | } |
| 5291 | category = category->get_next(); |
| 5292 | } |
| 5293 | |
| 5294 | graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); |
| 5295 | graph->set_warped_panning(EDITOR_GET("editors/panning/warped_mouse_panning")); |
| 5296 | } break; |
| 5297 | |
| 5298 | case NOTIFICATION_THEME_CHANGED: { |
| 5299 | site_search->set_button_icon(get_editor_theme_icon(SNAME("ExternalLink"))); |
| 5300 | highend_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor))); |
| 5301 | |
| 5302 | param_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search"))); |
| 5303 | node_filter->set_right_icon(Control::get_editor_theme_icon(SNAME("Search"))); |
| 5304 | |
| 5305 | code_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("Shader"))); |
| 5306 | shader_preview_button->set_button_icon(Control::get_editor_theme_icon(SNAME("SubViewport"))); |
| 5307 | |
| 5308 | { |
| 5309 | Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color"); |
| 5310 | Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); |
| 5311 | Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); |
| 5312 | Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); |
| 5313 | Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color"); |
| 5314 | Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color"); |
| 5315 | Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color"); |
| 5316 | Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); |
| 5317 | Color error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor)); |
| 5318 | |
| 5319 | varying_error_label->add_theme_color_override(SceneStringName(font_color), error_color); |
| 5320 | |
| 5321 | for (const String &E : keyword_list) { |
| 5322 | if (ShaderLanguage::is_control_flow_keyword(E)) { |
| 5323 | syntax_highlighter->add_keyword_color(E, control_flow_keyword_color); |
| 5324 | } else { |
| 5325 | syntax_highlighter->add_keyword_color(E, keyword_color); |
| 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | preview_text->begin_bulk_theme_override(); |
| 5330 | preview_text->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("expression"), EditorStringName(EditorFonts))); |
| 5331 | preview_text->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("expression_size"), EditorStringName(EditorFonts))); |
| 5332 | preview_text->add_theme_color_override(SceneStringName(font_color), text_color); |
| 5333 | preview_text->end_bulk_theme_override(); |
| 5334 | |
| 5335 | syntax_highlighter->set_number_color(number_color); |
| 5336 | syntax_highlighter->set_symbol_color(symbol_color); |
| 5337 | syntax_highlighter->set_function_color(function_color); |
| 5338 | syntax_highlighter->set_member_variable_color(members_color); |
| 5339 | syntax_highlighter->clear_color_regions(); |
| 5340 | syntax_highlighter->add_color_region("/*", "*/", comment_color, false); |
| 5341 | syntax_highlighter->add_color_region("//", "", comment_color, true); |
| 5342 | |
| 5343 | preview_text->clear_comment_delimiters(); |
| 5344 | preview_text->add_comment_delimiter("/*", "*/", false); |
| 5345 | preview_text->add_comment_delimiter("//", "", true); |
| 5346 | |
| 5347 | error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Panel"))); |
| 5348 | error_label->begin_bulk_theme_override(); |
| 5349 | error_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts))); |
| 5350 | error_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts))); |
| 5351 | error_label->add_theme_color_override(SceneStringName(font_color), error_color); |
| 5352 | error_label->end_bulk_theme_override(); |
| 5353 | } |
| 5354 | |
| 5355 | tools->set_button_icon(get_editor_theme_icon(SNAME("Tools"))); |
| 5356 | preview_tools->set_button_icon(get_editor_theme_icon(SNAME("Tools"))); |
| 5357 | |
| 5358 | cached_theme_base_scale = get_theme_default_base_scale(); |
| 5359 | |
| 5360 | if (is_visible_in_tree()) { |
| 5361 | _update_graph(); |
| 5362 | } else { |
| 5363 | theme_dirty = true; |
| 5364 | } |
| 5365 | update_toggle_files_button(); |
| 5366 | _update_options_menu(); |
| 5367 | } break; |
| 5368 | |
| 5369 | case NOTIFICATION_VISIBILITY_CHANGED: { |
| 5370 | update_toggle_files_button(); |
| 5371 | if (theme_dirty && is_visible_in_tree()) { |
| 5372 | theme_dirty = false; |
| 5373 | _update_graph(); |
| 5374 | } |
| 5375 | } break; |
| 5376 | |
| 5377 | case NOTIFICATION_DRAG_BEGIN: { |
| 5378 | Dictionary dd = get_viewport()->gui_get_drag_data(); |
| 5379 | if (members->is_visible_in_tree() && dd.has("id")) { |
| 5380 | members->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); |
| 5381 | } |
| 5382 | } break; |
| 5383 | |
| 5384 | case NOTIFICATION_DRAG_END: { |
| 5385 | members->set_drop_mode_flags(0); |
| 5386 | } break; |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | void VisualShaderEditor::_scroll_offset_changed(const Vector2 &p_scroll) { |
| 5391 | if (!shader_fully_loaded) { |
| 5392 | return; |
| 5393 | } |
| 5394 | |
| 5395 | panning_debounce_timer->start(); |
| 5396 | } |
| 5397 | |
| 5398 | void VisualShaderEditor::_node_changed(int p_id) { |
| 5399 | if (is_visible_in_tree()) { |
| 5400 | _update_graph(); |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | void VisualShaderEditor::_nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame) { |
| 5405 | Vector<int> node_ids; |
| 5406 | for (int i = 0; i < p_nodes.size(); i++) { |
| 5407 | node_ids.push_back(p_nodes[i].operator String().to_int()); |
| 5408 | } |
| 5409 | frame_node_id_to_link_to = p_frame.operator String().to_int(); |
| 5410 | nodes_link_to_frame_buffer = node_ids; |
| 5411 | } |
| 5412 | |
| 5413 | void VisualShaderEditor::_frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect) { |
| 5414 | if (p_frame == nullptr) { |
| 5415 | return; |
| 5416 | } |
| 5417 | |
| 5418 | int node_id = String(p_frame->get_name()).to_int(); |
| 5419 | Ref<VisualShaderNodeResizableBase> vsnode = visual_shader->get_node(get_current_shader_type(), node_id); |
| 5420 | if (vsnode.is_null()) { |
| 5421 | return; |
| 5422 | } |
| 5423 | vsnode->set_size(p_new_rect.size / graph->get_zoom()); |
| 5424 | } |
| 5425 | |
| 5426 | void VisualShaderEditor::_dup_copy_nodes(int p_type, List<CopyItem> &r_items, List<VisualShader::Connection> &r_connections) { |
| 5427 | VisualShader::Type type = (VisualShader::Type)p_type; |
| 5428 | |
| 5429 | selection_center.x = 0.0f; |
| 5430 | selection_center.y = 0.0f; |
| 5431 | |
| 5432 | HashSet<int> nodes; |
| 5433 | |
| 5434 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 5435 | GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i)); |
| 5436 | if (graph_element) { |
| 5437 | int id = String(graph_element->get_name()).to_int(); |
| 5438 | |
| 5439 | Ref<VisualShaderNode> node = visual_shader->get_node(type, id); |
| 5440 | Ref<VisualShaderNodeOutput> output = node; |
| 5441 | if (output.is_valid()) { // can't duplicate output |
| 5442 | continue; |
| 5443 | } |
| 5444 | |
| 5445 | if (node.is_valid() && graph_element->is_selected()) { |
| 5446 | Vector2 pos = visual_shader->get_node_position(type, id); |
| 5447 | selection_center += pos; |
| 5448 | |
| 5449 | CopyItem item; |
| 5450 | item.id = id; |
| 5451 | item.node = visual_shader->get_node(type, id)->duplicate(); |
| 5452 | item.position = visual_shader->get_node_position(type, id); |
| 5453 | |
| 5454 | Ref<VisualShaderNodeResizableBase> resizable_base = node; |
| 5455 | if (resizable_base.is_valid()) { |
| 5456 | item.size = resizable_base->get_size(); |
| 5457 | } |
| 5458 | |
| 5459 | Ref<VisualShaderNodeGroupBase> group = node; |
| 5460 | if (group.is_valid()) { |
| 5461 | item.group_inputs = group->get_inputs(); |
| 5462 | item.group_outputs = group->get_outputs(); |
| 5463 | } |
| 5464 | |
| 5465 | Ref<VisualShaderNodeExpression> expression = node; |
| 5466 | if (expression.is_valid()) { |
| 5467 | item.expression = expression->get_expression(); |
| 5468 | } |
| 5469 | |
| 5470 | r_items.push_back(item); |
| 5471 | |
| 5472 | nodes.insert(id); |
| 5473 | } |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | List<VisualShader::Connection> node_connections; |
| 5478 | visual_shader->get_node_connections(type, &node_connections); |
| 5479 | |
| 5480 | for (const VisualShader::Connection &E : node_connections) { |
| 5481 | if (nodes.has(E.from_node) && nodes.has(E.to_node)) { |
| 5482 | r_connections.push_back(E); |
| 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | selection_center /= (float)r_items.size(); |
| 5487 | } |
| 5488 | |
| 5489 | void VisualShaderEditor::_dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate) { |
| 5490 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 5491 | if (p_duplicate) { |
| 5492 | undo_redo->create_action(TTR("Duplicate VisualShader Node(s)")); |
| 5493 | } else { |
| 5494 | bool copy_buffer_empty = true; |
| 5495 | for (const CopyItem &item : copy_items_buffer) { |
| 5496 | if (!item.disabled) { |
| 5497 | copy_buffer_empty = false; |
| 5498 | break; |
| 5499 | } |
| 5500 | } |
| 5501 | if (copy_buffer_empty) { |
| 5502 | return; |
| 5503 | } |
| 5504 | |
| 5505 | undo_redo->create_action(TTR("Paste VisualShader Node(s)")); |
| 5506 | } |
| 5507 | |
| 5508 | VisualShader::Type type = (VisualShader::Type)p_type; |
| 5509 | |
| 5510 | int base_id = visual_shader->get_valid_node_id(type); |
| 5511 | int id_from = base_id; |
| 5512 | HashMap<int, int> connection_remap; // Used for connections and frame attachments. |
| 5513 | HashSet<int> unsupported_set; |
| 5514 | HashSet<int> added_set; |
| 5515 | |
| 5516 | for (CopyItem &item : r_items) { |
| 5517 | if (item.disabled) { |
| 5518 | unsupported_set.insert(item.id); |
| 5519 | continue; |
| 5520 | } |
| 5521 | connection_remap[item.id] = id_from; |
| 5522 | Ref<VisualShaderNode> node = item.node->duplicate(); |
| 5523 | node->set_frame(-1); // Do not reattach nodes to frame (for now). |
| 5524 | |
| 5525 | Ref<VisualShaderNodeResizableBase> resizable_base = Object::cast_to<VisualShaderNodeResizableBase>(node.ptr()); |
| 5526 | if (resizable_base.is_valid()) { |
| 5527 | undo_redo->add_do_method(node.ptr(), "set_size", item.size); |
| 5528 | } |
| 5529 | |
| 5530 | Ref<VisualShaderNodeFrame> frame = Object::cast_to<VisualShaderNodeFrame>(node.ptr()); |
| 5531 | if (frame.is_valid()) { |
| 5532 | // Do not reattach nodes to frame (for now). |
| 5533 | undo_redo->add_do_method(node.ptr(), "set_attached_nodes", PackedInt32Array()); |
| 5534 | } |
| 5535 | |
| 5536 | Ref<VisualShaderNodeGroupBase> group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr()); |
| 5537 | if (group.is_valid()) { |
| 5538 | undo_redo->add_do_method(node.ptr(), "set_inputs", item.group_inputs); |
| 5539 | undo_redo->add_do_method(node.ptr(), "set_outputs", item.group_outputs); |
| 5540 | } |
| 5541 | |
| 5542 | Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr()); |
| 5543 | if (expression.is_valid()) { |
| 5544 | undo_redo->add_do_method(node.ptr(), "set_expression", item.expression); |
| 5545 | } |
| 5546 | |
| 5547 | undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, node, item.position + p_offset, id_from); |
| 5548 | undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from, false, false); |
| 5549 | |
| 5550 | added_set.insert(id_from); |
| 5551 | id_from++; |
| 5552 | } |
| 5553 | |
| 5554 | // Attach nodes to frame. |
| 5555 | for (const CopyItem &item : r_items) { |
| 5556 | Ref<VisualShaderNode> node = item.node; |
| 5557 | if (node->get_frame() == -1) { |
| 5558 | continue; |
| 5559 | } |
| 5560 | |
| 5561 | int new_node_id = connection_remap[item.id]; |
| 5562 | int new_frame_id = node->get_frame(); |
| 5563 | |
| 5564 | if (connection_remap.has(new_frame_id)) { |
| 5565 | new_frame_id = connection_remap[new_frame_id]; |
| 5566 | } |
| 5567 | |
| 5568 | undo_redo->add_do_method(visual_shader.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id); |
| 5569 | undo_redo->add_do_method(graph_plugin.ptr(), "attach_node_to_frame", type, new_node_id, new_frame_id); |
| 5570 | } |
| 5571 | |
| 5572 | // Connect nodes. |
| 5573 | for (const VisualShader::Connection &E : p_connections) { |
| 5574 | if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) { |
| 5575 | continue; |
| 5576 | } |
| 5577 | |
| 5578 | undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); |
| 5579 | undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); |
| 5580 | undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); |
| 5581 | } |
| 5582 | |
| 5583 | id_from = base_id; |
| 5584 | for (const CopyItem &item : r_items) { |
| 5585 | if (item.disabled) { |
| 5586 | continue; |
| 5587 | } |
| 5588 | undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from); |
| 5589 | undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from, false); |
| 5590 | id_from++; |
| 5591 | } |
| 5592 | |
| 5593 | undo_redo->commit_action(); |
| 5594 | |
| 5595 | // Reselect nodes by excluding the other ones. |
| 5596 | for (int i = 0; i < graph->get_child_count(); i++) { |
| 5597 | GraphElement *graph_element = Object::cast_to<GraphElement>(graph->get_child(i)); |
| 5598 | if (graph_element) { |
| 5599 | int id = String(graph_element->get_name()).to_int(); |
| 5600 | if (added_set.has(id)) { |
| 5601 | graph_element->set_selected(true); |
| 5602 | } else { |
| 5603 | graph_element->set_selected(false); |
| 5604 | } |
| 5605 | } |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | void VisualShaderEditor::_clear_copy_buffer() { |
| 5610 | copy_items_buffer.clear(); |
| 5611 | copy_connections_buffer.clear(); |
| 5612 | } |
| 5613 | |
| 5614 | void VisualShaderEditor::_duplicate_nodes() { |
| 5615 | int type = get_current_shader_type(); |
| 5616 | |
| 5617 | List<CopyItem> items; |
| 5618 | List<VisualShader::Connection> node_connections; |
| 5619 | |
| 5620 | _dup_copy_nodes(type, items, node_connections); |
| 5621 | |
| 5622 | if (items.is_empty()) { |
| 5623 | return; |
| 5624 | } |
| 5625 | |
| 5626 | _dup_paste_nodes(type, items, node_connections, Vector2(10, 10) * EDSCALE, true); |
| 5627 | } |
| 5628 | |
| 5629 | void VisualShaderEditor::_copy_nodes(bool p_cut) { |
| 5630 | _clear_copy_buffer(); |
| 5631 | |
| 5632 | _dup_copy_nodes(get_current_shader_type(), copy_items_buffer, copy_connections_buffer); |
| 5633 | |
| 5634 | if (p_cut) { |
| 5635 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 5636 | undo_redo->create_action(TTR("Cut VisualShader Node(s)")); |
| 5637 | |
| 5638 | List<int> ids; |
| 5639 | for (const CopyItem &E : copy_items_buffer) { |
| 5640 | ids.push_back(E.id); |
| 5641 | } |
| 5642 | |
| 5643 | _delete_nodes(get_current_shader_type(), ids); |
| 5644 | |
| 5645 | undo_redo->commit_action(); |
| 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) { |
| 5650 | if (copy_items_buffer.is_empty()) { |
| 5651 | return; |
| 5652 | } |
| 5653 | |
| 5654 | int type = get_current_shader_type(); |
| 5655 | |
| 5656 | float scale = graph->get_zoom(); |
| 5657 | |
| 5658 | Vector2 mpos; |
| 5659 | if (p_use_custom_position) { |
| 5660 | mpos = p_custom_position; |
| 5661 | } else { |
| 5662 | mpos = graph->get_local_mouse_position(); |
| 5663 | } |
| 5664 | |
| 5665 | _dup_paste_nodes(type, copy_items_buffer, copy_connections_buffer, graph->get_scroll_offset() / scale + mpos / scale - selection_center, false); |
| 5666 | } |
| 5667 | |
| 5668 | void VisualShaderEditor::_type_selected(int p_id) { |
| 5669 | int offset = VisualShader::TYPE_VERTEX; |
| 5670 | if (mode & MODE_FLAGS_PARTICLES) { |
| 5671 | offset = VisualShader::TYPE_START; |
| 5672 | if (p_id + offset > VisualShader::TYPE_PROCESS) { |
| 5673 | custom_mode_box->set_visible(false); |
| 5674 | custom_mode_enabled = false; |
| 5675 | } else { |
| 5676 | custom_mode_box->set_visible(true); |
| 5677 | if (custom_mode_box->is_pressed()) { |
| 5678 | custom_mode_enabled = true; |
| 5679 | offset += 3; |
| 5680 | } |
| 5681 | } |
| 5682 | } else if (mode & MODE_FLAGS_SKY) { |
| 5683 | offset = VisualShader::TYPE_SKY; |
| 5684 | } else if (mode & MODE_FLAGS_FOG) { |
| 5685 | offset = VisualShader::TYPE_FOG; |
| 5686 | } |
| 5687 | |
| 5688 | set_current_shader_type(VisualShader::Type(p_id + offset)); |
| 5689 | _update_nodes(); |
| 5690 | _update_graph(); |
| 5691 | |
| 5692 | graph->grab_focus(true); |
| 5693 | } |
| 5694 | |
| 5695 | void VisualShaderEditor::_custom_mode_toggled(bool p_enabled) { |
| 5696 | if (!(mode & MODE_FLAGS_PARTICLES)) { |
| 5697 | return; |
| 5698 | } |
| 5699 | custom_mode_enabled = p_enabled; |
| 5700 | int id = edit_type->get_selected() + 3; |
| 5701 | if (p_enabled) { |
| 5702 | set_current_shader_type(VisualShader::Type(id + 3)); |
| 5703 | } else { |
| 5704 | set_current_shader_type(VisualShader::Type(id)); |
| 5705 | } |
| 5706 | _update_options_menu(); |
| 5707 | _update_graph(); |
| 5708 | } |
| 5709 | |
| 5710 | void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name) { |
| 5711 | String prev_name = p_input->get_input_name(); |
| 5712 | |
| 5713 | if (p_name == prev_name) { |
| 5714 | return; |
| 5715 | } |
| 5716 | |
| 5717 | VisualShaderNode::PortType next_input_type = p_input->get_input_type_by_name(p_name); |
| 5718 | VisualShaderNode::PortType prev_input_type = p_input->get_input_type_by_name(prev_name); |
| 5719 | |
| 5720 | bool type_changed = next_input_type != prev_input_type; |
| 5721 | |
| 5722 | EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton(); |
| 5723 | undo_redo_man->create_action(TTR("Visual Shader Input Type Changed")); |
| 5724 | |
| 5725 | undo_redo_man->add_do_method(p_input.ptr(), "set_input_name", p_name); |
| 5726 | undo_redo_man->add_undo_method(p_input.ptr(), "set_input_name", prev_name); |
| 5727 | |
| 5728 | if (type_changed) { |
| 5729 | for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) { |
| 5730 | VisualShader::Type type = VisualShader::Type(type_id); |
| 5731 | |
| 5732 | int id = visual_shader->find_node_id(type, p_input); |
| 5733 | if (id != VisualShader::NODE_ID_INVALID) { |
| 5734 | bool is_expanded = p_input->is_output_port_expandable(0) && p_input->_is_output_port_expanded(0); |
| 5735 | |
| 5736 | int type_size = 0; |
| 5737 | if (is_expanded) { |
| 5738 | switch (next_input_type) { |
| 5739 | case VisualShaderNode::PORT_TYPE_VECTOR_2D: { |
| 5740 | type_size = 2; |
| 5741 | } break; |
| 5742 | case VisualShaderNode::PORT_TYPE_VECTOR_3D: { |
| 5743 | type_size = 3; |
| 5744 | } break; |
| 5745 | case VisualShaderNode::PORT_TYPE_VECTOR_4D: { |
| 5746 | type_size = 4; |
| 5747 | } break; |
| 5748 | default: |
| 5749 | break; |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | List<VisualShader::Connection> conns; |
| 5754 | visual_shader->get_node_connections(type, &conns); |
| 5755 | for (const VisualShader::Connection &E : conns) { |
| 5756 | int cn_from_node = E.from_node; |
| 5757 | int cn_from_port = E.from_port; |
| 5758 | int cn_to_node = E.to_node; |
| 5759 | int cn_to_port = E.to_port; |
| 5760 | |
| 5761 | if (cn_from_node == id) { |
| 5762 | bool is_incompatible_types = !visual_shader->is_port_types_compatible(p_input->get_input_type_by_name(p_name), visual_shader->get_node(type, cn_to_node)->get_input_port_type(cn_to_port)); |
| 5763 | |
| 5764 | if (is_incompatible_types || cn_from_port > type_size) { |
| 5765 | undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 5766 | undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 5767 | undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 5768 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, cn_from_node, cn_from_port, cn_to_node, cn_to_port); |
| 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5774 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | undo_redo_man->commit_action(); |
| 5780 | } |
| 5781 | |
| 5782 | void VisualShaderEditor::_parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name) { |
| 5783 | String prev_name = p_parameter_ref->get_parameter_name(); |
| 5784 | |
| 5785 | if (p_name == prev_name) { |
| 5786 | return; |
| 5787 | } |
| 5788 | |
| 5789 | bool type_changed = p_parameter_ref->get_parameter_type_by_name(p_name) != p_parameter_ref->get_parameter_type_by_name(prev_name); |
| 5790 | |
| 5791 | EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton(); |
| 5792 | undo_redo_man->create_action(TTR("ParameterRef Name Changed")); |
| 5793 | |
| 5794 | undo_redo_man->add_do_method(p_parameter_ref.ptr(), "set_parameter_name", p_name); |
| 5795 | undo_redo_man->add_undo_method(p_parameter_ref.ptr(), "set_parameter_name", prev_name); |
| 5796 | |
| 5797 | // update output port |
| 5798 | for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) { |
| 5799 | VisualShader::Type type = VisualShader::Type(type_id); |
| 5800 | int id = visual_shader->find_node_id(type, p_parameter_ref); |
| 5801 | if (id != VisualShader::NODE_ID_INVALID) { |
| 5802 | if (type_changed) { |
| 5803 | List<VisualShader::Connection> conns; |
| 5804 | visual_shader->get_node_connections(type, &conns); |
| 5805 | for (const VisualShader::Connection &E : conns) { |
| 5806 | if (E.from_node == id) { |
| 5807 | if (visual_shader->is_port_types_compatible(p_parameter_ref->get_parameter_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) { |
| 5808 | continue; |
| 5809 | } |
| 5810 | undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5811 | undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5812 | undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5813 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5818 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5819 | break; |
| 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | undo_redo_man->commit_action(); |
| 5824 | } |
| 5825 | |
| 5826 | void VisualShaderEditor::_varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name) { |
| 5827 | String prev_name = p_varying->get_varying_name(); |
| 5828 | |
| 5829 | if (p_name == prev_name) { |
| 5830 | return; |
| 5831 | } |
| 5832 | |
| 5833 | bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid(); |
| 5834 | |
| 5835 | EditorUndoRedoManager *undo_redo_man = EditorUndoRedoManager::get_singleton(); |
| 5836 | undo_redo_man->create_action(TTR("Varying Name Changed")); |
| 5837 | |
| 5838 | undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_name", p_name); |
| 5839 | undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_name", prev_name); |
| 5840 | |
| 5841 | VisualShader::VaryingType vtype = p_varying->get_varying_type_by_name(p_name); |
| 5842 | VisualShader::VaryingType prev_vtype = p_varying->get_varying_type_by_name(prev_name); |
| 5843 | |
| 5844 | bool type_changed = vtype != prev_vtype; |
| 5845 | |
| 5846 | if (type_changed) { |
| 5847 | undo_redo_man->add_do_method(p_varying.ptr(), "set_varying_type", vtype); |
| 5848 | undo_redo_man->add_undo_method(p_varying.ptr(), "set_varying_type", prev_vtype); |
| 5849 | } |
| 5850 | |
| 5851 | // update ports |
| 5852 | for (int type_id = 0; type_id < VisualShader::TYPE_MAX; type_id++) { |
| 5853 | VisualShader::Type type = VisualShader::Type(type_id); |
| 5854 | int id = visual_shader->find_node_id(type, p_varying); |
| 5855 | |
| 5856 | if (id != VisualShader::NODE_ID_INVALID) { |
| 5857 | if (type_changed) { |
| 5858 | List<VisualShader::Connection> conns; |
| 5859 | visual_shader->get_node_connections(type, &conns); |
| 5860 | |
| 5861 | for (const VisualShader::Connection &E : conns) { |
| 5862 | if (is_getter) { |
| 5863 | if (E.from_node == id) { |
| 5864 | if (visual_shader->is_port_types_compatible(p_varying->get_varying_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) { |
| 5865 | continue; |
| 5866 | } |
| 5867 | undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5868 | undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5869 | undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5870 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5871 | } |
| 5872 | } else { |
| 5873 | if (E.to_node == id) { |
| 5874 | if (visual_shader->is_port_types_compatible(p_varying->get_varying_type_by_name(p_name), visual_shader->get_node(type, E.from_node)->get_output_port_type(E.from_port))) { |
| 5875 | continue; |
| 5876 | } |
| 5877 | undo_redo_man->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5878 | undo_redo_man->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5879 | undo_redo_man->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5880 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 5881 | } |
| 5882 | } |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | undo_redo_man->add_do_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5887 | undo_redo_man->add_undo_method(graph_plugin.ptr(), "update_node", type_id, id); |
| 5888 | break; |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | undo_redo_man->commit_action(); |
| 5893 | } |
| 5894 | |
| 5895 | void VisualShaderEditor::_float_constant_selected(int p_which) { |
| 5896 | ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS); |
| 5897 | |
| 5898 | VisualShader::Type type = get_current_shader_type(); |
| 5899 | Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant); |
| 5900 | ERR_FAIL_COND(node.is_null()); |
| 5901 | |
| 5902 | if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) { |
| 5903 | return; // same |
| 5904 | } |
| 5905 | |
| 5906 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 5907 | undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name)); |
| 5908 | undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value); |
| 5909 | undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant()); |
| 5910 | undo_redo->commit_action(); |
| 5911 | } |
| 5912 | |
| 5913 | void VisualShaderEditor::_member_filter_changed(const String &p_text) { |
| 5914 | _update_options_menu(); |
| 5915 | } |
| 5916 | |
| 5917 | void VisualShaderEditor::_member_selected() { |
| 5918 | TreeItem *item = members->get_selected(); |
| 5919 | |
| 5920 | if (item != nullptr && item->has_meta("id")) { |
| 5921 | members_dialog->get_ok_button()->set_disabled(false); |
| 5922 | highend_label->set_visible(add_options[item->get_meta("id")].highend); |
| 5923 | node_desc->set_text(_get_description(item->get_meta("id"))); |
| 5924 | } else { |
| 5925 | highend_label->set_visible(false); |
| 5926 | members_dialog->get_ok_button()->set_disabled(true); |
| 5927 | node_desc->set_text(""); |
| 5928 | } |
| 5929 | } |
| 5930 | |
| 5931 | void VisualShaderEditor::_member_create() { |
| 5932 | TreeItem *item = members->get_selected(); |
| 5933 | if (item != nullptr && item->has_meta("id")) { |
| 5934 | int idx = members->get_selected()->get_meta("id"); |
| 5935 | if (connection_node_insert_requested) { |
| 5936 | from_node = String(clicked_connection->from_node).to_int(); |
| 5937 | from_slot = clicked_connection->from_port; |
| 5938 | to_node = String(clicked_connection->to_node).to_int(); |
| 5939 | to_slot = clicked_connection->to_port; |
| 5940 | |
| 5941 | connection_node_insert_requested = false; |
| 5942 | |
| 5943 | saved_node_pos_dirty = true; |
| 5944 | |
| 5945 | // Find both graph nodes and get their positions. |
| 5946 | GraphNode *from_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(from_node))); |
| 5947 | GraphNode *to_graph_element = Object::cast_to<GraphNode>(graph->get_node(itos(to_node))); |
| 5948 | |
| 5949 | ERR_FAIL_NULL(from_graph_element); |
| 5950 | ERR_FAIL_NULL(to_graph_element); |
| 5951 | |
| 5952 | // Since the size of the node to add is not known yet, it's not possible to center it exactly. |
| 5953 | float zoom = graph->get_zoom(); |
| 5954 | saved_node_pos = 0.5 * (from_graph_element->get_position() + zoom * from_graph_element->get_output_port_position(from_slot) + to_graph_element->get_position() + zoom * to_graph_element->get_input_port_position(to_slot)); |
| 5955 | } |
| 5956 | _add_node(idx, add_options[idx].ops); |
| 5957 | members_dialog->hide(); |
| 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | void VisualShaderEditor::_member_cancel() { |
| 5962 | to_node = -1; |
| 5963 | to_slot = -1; |
| 5964 | from_node = -1; |
| 5965 | from_slot = -1; |
| 5966 | connection_node_insert_requested = false; |
| 5967 | } |
| 5968 | |
| 5969 | void VisualShaderEditor::_update_varying_tree() { |
| 5970 | varyings->clear(); |
| 5971 | TreeItem *root = varyings->create_item(); |
| 5972 | |
| 5973 | int count = visual_shader->get_varyings_count(); |
| 5974 | |
| 5975 | for (int i = 0; i < count; i++) { |
| 5976 | const VisualShader::Varying *varying = visual_shader->get_varying_by_index(i); |
| 5977 | |
| 5978 | if (varying) { |
| 5979 | TreeItem *item = varyings->create_item(root); |
| 5980 | item->set_text(0, varying->name); |
| 5981 | |
| 5982 | if (i == 0) { |
| 5983 | item->select(0); |
| 5984 | } |
| 5985 | |
| 5986 | switch (varying->type) { |
| 5987 | case VisualShader::VARYING_TYPE_FLOAT: |
| 5988 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons))); |
| 5989 | break; |
| 5990 | case VisualShader::VARYING_TYPE_INT: |
| 5991 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons))); |
| 5992 | break; |
| 5993 | case VisualShader::VARYING_TYPE_UINT: |
| 5994 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons))); |
| 5995 | break; |
| 5996 | case VisualShader::VARYING_TYPE_VECTOR_2D: |
| 5997 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons))); |
| 5998 | break; |
| 5999 | case VisualShader::VARYING_TYPE_VECTOR_3D: |
| 6000 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons))); |
| 6001 | break; |
| 6002 | case VisualShader::VARYING_TYPE_VECTOR_4D: |
| 6003 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons))); |
| 6004 | break; |
| 6005 | case VisualShader::VARYING_TYPE_BOOLEAN: |
| 6006 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons))); |
| 6007 | break; |
| 6008 | case VisualShader::VARYING_TYPE_TRANSFORM: |
| 6009 | item->set_icon(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons))); |
| 6010 | break; |
| 6011 | default: |
| 6012 | break; |
| 6013 | } |
| 6014 | } |
| 6015 | } |
| 6016 | |
| 6017 | varying_button->get_popup()->set_item_disabled(int(VaryingMenuOptions::REMOVE), count == 0); |
| 6018 | } |
| 6019 | |
| 6020 | void VisualShaderEditor::_varying_create() { |
| 6021 | _add_varying(varying_name->get_text(), (VisualShader::VaryingMode)varying_mode->get_selected(), (VisualShader::VaryingType)varying_type->get_selected()); |
| 6022 | add_varying_dialog->hide(); |
| 6023 | } |
| 6024 | |
| 6025 | void VisualShaderEditor::_varying_validate() { |
| 6026 | bool has_error = false; |
| 6027 | String error; |
| 6028 | String varname = varying_name->get_text(); |
| 6029 | |
| 6030 | if (!varname.is_valid_ascii_identifier()) { |
| 6031 | error += TTR("Invalid name for varying."); |
| 6032 | has_error = true; |
| 6033 | } else if (visual_shader->has_varying(varname)) { |
| 6034 | error += TTR("Varying with that name already exists."); |
| 6035 | has_error = true; |
| 6036 | } |
| 6037 | |
| 6038 | if (varying_type->get_selected() == 6 && varying_mode->get_selected() == VisualShader::VaryingMode::VARYING_MODE_VERTEX_TO_FRAG_LIGHT) { |
| 6039 | if (has_error) { |
| 6040 | error += "\n"; |
| 6041 | } |
| 6042 | error += vformat(TTR("Boolean type cannot be used with `%s` varying mode."), U"Vertex → [Fragment, Light]"); |
| 6043 | has_error = true; |
| 6044 | } |
| 6045 | |
| 6046 | if (has_error) { |
| 6047 | varying_error_label->show(); |
| 6048 | varying_error_label->set_text(error); |
| 6049 | add_varying_dialog->get_ok_button()->set_disabled(true); |
| 6050 | } else { |
| 6051 | varying_error_label->hide(); |
| 6052 | varying_error_label->set_text(""); |
| 6053 | add_varying_dialog->get_ok_button()->set_disabled(false); |
| 6054 | } |
| 6055 | add_varying_dialog->reset_size(); |
| 6056 | } |
| 6057 | |
| 6058 | void VisualShaderEditor::_varying_type_changed(int p_index) { |
| 6059 | _varying_validate(); |
| 6060 | } |
| 6061 | |
| 6062 | void VisualShaderEditor::_varying_mode_changed(int p_index) { |
| 6063 | _varying_validate(); |
| 6064 | } |
| 6065 | |
| 6066 | void VisualShaderEditor::_varying_name_changed(const String &p_name) { |
| 6067 | _varying_validate(); |
| 6068 | } |
| 6069 | |
| 6070 | void VisualShaderEditor::_varying_deleted() { |
| 6071 | TreeItem *item = varyings->get_selected(); |
| 6072 | |
| 6073 | if (item != nullptr) { |
| 6074 | _remove_varying(item->get_text(0)); |
| 6075 | remove_varying_dialog->hide(); |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | void VisualShaderEditor::_varying_selected() { |
| 6080 | add_varying_dialog->get_ok_button()->set_disabled(false); |
| 6081 | } |
| 6082 | |
| 6083 | void VisualShaderEditor::_varying_unselected() { |
| 6084 | add_varying_dialog->get_ok_button()->set_disabled(true); |
| 6085 | } |
| 6086 | |
| 6087 | void VisualShaderEditor::_tools_menu_option(int p_idx) { |
| 6088 | TreeItem *category = members->get_root()->get_first_child(); |
| 6089 | |
| 6090 | switch (p_idx) { |
| 6091 | case EXPAND_ALL: |
| 6092 | |
| 6093 | while (category) { |
| 6094 | category->set_collapsed(false); |
| 6095 | TreeItem *sub_category = category->get_first_child(); |
| 6096 | while (sub_category) { |
| 6097 | sub_category->set_collapsed(false); |
| 6098 | sub_category = sub_category->get_next(); |
| 6099 | } |
| 6100 | category = category->get_next(); |
| 6101 | } |
| 6102 | |
| 6103 | break; |
| 6104 | |
| 6105 | case COLLAPSE_ALL: |
| 6106 | |
| 6107 | while (category) { |
| 6108 | category->set_collapsed(true); |
| 6109 | TreeItem *sub_category = category->get_first_child(); |
| 6110 | while (sub_category) { |
| 6111 | sub_category->set_collapsed(true); |
| 6112 | sub_category = sub_category->get_next(); |
| 6113 | } |
| 6114 | category = category->get_next(); |
| 6115 | } |
| 6116 | |
| 6117 | break; |
| 6118 | default: |
| 6119 | break; |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | void VisualShaderEditor::_node_menu_id_pressed(int p_idx) { |
| 6124 | switch (p_idx) { |
| 6125 | case NodeMenuOptions::ADD: |
| 6126 | _show_members_dialog(true); |
| 6127 | break; |
| 6128 | case NodeMenuOptions::CUT: |
| 6129 | _copy_nodes(true); |
| 6130 | break; |
| 6131 | case NodeMenuOptions::COPY: |
| 6132 | _copy_nodes(false); |
| 6133 | break; |
| 6134 | case NodeMenuOptions::PASTE: |
| 6135 | _paste_nodes(true, menu_point); |
| 6136 | break; |
| 6137 | case NodeMenuOptions::DELETE_: |
| 6138 | _delete_nodes_request(TypedArray<StringName>()); |
| 6139 | break; |
| 6140 | case NodeMenuOptions::DUPLICATE: |
| 6141 | _duplicate_nodes(); |
| 6142 | break; |
| 6143 | case NodeMenuOptions::CLEAR_COPY_BUFFER: |
| 6144 | _clear_copy_buffer(); |
| 6145 | break; |
| 6146 | case NodeMenuOptions::CONVERT_CONSTANTS_TO_PARAMETERS: |
| 6147 | _convert_constants_to_parameters(false); |
| 6148 | break; |
| 6149 | case NodeMenuOptions::CONVERT_PARAMETERS_TO_CONSTANTS: |
| 6150 | _convert_constants_to_parameters(true); |
| 6151 | break; |
| 6152 | case NodeMenuOptions::UNLINK_FROM_PARENT_FRAME: |
| 6153 | _detach_nodes_from_frame_request(); |
| 6154 | break; |
| 6155 | case NodeMenuOptions::SET_FRAME_TITLE: |
| 6156 | _frame_title_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame); |
| 6157 | break; |
| 6158 | case NodeMenuOptions::ENABLE_FRAME_COLOR: |
| 6159 | _frame_color_enabled_changed(selected_frame); |
| 6160 | break; |
| 6161 | case NodeMenuOptions::SET_FRAME_COLOR: |
| 6162 | _frame_color_popup_show(get_screen_position() + get_local_mouse_position(), selected_frame); |
| 6163 | break; |
| 6164 | case NodeMenuOptions::ENABLE_FRAME_AUTOSHRINK: |
| 6165 | _frame_autoshrink_enabled_changed(selected_frame); |
| 6166 | break; |
| 6167 | default: |
| 6168 | break; |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) { |
| 6173 | switch (p_idx) { |
| 6174 | case ConnectionMenuOptions::DISCONNECT: { |
| 6175 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 6176 | undo_redo->create_action(TTR("Disconnect")); |
| 6177 | undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port); |
| 6178 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port); |
| 6179 | undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port); |
| 6180 | undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", get_current_shader_type(), String(clicked_connection->from_node).to_int(), clicked_connection->from_port, String(clicked_connection->to_node).to_int(), clicked_connection->to_port); |
| 6181 | undo_redo->commit_action(); |
| 6182 | } break; |
| 6183 | case ConnectionMenuOptions::INSERT_NEW_NODE: { |
| 6184 | VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 6185 | VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX; |
| 6186 | Ref<VisualShaderNode> node1 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->from_node).to_int()); |
| 6187 | if (node1.is_valid()) { |
| 6188 | output_port_type = node1->get_output_port_type(from_slot); |
| 6189 | } |
| 6190 | Ref<VisualShaderNode> node2 = visual_shader->get_node(get_current_shader_type(), String(clicked_connection->to_node).to_int()); |
| 6191 | if (node2.is_valid()) { |
| 6192 | input_port_type = node2->get_input_port_type(to_slot); |
| 6193 | } |
| 6194 | |
| 6195 | connection_node_insert_requested = true; |
| 6196 | _show_members_dialog(true, input_port_type, output_port_type); |
| 6197 | } break; |
| 6198 | case ConnectionMenuOptions::INSERT_NEW_REROUTE: { |
| 6199 | from_node = String(clicked_connection->from_node).to_int(); |
| 6200 | from_slot = clicked_connection->from_port; |
| 6201 | to_node = String(clicked_connection->to_node).to_int(); |
| 6202 | to_slot = clicked_connection->to_port; |
| 6203 | |
| 6204 | // Manual offset to place the port exactly at the mouse position. |
| 6205 | saved_node_pos -= Vector2(11 * EDSCALE * graph->get_zoom(), 50 * EDSCALE * graph->get_zoom()); |
| 6206 | |
| 6207 | // Find reroute addoptions. |
| 6208 | int idx = -1; |
| 6209 | for (int i = 0; i < add_options.size(); i++) { |
| 6210 | if (add_options[i].name == "Reroute") { |
| 6211 | idx = i; |
| 6212 | break; |
| 6213 | } |
| 6214 | } |
| 6215 | _add_node(idx, add_options[idx].ops); |
| 6216 | } break; |
| 6217 | default: |
| 6218 | break; |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { |
| 6223 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 6224 | return Variant(); |
| 6225 | } |
| 6226 | |
| 6227 | if (p_from == members) { |
| 6228 | TreeItem *it = members->get_item_at_position(p_point); |
| 6229 | if (!it) { |
| 6230 | return Variant(); |
| 6231 | } |
| 6232 | if (!it->has_meta("id")) { |
| 6233 | return Variant(); |
| 6234 | } |
| 6235 | |
| 6236 | int id = it->get_meta("id"); |
| 6237 | AddOption op = add_options[id]; |
| 6238 | |
| 6239 | Dictionary d; |
| 6240 | d["id"] = id; |
| 6241 | |
| 6242 | Label *label = memnew(Label); |
| 6243 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 6244 | label->set_text(it->get_text(0)); |
| 6245 | label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 6246 | set_drag_preview(label); |
| 6247 | return d; |
| 6248 | } |
| 6249 | return Variant(); |
| 6250 | } |
| 6251 | |
| 6252 | bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { |
| 6253 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 6254 | return false; |
| 6255 | } |
| 6256 | |
| 6257 | if (p_from == graph) { |
| 6258 | Dictionary d = p_data; |
| 6259 | |
| 6260 | if (d.has("id")) { |
| 6261 | return true; |
| 6262 | } |
| 6263 | if (d.has("files")) { |
| 6264 | return true; |
| 6265 | } |
| 6266 | } |
| 6267 | |
| 6268 | return false; |
| 6269 | } |
| 6270 | |
| 6271 | void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { |
| 6272 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 6273 | return; |
| 6274 | } |
| 6275 | |
| 6276 | if (p_from == graph) { |
| 6277 | Dictionary d = p_data; |
| 6278 | |
| 6279 | if (d.has("id")) { |
| 6280 | int idx = d["id"]; |
| 6281 | saved_node_pos = p_point; |
| 6282 | saved_node_pos_dirty = true; |
| 6283 | _add_node(idx, add_options[idx].ops); |
| 6284 | } else if (d.has("files")) { |
| 6285 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 6286 | undo_redo->create_action(TTR("Add Node(s) to Visual Shader")); |
| 6287 | |
| 6288 | if (d["files"].get_type() == Variant::PACKED_STRING_ARRAY) { |
| 6289 | PackedStringArray arr = d["files"]; |
| 6290 | for (int i = 0; i < arr.size(); i++) { |
| 6291 | String type = ResourceLoader::get_resource_type(arr[i]); |
| 6292 | if (type == "GDScript") { |
| 6293 | Ref<Script> scr = ResourceLoader::load(arr[i]); |
| 6294 | if (scr->get_instance_base_type() == "VisualShaderNodeCustom") { |
| 6295 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6296 | saved_node_pos_dirty = true; |
| 6297 | |
| 6298 | int idx = -1; |
| 6299 | |
| 6300 | for (int j = custom_node_option_idx; j < add_options.size(); j++) { |
| 6301 | if (add_options[j].script.is_valid()) { |
| 6302 | if (add_options[j].script->get_path() == arr[i]) { |
| 6303 | idx = j; |
| 6304 | break; |
| 6305 | } |
| 6306 | } |
| 6307 | } |
| 6308 | if (idx != -1) { |
| 6309 | _add_node(idx, {}, arr[i], i); |
| 6310 | } |
| 6311 | } |
| 6312 | } else if (type == "CurveTexture") { |
| 6313 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6314 | saved_node_pos_dirty = true; |
| 6315 | _add_node(curve_node_option_idx, {}, arr[i], i); |
| 6316 | } else if (type == "CurveXYZTexture") { |
| 6317 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6318 | saved_node_pos_dirty = true; |
| 6319 | _add_node(curve_xyz_node_option_idx, {}, arr[i], i); |
| 6320 | } else if (ClassDB::get_parent_class(type) == "Texture2D") { |
| 6321 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6322 | saved_node_pos_dirty = true; |
| 6323 | _add_node(texture2d_node_option_idx, {}, arr[i], i); |
| 6324 | } else if (type == "Texture2DArray") { |
| 6325 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6326 | saved_node_pos_dirty = true; |
| 6327 | _add_node(texture2d_array_node_option_idx, {}, arr[i], i); |
| 6328 | } else if (ClassDB::get_parent_class(type) == "Texture3D") { |
| 6329 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6330 | saved_node_pos_dirty = true; |
| 6331 | _add_node(texture3d_node_option_idx, {}, arr[i], i); |
| 6332 | } else if (type == "Cubemap") { |
| 6333 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6334 | saved_node_pos_dirty = true; |
| 6335 | _add_node(cubemap_node_option_idx, {}, arr[i], i); |
| 6336 | } else if (type == "Mesh" && visual_shader->get_mode() == Shader::MODE_PARTICLES && |
| 6337 | (get_current_shader_type() == VisualShader::TYPE_START || get_current_shader_type() == VisualShader::TYPE_START_CUSTOM)) { |
| 6338 | saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); |
| 6339 | saved_node_pos_dirty = true; |
| 6340 | _add_node(mesh_emitter_option_idx, {}, arr[i], i); |
| 6341 | } |
| 6342 | } |
| 6343 | } |
| 6344 | undo_redo->commit_action(); |
| 6345 | } |
| 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | void VisualShaderEditor::_show_preview_text() { |
| 6350 | code_preview_showed = !code_preview_showed; |
| 6351 | if (code_preview_showed) { |
| 6352 | if (code_preview_first) { |
| 6353 | code_preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE)); |
| 6354 | code_preview_window->popup_centered(); |
| 6355 | code_preview_first = false; |
| 6356 | } else { |
| 6357 | code_preview_window->popup(); |
| 6358 | } |
| 6359 | |
| 6360 | if (pending_update_preview) { |
| 6361 | _update_preview(); |
| 6362 | pending_update_preview = false; |
| 6363 | } |
| 6364 | } else { |
| 6365 | code_preview_window->hide(); |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | void VisualShaderEditor::_preview_close_requested() { |
| 6370 | code_preview_showed = false; |
| 6371 | code_preview_button->set_pressed(false); |
| 6372 | } |
| 6373 | |
| 6374 | static ShaderLanguage::DataType _visual_shader_editor_get_global_shader_uniform_type(const StringName &p_variable) { |
| 6375 | RS::GlobalShaderParameterType gvt = RS::get_singleton()->global_shader_parameter_get_type(p_variable); |
| 6376 | return (ShaderLanguage::DataType)RS::global_shader_uniform_type_get_shader_datatype(gvt); |
| 6377 | } |
| 6378 | |
| 6379 | void VisualShaderEditor::_update_preview() { |
| 6380 | if (!code_preview_showed) { |
| 6381 | pending_update_preview = true; |
| 6382 | return; |
| 6383 | } |
| 6384 | |
| 6385 | String code = visual_shader->get_code(); |
| 6386 | |
| 6387 | preview_text->set_text(code); |
| 6388 | |
| 6389 | ShaderLanguage::ShaderCompileInfo info; |
| 6390 | info.functions = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode())); |
| 6391 | info.render_modes = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode())); |
| 6392 | info.stencil_modes = ShaderTypes::get_singleton()->get_stencil_modes(RenderingServer::ShaderMode(visual_shader->get_mode())); |
| 6393 | info.shader_types = ShaderTypes::get_singleton()->get_types(); |
| 6394 | info.global_shader_uniform_type_func = _visual_shader_editor_get_global_shader_uniform_type; |
| 6395 | |
| 6396 | for (int i = 0; i < preview_text->get_line_count(); i++) { |
| 6397 | preview_text->set_line_background_color(i, Color(0, 0, 0, 0)); |
| 6398 | } |
| 6399 | |
| 6400 | String preprocessed_code; |
| 6401 | { |
| 6402 | String path = visual_shader->get_path(); |
| 6403 | String error_pp; |
| 6404 | List<ShaderPreprocessor::FilePosition> err_positions; |
| 6405 | ShaderPreprocessor preprocessor; |
| 6406 | Error err = preprocessor.preprocess(code, path, preprocessed_code, &error_pp, &err_positions); |
| 6407 | if (err != OK) { |
| 6408 | ERR_FAIL_COND(err_positions.is_empty()); |
| 6409 | |
| 6410 | String file = err_positions.front()->get().file; |
| 6411 | int err_line = err_positions.front()->get().line; |
| 6412 | Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color"); |
| 6413 | preview_text->set_line_background_color(err_line - 1, error_line_color); |
| 6414 | error_panel->show(); |
| 6415 | |
| 6416 | error_label->set_text("error(" + file + ":" + itos(err_line) + "): " + error_pp); |
| 6417 | shader_error = true; |
| 6418 | return; |
| 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | ShaderLanguage sl; |
| 6423 | Error err = sl.compile(preprocessed_code, info); |
| 6424 | if (err != OK) { |
| 6425 | int err_line; |
| 6426 | String err_text; |
| 6427 | Vector<ShaderLanguage::FilePosition> include_positions = sl.get_include_positions(); |
| 6428 | if (include_positions.size() > 1) { |
| 6429 | // Error is in an include. |
| 6430 | err_line = include_positions[0].line; |
| 6431 | err_text = "error(" + itos(err_line) + ") in include " + include_positions[include_positions.size() - 1].file + ":" + itos(include_positions[include_positions.size() - 1].line) + ": " + sl.get_error_text(); |
| 6432 | } else { |
| 6433 | err_line = sl.get_error_line(); |
| 6434 | err_text = "error(" + itos(err_line) + "): " + sl.get_error_text(); |
| 6435 | } |
| 6436 | |
| 6437 | Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color"); |
| 6438 | preview_text->set_line_background_color(err_line - 1, error_line_color); |
| 6439 | error_panel->show(); |
| 6440 | |
| 6441 | error_label->set_text(err_text); |
| 6442 | shader_error = true; |
| 6443 | } else { |
| 6444 | error_panel->hide(); |
| 6445 | shader_error = false; |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | void VisualShaderEditor::_update_next_previews(int p_node_id) { |
| 6450 | VisualShader::Type type = get_current_shader_type(); |
| 6451 | |
| 6452 | LocalVector<int> nodes; |
| 6453 | _get_next_nodes_recursively(type, p_node_id, nodes); |
| 6454 | |
| 6455 | for (int node_id : nodes) { |
| 6456 | if (graph_plugin->is_preview_visible(node_id)) { |
| 6457 | graph_plugin->update_node_deferred(type, node_id); |
| 6458 | } |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | void VisualShaderEditor::_get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const { |
| 6463 | const LocalVector<int> &next_connections = visual_shader->get_next_connected_nodes(p_type, p_node_id); |
| 6464 | |
| 6465 | for (int node_id : next_connections) { |
| 6466 | r_nodes.push_back(node_id); |
| 6467 | _get_next_nodes_recursively(p_type, node_id, r_nodes); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | void VisualShaderEditor::_visibility_changed() { |
| 6472 | if (!is_visible()) { |
| 6473 | if (code_preview_window->is_visible()) { |
| 6474 | code_preview_button->set_pressed(false); |
| 6475 | code_preview_window->hide(); |
| 6476 | code_preview_showed = false; |
| 6477 | } |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | void VisualShaderEditor::_show_shader_preview() { |
| 6482 | shader_preview_showed = !shader_preview_showed; |
| 6483 | if (shader_preview_showed) { |
| 6484 | shader_preview_vbox->show(); |
| 6485 | } else { |
| 6486 | shader_preview_vbox->hide(); |
| 6487 | |
| 6488 | _param_unselected(); |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | void VisualShaderEditor::set_toggle_list_control(Control *p_toggle_list_control) { |
| 6493 | toggle_files_list = p_toggle_list_control; |
| 6494 | } |
| 6495 | |
| 6496 | void VisualShaderEditor::_toggle_files_pressed() { |
| 6497 | ERR_FAIL_NULL(toggle_files_list); |
| 6498 | toggle_files_list->set_visible(!toggle_files_list->is_visible()); |
| 6499 | update_toggle_files_button(); |
| 6500 | } |
| 6501 | |
| 6502 | void VisualShaderEditor::_bind_methods() { |
| 6503 | ClassDB::bind_method("_update_nodes", &VisualShaderEditor::_update_nodes); |
| 6504 | ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph); |
| 6505 | ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item); |
| 6506 | ClassDB::bind_method("_parameter_ref_select_item", &VisualShaderEditor::_parameter_ref_select_item); |
| 6507 | ClassDB::bind_method("_varying_select_item", &VisualShaderEditor::_varying_select_item); |
| 6508 | ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size); |
| 6509 | ClassDB::bind_method("_update_parameters", &VisualShaderEditor::_update_parameters); |
| 6510 | ClassDB::bind_method("_update_varyings", &VisualShaderEditor::_update_varyings); |
| 6511 | ClassDB::bind_method("_update_varying_tree", &VisualShaderEditor::_update_varying_tree); |
| 6512 | ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode); |
| 6513 | ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant); |
| 6514 | ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter); |
| 6515 | ClassDB::bind_method("_update_next_previews", &VisualShaderEditor::_update_next_previews); |
| 6516 | ClassDB::bind_method("_update_current_param", &VisualShaderEditor::_update_current_param); |
| 6517 | } |
| 6518 | |
| 6519 | VisualShaderEditor::VisualShaderEditor() { |
| 6520 | vs_editor_cache.instantiate(); |
| 6521 | vs_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("vs_editor_cache.cfg")); |
| 6522 | |
| 6523 | ShaderLanguage::get_keyword_list(&keyword_list); |
| 6524 | EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::_resource_saved)); |
| 6525 | FileSystemDock::get_singleton()->get_script_create_dialog()->connect("script_created", callable_mp(this, &VisualShaderEditor::_script_created)); |
| 6526 | FileSystemDock::get_singleton()->connect("resource_removed", callable_mp(this, &VisualShaderEditor::_resource_removed)); |
| 6527 | |
| 6528 | HSplitContainer *main_box = memnew(HSplitContainer); |
| 6529 | main_box->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); |
| 6530 | add_child(main_box); |
| 6531 | |
| 6532 | graph = memnew(GraphEdit); |
| 6533 | graph->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6534 | graph->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6535 | graph->set_custom_minimum_size(Size2(200 * EDSCALE, 0)); |
| 6536 | graph->set_grid_pattern(GraphEdit::GridPattern::GRID_PATTERN_DOTS); |
| 6537 | int grid_pattern = EDITOR_GET("editors/visual_editors/grid_pattern"); |
| 6538 | graph->set_grid_pattern((GraphEdit::GridPattern)grid_pattern); |
| 6539 | graph->set_show_zoom_label(true); |
| 6540 | main_box->add_child(graph); |
| 6541 | SET_DRAG_FORWARDING_GCD(graph, VisualShaderEditor); |
| 6542 | float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity"); |
| 6543 | graph->set_minimap_opacity(graph_minimap_opacity); |
| 6544 | float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature"); |
| 6545 | graph->set_connection_lines_curvature(graph_lines_curvature); |
| 6546 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); |
| 6547 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6548 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6549 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6550 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6551 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6552 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6553 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_TRANSFORM); |
| 6554 | graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SAMPLER); |
| 6555 | //graph->add_valid_left_disconnect_type(0); |
| 6556 | graph->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6557 | graph->connect("connection_request", callable_mp(this, &VisualShaderEditor::_connection_request), CONNECT_DEFERRED); |
| 6558 | graph->connect("disconnection_request", callable_mp(this, &VisualShaderEditor::_disconnection_request), CONNECT_DEFERRED); |
| 6559 | graph->connect("node_selected", callable_mp(this, &VisualShaderEditor::_node_selected)); |
| 6560 | graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_offset_changed)); |
| 6561 | graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes)); |
| 6562 | graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false)); |
| 6563 | graph->connect("cut_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(true)); |
| 6564 | graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2())); |
| 6565 | graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request)); |
| 6566 | graph->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_graph_gui_input)); |
| 6567 | graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty)); |
| 6568 | graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty)); |
| 6569 | graph->connect("connection_drag_ended", callable_mp(this, &VisualShaderEditor::_connection_drag_ended)); |
| 6570 | graph->connect(SceneStringName(visibility_changed), callable_mp(this, &VisualShaderEditor::_visibility_changed)); |
| 6571 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6572 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6573 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6574 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6575 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6576 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6577 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6578 | |
| 6579 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6580 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6581 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6582 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6583 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6584 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6585 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6586 | |
| 6587 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6588 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6589 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6590 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6591 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6592 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6593 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6594 | |
| 6595 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6596 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6597 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6598 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6599 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6600 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6601 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6602 | |
| 6603 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6604 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6605 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6606 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6607 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6608 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6609 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6610 | |
| 6611 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6612 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6613 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6614 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6615 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6616 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6617 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6618 | |
| 6619 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR); |
| 6620 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT); |
| 6621 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT); |
| 6622 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D); |
| 6623 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D); |
| 6624 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D); |
| 6625 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_BOOLEAN); |
| 6626 | |
| 6627 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_TRANSFORM, VisualShaderNode::PORT_TYPE_TRANSFORM); |
| 6628 | graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SAMPLER, VisualShaderNode::PORT_TYPE_SAMPLER); |
| 6629 | |
| 6630 | info_label = memnew(Label); |
| 6631 | info_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 6632 | info_label->set_text(vformat(TTR("Hold %s Key To Swap Connections"), keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL))); |
| 6633 | info_label->set_anchors_and_offsets_preset(Control::PRESET_BOTTOM_WIDE, PRESET_MODE_MINSIZE, 20); |
| 6634 | info_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 6635 | info_label->hide(); |
| 6636 | graph->get_top_layer()->add_child(info_label); |
| 6637 | |
| 6638 | PanelContainer *toolbar_panel = static_cast<PanelContainer *>(graph->get_menu_hbox()->get_parent()); |
| 6639 | toolbar_panel->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE, PRESET_MODE_MINSIZE, 10); |
| 6640 | toolbar_panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); |
| 6641 | |
| 6642 | toolbar_hflow = memnew(HFlowContainer); |
| 6643 | { |
| 6644 | LocalVector<Node *> nodes; |
| 6645 | for (int i = 0; i < graph->get_menu_hbox()->get_child_count(); i++) { |
| 6646 | Node *child = graph->get_menu_hbox()->get_child(i); |
| 6647 | nodes.push_back(child); |
| 6648 | } |
| 6649 | |
| 6650 | for (Node *node : nodes) { |
| 6651 | graph->get_menu_hbox()->remove_child(node); |
| 6652 | toolbar_hflow->add_child(node); |
| 6653 | } |
| 6654 | |
| 6655 | graph->get_menu_hbox()->hide(); |
| 6656 | toolbar_panel->add_child(toolbar_hflow); |
| 6657 | } |
| 6658 | |
| 6659 | VSeparator *vs = memnew(VSeparator); |
| 6660 | toolbar_hflow->add_child(vs); |
| 6661 | toolbar_hflow->move_child(vs, 0); |
| 6662 | |
| 6663 | custom_mode_box = memnew(CheckBox); |
| 6664 | custom_mode_box->set_text(TTR("Custom")); |
| 6665 | custom_mode_box->set_pressed(false); |
| 6666 | custom_mode_box->set_visible(false); |
| 6667 | custom_mode_box->connect(SceneStringName(toggled), callable_mp(this, &VisualShaderEditor::_custom_mode_toggled)); |
| 6668 | |
| 6669 | edit_type_standard = memnew(OptionButton); |
| 6670 | edit_type_standard->add_item(TTR("Vertex")); |
| 6671 | edit_type_standard->add_item(TTR("Fragment")); |
| 6672 | edit_type_standard->add_item(TTR("Light")); |
| 6673 | edit_type_standard->select(1); |
| 6674 | edit_type_standard->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected)); |
| 6675 | |
| 6676 | edit_type_particles = memnew(OptionButton); |
| 6677 | edit_type_particles->add_item(TTR("Start")); |
| 6678 | edit_type_particles->add_item(TTR("Process")); |
| 6679 | edit_type_particles->add_item(TTR("Collide")); |
| 6680 | edit_type_particles->select(0); |
| 6681 | edit_type_particles->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected)); |
| 6682 | |
| 6683 | edit_type_sky = memnew(OptionButton); |
| 6684 | edit_type_sky->add_item(TTR("Sky")); |
| 6685 | edit_type_sky->select(0); |
| 6686 | edit_type_sky->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected)); |
| 6687 | |
| 6688 | edit_type_fog = memnew(OptionButton); |
| 6689 | edit_type_fog->add_item(TTR("Fog")); |
| 6690 | edit_type_fog->select(0); |
| 6691 | edit_type_fog->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_type_selected)); |
| 6692 | |
| 6693 | edit_type = edit_type_standard; |
| 6694 | |
| 6695 | toolbar_hflow->add_child(custom_mode_box); |
| 6696 | toolbar_hflow->move_child(custom_mode_box, 0); |
| 6697 | toolbar_hflow->add_child(edit_type_standard); |
| 6698 | toolbar_hflow->move_child(edit_type_standard, 0); |
| 6699 | toolbar_hflow->add_child(edit_type_particles); |
| 6700 | toolbar_hflow->move_child(edit_type_particles, 0); |
| 6701 | toolbar_hflow->add_child(edit_type_sky); |
| 6702 | toolbar_hflow->move_child(edit_type_sky, 0); |
| 6703 | toolbar_hflow->add_child(edit_type_fog); |
| 6704 | toolbar_hflow->move_child(edit_type_fog, 0); |
| 6705 | |
| 6706 | add_node = memnew(Button); |
| 6707 | add_node->set_theme_type_variation(SceneStringName(FlatButton)); |
| 6708 | add_node->set_text(TTR("Add Node...")); |
| 6709 | toolbar_hflow->add_child(add_node); |
| 6710 | toolbar_hflow->move_child(add_node, 0); |
| 6711 | add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX)); |
| 6712 | |
| 6713 | graph->connect("graph_elements_linked_to_frame_request", callable_mp(this, &VisualShaderEditor::_nodes_linked_to_frame_request)); |
| 6714 | graph->connect("frame_rect_changed", callable_mp(this, &VisualShaderEditor::_frame_rect_changed)); |
| 6715 | |
| 6716 | varying_button = memnew(MenuButton); |
| 6717 | varying_button->set_flat(false); |
| 6718 | varying_button->set_theme_type_variation("FlatMenuButton"); |
| 6719 | varying_button->set_text(TTR("Manage Varyings")); |
| 6720 | varying_button->set_switch_on_hover(true); |
| 6721 | toolbar_hflow->add_child(varying_button); |
| 6722 | |
| 6723 | PopupMenu *varying_menu = varying_button->get_popup(); |
| 6724 | varying_menu->add_item(TTR("Add Varying"), int(VaryingMenuOptions::ADD)); |
| 6725 | varying_menu->add_item(TTR("Remove Varying"), int(VaryingMenuOptions::REMOVE)); |
| 6726 | varying_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_varying_menu_id_pressed)); |
| 6727 | |
| 6728 | code_preview_button = memnew(Button); |
| 6729 | code_preview_button->set_theme_type_variation(SceneStringName(FlatButton)); |
| 6730 | code_preview_button->set_toggle_mode(true); |
| 6731 | code_preview_button->set_tooltip_text(TTR("Show generated shader code.")); |
| 6732 | toolbar_hflow->add_child(code_preview_button); |
| 6733 | code_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_preview_text)); |
| 6734 | |
| 6735 | shader_preview_button = memnew(Button); |
| 6736 | shader_preview_button->set_theme_type_variation(SceneStringName(FlatButton)); |
| 6737 | shader_preview_button->set_toggle_mode(true); |
| 6738 | shader_preview_button->set_tooltip_text(TTR("Toggle shader preview.")); |
| 6739 | shader_preview_button->set_pressed(true); |
| 6740 | toolbar_hflow->add_child(shader_preview_button); |
| 6741 | shader_preview_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_shader_preview)); |
| 6742 | |
| 6743 | Control *spacer = memnew(Control); |
| 6744 | spacer->set_h_size_flags(Control::SIZE_EXPAND); |
| 6745 | toolbar_hflow->add_child(spacer); |
| 6746 | |
| 6747 | site_search = memnew(Button); |
| 6748 | site_search->set_theme_type_variation(SceneStringName(FlatButton)); |
| 6749 | site_search->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_help_open)); |
| 6750 | site_search->set_text(TTR("Online Docs")); |
| 6751 | site_search->set_tooltip_text(TTR("Open Godot online documentation.")); |
| 6752 | toolbar_hflow->add_child(site_search); |
| 6753 | |
| 6754 | VSeparator *separator = memnew(VSeparator); |
| 6755 | toolbar_hflow->add_child(separator); |
| 6756 | toolbar_hflow->move_child(separator, 0); |
| 6757 | |
| 6758 | separator = memnew(VSeparator); |
| 6759 | toolbar_hflow->add_child(separator); |
| 6760 | toolbar_hflow->move_child(separator, 0); |
| 6761 | |
| 6762 | toggle_files_button = memnew(Button); |
| 6763 | toggle_files_button->set_theme_type_variation(SceneStringName(FlatButton)); |
| 6764 | toggle_files_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_toggle_files_pressed)); |
| 6765 | toolbar_hflow->add_child(toggle_files_button); |
| 6766 | toolbar_hflow->move_child(toggle_files_button, 0); |
| 6767 | |
| 6768 | /////////////////////////////////////// |
| 6769 | // CODE PREVIEW |
| 6770 | /////////////////////////////////////// |
| 6771 | |
| 6772 | code_preview_window = memnew(AcceptDialog); |
| 6773 | code_preview_window->set_title(TTR("Generated Shader Code")); |
| 6774 | code_preview_window->set_visible(code_preview_showed); |
| 6775 | code_preview_window->set_ok_button_text(TTR("Close")); |
| 6776 | code_preview_window->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_preview_close_requested)); |
| 6777 | code_preview_window->connect("canceled", callable_mp(this, &VisualShaderEditor::_preview_close_requested)); |
| 6778 | add_child(code_preview_window); |
| 6779 | |
| 6780 | code_preview_vbox = memnew(VBoxContainer); |
| 6781 | code_preview_window->add_child(code_preview_vbox); |
| 6782 | code_preview_vbox->add_theme_constant_override("separation", 0); |
| 6783 | |
| 6784 | preview_text = memnew(CodeEdit); |
| 6785 | syntax_highlighter.instantiate(); |
| 6786 | code_preview_vbox->add_child(preview_text); |
| 6787 | preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 6788 | preview_text->set_syntax_highlighter(syntax_highlighter); |
| 6789 | preview_text->set_draw_line_numbers(true); |
| 6790 | preview_text->set_editable(false); |
| 6791 | |
| 6792 | error_panel = memnew(PanelContainer); |
| 6793 | code_preview_vbox->add_child(error_panel); |
| 6794 | error_panel->set_visible(false); |
| 6795 | |
| 6796 | error_label = memnew(Label); |
| 6797 | error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 6798 | error_panel->add_child(error_label); |
| 6799 | error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 6800 | |
| 6801 | /////////////////////////////////////// |
| 6802 | // POPUP MENU |
| 6803 | /////////////////////////////////////// |
| 6804 | |
| 6805 | popup_menu = memnew(PopupMenu); |
| 6806 | add_child(popup_menu); |
| 6807 | popup_menu->set_hide_on_checkable_item_selection(false); |
| 6808 | popup_menu->add_item(TTR("Add Node"), NodeMenuOptions::ADD); |
| 6809 | popup_menu->add_separator(); |
| 6810 | popup_menu->add_item(TTR("Cut"), NodeMenuOptions::CUT); |
| 6811 | popup_menu->add_item(TTR("Copy"), NodeMenuOptions::COPY); |
| 6812 | popup_menu->add_item(TTR("Paste"), NodeMenuOptions::PASTE); |
| 6813 | popup_menu->add_item(TTR("Delete"), NodeMenuOptions::DELETE_); |
| 6814 | popup_menu->add_item(TTR("Duplicate"), NodeMenuOptions::DUPLICATE); |
| 6815 | popup_menu->add_item(TTR("Clear Copy Buffer"), NodeMenuOptions::CLEAR_COPY_BUFFER); |
| 6816 | popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_node_menu_id_pressed)); |
| 6817 | |
| 6818 | connection_popup_menu = memnew(PopupMenu); |
| 6819 | add_child(connection_popup_menu); |
| 6820 | connection_popup_menu->add_item(TTR("Disconnect"), ConnectionMenuOptions::DISCONNECT); |
| 6821 | connection_popup_menu->add_item(TTR("Insert New Node"), ConnectionMenuOptions::INSERT_NEW_NODE); |
| 6822 | connection_popup_menu->add_item(TTR("Insert New Reroute"), ConnectionMenuOptions::INSERT_NEW_REROUTE); |
| 6823 | connection_popup_menu->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_connection_menu_id_pressed)); |
| 6824 | |
| 6825 | /////////////////////////////////////// |
| 6826 | // SHADER PREVIEW |
| 6827 | /////////////////////////////////////// |
| 6828 | |
| 6829 | shader_preview_vbox = memnew(VBoxContainer); |
| 6830 | shader_preview_vbox->set_custom_minimum_size(Size2(200 * EDSCALE, 0)); |
| 6831 | main_box->add_child(shader_preview_vbox); |
| 6832 | |
| 6833 | VSplitContainer *preview_split = memnew(VSplitContainer); |
| 6834 | preview_split->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6835 | shader_preview_vbox->add_child(preview_split); |
| 6836 | |
| 6837 | // Initialize material editor. |
| 6838 | { |
| 6839 | env.instantiate(); |
| 6840 | Ref<Sky> sky = memnew(Sky()); |
| 6841 | env->set_sky(sky); |
| 6842 | env->set_background(Environment::BG_COLOR); |
| 6843 | env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY); |
| 6844 | env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY); |
| 6845 | |
| 6846 | preview_material.instantiate(); |
| 6847 | preview_material->connect(CoreStringName(property_list_changed), callable_mp(this, &VisualShaderEditor::_update_preview_parameter_list)); |
| 6848 | |
| 6849 | material_editor = memnew(MaterialEditor); |
| 6850 | preview_split->add_child(material_editor); |
| 6851 | } |
| 6852 | |
| 6853 | VBoxContainer *params_vbox = memnew(VBoxContainer); |
| 6854 | preview_split->add_child(params_vbox); |
| 6855 | |
| 6856 | HBoxContainer *filter_hbox = memnew(HBoxContainer); |
| 6857 | params_vbox->add_child(filter_hbox); |
| 6858 | |
| 6859 | param_filter = memnew(LineEdit); |
| 6860 | filter_hbox->add_child(param_filter); |
| 6861 | param_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_param_filter_changed)); |
| 6862 | param_filter->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6863 | param_filter->set_placeholder(TTR("Filter Parameters")); |
| 6864 | |
| 6865 | preview_tools = memnew(MenuButton); |
| 6866 | filter_hbox->add_child(preview_tools); |
| 6867 | preview_tools->set_tooltip_text(TTR("Options")); |
| 6868 | preview_tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_preview_tools_menu_option)); |
| 6869 | preview_tools->get_popup()->add_item(TTR("Copy Parameters From Material"), COPY_PARAMS_FROM_MATERIAL); |
| 6870 | preview_tools->get_popup()->add_item(TTR("Paste Parameters To Material"), PASTE_PARAMS_TO_MATERIAL); |
| 6871 | |
| 6872 | ScrollContainer *sc = memnew(ScrollContainer); |
| 6873 | sc->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6874 | params_vbox->add_child(sc); |
| 6875 | |
| 6876 | parameters = memnew(Tree); |
| 6877 | parameters->set_hide_root(true); |
| 6878 | parameters->set_allow_reselect(true); |
| 6879 | parameters->set_hide_folding(false); |
| 6880 | parameters->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6881 | parameters->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6882 | parameters->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 6883 | parameters->set_theme_type_variation("TreeSecondary"); |
| 6884 | parameters->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_param_selected)); |
| 6885 | parameters->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_param_unselected)); |
| 6886 | sc->add_child(parameters); |
| 6887 | |
| 6888 | param_vbox = memnew(VBoxContainer); |
| 6889 | param_vbox->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6890 | param_vbox->hide(); |
| 6891 | params_vbox->add_child(param_vbox); |
| 6892 | |
| 6893 | ScrollContainer *sc2 = memnew(ScrollContainer); |
| 6894 | sc2->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6895 | param_vbox->add_child(sc2); |
| 6896 | |
| 6897 | param_vbox2 = memnew(VBoxContainer); |
| 6898 | param_vbox2->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6899 | sc2->add_child(param_vbox2); |
| 6900 | |
| 6901 | /////////////////////////////////////// |
| 6902 | // SHADER NODES TREE |
| 6903 | /////////////////////////////////////// |
| 6904 | |
| 6905 | VBoxContainer *members_vb = memnew(VBoxContainer); |
| 6906 | members_vb->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6907 | |
| 6908 | HBoxContainer *filter_hb = memnew(HBoxContainer); |
| 6909 | members_vb->add_child(filter_hb); |
| 6910 | |
| 6911 | node_filter = memnew(LineEdit); |
| 6912 | filter_hb->add_child(node_filter); |
| 6913 | node_filter->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_member_filter_changed)); |
| 6914 | node_filter->connect(SceneStringName(gui_input), callable_mp(this, &VisualShaderEditor::_sbox_input)); |
| 6915 | node_filter->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6916 | node_filter->set_placeholder(TTR("Search")); |
| 6917 | |
| 6918 | tools = memnew(MenuButton); |
| 6919 | filter_hb->add_child(tools); |
| 6920 | tools->set_tooltip_text(TTR("Options")); |
| 6921 | tools->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VisualShaderEditor::_tools_menu_option)); |
| 6922 | tools->get_popup()->add_item(TTR("Expand All"), EXPAND_ALL); |
| 6923 | tools->get_popup()->add_item(TTR("Collapse All"), COLLAPSE_ALL); |
| 6924 | |
| 6925 | members = memnew(Tree); |
| 6926 | members_vb->add_child(members); |
| 6927 | SET_DRAG_FORWARDING_GCD(members, VisualShaderEditor); |
| 6928 | members->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. |
| 6929 | members->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6930 | members->set_v_size_flags(SIZE_EXPAND_FILL); |
| 6931 | members->set_hide_root(true); |
| 6932 | members->set_allow_reselect(true); |
| 6933 | members->set_hide_folding(false); |
| 6934 | members->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE)); |
| 6935 | members->connect("item_activated", callable_mp(this, &VisualShaderEditor::_member_create)); |
| 6936 | members->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_member_selected)); |
| 6937 | |
| 6938 | HBoxContainer *desc_hbox = memnew(HBoxContainer); |
| 6939 | members_vb->add_child(desc_hbox); |
| 6940 | |
| 6941 | Label *desc_label = memnew(Label); |
| 6942 | desc_hbox->add_child(desc_label); |
| 6943 | desc_label->set_text(TTR("Description:")); |
| 6944 | |
| 6945 | desc_hbox->add_spacer(); |
| 6946 | |
| 6947 | highend_label = memnew(Label); |
| 6948 | highend_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 6949 | desc_hbox->add_child(highend_label); |
| 6950 | highend_label->set_visible(false); |
| 6951 | highend_label->set_text(TTRC("Forward+/Mobile")); |
| 6952 | highend_label->set_mouse_filter(Control::MOUSE_FILTER_STOP); |
| 6953 | highend_label->set_tooltip_text(TTR("Only supported in the Forward+ and Mobile rendering methods, not Compatibility.")); |
| 6954 | |
| 6955 | node_desc = memnew(RichTextLabel); |
| 6956 | members_vb->add_child(node_desc); |
| 6957 | node_desc->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6958 | node_desc->set_v_size_flags(SIZE_FILL); |
| 6959 | node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE)); |
| 6960 | |
| 6961 | members_dialog = memnew(ConfirmationDialog); |
| 6962 | members_dialog->set_title(TTR("Create Shader Node")); |
| 6963 | members_dialog->add_child(members_vb); |
| 6964 | members_dialog->set_ok_button_text(TTR("Create")); |
| 6965 | members_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_member_create)); |
| 6966 | members_dialog->get_ok_button()->set_disabled(true); |
| 6967 | members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel)); |
| 6968 | members_dialog->register_text_enter(node_filter); |
| 6969 | add_child(members_dialog); |
| 6970 | |
| 6971 | // add varyings dialog |
| 6972 | { |
| 6973 | add_varying_dialog = memnew(ConfirmationDialog); |
| 6974 | add_varying_dialog->set_title(TTR("Create Shader Varying")); |
| 6975 | add_varying_dialog->set_ok_button_text(TTR("Create")); |
| 6976 | add_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_create)); |
| 6977 | add_varying_dialog->get_ok_button()->set_disabled(true); |
| 6978 | add_child(add_varying_dialog); |
| 6979 | |
| 6980 | VBoxContainer *vb = memnew(VBoxContainer); |
| 6981 | add_varying_dialog->add_child(vb); |
| 6982 | |
| 6983 | HBoxContainer *hb = memnew(HBoxContainer); |
| 6984 | vb->add_child(hb); |
| 6985 | hb->set_h_size_flags(SIZE_EXPAND_FILL); |
| 6986 | |
| 6987 | varying_type = memnew(OptionButton); |
| 6988 | hb->add_child(varying_type); |
| 6989 | varying_type->add_item("Float"); |
| 6990 | varying_type->add_item("Int"); |
| 6991 | varying_type->add_item("UInt"); |
| 6992 | varying_type->add_item("Vector2"); |
| 6993 | varying_type->add_item("Vector3"); |
| 6994 | varying_type->add_item("Vector4"); |
| 6995 | varying_type->add_item("Boolean"); |
| 6996 | varying_type->add_item("Transform"); |
| 6997 | varying_type->set_accessibility_name(TTRC("Varying Type")); |
| 6998 | varying_type->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_type_changed)); |
| 6999 | |
| 7000 | varying_name = memnew(LineEdit); |
| 7001 | hb->add_child(varying_name); |
| 7002 | varying_name->set_custom_minimum_size(Size2(150 * EDSCALE, 0)); |
| 7003 | varying_name->set_h_size_flags(SIZE_EXPAND_FILL); |
| 7004 | varying_name->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_varying_name_changed)); |
| 7005 | add_varying_dialog->register_text_enter(varying_name); |
| 7006 | |
| 7007 | varying_mode = memnew(OptionButton); |
| 7008 | hb->add_child(varying_mode); |
| 7009 | varying_mode->add_item(U"Vertex → [Fragment, Light]"); |
| 7010 | varying_mode->add_item(U"Fragment → Light"); |
| 7011 | varying_mode->set_accessibility_name(TTRC("Varying Mode")); |
| 7012 | varying_mode->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_mode_changed)); |
| 7013 | |
| 7014 | varying_error_label = memnew(Label); |
| 7015 | varying_error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 7016 | vb->add_child(varying_error_label); |
| 7017 | varying_error_label->set_h_size_flags(SIZE_EXPAND_FILL); |
| 7018 | |
| 7019 | varying_error_label->hide(); |
| 7020 | } |
| 7021 | |
| 7022 | // remove varying dialog |
| 7023 | { |
| 7024 | remove_varying_dialog = memnew(ConfirmationDialog); |
| 7025 | remove_varying_dialog->set_title(TTR("Delete Shader Varying")); |
| 7026 | remove_varying_dialog->set_ok_button_text(TTR("Delete")); |
| 7027 | remove_varying_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_varying_deleted)); |
| 7028 | add_child(remove_varying_dialog); |
| 7029 | |
| 7030 | VBoxContainer *vb = memnew(VBoxContainer); |
| 7031 | remove_varying_dialog->add_child(vb); |
| 7032 | |
| 7033 | varyings = memnew(Tree); |
| 7034 | vb->add_child(varyings); |
| 7035 | varyings->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 7036 | varyings->set_h_size_flags(SIZE_EXPAND_FILL); |
| 7037 | varyings->set_v_size_flags(SIZE_EXPAND_FILL); |
| 7038 | varyings->set_hide_root(true); |
| 7039 | varyings->set_allow_reselect(true); |
| 7040 | varyings->set_hide_folding(false); |
| 7041 | varyings->set_custom_minimum_size(Size2(180 * EDSCALE, 200 * EDSCALE)); |
| 7042 | varyings->connect("item_activated", callable_mp(this, &VisualShaderEditor::_varying_deleted)); |
| 7043 | varyings->connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderEditor::_varying_selected)); |
| 7044 | varyings->connect("nothing_selected", callable_mp(this, &VisualShaderEditor::_varying_unselected)); |
| 7045 | } |
| 7046 | |
| 7047 | alert = memnew(AcceptDialog); |
| 7048 | alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD); |
| 7049 | alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 7050 | alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); |
| 7051 | alert->get_label()->set_custom_minimum_size(Size2(400, 60) * EDSCALE); |
| 7052 | add_child(alert); |
| 7053 | |
| 7054 | frame_title_change_popup = memnew(PopupPanel); |
| 7055 | frame_title_change_edit = memnew(LineEdit); |
| 7056 | frame_title_change_edit->set_expand_to_text_length_enabled(true); |
| 7057 | frame_title_change_edit->set_select_all_on_focus(true); |
| 7058 | frame_title_change_edit->connect(SceneStringName(text_changed), callable_mp(this, &VisualShaderEditor::_frame_title_text_changed)); |
| 7059 | frame_title_change_edit->connect(SceneStringName(text_submitted), callable_mp(this, &VisualShaderEditor::_frame_title_text_submitted)); |
| 7060 | frame_title_change_popup->add_child(frame_title_change_edit); |
| 7061 | frame_title_change_edit->reset_size(); |
| 7062 | frame_title_change_popup->reset_size(); |
| 7063 | frame_title_change_popup->connect(SceneStringName(focus_exited), callable_mp(this, &VisualShaderEditor::_frame_title_popup_focus_out)); |
| 7064 | frame_title_change_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_title_popup_hide)); |
| 7065 | add_child(frame_title_change_popup); |
| 7066 | |
| 7067 | frame_tint_color_pick_popup = memnew(PopupPanel); |
| 7068 | VBoxContainer *frame_popup_item_tint_color_editor = memnew(VBoxContainer); |
| 7069 | frame_tint_color_pick_popup->add_child(frame_popup_item_tint_color_editor); |
| 7070 | frame_tint_color_picker = memnew(ColorPicker); |
| 7071 | frame_popup_item_tint_color_editor->add_child(frame_tint_color_picker); |
| 7072 | frame_tint_color_picker->reset_size(); |
| 7073 | frame_tint_color_picker->connect("color_changed", callable_mp(this, &VisualShaderEditor::_frame_color_changed)); |
| 7074 | Button *frame_tint_color_confirm_button = memnew(Button); |
| 7075 | frame_tint_color_confirm_button->set_text(TTR("OK")); |
| 7076 | frame_popup_item_tint_color_editor->add_child(frame_tint_color_confirm_button); |
| 7077 | frame_tint_color_confirm_button->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_frame_color_confirm)); |
| 7078 | |
| 7079 | frame_tint_color_pick_popup->connect("popup_hide", callable_mp(this, &VisualShaderEditor::_frame_color_popup_hide)); |
| 7080 | add_child(frame_tint_color_pick_popup); |
| 7081 | |
| 7082 | /////////////////////////////////////// |
| 7083 | // SHADER NODES TREE OPTIONS |
| 7084 | /////////////////////////////////////// |
| 7085 | |
| 7086 | // COLOR |
| 7087 | |
| 7088 | add_options.push_back(AddOption("ColorFunc", "Color/Common", "VisualShaderNodeColorFunc", TTR("Color function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7089 | add_options.push_back(AddOption("ColorOp", "Color/Common", "VisualShaderNodeColorOp", TTR("Color operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7090 | |
| 7091 | add_options.push_back(AddOption("Grayscale", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Grayscale function."), { VisualShaderNodeColorFunc::FUNC_GRAYSCALE }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7092 | add_options.push_back(AddOption("HSV2RGB", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts HSV vector to RGB equivalent."), { VisualShaderNodeColorFunc::FUNC_HSV2RGB, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7093 | add_options.push_back(AddOption("LinearToSRGB", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts color from linear to sRGB color space."), { VisualShaderNodeColorFunc::FUNC_LINEAR_TO_SRGB }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7094 | add_options.push_back(AddOption("RGB2HSV", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts RGB vector to HSV equivalent."), { VisualShaderNodeColorFunc::FUNC_RGB2HSV, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7095 | add_options.push_back(AddOption("Sepia", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Sepia function."), { VisualShaderNodeColorFunc::FUNC_SEPIA }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7096 | add_options.push_back(AddOption("SRGBToLinear", "Color/Functions", "VisualShaderNodeColorFunc", TTR("Converts color from sRGB to linear color space."), { VisualShaderNodeColorFunc::FUNC_SRGB_TO_LINEAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7097 | |
| 7098 | add_options.push_back(AddOption("Burn", "Color/Operators", "VisualShaderNodeColorOp", TTR("Burn operator."), { VisualShaderNodeColorOp::OP_BURN }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7099 | add_options.push_back(AddOption("Darken", "Color/Operators", "VisualShaderNodeColorOp", TTR("Darken operator."), { VisualShaderNodeColorOp::OP_DARKEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7100 | add_options.push_back(AddOption("Difference", "Color/Operators", "VisualShaderNodeColorOp", TTR("Difference operator."), { VisualShaderNodeColorOp::OP_DIFFERENCE }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7101 | add_options.push_back(AddOption("Dodge", "Color/Operators", "VisualShaderNodeColorOp", TTR("Dodge operator."), { VisualShaderNodeColorOp::OP_DODGE }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7102 | add_options.push_back(AddOption("HardLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("HardLight operator."), { VisualShaderNodeColorOp::OP_HARD_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7103 | add_options.push_back(AddOption("Lighten", "Color/Operators", "VisualShaderNodeColorOp", TTR("Lighten operator."), { VisualShaderNodeColorOp::OP_LIGHTEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7104 | add_options.push_back(AddOption("Overlay", "Color/Operators", "VisualShaderNodeColorOp", TTR("Overlay operator."), { VisualShaderNodeColorOp::OP_OVERLAY }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7105 | add_options.push_back(AddOption("Screen", "Color/Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), { VisualShaderNodeColorOp::OP_SCREEN }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7106 | add_options.push_back(AddOption("SoftLight", "Color/Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), { VisualShaderNodeColorOp::OP_SOFT_LIGHT }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7107 | |
| 7108 | add_options.push_back(AddOption("ColorConstant", "Color/Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7109 | add_options.push_back(AddOption("ColorParameter", "Color/Variables", "VisualShaderNodeColorParameter", TTR("Color parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7110 | |
| 7111 | // COMMON |
| 7112 | |
| 7113 | add_options.push_back(AddOption("DerivativeFunc", "Common", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) Derivative function."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7114 | add_options.push_back(AddOption("DerivativeFunc", "Common", "VisualShaderNodeDerivativeFunc", TTR("Derivative function."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7115 | |
| 7116 | // CONDITIONAL |
| 7117 | |
| 7118 | const String &compare_func_desc = TTR("Returns the boolean result of the %s comparison between two parameters."); |
| 7119 | |
| 7120 | add_options.push_back(AddOption("Equal (==)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Equal (==)")), { VisualShaderNodeCompare::FUNC_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7121 | add_options.push_back(AddOption("GreaterThan (>)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7122 | add_options.push_back(AddOption("GreaterThanEqual (>=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than or Equal (>=)")), { VisualShaderNodeCompare::FUNC_GREATER_THAN_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7123 | add_options.push_back(AddOption("If", "Conditional/Functions", "VisualShaderNodeIf", TTR("Returns an associated vector if the provided scalars are equal, greater or less."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7124 | add_options.push_back(AddOption("IsInf", "Conditional/Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF and a scalar parameter."), { VisualShaderNodeIs::FUNC_IS_INF }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7125 | add_options.push_back(AddOption("IsNaN", "Conditional/Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between NaN and a scalar parameter."), { VisualShaderNodeIs::FUNC_IS_NAN }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7126 | add_options.push_back(AddOption("LessThan (<)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), { VisualShaderNodeCompare::FUNC_LESS_THAN }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7127 | add_options.push_back(AddOption("LessThanEqual (<=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than or Equal (<=)")), { VisualShaderNodeCompare::FUNC_LESS_THAN_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7128 | add_options.push_back(AddOption("NotEqual (!=)", "Conditional/Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), { VisualShaderNodeCompare::FUNC_NOT_EQUAL }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7129 | add_options.push_back(AddOption("SwitchVector2D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 2D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7130 | add_options.push_back(AddOption("SwitchVector3D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 3D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7131 | add_options.push_back(AddOption("SwitchVector4D (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated 4D vector if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7132 | add_options.push_back(AddOption("SwitchBool (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated boolean if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_BOOLEAN }, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7133 | add_options.push_back(AddOption("SwitchFloat (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated floating-point scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7134 | add_options.push_back(AddOption("SwitchInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7135 | add_options.push_back(AddOption("SwitchTransform (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated transform if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_TRANSFORM }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7136 | add_options.push_back(AddOption("SwitchUInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated unsigned integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7137 | |
| 7138 | add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7139 | add_options.push_back(AddOption("Is", "Conditional/Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7140 | |
| 7141 | add_options.push_back(AddOption("BooleanConstant", "Conditional/Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7142 | add_options.push_back(AddOption("BooleanParameter", "Conditional/Variables", "VisualShaderNodeBooleanParameter", TTR("Boolean parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); |
| 7143 | |
| 7144 | // INPUT |
| 7145 | |
| 7146 | const String translation_gdsl = "\n\n" + TTR("Translated to '%s' in Godot Shading Language."); |
| 7147 | const String input_param_shader_modes = TTR("'%s' input parameter for all shader modes.") + translation_gdsl; |
| 7148 | |
| 7149 | // NODE3D-FOR-ALL |
| 7150 | |
| 7151 | add_options.push_back(AddOption("ClipSpaceFar", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "clip_space_far", "CLIP_SPACE_FAR"), { "clip_space_far" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); |
| 7152 | add_options.push_back(AddOption("Exposure", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "exposure", "EXPOSURE"), { "exposure" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); |
| 7153 | add_options.push_back(AddOption("InvProjectionMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_projection_matrix", "INV_PROJECTION_MATRIX"), { "inv_projection_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); |
| 7154 | add_options.push_back(AddOption("InvViewMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_view_matrix", "INV_VIEW_MATRIX"), { "inv_view_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); |
| 7155 | add_options.push_back(AddOption("ModelMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "model_matrix", "MODEL_MATRIX"), { "model_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); |
| 7156 | add_options.push_back(AddOption("Normal", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "normal", "NORMAL"), { "normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_SPATIAL)); |
| 7157 | add_options.push_back(AddOption("OutputIsSRGB", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "output_is_srgb", "OUTPUT_IS_SRGB"), { "output_is_srgb" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_SPATIAL)); |
| 7158 | add_options.push_back(AddOption("ProjectionMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "projection_matrix", "PROJECTION_MATRIX"), { "projection_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); |
| 7159 | add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); |
| 7160 | add_options.push_back(AddOption("UV", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv", "UV"), { "uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL)); |
| 7161 | add_options.push_back(AddOption("UV2", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv2", "UV2"), { "uv2" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL)); |
| 7162 | add_options.push_back(AddOption("ViewMatrix", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "view_matrix", "VIEW_MATRIX"), { "view_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); |
| 7163 | add_options.push_back(AddOption("ViewportSize", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "viewport_size", "VIEWPORT_SIZE"), { "viewport_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_SPATIAL)); |
| 7164 | |
| 7165 | // CANVASITEM-FOR-ALL |
| 7166 | |
| 7167 | add_options.push_back(AddOption("Color", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_CANVAS_ITEM)); |
| 7168 | add_options.push_back(AddOption("TexturePixelSize", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "texture_pixel_size", "TEXTURE_PIXEL_SIZE"), { "texture_pixel_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_CANVAS_ITEM)); |
| 7169 | add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_CANVAS_ITEM)); |
| 7170 | add_options.push_back(AddOption("UV", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "uv", "UV"), { "uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, -1, Shader::MODE_CANVAS_ITEM)); |
| 7171 | |
| 7172 | // PARTICLES-FOR-ALL |
| 7173 | |
| 7174 | add_options.push_back(AddOption("Active", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "active", "ACTIVE"), { "active" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_PARTICLES)); |
| 7175 | add_options.push_back(AddOption("AttractorForce", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "attractor_force", "ATTRACTOR_FORCE"), { "attractor_force" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_PARTICLES)); |
| 7176 | add_options.push_back(AddOption("Color", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_PARTICLES)); |
| 7177 | add_options.push_back(AddOption("Custom", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom", "CUSTOM"), { "custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_PARTICLES)); |
| 7178 | add_options.push_back(AddOption("Delta", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta", "DELTA"), { "delta" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); |
| 7179 | add_options.push_back(AddOption("EmissionTransform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform", "EMISSION_TRANSFORM"), { "emission_transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES)); |
| 7180 | add_options.push_back(AddOption("Index", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index", "INDEX"), { "index" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); |
| 7181 | add_options.push_back(AddOption("LifeTime", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime", "LIFETIME"), { "lifetime" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); |
| 7182 | add_options.push_back(AddOption("Number", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "number", "NUMBER"), { "number" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); |
| 7183 | add_options.push_back(AddOption("RandomSeed", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "random_seed", "RANDOM_SEED"), { "random_seed" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); |
| 7184 | add_options.push_back(AddOption("Restart", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart", "RESTART"), { "restart" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_PARTICLES)); |
| 7185 | add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); |
| 7186 | add_options.push_back(AddOption("Transform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform", "TRANSFORM"), { "transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES)); |
| 7187 | add_options.push_back(AddOption("Velocity", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "velocity", "VELOCITY"), { "velocity" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, -1, Shader::MODE_PARTICLES)); |
| 7188 | |
| 7189 | ///////////////// |
| 7190 | |
| 7191 | add_options.push_back(AddOption("Input", "Input/Common", "VisualShaderNodeInput", TTR("Input parameter."))); |
| 7192 | |
| 7193 | const String input_param_for_vertex_and_fragment_shader_modes = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl; |
| 7194 | const String input_param_for_fragment_and_light_shader_modes = TTR("'%s' input parameter for fragment and light shader modes.") + translation_gdsl; |
| 7195 | const String input_param_for_fragment_shader_mode = TTR("'%s' input parameter for fragment shader mode.") + translation_gdsl; |
| 7196 | const String input_param_for_sky_shader_mode = TTR("'%s' input parameter for sky shader mode.") + translation_gdsl; |
| 7197 | const String input_param_for_fog_shader_mode = TTR("'%s' input parameter for fog shader mode.") + translation_gdsl; |
| 7198 | const String input_param_for_light_shader_mode = TTR("'%s' input parameter for light shader mode.") + translation_gdsl; |
| 7199 | const String input_param_for_vertex_shader_mode = TTR("'%s' input parameter for vertex shader mode.") + translation_gdsl; |
| 7200 | const String input_param_for_start_shader_mode = TTR("'%s' input parameter for start shader mode.") + translation_gdsl; |
| 7201 | const String input_param_for_process_shader_mode = TTR("'%s' input parameter for process shader mode.") + translation_gdsl; |
| 7202 | const String input_param_for_collide_shader_mode = TTR("'%s' input parameter for collide shader mode." + translation_gdsl); |
| 7203 | const String input_param_for_start_and_process_shader_mode = TTR("'%s' input parameter for start and process shader modes.") + translation_gdsl; |
| 7204 | const String input_param_for_process_and_collide_shader_mode = TTR("'%s' input parameter for process and collide shader modes.") + translation_gdsl; |
| 7205 | const String input_param_for_vertex_and_fragment_shader_mode = TTR("'%s' input parameter for vertex and fragment shader modes.") + translation_gdsl; |
| 7206 | |
| 7207 | // NODE3D INPUTS |
| 7208 | |
| 7209 | add_options.push_back(AddOption("Binormal", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal", "BINORMAL"), { "binormal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7210 | add_options.push_back(AddOption("CameraDirectionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7211 | add_options.push_back(AddOption("CameraPositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7212 | add_options.push_back(AddOption("CameraVisibleLayers", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7213 | add_options.push_back(AddOption("Color", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7214 | add_options.push_back(AddOption("Custom0", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom0", "CUSTOM0"), { "custom0" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7215 | add_options.push_back(AddOption("Custom1", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom1", "CUSTOM1"), { "custom1" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7216 | add_options.push_back(AddOption("Custom2", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom2", "CUSTOM2"), { "custom2" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7217 | add_options.push_back(AddOption("Custom3", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom3", "CUSTOM3"), { "custom3" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7218 | add_options.push_back(AddOption("EyeOffset", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "eye_offset", "EYE_OFFSET"), { "eye_offset" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7219 | add_options.push_back(AddOption("InstanceCustom", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_custom", "INSTANCE_CUSTOM"), { "instance_custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7220 | add_options.push_back(AddOption("InstanceId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_id", "INSTANCE_ID"), { "instance_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7221 | add_options.push_back(AddOption("ModelViewMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "modelview_matrix", "MODELVIEW_MATRIX"), { "modelview_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7222 | add_options.push_back(AddOption("NodePositionView", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7223 | add_options.push_back(AddOption("NodePositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7224 | add_options.push_back(AddOption("PointSize", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size", "POINT_SIZE"), { "point_size" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7225 | add_options.push_back(AddOption("Tangent", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "tangent", "TANGENT"), { "tangent" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7226 | add_options.push_back(AddOption("Vertex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7227 | add_options.push_back(AddOption("VertexId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "vertex_id", "VERTEX_ID"), { "vertex_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7228 | add_options.push_back(AddOption("ViewIndex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_index", "VIEW_INDEX"), { "view_index" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7229 | add_options.push_back(AddOption("ViewMonoLeft", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_mono_left", "VIEW_MONO_LEFT"), { "view_mono_left" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7230 | add_options.push_back(AddOption("ViewRight", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_right", "VIEW_RIGHT"), { "view_right" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7231 | |
| 7232 | add_options.push_back(AddOption("Binormal", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal", "BINORMAL"), { "binormal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7233 | add_options.push_back(AddOption("CameraDirectionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7234 | add_options.push_back(AddOption("CameraPositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7235 | add_options.push_back(AddOption("CameraVisibleLayers", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7236 | add_options.push_back(AddOption("Color", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color", "COLOR"), { "color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7237 | add_options.push_back(AddOption("EyeOffset", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "eye_offset", "EYE_OFFSET"), { "eye_offset" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7238 | add_options.push_back(AddOption("FragCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7239 | add_options.push_back(AddOption("FrontFacing", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "front_facing", "FRONT_FACING"), { "front_facing" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7240 | add_options.push_back(AddOption("NodePositionView", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7241 | add_options.push_back(AddOption("NodePositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7242 | add_options.push_back(AddOption("PointCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7243 | add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7244 | add_options.push_back(AddOption("Tangent", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "tangent", "TANGENT"), { "tangent" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7245 | add_options.push_back(AddOption("Vertex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7246 | add_options.push_back(AddOption("View", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view", "VIEW"), { "view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7247 | add_options.push_back(AddOption("ViewIndex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_index", "VIEW_INDEX"), { "view_index" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7248 | add_options.push_back(AddOption("ViewMonoLeft", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_mono_left", "VIEW_MONO_LEFT"), { "view_mono_left" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7249 | add_options.push_back(AddOption("ViewRight", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "view_right", "VIEW_RIGHT"), { "view_right" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7250 | |
| 7251 | add_options.push_back(AddOption("Albedo", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "albedo", "ALBEDO"), { "albedo" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7252 | add_options.push_back(AddOption("Attenuation", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "attenuation", "ATTENUATION"), { "attenuation" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7253 | add_options.push_back(AddOption("Backlight", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "backlight", "BACKLIGHT"), { "backlight" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7254 | add_options.push_back(AddOption("Diffuse", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "diffuse", "DIFFUSE_LIGHT"), { "diffuse" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7255 | add_options.push_back(AddOption("FragCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7256 | add_options.push_back(AddOption("Light", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light", "LIGHT"), { "light" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7257 | add_options.push_back(AddOption("LightColor", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color", "LIGHT_COLOR"), { "light_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7258 | add_options.push_back(AddOption("LightIsDirectional", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_is_directional", "LIGHT_IS_DIRECTIONAL"), { "light_is_directional" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7259 | add_options.push_back(AddOption("Metallic", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "metallic", "METALLIC"), { "metallic" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7260 | add_options.push_back(AddOption("Roughness", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "roughness", "ROUGHNESS"), { "roughness" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7261 | add_options.push_back(AddOption("ScreenUV", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7262 | add_options.push_back(AddOption("Specular", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "specular", "SPECULAR_LIGHT"), { "specular" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7263 | add_options.push_back(AddOption("View", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "view", "VIEW"), { "view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7264 | |
| 7265 | // CANVASITEM INPUTS |
| 7266 | |
| 7267 | add_options.push_back(AddOption("AtLightPass", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "at_light_pass", "AT_LIGHT_PASS"), { "at_light_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7268 | add_options.push_back(AddOption("CanvasMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "canvas_matrix", "CANVAS_MATRIX"), { "canvas_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7269 | add_options.push_back(AddOption("Custom0", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom0", "CUSTOM0"), { "custom0" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7270 | add_options.push_back(AddOption("Custom1", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "custom1", "CUSTOM1"), { "custom1" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7271 | add_options.push_back(AddOption("InstanceCustom", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_custom", "INSTANCE_CUSTOM"), { "instance_custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7272 | add_options.push_back(AddOption("InstanceId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "instance_id", "INSTANCE_ID"), { "instance_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7273 | add_options.push_back(AddOption("ModelMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "model_matrix", "MODEL_MATRIX"), { "model_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7274 | add_options.push_back(AddOption("PointSize", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "point_size", "POINT_SIZE"), { "point_size" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7275 | add_options.push_back(AddOption("ScreenMatrix", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "screen_matrix", "SCREEN_MATRIX"), { "screen_matrix" }, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7276 | add_options.push_back(AddOption("Vertex", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7277 | add_options.push_back(AddOption("VertexId", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_shader_mode, "vertex_id", "VERTEX_ID"), { "vertex_id" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_CANVAS_ITEM)); |
| 7278 | |
| 7279 | add_options.push_back(AddOption("AtLightPass", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "at_light_pass", "AT_LIGHT_PASS"), { "at_light_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7280 | add_options.push_back(AddOption("FragCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7281 | add_options.push_back(AddOption("NormalTexture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "normal_texture", "NORMAL_TEXTURE"), { "normal_texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7282 | add_options.push_back(AddOption("PointCoord", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7283 | add_options.push_back(AddOption("RegionRect", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "region_rect", "REGION_RECT"), { "region_rect" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7284 | add_options.push_back(AddOption("ScreenPixelSize", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_pixel_size", "SCREEN_PIXEL_SIZE"), { "screen_pixel_size" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7285 | add_options.push_back(AddOption("ScreenUV", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7286 | add_options.push_back(AddOption("SpecularShininess", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "specular_shininess", "SPECULAR_SHININESS"), { "specular_shininess" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7287 | add_options.push_back(AddOption("SpecularShininessTexture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "specular_shininess_texture", "SPECULAR_SHININESS_TEXTURE"), { "specular_shininess_texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7288 | add_options.push_back(AddOption("Texture", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture", "TEXTURE"), { "texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7289 | add_options.push_back(AddOption("Vertex", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_mode, "vertex", "VERTEX"), { "vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7290 | |
| 7291 | add_options.push_back(AddOption("FragCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7292 | add_options.push_back(AddOption("Light", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light", "LIGHT"), { "light" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7293 | add_options.push_back(AddOption("LightColor", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color", "LIGHT_COLOR"), { "light_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7294 | add_options.push_back(AddOption("LightDirection", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_direction", "LIGHT_DIRECTION"), { "light_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7295 | add_options.push_back(AddOption("LightEnergy", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_energy", "LIGHT_ENERGY"), { "light_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7296 | add_options.push_back(AddOption("LightIsDirectional", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_is_directional", "LIGHT_IS_DIRECTIONAL"), { "light_is_directional" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7297 | add_options.push_back(AddOption("LightPosition", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_position", "LIGHT_POSITION"), { "light_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7298 | add_options.push_back(AddOption("LightVertex", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "light_vertex", "LIGHT_VERTEX"), { "light_vertex" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7299 | add_options.push_back(AddOption("Normal", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "normal", "NORMAL"), { "normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7300 | add_options.push_back(AddOption("PointCoord", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "point_coord", "POINT_COORD"), { "point_coord" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7301 | add_options.push_back(AddOption("ScreenUV", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7302 | add_options.push_back(AddOption("Shadow", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "shadow", "SHADOW_MODULATE"), { "shadow" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7303 | add_options.push_back(AddOption("SpecularShininess", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "specular_shininess", "SPECULAR_SHININESS"), { "specular_shininess" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7304 | add_options.push_back(AddOption("Texture", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "texture", "TEXTURE"), { "texture" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7305 | |
| 7306 | // SKY INPUTS |
| 7307 | |
| 7308 | add_options.push_back(AddOption("AtCubeMapPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_cubemap_pass", "AT_CUBEMAP_PASS"), { "at_cubemap_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7309 | add_options.push_back(AddOption("AtHalfResPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_half_res_pass", "AT_HALF_RES_PASS"), { "at_half_res_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7310 | add_options.push_back(AddOption("AtQuarterResPass", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "at_quarter_res_pass", "AT_QUARTER_RES_PASS"), { "at_quarter_res_pass" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7311 | add_options.push_back(AddOption("EyeDir", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "eyedir", "EYEDIR"), { "eyedir" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7312 | add_options.push_back(AddOption("FragCoord", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "fragcoord", "FRAGCOORD"), { "fragcoord" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7313 | add_options.push_back(AddOption("HalfResColor", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "half_res_color", "HALF_RES_COLOR"), { "half_res_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7314 | add_options.push_back(AddOption("Light0Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_color", "LIGHT0_COLOR"), { "light0_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7315 | add_options.push_back(AddOption("Light0Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_direction", "LIGHT0_DIRECTION"), { "light0_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7316 | add_options.push_back(AddOption("Light0Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_enabled", "LIGHT0_ENABLED"), { "light0_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7317 | add_options.push_back(AddOption("Light0Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light0_energy", "LIGHT0_ENERGY"), { "light0_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7318 | add_options.push_back(AddOption("Light1Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_color", "LIGHT1_COLOR"), { "light1_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7319 | add_options.push_back(AddOption("Light1Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_direction", "LIGHT1_DIRECTION"), { "light1_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7320 | add_options.push_back(AddOption("Light1Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_enabled", "LIGHT1_ENABLED"), { "light1_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7321 | add_options.push_back(AddOption("Light1Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light1_energy", "LIGHT1_ENERGY"), { "light1_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7322 | add_options.push_back(AddOption("Light2Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_color", "LIGHT2_COLOR"), { "light2_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7323 | add_options.push_back(AddOption("Light2Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_direction", "LIGHT2_DIRECTION"), { "light2_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7324 | add_options.push_back(AddOption("Light2Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_enabled", "LIGHT2_ENABLED"), { "light2_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7325 | add_options.push_back(AddOption("Light2Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light2_energy", "LIGHT2_ENERGY"), { "light2_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7326 | add_options.push_back(AddOption("Light3Color", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_color", "LIGHT3_COLOR"), { "light3_color" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7327 | add_options.push_back(AddOption("Light3Direction", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_direction", "LIGHT3_DIRECTION"), { "light3_direction" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7328 | add_options.push_back(AddOption("Light3Enabled", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_enabled", "LIGHT3_ENABLED"), { "light3_enabled" }, VisualShaderNode::PORT_TYPE_BOOLEAN, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7329 | add_options.push_back(AddOption("Light3Energy", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "light3_energy", "LIGHT3_ENERGY"), { "light3_energy" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7330 | add_options.push_back(AddOption("Position", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "position", "POSITION"), { "position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7331 | add_options.push_back(AddOption("QuarterResColor", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "quarter_res_color", "QUARTER_RES_COLOR"), { "quarter_res_color" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7332 | add_options.push_back(AddOption("Radiance", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "radiance", "RADIANCE"), { "radiance" }, VisualShaderNode::PORT_TYPE_SAMPLER, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7333 | add_options.push_back(AddOption("ScreenUV", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "screen_uv", "SCREEN_UV"), { "screen_uv" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7334 | add_options.push_back(AddOption("SkyCoords", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "sky_coords", "SKY_COORDS"), { "sky_coords" }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7335 | add_options.push_back(AddOption("Time", "Input/Sky", "VisualShaderNodeInput", vformat(input_param_for_sky_shader_mode, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY)); |
| 7336 | |
| 7337 | // FOG INPUTS |
| 7338 | |
| 7339 | add_options.push_back(AddOption("ObjectPosition", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "object_position", "OBJECT_POSITION"), { "object_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7340 | add_options.push_back(AddOption("SDF", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "sdf", "SDF"), { "sdf" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7341 | add_options.push_back(AddOption("Size", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "size", "SIZE"), { "size" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7342 | add_options.push_back(AddOption("Time", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7343 | add_options.push_back(AddOption("UVW", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "uvw", "UVW"), { "uvw" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7344 | add_options.push_back(AddOption("WorldPosition", "Input/Fog", "VisualShaderNodeInput", vformat(input_param_for_fog_shader_mode, "world_position", "WORLD_POSITION"), { "world_position" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FOG, Shader::MODE_FOG)); |
| 7345 | |
| 7346 | // PARTICLES INPUTS |
| 7347 | |
| 7348 | add_options.push_back(AddOption("CollisionDepth", "Input/Collide", "VisualShaderNodeInput", vformat(input_param_for_collide_shader_mode, "collision_depth", "COLLISION_DEPTH"), { "collision_depth" }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); |
| 7349 | add_options.push_back(AddOption("CollisionNormal", "Input/Collide", "VisualShaderNodeInput", vformat(input_param_for_collide_shader_mode, "collision_normal", "COLLISION_NORMAL"), { "collision_normal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); |
| 7350 | |
| 7351 | // PARTICLES |
| 7352 | |
| 7353 | add_options.push_back(AddOption("EmitParticle", "Particles", "VisualShaderNodeParticleEmit", "", {}, -1, TYPE_FLAGS_PROCESS | TYPE_FLAGS_PROCESS_CUSTOM | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); |
| 7354 | add_options.push_back(AddOption("ParticleAccelerator", "Particles", "VisualShaderNodeParticleAccelerator", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_PROCESS, Shader::MODE_PARTICLES)); |
| 7355 | add_options.push_back(AddOption("ParticleRandomness", "Particles", "VisualShaderNodeParticleRandomness", "", {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); |
| 7356 | add_options.push_back(AddOption("MultiplyByAxisAngle (*)", "Particles/Transform", "VisualShaderNodeParticleMultiplyByAxisAngle", TTR("A node for help to multiply a position input vector by rotation using specific axis. Intended to work with emitters."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES)); |
| 7357 | |
| 7358 | add_options.push_back(AddOption("BoxEmitter", "Particles/Emitters", "VisualShaderNodeParticleBoxEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES)); |
| 7359 | |
| 7360 | mesh_emitter_option_idx = add_options.size(); |
| 7361 | add_options.push_back(AddOption("MeshEmitter", "Particles/Emitters", "VisualShaderNodeParticleMeshEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES)); |
| 7362 | |
| 7363 | add_options.push_back(AddOption("RingEmitter", "Particles/Emitters", "VisualShaderNodeParticleRingEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES)); |
| 7364 | add_options.push_back(AddOption("SphereEmitter", "Particles/Emitters", "VisualShaderNodeParticleSphereEmitter", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES)); |
| 7365 | |
| 7366 | add_options.push_back(AddOption("ConeVelocity", "Particles/Velocity", "VisualShaderNodeParticleConeVelocity", "", {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES)); |
| 7367 | |
| 7368 | // SCALAR |
| 7369 | |
| 7370 | add_options.push_back(AddOption("FloatFunc", "Scalar/Common", "VisualShaderNodeFloatFunc", TTR("Float function."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7371 | add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7372 | add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7373 | add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7374 | add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7375 | add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7376 | |
| 7377 | // CONSTANTS |
| 7378 | |
| 7379 | for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { |
| 7380 | add_options.push_back(AddOption(float_constant_defs[i].name, "Scalar/Constants", "VisualShaderNodeFloatConstant", TTRGET(float_constant_defs[i].desc_key), { float_constant_defs[i].value }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7381 | } |
| 7382 | // FUNCTIONS |
| 7383 | |
| 7384 | add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7385 | add_options.push_back(AddOption("Abs", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeIntFunc::FUNC_ABS }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7386 | add_options.push_back(AddOption("ACos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOS }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7387 | add_options.push_back(AddOption("ACosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ACOSH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7388 | add_options.push_back(AddOption("ASin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASIN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7389 | add_options.push_back(AddOption("ASinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ASINH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7390 | add_options.push_back(AddOption("ATan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATAN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7391 | add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7392 | add_options.push_back(AddOption("ATanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATANH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7393 | add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the integer."), { VisualShaderNodeIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7394 | add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the unsigned integer."), { VisualShaderNodeUIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7395 | add_options.push_back(AddOption("Ceil", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeFloatFunc::FUNC_CEIL }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7396 | add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7397 | add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7398 | add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7399 | add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7400 | add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7401 | add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7402 | add_options.push_back(AddOption("DFdX", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7403 | add_options.push_back(AddOption("DFdY", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7404 | add_options.push_back(AddOption("DFdX", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7405 | add_options.push_back(AddOption("DFdY", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7406 | add_options.push_back(AddOption("Exp", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-e Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7407 | add_options.push_back(AddOption("Exp2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 Exponential."), { VisualShaderNodeFloatFunc::FUNC_EXP2 }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7408 | add_options.push_back(AddOption("Floor", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeFloatFunc::FUNC_FLOOR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7409 | add_options.push_back(AddOption("Fract", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeFloatFunc::FUNC_FRACT }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7410 | add_options.push_back(AddOption("InverseSqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_INVERSE_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7411 | add_options.push_back(AddOption("Log", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Natural logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7412 | add_options.push_back(AddOption("Log2", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), { VisualShaderNodeFloatFunc::FUNC_LOG2 }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7413 | add_options.push_back(AddOption("Max", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), { VisualShaderNodeFloatOp::OP_MAX }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7414 | add_options.push_back(AddOption("Min", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), { VisualShaderNodeFloatOp::OP_MIN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7415 | add_options.push_back(AddOption("Mix", "Scalar/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), { VisualShaderNodeMix::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7416 | add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Scalar/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on scalars."), { VisualShaderNodeMultiplyAdd::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7417 | add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7418 | add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7419 | add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeUIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7420 | add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7421 | add_options.push_back(AddOption("Pow", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the value of the first parameter raised to the power of the second."), { VisualShaderNodeFloatOp::OP_POW }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7422 | add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7423 | add_options.push_back(AddOption("Reciprocal", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 / scalar"), { VisualShaderNodeFloatFunc::FUNC_RECIPROCAL }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7424 | add_options.push_back(AddOption("Remap", "Scalar/Functions", "VisualShaderNodeRemap", TTR("Remaps a value from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7425 | add_options.push_back(AddOption("Round", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUND }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7426 | add_options.push_back(AddOption("RoundEven", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeFloatFunc::FUNC_ROUNDEVEN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7427 | add_options.push_back(AddOption("Saturate", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeFloatFunc::FUNC_SATURATE }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7428 | add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7429 | add_options.push_back(AddOption("Sign", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeIntFunc::FUNC_SIGN }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7430 | add_options.push_back(AddOption("Sin", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SIN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7431 | add_options.push_back(AddOption("SinH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SINH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7432 | add_options.push_back(AddOption("Sqrt", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeFloatFunc::FUNC_SQRT }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7433 | add_options.push_back(AddOption("SmoothStep", "Scalar/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7434 | add_options.push_back(AddOption("Step", "Scalar/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7435 | add_options.push_back(AddOption("Sum", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Scalar) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7436 | add_options.push_back(AddOption("Sum", "Scalar/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Scalar) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7437 | add_options.push_back(AddOption("Tan", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TAN }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7438 | add_options.push_back(AddOption("TanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TANH }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7439 | add_options.push_back(AddOption("Trunc", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_TRUNC }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7440 | |
| 7441 | add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7442 | add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7443 | add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7444 | add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7445 | add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7446 | add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7447 | add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7448 | add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7449 | add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7450 | add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7451 | add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the unsigned integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7452 | add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7453 | add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7454 | add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7455 | add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7456 | add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7457 | add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7458 | add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7459 | add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7460 | add_options.push_back(AddOption("Remainder (%)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Returns the remainder of the two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7461 | add_options.push_back(AddOption("Remainder (%)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the remainder of the two integer scalars."), { VisualShaderNodeIntOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7462 | add_options.push_back(AddOption("Remainder (%)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the remainder of the two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7463 | add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7464 | add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7465 | add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7466 | |
| 7467 | add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7468 | add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7469 | add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7470 | add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7471 | add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); |
| 7472 | add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); |
| 7473 | |
| 7474 | // SDF |
| 7475 | { |
| 7476 | add_options.push_back(AddOption("ScreenUVToSDF", "SDF", "VisualShaderNodeScreenUVToSDF", TTR("Converts screen UV to a SDF."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7477 | add_options.push_back(AddOption("SDFRaymarch", "SDF", "VisualShaderNodeSDFRaymarch", TTR("Casts a ray against the screen SDF and returns the distance travelled."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7478 | add_options.push_back(AddOption("SDFToScreenUV", "SDF", "VisualShaderNodeSDFToScreenUV", TTR("Converts a SDF to screen UV."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7479 | add_options.push_back(AddOption("TextureSDF", "SDF", "VisualShaderNodeTextureSDF", TTR("Performs a SDF texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7480 | add_options.push_back(AddOption("TextureSDFNormal", "SDF", "VisualShaderNodeTextureSDFNormal", TTR("Performs a SDF normal texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7481 | } |
| 7482 | |
| 7483 | // TEXTURES |
| 7484 | |
| 7485 | add_options.push_back(AddOption("UVFunc", "Textures/Common", "VisualShaderNodeUVFunc", TTR("Function to be applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7486 | add_options.push_back(AddOption("UVPolarCoord", "Textures/Common", "VisualShaderNodeUVPolarCoord", TTR("Polar coordinates conversion applied on texture coordinates."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7487 | |
| 7488 | cubemap_node_option_idx = add_options.size(); |
| 7489 | add_options.push_back(AddOption("CubeMap", "Textures/Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7490 | curve_node_option_idx = add_options.size(); |
| 7491 | add_options.push_back(AddOption("CurveTexture", "Textures/Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7492 | curve_xyz_node_option_idx = add_options.size(); |
| 7493 | add_options.push_back(AddOption("CurveXYZTexture", "Textures/Functions", "VisualShaderNodeCurveXYZTexture", TTR("Perform the three components curve texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7494 | add_options.push_back(AddOption("LinearSceneDepth", "Textures/Functions", "VisualShaderNodeLinearSceneDepth", TTR("Returns the depth value obtained from the depth prepass in a linear space."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7495 | texture2d_node_option_idx = add_options.size(); |
| 7496 | add_options.push_back(AddOption("WorldPositionFromDepth", "Textures/Functions", "VisualShaderNodeWorldPositionFromDepth", TTR("Reconstructs the World Position of the Node from the depth texture."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7497 | texture2d_node_option_idx = add_options.size(); |
| 7498 | add_options.push_back(AddOption("ScreenNormalWorldSpace", "Textures/Functions", "VisualShaderNodeScreenNormalWorldSpace", TTR("Unpacks the Screen Normal Texture in World Space"), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7499 | texture2d_node_option_idx = add_options.size(); |
| 7500 | add_options.push_back(AddOption("Texture2D", "Textures/Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7501 | texture2d_array_node_option_idx = add_options.size(); |
| 7502 | add_options.push_back(AddOption("Texture2DArray", "Textures/Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7503 | texture3d_node_option_idx = add_options.size(); |
| 7504 | add_options.push_back(AddOption("Texture3D", "Textures/Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7505 | add_options.push_back(AddOption("UVPanning", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply panning function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_PANNING }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7506 | add_options.push_back(AddOption("UVScaling", "Textures/Functions", "VisualShaderNodeUVFunc", TTR("Apply scaling function on texture coordinates."), { VisualShaderNodeUVFunc::FUNC_SCALING }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7507 | |
| 7508 | add_options.push_back(AddOption("CubeMapParameter", "Textures/Variables", "VisualShaderNodeCubemapParameter", TTR("Cubic texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER)); |
| 7509 | add_options.push_back(AddOption("Texture2DParameter", "Textures/Variables", "VisualShaderNodeTexture2DParameter", TTR("2D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER)); |
| 7510 | add_options.push_back(AddOption("TextureParameterTriplanar", "Textures/Variables", "VisualShaderNodeTextureParameterTriplanar", TTR("2D texture parameter lookup with triplanar."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7511 | add_options.push_back(AddOption("Texture2DArrayParameter", "Textures/Variables", "VisualShaderNodeTexture2DArrayParameter", TTR("2D array of textures parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER)); |
| 7512 | add_options.push_back(AddOption("Texture3DParameter", "Textures/Variables", "VisualShaderNodeTexture3DParameter", TTR("3D texture parameter lookup."), {}, VisualShaderNode::PORT_TYPE_SAMPLER)); |
| 7513 | |
| 7514 | // TRANSFORM |
| 7515 | |
| 7516 | add_options.push_back(AddOption("TransformFunc", "Transform/Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7517 | add_options.push_back(AddOption("TransformOp", "Transform/Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7518 | |
| 7519 | add_options.push_back(AddOption("OuterProduct", "Transform/Composition", "VisualShaderNodeOuterProduct", TTR("Calculate the outer product of a pair of vectors.\n\nOuterProduct treats the first parameter 'c' as a column vector (matrix with one column) and the second parameter 'r' as a row vector (matrix with one row) and does a linear algebraic matrix multiply 'c * r', yielding a matrix whose number of rows is the number of components in 'c' and whose number of columns is the number of components in 'r'."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7520 | add_options.push_back(AddOption("TransformCompose", "Transform/Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7521 | add_options.push_back(AddOption("TransformDecompose", "Transform/Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors."))); |
| 7522 | |
| 7523 | add_options.push_back(AddOption("Determinant", "Transform/Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7524 | add_options.push_back(AddOption("GetBillboardMatrix", "Transform/Functions", "VisualShaderNodeBillboard", TTR("Calculates how the object should face the camera to be applied on Model View Matrix output port for 3D objects."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); |
| 7525 | add_options.push_back(AddOption("Inverse", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), { VisualShaderNodeTransformFunc::FUNC_INVERSE }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7526 | add_options.push_back(AddOption("Transpose", "Transform/Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), { VisualShaderNodeTransformFunc::FUNC_TRANSPOSE }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7527 | |
| 7528 | add_options.push_back(AddOption("Add (+)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), { VisualShaderNodeTransformOp::OP_ADD }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7529 | add_options.push_back(AddOption("Divide (/)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), { VisualShaderNodeTransformOp::OP_A_DIV_B }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7530 | add_options.push_back(AddOption("Multiply (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), { VisualShaderNodeTransformOp::OP_AxB }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7531 | add_options.push_back(AddOption("MultiplyComp (*)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Performs per-component multiplication of two transforms."), { VisualShaderNodeTransformOp::OP_AxB_COMP }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7532 | add_options.push_back(AddOption("Subtract (-)", "Transform/Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), { VisualShaderNodeTransformOp::OP_A_MINUS_B }, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7533 | add_options.push_back(AddOption("TransformVectorMult (*)", "Transform/Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7534 | |
| 7535 | add_options.push_back(AddOption("TransformConstant", "Transform/Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7536 | add_options.push_back(AddOption("TransformParameter", "Transform/Variables", "VisualShaderNodeTransformParameter", TTR("Transform parameter."), {}, VisualShaderNode::PORT_TYPE_TRANSFORM)); |
| 7537 | |
| 7538 | // UTILITY |
| 7539 | |
| 7540 | add_options.push_back(AddOption("DistanceFade", "Utility", "VisualShaderNodeDistanceFade", TTR("The distance fade effect fades out each pixel based on its distance to another object."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7541 | add_options.push_back(AddOption("ProximityFade", "Utility", "VisualShaderNodeProximityFade", TTR("The proximity fade effect fades out each pixel based on its distance to another object."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7542 | add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7543 | add_options.push_back(AddOption("RotationByAxis", "Utility", "VisualShaderNodeRotationByAxis", TTR("Builds a rotation matrix from the given axis and angle, multiply the input vector by it and returns both this vector and a matrix."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7544 | |
| 7545 | // VECTOR |
| 7546 | |
| 7547 | add_options.push_back(AddOption("VectorFunc", "Vector/Common", "VisualShaderNodeVectorFunc", TTR("Vector function."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7548 | add_options.push_back(AddOption("VectorOp", "Vector/Common", "VisualShaderNodeVectorOp", TTR("Vector operator."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7549 | add_options.push_back(AddOption("VectorCompose", "Vector/Common", "VisualShaderNodeVectorCompose", TTR("Composes vector from scalars."))); |
| 7550 | add_options.push_back(AddOption("VectorDecompose", "Vector/Common", "VisualShaderNodeVectorDecompose", TTR("Decomposes vector to scalars."))); |
| 7551 | |
| 7552 | add_options.push_back(AddOption("Vector2Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 2D vector from two scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7553 | add_options.push_back(AddOption("Vector2Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 2D vector to two scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_2D })); |
| 7554 | add_options.push_back(AddOption("Vector3Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 3D vector from three scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7555 | add_options.push_back(AddOption("Vector3Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 3D vector to three scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_3D })); |
| 7556 | add_options.push_back(AddOption("Vector4Compose", "Vector/Composition", "VisualShaderNodeVectorCompose", TTR("Composes 4D vector from four scalars."), { VisualShaderNodeVectorCompose::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7557 | add_options.push_back(AddOption("Vector4Decompose", "Vector/Composition", "VisualShaderNodeVectorDecompose", TTR("Decomposes 4D vector to four scalars."), { VisualShaderNodeVectorDecompose::OP_TYPE_VECTOR_4D })); |
| 7558 | |
| 7559 | add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7560 | add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7561 | add_options.push_back(AddOption("Abs", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7562 | add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7563 | add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7564 | add_options.push_back(AddOption("ACos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7565 | add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7566 | add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7567 | add_options.push_back(AddOption("ACosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7568 | add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7569 | add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7570 | add_options.push_back(AddOption("ASin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7571 | add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7572 | add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7573 | add_options.push_back(AddOption("ASinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7574 | add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7575 | add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7576 | add_options.push_back(AddOption("ATan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7577 | add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7578 | add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7579 | add_options.push_back(AddOption("ATan2", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7580 | add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7581 | add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7582 | add_options.push_back(AddOption("ATanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7583 | add_options.push_back(AddOption("Ceil", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_CEIL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7584 | add_options.push_back(AddOption("Ceil", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_CEIL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7585 | add_options.push_back(AddOption("Ceil", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_CEIL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7586 | add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7587 | add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7588 | add_options.push_back(AddOption("Clamp", "Vector/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7589 | add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7590 | add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7591 | add_options.push_back(AddOption("Cos", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7592 | add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7593 | add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7594 | add_options.push_back(AddOption("CosH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7595 | add_options.push_back(AddOption("Cross", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Calculates the cross product of two vectors."), { VisualShaderNodeVectorOp::OP_CROSS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7596 | add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7597 | add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7598 | add_options.push_back(AddOption("Degrees", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7599 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7600 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7601 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7602 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7603 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7604 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7605 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7606 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7607 | add_options.push_back(AddOption("DFdX", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'x' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_X, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7608 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7609 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7610 | add_options.push_back(AddOption("DFdY", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Derivative in 'y' using local differencing."), { VisualShaderNodeDerivativeFunc::FUNC_Y, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7611 | add_options.push_back(AddOption("Distance2D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7612 | add_options.push_back(AddOption("Distance3D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7613 | add_options.push_back(AddOption("Distance4D", "Vector/Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), { VisualShaderNodeVectorDistance::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7614 | add_options.push_back(AddOption("Dot", "Vector/Functions", "VisualShaderNodeDotProduct", TTR("Calculates the dot product of two vectors."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7615 | add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7616 | add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7617 | add_options.push_back(AddOption("Exp", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-e Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7618 | add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7619 | add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7620 | add_options.push_back(AddOption("Exp2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 Exponential."), { VisualShaderNodeVectorFunc::FUNC_EXP2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7621 | add_options.push_back(AddOption("FaceForward", "Vector/Functions", "VisualShaderNodeFaceForward", TTR("Returns the vector that points in the same direction as a reference vector. The function has three vector parameters : N, the vector to orient, I, the incident vector, and Nref, the reference vector. If the dot product of I and Nref is smaller than zero the return value is N. Otherwise -N is returned."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7622 | add_options.push_back(AddOption("FaceForward", "Vector/Functions", "VisualShaderNodeFaceForward", TTR("Returns the vector that points in the same direction as a reference vector. The function has three vector parameters : N, the vector to orient, I, the incident vector, and Nref, the reference vector. If the dot product of I and Nref is smaller than zero the return value is N. Otherwise -N is returned."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7623 | add_options.push_back(AddOption("FaceForward", "Vector/Functions", "VisualShaderNodeFaceForward", TTR("Returns the vector that points in the same direction as a reference vector. The function has three vector parameters : N, the vector to orient, I, the incident vector, and Nref, the reference vector. If the dot product of I and Nref is smaller than zero the return value is N. Otherwise -N is returned."), { VisualShaderNodeFaceForward::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7624 | add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7625 | add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7626 | add_options.push_back(AddOption("Floor", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer less than or equal to the parameter."), { VisualShaderNodeVectorFunc::FUNC_FLOOR, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7627 | add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7628 | add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7629 | add_options.push_back(AddOption("Fract", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Computes the fractional part of the argument."), { VisualShaderNodeVectorFunc::FUNC_FRACT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7630 | add_options.push_back(AddOption("Fresnel", "Vector/Functions", "VisualShaderNodeFresnel", TTR("Returns falloff based on the dot product of surface normal and view direction of camera (pass associated inputs to it)."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7631 | add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7632 | add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7633 | add_options.push_back(AddOption("InverseSqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse of the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_INVERSE_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7634 | add_options.push_back(AddOption("Length2D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7635 | add_options.push_back(AddOption("Length3D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7636 | add_options.push_back(AddOption("Length4D", "Vector/Functions", "VisualShaderNodeVectorLen", TTR("Calculates the length of a vector."), { VisualShaderNodeVectorLen::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_SCALAR)); |
| 7637 | add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7638 | add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7639 | add_options.push_back(AddOption("Log", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Natural logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7640 | add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7641 | add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7642 | add_options.push_back(AddOption("Log2", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), { VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7643 | add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7644 | add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7645 | add_options.push_back(AddOption("Max", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), { VisualShaderNodeVectorOp::OP_MAX, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7646 | add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7647 | add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7648 | add_options.push_back(AddOption("Min", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), { VisualShaderNodeVectorOp::OP_MIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7649 | add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7650 | add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7651 | add_options.push_back(AddOption("Mix", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), { VisualShaderNodeMix::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7652 | add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7653 | add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7654 | add_options.push_back(AddOption("MixS", "Vector/Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), { VisualShaderNodeMix::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7655 | add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7656 | add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7657 | add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Vector/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), { VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7658 | add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7659 | add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7660 | add_options.push_back(AddOption("Negate (*-1)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7661 | add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7662 | add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7663 | add_options.push_back(AddOption("Normalize", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), { VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7664 | add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7665 | add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7666 | add_options.push_back(AddOption("OneMinus (1-)", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), { VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7667 | add_options.push_back(AddOption("Pow (^)", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the value of the first parameter raised to the power of the second."), { VisualShaderNodeVectorOp::OP_POW, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7668 | add_options.push_back(AddOption("Pow (^)", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the value of the first parameter raised to the power of the second."), { VisualShaderNodeVectorOp::OP_POW, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7669 | add_options.push_back(AddOption("Pow (^)", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the value of the first parameter raised to the power of the second."), { VisualShaderNodeVectorOp::OP_POW, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7670 | add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7671 | add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7672 | add_options.push_back(AddOption("Radians", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeVectorFunc::FUNC_RADIANS, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7673 | add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7674 | add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7675 | add_options.push_back(AddOption("Reciprocal", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), { VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7676 | add_options.push_back(AddOption("Reflect", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the vector that points in the direction of reflection ( a : incident vector, b : normal vector )."), { VisualShaderNodeVectorOp::OP_REFLECT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7677 | add_options.push_back(AddOption("Reflect", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the vector that points in the direction of reflection ( a : incident vector, b : normal vector )."), { VisualShaderNodeVectorOp::OP_REFLECT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7678 | add_options.push_back(AddOption("Reflect", "Vector/Functions", "VisualShaderNodeVectorOp", TTR("Returns the vector that points in the direction of reflection ( a : incident vector, b : normal vector )."), { VisualShaderNodeVectorOp::OP_REFLECT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7679 | add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), { VisualShaderNodeVectorRefract::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7680 | add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), { VisualShaderNodeVectorRefract::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7681 | add_options.push_back(AddOption("Refract", "Vector/Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), { VisualShaderNodeVectorRefract::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7682 | add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7683 | add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7684 | add_options.push_back(AddOption("Remap", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7685 | add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7686 | add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7687 | add_options.push_back(AddOption("RemapS", "Vector/Functions", "VisualShaderNodeRemap", TTR("Remaps a vector from the input range to the output range. Ranges defined with scalars."), { VisualShaderNodeRemap::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7688 | add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7689 | add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7690 | add_options.push_back(AddOption("Round", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7691 | add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7692 | add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7693 | add_options.push_back(AddOption("RoundEven", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), { VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7694 | add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7695 | add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7696 | add_options.push_back(AddOption("Saturate", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), { VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7697 | add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7698 | add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7699 | add_options.push_back(AddOption("Sign", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7700 | add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7701 | add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7702 | add_options.push_back(AddOption("Sin", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7703 | add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7704 | add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7705 | add_options.push_back(AddOption("SinH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7706 | add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7707 | add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7708 | add_options.push_back(AddOption("Sqrt", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), { VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7709 | add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7710 | add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7711 | add_options.push_back(AddOption("SmoothStep", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7712 | add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7713 | add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7714 | add_options.push_back(AddOption("SmoothStepS", "Vector/Functions", "VisualShaderNodeSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), { VisualShaderNodeSmoothStep::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7715 | add_options.push_back(AddOption("Step", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7716 | add_options.push_back(AddOption("Step", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7717 | add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_2D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7718 | add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_3D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7719 | add_options.push_back(AddOption("StepS", "Vector/Functions", "VisualShaderNodeStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), { VisualShaderNodeStep::OP_TYPE_VECTOR_4D_SCALAR }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7720 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7721 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7722 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, -1, true)); |
| 7723 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7724 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7725 | add_options.push_back(AddOption("Sum (+)", "Vector/Functions", "VisualShaderNodeDerivativeFunc", TTR("(Vector) Sum of absolute derivative in 'x' and 'y'."), { VisualShaderNodeDerivativeFunc::FUNC_SUM, VisualShaderNodeDerivativeFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D, TYPE_FLAGS_SKY, Shader::MODE_SKY, true)); |
| 7726 | add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7727 | add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7728 | add_options.push_back(AddOption("Tan", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7729 | add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7730 | add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7731 | add_options.push_back(AddOption("TanH", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7732 | add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7733 | add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7734 | add_options.push_back(AddOption("Trunc", "Vector/Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), { VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNodeVectorFunc::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7735 | |
| 7736 | add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 2D vector to 2D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7737 | add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 3D vector to 3D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7738 | add_options.push_back(AddOption("Add (+)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Adds 4D vector to 4D vector."), { VisualShaderNodeVectorOp::OP_ADD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7739 | add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 2D vector by 2D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7740 | add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 3D vector by 3D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7741 | add_options.push_back(AddOption("Divide (/)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Divides 4D vector by 4D vector."), { VisualShaderNodeVectorOp::OP_DIV, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7742 | add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 2D vector by 2D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7743 | add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 3D vector by 3D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7744 | add_options.push_back(AddOption("Multiply (*)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Multiplies 4D vector by 4D vector."), { VisualShaderNodeVectorOp::OP_MUL, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7745 | add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 2D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7746 | add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 3D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7747 | add_options.push_back(AddOption("Remainder (%)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Returns the remainder of the two 4D vectors."), { VisualShaderNodeVectorOp::OP_MOD, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7748 | add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 2D vector from 2D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_2D }, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7749 | add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 3D vector from 3D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_3D }, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7750 | add_options.push_back(AddOption("Subtract (-)", "Vector/Operators", "VisualShaderNodeVectorOp", TTR("Subtracts 4D vector from 4D vector."), { VisualShaderNodeVectorOp::OP_SUB, VisualShaderNodeVectorOp::OP_TYPE_VECTOR_4D }, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7751 | |
| 7752 | add_options.push_back(AddOption("Vector2Constant", "Vector/Variables", "VisualShaderNodeVec2Constant", TTR("2D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7753 | add_options.push_back(AddOption("Vector2Parameter", "Vector/Variables", "VisualShaderNodeVec2Parameter", TTR("2D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_2D)); |
| 7754 | add_options.push_back(AddOption("Vector3Constant", "Vector/Variables", "VisualShaderNodeVec3Constant", TTR("3D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7755 | add_options.push_back(AddOption("Vector3Parameter", "Vector/Variables", "VisualShaderNodeVec3Parameter", TTR("3D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D)); |
| 7756 | add_options.push_back(AddOption("Vector4Constant", "Vector/Variables", "VisualShaderNodeVec4Constant", TTR("4D vector constant."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7757 | add_options.push_back(AddOption("Vector4Parameter", "Vector/Variables", "VisualShaderNodeVec4Parameter", TTR("4D vector parameter."), {}, VisualShaderNode::PORT_TYPE_VECTOR_4D)); |
| 7758 | |
| 7759 | // SPECIAL |
| 7760 | add_options.push_back(AddOption("Frame", "Special", "VisualShaderNodeFrame", TTR("A rectangular area with a description string for better graph organization."))); |
| 7761 | add_options.push_back(AddOption("Expression", "Special", "VisualShaderNodeExpression", TTR("Custom Godot Shader Language expression, with custom amount of input and output ports. This is a direct injection of code into the vertex/fragment/light function, do not use it to write the function declarations inside."))); |
| 7762 | add_options.push_back(AddOption("GlobalExpression", "Special", "VisualShaderNodeGlobalExpression", TTR("Custom Godot Shader Language expression, which is placed on top of the resulted shader. You can place various function definitions inside and call it later in the Expressions. You can also declare varyings, parameters and constants."))); |
| 7763 | add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter."))); |
| 7764 | add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); |
| 7765 | add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); |
| 7766 | add_options.push_back(AddOption("VaryingGetter", "Special", "VisualShaderNodeVaryingGetter", TTR("Get varying parameter."), {}, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM)); |
| 7767 | add_options.push_back(AddOption("VaryingSetter", "Special", "VisualShaderNodeVaryingSetter", TTR("Set varying parameter."), {}, -1, TYPE_FLAGS_VERTEX | TYPE_FLAGS_FRAGMENT, Shader::MODE_CANVAS_ITEM)); |
| 7768 | add_options.push_back(AddOption("Reroute", "Special", "VisualShaderNodeReroute", TTR("Reroute connections freely, can be used to connect multiple input ports to single output port."))); |
| 7769 | |
| 7770 | custom_node_option_idx = add_options.size(); |
| 7771 | |
| 7772 | ///////////////////////////////////////////////////////////////////// |
| 7773 | |
| 7774 | Ref<VisualShaderNodePluginDefault> default_plugin; |
| 7775 | default_plugin.instantiate(); |
| 7776 | default_plugin->set_editor(this); |
| 7777 | add_plugin(default_plugin); |
| 7778 | |
| 7779 | graph_plugin.instantiate(); |
| 7780 | graph_plugin->set_editor(this); |
| 7781 | |
| 7782 | property_editor_popup = memnew(PopupPanel); |
| 7783 | property_editor_popup->set_min_size(Size2(360, 0) * EDSCALE); |
| 7784 | add_child(property_editor_popup); |
| 7785 | |
| 7786 | edited_property_holder.instantiate(); |
| 7787 | |
| 7788 | panning_debounce_timer = memnew(Timer); |
| 7789 | panning_debounce_timer->set_one_shot(true); |
| 7790 | panning_debounce_timer->set_wait_time(1.0); |
| 7791 | panning_debounce_timer->connect("timeout", callable_mp(this, &VisualShaderEditor::save_editor_layout)); |
| 7792 | add_child(panning_debounce_timer); |
| 7793 | } |
| 7794 | |
| 7795 | VisualShaderEditor::~VisualShaderEditor() { |
| 7796 | save_editor_layout(); |
| 7797 | } |
| 7798 | |
| 7799 | class VisualShaderNodePluginInputEditor : public OptionButton { |
| 7800 | GDCLASS(VisualShaderNodePluginInputEditor, OptionButton); |
| 7801 | |
| 7802 | VisualShaderEditor *editor = nullptr; |
| 7803 | Ref<VisualShaderNodeInput> input; |
| 7804 | |
| 7805 | public: |
| 7806 | void _notification(int p_what) { |
| 7807 | switch (p_what) { |
| 7808 | case NOTIFICATION_READY: { |
| 7809 | connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginInputEditor::_item_selected)); |
| 7810 | } break; |
| 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | void _item_selected(int p_item) { |
| 7815 | editor->call_deferred(SNAME("_input_select_item"), input, get_item_metadata(p_item)); |
| 7816 | } |
| 7817 | |
| 7818 | void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeInput> &p_input) { |
| 7819 | set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 7820 | |
| 7821 | editor = p_editor; |
| 7822 | input = p_input; |
| 7823 | |
| 7824 | Ref<Texture2D> type_icon[] = { |
| 7825 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)), |
| 7826 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)), |
| 7827 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)), |
| 7828 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)), |
| 7829 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)), |
| 7830 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)), |
| 7831 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)), |
| 7832 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)), |
| 7833 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)), |
| 7834 | }; |
| 7835 | |
| 7836 | add_item(TTR("[None]")); |
| 7837 | set_item_metadata(-1, "[None]"); |
| 7838 | |
| 7839 | int to_select = -1; |
| 7840 | for (int i = 0; i < input->get_input_index_count(); i++) { |
| 7841 | if (input->get_input_name() == input->get_input_index_name(i)) { |
| 7842 | to_select = i + 1; |
| 7843 | } |
| 7844 | add_icon_item(type_icon[input->get_input_index_type(i)], input->get_input_index_name(i)); |
| 7845 | set_item_metadata(-1, input->get_input_index_name(i)); |
| 7846 | } |
| 7847 | |
| 7848 | if (to_select >= 0) { |
| 7849 | select(to_select); |
| 7850 | } |
| 7851 | } |
| 7852 | }; |
| 7853 | |
| 7854 | //////////////// |
| 7855 | |
| 7856 | class VisualShaderNodePluginVaryingEditor : public OptionButton { |
| 7857 | GDCLASS(VisualShaderNodePluginVaryingEditor, OptionButton); |
| 7858 | |
| 7859 | VisualShaderEditor *editor = nullptr; |
| 7860 | Ref<VisualShaderNodeVarying> varying; |
| 7861 | |
| 7862 | public: |
| 7863 | void _notification(int p_what) { |
| 7864 | if (p_what == NOTIFICATION_READY) { |
| 7865 | connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginVaryingEditor::_item_selected)); |
| 7866 | } |
| 7867 | } |
| 7868 | |
| 7869 | void _item_selected(int p_item) { |
| 7870 | editor->call_deferred(SNAME("_varying_select_item"), varying, get_item_metadata(p_item)); |
| 7871 | } |
| 7872 | |
| 7873 | void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeVarying> &p_varying, VisualShader::Type p_type) { |
| 7874 | set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 7875 | |
| 7876 | editor = p_editor; |
| 7877 | varying = p_varying; |
| 7878 | |
| 7879 | Ref<Texture2D> type_icon[] = { |
| 7880 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)), |
| 7881 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)), |
| 7882 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)), |
| 7883 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)), |
| 7884 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)), |
| 7885 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)), |
| 7886 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)), |
| 7887 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)), |
| 7888 | }; |
| 7889 | |
| 7890 | bool is_getter = Ref<VisualShaderNodeVaryingGetter>(p_varying.ptr()).is_valid(); |
| 7891 | |
| 7892 | add_item(TTR("[None]")); |
| 7893 | set_item_metadata(-1, "[None]"); |
| 7894 | |
| 7895 | int to_select = -1; |
| 7896 | for (int i = 0, j = 0; i < varying->get_varyings_count(); i++) { |
| 7897 | VisualShader::VaryingMode mode = varying->get_varying_mode_by_index(i); |
| 7898 | if (is_getter) { |
| 7899 | if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) { |
| 7900 | if (p_type != VisualShader::TYPE_LIGHT) { |
| 7901 | j++; |
| 7902 | continue; |
| 7903 | } |
| 7904 | } else { |
| 7905 | if (p_type != VisualShader::TYPE_FRAGMENT && p_type != VisualShader::TYPE_LIGHT) { |
| 7906 | j++; |
| 7907 | continue; |
| 7908 | } |
| 7909 | } |
| 7910 | } else { |
| 7911 | if (mode == VisualShader::VARYING_MODE_FRAG_TO_LIGHT) { |
| 7912 | if (p_type != VisualShader::TYPE_FRAGMENT) { |
| 7913 | j++; |
| 7914 | continue; |
| 7915 | } |
| 7916 | } else { |
| 7917 | if (p_type != VisualShader::TYPE_VERTEX) { |
| 7918 | j++; |
| 7919 | continue; |
| 7920 | } |
| 7921 | } |
| 7922 | } |
| 7923 | if (varying->get_varying_name() == varying->get_varying_name_by_index(i)) { |
| 7924 | to_select = i - j + 1; |
| 7925 | } |
| 7926 | add_icon_item(type_icon[varying->get_varying_type_by_index(i)], varying->get_varying_name_by_index(i)); |
| 7927 | set_item_metadata(-1, varying->get_varying_name_by_index(i)); |
| 7928 | } |
| 7929 | |
| 7930 | if (to_select >= 0) { |
| 7931 | select(to_select); |
| 7932 | } |
| 7933 | } |
| 7934 | }; |
| 7935 | |
| 7936 | //////////////// |
| 7937 | |
| 7938 | class VisualShaderNodePluginParameterRefEditor : public OptionButton { |
| 7939 | GDCLASS(VisualShaderNodePluginParameterRefEditor, OptionButton); |
| 7940 | |
| 7941 | VisualShaderEditor *editor = nullptr; |
| 7942 | Ref<VisualShaderNodeParameterRef> parameter_ref; |
| 7943 | |
| 7944 | public: |
| 7945 | void _notification(int p_what) { |
| 7946 | switch (p_what) { |
| 7947 | case NOTIFICATION_READY: { |
| 7948 | connect(SceneStringName(item_selected), callable_mp(this, &VisualShaderNodePluginParameterRefEditor::_item_selected)); |
| 7949 | } break; |
| 7950 | } |
| 7951 | } |
| 7952 | |
| 7953 | void _item_selected(int p_item) { |
| 7954 | editor->call_deferred(SNAME("_parameter_ref_select_item"), parameter_ref, get_item_metadata(p_item)); |
| 7955 | } |
| 7956 | |
| 7957 | void setup(VisualShaderEditor *p_editor, const Ref<VisualShaderNodeParameterRef> &p_parameter_ref) { |
| 7958 | set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 7959 | |
| 7960 | editor = p_editor; |
| 7961 | parameter_ref = p_parameter_ref; |
| 7962 | |
| 7963 | Ref<Texture2D> type_icon[] = { |
| 7964 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("float"), EditorStringName(EditorIcons)), |
| 7965 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("int"), EditorStringName(EditorIcons)), |
| 7966 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("uint"), EditorStringName(EditorIcons)), |
| 7967 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("bool"), EditorStringName(EditorIcons)), |
| 7968 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector2"), EditorStringName(EditorIcons)), |
| 7969 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector3"), EditorStringName(EditorIcons)), |
| 7970 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Vector4"), EditorStringName(EditorIcons)), |
| 7971 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Transform3D"), EditorStringName(EditorIcons)), |
| 7972 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Color"), EditorStringName(EditorIcons)), |
| 7973 | EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ImageTexture"), EditorStringName(EditorIcons)), |
| 7974 | }; |
| 7975 | |
| 7976 | add_item(TTR("[None]")); |
| 7977 | set_item_metadata(-1, "[None]"); |
| 7978 | |
| 7979 | int to_select = -1; |
| 7980 | for (int i = 0; i < p_parameter_ref->get_parameters_count(); i++) { |
| 7981 | if (p_parameter_ref->get_parameter_name() == p_parameter_ref->get_parameter_name_by_index(i)) { |
| 7982 | to_select = i + 1; |
| 7983 | } |
| 7984 | add_icon_item(type_icon[p_parameter_ref->get_parameter_type_by_index(i)], p_parameter_ref->get_parameter_name_by_index(i)); |
| 7985 | set_item_metadata(-1, p_parameter_ref->get_parameter_name_by_index(i)); |
| 7986 | } |
| 7987 | |
| 7988 | if (to_select >= 0) { |
| 7989 | select(to_select); |
| 7990 | } |
| 7991 | } |
| 7992 | }; |
| 7993 | |
| 7994 | //////////////// |
| 7995 | |
| 7996 | class VisualShaderNodePluginDefaultEditor : public VBoxContainer { |
| 7997 | GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer); |
| 7998 | VisualShaderEditor *editor = nullptr; |
| 7999 | Ref<Resource> parent_resource; |
| 8000 | int node_id = 0; |
| 8001 | VisualShader::Type shader_type; |
| 8002 | |
| 8003 | public: |
| 8004 | void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) { |
| 8005 | if (p_changing) { |
| 8006 | return; |
| 8007 | } |
| 8008 | |
| 8009 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 8010 | |
| 8011 | updating = true; |
| 8012 | undo_redo->create_action(vformat(TTR("Edit Visual Property: %s"), p_property), UndoRedo::MERGE_ENDS); |
| 8013 | undo_redo->add_do_property(node.ptr(), p_property, p_value); |
| 8014 | undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property)); |
| 8015 | |
| 8016 | Ref<VisualShaderNode> vsnode = editor->get_visual_shader()->get_node(shader_type, node_id); |
| 8017 | ERR_FAIL_COND(vsnode.is_null()); |
| 8018 | |
| 8019 | // Check for invalid connections due to removed ports. |
| 8020 | // We need to know the new state of the node to generate the proper undo/redo instructions. |
| 8021 | // Quite hacky but the best way I could come up with for now. |
| 8022 | Ref<VisualShaderNode> vsnode_new = vsnode->duplicate(); |
| 8023 | vsnode_new->set(p_property, p_value); |
| 8024 | const int input_port_count = vsnode_new->get_input_port_count(); |
| 8025 | const int output_port_count = vsnode_new->get_expanded_output_port_count(); |
| 8026 | |
| 8027 | List<VisualShader::Connection> conns; |
| 8028 | editor->get_visual_shader()->get_node_connections(shader_type, &conns); |
| 8029 | VisualShaderGraphPlugin *graph_plugin = editor->get_graph_plugin(); |
| 8030 | bool undo_node_already_updated = false; |
| 8031 | for (const VisualShader::Connection &c : conns) { |
| 8032 | if ((c.from_node == node_id && c.from_port >= output_port_count) || (c.to_node == node_id && c.to_port >= input_port_count)) { |
| 8033 | undo_redo->add_do_method(editor->get_visual_shader().ptr(), "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port); |
| 8034 | undo_redo->add_do_method(graph_plugin, "disconnect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port); |
| 8035 | // We need to update the node before reconnecting to avoid accessing a non-existing port. |
| 8036 | undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id); |
| 8037 | undo_node_already_updated = true; |
| 8038 | undo_redo->add_undo_method(editor->get_visual_shader().ptr(), "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port); |
| 8039 | undo_redo->add_undo_method(graph_plugin, "connect_nodes", shader_type, c.from_node, c.from_port, c.to_node, c.to_port); |
| 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | if (p_value.get_type() == Variant::OBJECT) { |
| 8044 | Ref<Resource> prev_res = vsnode->get(p_property); |
| 8045 | Ref<Resource> curr_res = p_value; |
| 8046 | |
| 8047 | if (curr_res.is_null()) { |
| 8048 | undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr()); |
| 8049 | } else { |
| 8050 | undo_redo->add_do_method(this, "_open_inspector", (Ref<Resource>)curr_res.ptr()); |
| 8051 | } |
| 8052 | if (prev_res.is_valid()) { |
| 8053 | undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)prev_res.ptr()); |
| 8054 | } else { |
| 8055 | undo_redo->add_undo_method(this, "_open_inspector", (Ref<Resource>)parent_resource.ptr()); |
| 8056 | } |
| 8057 | } |
| 8058 | if (p_property != "constant") { |
| 8059 | if (graph_plugin) { |
| 8060 | undo_redo->add_do_method(editor, "_update_next_previews", node_id); |
| 8061 | undo_redo->add_undo_method(editor, "_update_next_previews", node_id); |
| 8062 | undo_redo->add_do_method(graph_plugin, "update_node_deferred", shader_type, node_id); |
| 8063 | if (!undo_node_already_updated) { |
| 8064 | undo_redo->add_undo_method(graph_plugin, "update_node_deferred", shader_type, node_id); |
| 8065 | } |
| 8066 | } |
| 8067 | } |
| 8068 | |
| 8069 | undo_redo->commit_action(); |
| 8070 | |
| 8071 | updating = false; |
| 8072 | } |
| 8073 | |
| 8074 | void _node_changed() { |
| 8075 | if (updating) { |
| 8076 | return; |
| 8077 | } |
| 8078 | for (int i = 0; i < properties.size(); i++) { |
| 8079 | properties[i]->update_property(); |
| 8080 | } |
| 8081 | } |
| 8082 | |
| 8083 | void _resource_selected(const String &p_path, Ref<Resource> p_resource) { |
| 8084 | _open_inspector(p_resource); |
| 8085 | } |
| 8086 | |
| 8087 | void _open_inspector(Ref<Resource> p_resource) { |
| 8088 | InspectorDock::get_inspector_singleton()->edit(p_resource.ptr()); |
| 8089 | } |
| 8090 | |
| 8091 | bool updating = false; |
| 8092 | Ref<VisualShaderNode> node; |
| 8093 | Vector<EditorProperty *> properties; |
| 8094 | Vector<Label *> prop_names; |
| 8095 | |
| 8096 | void _show_prop_names(bool p_show) { |
| 8097 | for (int i = 0; i < prop_names.size(); i++) { |
| 8098 | prop_names[i]->set_visible(p_show); |
| 8099 | } |
| 8100 | } |
| 8101 | |
| 8102 | void setup(VisualShaderEditor *p_editor, Ref<Resource> p_parent_resource, const Vector<EditorProperty *> &p_properties, const Vector<StringName> &p_names, const HashMap<StringName, String> &p_overrided_names, Ref<VisualShaderNode> p_node) { |
| 8103 | editor = p_editor; |
| 8104 | parent_resource = p_parent_resource; |
| 8105 | updating = false; |
| 8106 | node = p_node; |
| 8107 | properties = p_properties; |
| 8108 | |
| 8109 | node_id = (int)p_node->get_meta("id"); |
| 8110 | shader_type = VisualShader::Type((int)p_node->get_meta("shader_type")); |
| 8111 | |
| 8112 | for (int i = 0; i < p_properties.size(); i++) { |
| 8113 | HBoxContainer *hbox = memnew(HBoxContainer); |
| 8114 | hbox->set_h_size_flags(SIZE_EXPAND_FILL); |
| 8115 | add_child(hbox); |
| 8116 | |
| 8117 | Label *prop_name = memnew(Label); |
| 8118 | prop_name->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 8119 | String prop_name_str = p_names[i]; |
| 8120 | if (p_overrided_names.has(p_names[i])) { |
| 8121 | prop_name_str = p_overrided_names[p_names[i]] + ":"; |
| 8122 | } else { |
| 8123 | prop_name_str = prop_name_str.capitalize() + ":"; |
| 8124 | } |
| 8125 | prop_name->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. |
| 8126 | prop_name->set_text(prop_name_str); |
| 8127 | prop_name->set_visible(false); |
| 8128 | hbox->add_child(prop_name); |
| 8129 | prop_names.push_back(prop_name); |
| 8130 | |
| 8131 | p_properties[i]->set_h_size_flags(SIZE_EXPAND_FILL); |
| 8132 | hbox->add_child(p_properties[i]); |
| 8133 | |
| 8134 | bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]); |
| 8135 | if (res_prop) { |
| 8136 | p_properties[i]->connect("resource_selected", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_resource_selected)); |
| 8137 | } |
| 8138 | |
| 8139 | properties[i]->connect("property_changed", callable_mp(this, &VisualShaderNodePluginDefaultEditor::_property_changed)); |
| 8140 | properties[i]->set_object_and_property(node.ptr(), p_names[i]); |
| 8141 | properties[i]->update_property(); |
| 8142 | properties[i]->set_name_split_ratio(0); |
| 8143 | } |
| 8144 | node->connect_changed(callable_mp(this, &VisualShaderNodePluginDefaultEditor::_node_changed)); |
| 8145 | } |
| 8146 | |
| 8147 | static void _bind_methods() { |
| 8148 | ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); // Used by UndoRedo. |
| 8149 | ClassDB::bind_method("_show_prop_names", &VisualShaderNodePluginDefaultEditor::_show_prop_names); // Used with call_deferred. |
| 8150 | } |
| 8151 | }; |
| 8152 | |
| 8153 | Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { |
| 8154 | Ref<VisualShader> p_shader = Ref<VisualShader>(p_parent_resource.ptr()); |
| 8155 | |
| 8156 | if (p_shader.is_valid() && (p_node->is_class("VisualShaderNodeVaryingGetter") || p_node->is_class("VisualShaderNodeVaryingSetter"))) { |
| 8157 | VisualShaderNodePluginVaryingEditor *editor = memnew(VisualShaderNodePluginVaryingEditor); |
| 8158 | editor->setup(vseditor, p_node, vseditor->get_current_shader_type()); |
| 8159 | return editor; |
| 8160 | } |
| 8161 | |
| 8162 | if (p_node->is_class("VisualShaderNodeParameterRef")) { |
| 8163 | VisualShaderNodePluginParameterRefEditor *editor = memnew(VisualShaderNodePluginParameterRefEditor); |
| 8164 | editor->setup(vseditor, p_node); |
| 8165 | return editor; |
| 8166 | } |
| 8167 | |
| 8168 | if (p_node->is_class("VisualShaderNodeInput")) { |
| 8169 | VisualShaderNodePluginInputEditor *editor = memnew(VisualShaderNodePluginInputEditor); |
| 8170 | editor->setup(vseditor, p_node); |
| 8171 | return editor; |
| 8172 | } |
| 8173 | |
| 8174 | Vector<StringName> properties = p_node->get_editable_properties(); |
| 8175 | if (properties.is_empty()) { |
| 8176 | return nullptr; |
| 8177 | } |
| 8178 | |
| 8179 | List<PropertyInfo> props; |
| 8180 | p_node->get_property_list(&props); |
| 8181 | |
| 8182 | Vector<PropertyInfo> pinfo; |
| 8183 | |
| 8184 | for (const PropertyInfo &E : props) { |
| 8185 | for (int i = 0; i < properties.size(); i++) { |
| 8186 | if (E.name == String(properties[i])) { |
| 8187 | pinfo.push_back(E); |
| 8188 | } |
| 8189 | } |
| 8190 | } |
| 8191 | |
| 8192 | if (pinfo.is_empty()) { |
| 8193 | return nullptr; |
| 8194 | } |
| 8195 | |
| 8196 | properties.clear(); |
| 8197 | |
| 8198 | Ref<VisualShaderNode> node = p_node; |
| 8199 | Vector<EditorProperty *> editors; |
| 8200 | |
| 8201 | for (int i = 0; i < pinfo.size(); i++) { |
| 8202 | EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage); |
| 8203 | if (!prop) { |
| 8204 | return nullptr; |
| 8205 | } |
| 8206 | |
| 8207 | if (Object::cast_to<EditorPropertyResource>(prop)) { |
| 8208 | Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false); |
| 8209 | prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
| 8210 | } else if (Object::cast_to<EditorPropertyTransform3D>(prop) || Object::cast_to<EditorPropertyVector3>(prop)) { |
| 8211 | prop->set_custom_minimum_size(Size2(250 * EDSCALE, 0)); |
| 8212 | } else if (Object::cast_to<EditorPropertyVector4>(prop)) { |
| 8213 | prop->set_custom_minimum_size(Size2(320 * EDSCALE, 0)); |
| 8214 | } else if (Object::cast_to<EditorPropertyFloat>(prop)) { |
| 8215 | prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
| 8216 | } else if (Object::cast_to<EditorPropertyEnum>(prop)) { |
| 8217 | prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
| 8218 | Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false); |
| 8219 | } else if (Object::cast_to<EditorPropertyColor>(prop)) { |
| 8220 | Object::cast_to<EditorPropertyColor>(prop)->set_live_changes_enabled(false); |
| 8221 | } |
| 8222 | |
| 8223 | editors.push_back(prop); |
| 8224 | properties.push_back(pinfo[i].name); |
| 8225 | } |
| 8226 | VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor); |
| 8227 | editor->setup(vseditor, p_parent_resource, editors, properties, p_node->get_editable_properties_names(), p_node); |
| 8228 | return editor; |
| 8229 | } |
| 8230 | |
| 8231 | void EditorPropertyVisualShaderMode::_option_selected(int p_which) { |
| 8232 | Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object())); |
| 8233 | if (visual_shader->get_mode() == p_which) { |
| 8234 | return; |
| 8235 | } |
| 8236 | |
| 8237 | ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_editor_data().get_editor_by_name("Shader")); |
| 8238 | if (!shader_editor) { |
| 8239 | return; |
| 8240 | } |
| 8241 | VisualShaderEditor *editor = Object::cast_to<VisualShaderEditor>(shader_editor->get_shader_editor(visual_shader)); |
| 8242 | if (!editor) { |
| 8243 | return; |
| 8244 | } |
| 8245 | |
| 8246 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 8247 | undo_redo->create_action(TTR("Visual Shader Mode Changed")); |
| 8248 | //do is easy |
| 8249 | undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which); |
| 8250 | undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode()); |
| 8251 | |
| 8252 | undo_redo->add_do_method(editor, "_set_mode", p_which); |
| 8253 | undo_redo->add_undo_method(editor, "_set_mode", visual_shader->get_mode()); |
| 8254 | |
| 8255 | //now undo is hell |
| 8256 | |
| 8257 | //1. restore connections to output |
| 8258 | for (int i = 0; i < VisualShader::TYPE_MAX; i++) { |
| 8259 | VisualShader::Type type = VisualShader::Type(i); |
| 8260 | List<VisualShader::Connection> conns; |
| 8261 | visual_shader->get_node_connections(type, &conns); |
| 8262 | for (const VisualShader::Connection &E : conns) { |
| 8263 | if (E.to_node == VisualShader::NODE_ID_OUTPUT) { |
| 8264 | undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); |
| 8265 | } |
| 8266 | } |
| 8267 | } |
| 8268 | //2. restore input indices |
| 8269 | for (int i = 0; i < VisualShader::TYPE_MAX; i++) { |
| 8270 | VisualShader::Type type = VisualShader::Type(i); |
| 8271 | Vector<int> nodes = visual_shader->get_node_list(type); |
| 8272 | for (int j = 0; j < nodes.size(); j++) { |
| 8273 | Ref<VisualShaderNodeInput> input = visual_shader->get_node(type, nodes[j]); |
| 8274 | if (input.is_null()) { |
| 8275 | continue; |
| 8276 | } |
| 8277 | |
| 8278 | undo_redo->add_undo_method(input.ptr(), "set_input_name", input->get_input_name()); |
| 8279 | } |
| 8280 | } |
| 8281 | |
| 8282 | //3. restore enums and flags |
| 8283 | List<PropertyInfo> props; |
| 8284 | visual_shader->get_property_list(&props); |
| 8285 | |
| 8286 | for (const PropertyInfo &E : props) { |
| 8287 | if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) { |
| 8288 | undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name)); |
| 8289 | } |
| 8290 | } |
| 8291 | |
| 8292 | //4. delete varyings (if needed) |
| 8293 | if (p_which == VisualShader::MODE_PARTICLES || p_which == VisualShader::MODE_SKY || p_which == VisualShader::MODE_FOG) { |
| 8294 | int var_count = visual_shader->get_varyings_count(); |
| 8295 | |
| 8296 | if (var_count > 0) { |
| 8297 | for (int i = 0; i < var_count; i++) { |
| 8298 | const VisualShader::Varying *var = visual_shader->get_varying_by_index(i); |
| 8299 | undo_redo->add_do_method(visual_shader.ptr(), "remove_varying", var->name); |
| 8300 | undo_redo->add_undo_method(visual_shader.ptr(), "add_varying", var->name, var->mode, var->type); |
| 8301 | } |
| 8302 | |
| 8303 | undo_redo->add_do_method(editor, "_update_varyings"); |
| 8304 | undo_redo->add_undo_method(editor, "_update_varyings"); |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | undo_redo->add_do_method(editor, "_update_nodes"); |
| 8309 | undo_redo->add_undo_method(editor, "_update_nodes"); |
| 8310 | |
| 8311 | undo_redo->add_do_method(editor, "_update_graph"); |
| 8312 | undo_redo->add_undo_method(editor, "_update_graph"); |
| 8313 | |
| 8314 | undo_redo->commit_action(); |
| 8315 | } |
| 8316 | |
| 8317 | void EditorPropertyVisualShaderMode::update_property() { |
| 8318 | int which = get_edited_property_value(); |
| 8319 | options->select(which); |
| 8320 | } |
| 8321 | |
| 8322 | void EditorPropertyVisualShaderMode::setup(const Vector<String> &p_options) { |
| 8323 | for (int i = 0; i < p_options.size(); i++) { |
| 8324 | options->add_item(p_options[i], i); |
| 8325 | } |
| 8326 | } |
| 8327 | |
| 8328 | void EditorPropertyVisualShaderMode::set_option_button_clip(bool p_enable) { |
| 8329 | options->set_clip_text(p_enable); |
| 8330 | } |
| 8331 | |
| 8332 | EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() { |
| 8333 | options = memnew(OptionButton); |
| 8334 | options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 8335 | options->set_clip_text(true); |
| 8336 | add_child(options); |
| 8337 | add_focusable(options); |
| 8338 | options->connect(SceneStringName(item_selected), callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected)); |
| 8339 | } |
| 8340 | |
| 8341 | bool EditorInspectorVisualShaderModePlugin::can_handle(Object *p_object) { |
| 8342 | return true; // Can handle everything. |
| 8343 | } |
| 8344 | |
| 8345 | bool EditorInspectorVisualShaderModePlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) { |
| 8346 | if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) { |
| 8347 | EditorPropertyVisualShaderMode *mode_editor = memnew(EditorPropertyVisualShaderMode); |
| 8348 | Vector<String> options = p_hint_text.split(","); |
| 8349 | mode_editor->setup(options); |
| 8350 | add_property_editor(p_path, mode_editor); |
| 8351 | |
| 8352 | return true; |
| 8353 | } |
| 8354 | |
| 8355 | return false; |
| 8356 | } |
| 8357 | |
| 8358 | ////////////////////////////////// |
| 8359 | |
| 8360 | void VisualShaderNodePortPreview::_shader_changed() { |
| 8361 | if (!is_valid || shader.is_null()) { |
| 8362 | return; |
| 8363 | } |
| 8364 | |
| 8365 | Vector<VisualShader::DefaultTextureParam> default_textures; |
| 8366 | String shader_code = shader->generate_preview_shader(type, node, port, default_textures); |
| 8367 | |
| 8368 | Ref<Shader> preview_shader; |
| 8369 | preview_shader.instantiate(); |
| 8370 | preview_shader->set_code(shader_code); |
| 8371 | for (int i = 0; i < default_textures.size(); i++) { |
| 8372 | int j = 0; |
| 8373 | for (List<Ref<Texture>>::ConstIterator itr = default_textures[i].params.begin(); itr != default_textures[i].params.end(); ++itr, ++j) { |
| 8374 | preview_shader->set_default_texture_parameter(default_textures[i].name, *itr, j); |
| 8375 | } |
| 8376 | } |
| 8377 | |
| 8378 | Ref<ShaderMaterial> mat; |
| 8379 | mat.instantiate(); |
| 8380 | mat->set_shader(preview_shader); |
| 8381 | |
| 8382 | if (preview_mat.is_valid() && preview_mat->get_shader().is_valid()) { |
| 8383 | List<PropertyInfo> params; |
| 8384 | preview_mat->get_shader()->get_shader_uniform_list(¶ms); |
| 8385 | for (const PropertyInfo &E : params) { |
| 8386 | mat->set_shader_parameter(E.name, preview_mat->get_shader_parameter(E.name)); |
| 8387 | } |
| 8388 | } |
| 8389 | |
| 8390 | set_material(mat); |
| 8391 | } |
| 8392 | |
| 8393 | void VisualShaderNodePortPreview::setup(const Ref<VisualShader> &p_shader, Ref<ShaderMaterial> &p_preview_material, VisualShader::Type p_type, bool p_has_transparency, int p_node, int p_port, bool p_is_valid) { |
| 8394 | if (p_has_transparency) { |
| 8395 | checkerboard = memnew(TextureRect); |
| 8396 | checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE); |
| 8397 | checkerboard->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); |
| 8398 | checkerboard->set_draw_behind_parent(true); |
| 8399 | add_child(checkerboard); |
| 8400 | } |
| 8401 | |
| 8402 | set_mouse_filter(MOUSE_FILTER_PASS); |
| 8403 | shader = p_shader; |
| 8404 | shader->connect_changed(callable_mp(this, &VisualShaderNodePortPreview::_shader_changed), CONNECT_DEFERRED); |
| 8405 | preview_mat = p_preview_material; |
| 8406 | type = p_type; |
| 8407 | port = p_port; |
| 8408 | node = p_node; |
| 8409 | is_valid = p_is_valid; |
| 8410 | queue_redraw(); |
| 8411 | _shader_changed(); |
| 8412 | } |
| 8413 | |
| 8414 | Size2 VisualShaderNodePortPreview::get_minimum_size() const { |
| 8415 | int port_preview_size = EDITOR_GET("editors/visual_editors/visual_shader/port_preview_size"); |
| 8416 | return Size2(port_preview_size, port_preview_size) * EDSCALE; |
| 8417 | } |
| 8418 | |
| 8419 | void VisualShaderNodePortPreview::_notification(int p_what) { |
| 8420 | switch (p_what) { |
| 8421 | case NOTIFICATION_THEME_CHANGED: { |
| 8422 | if (checkerboard != nullptr) { |
| 8423 | checkerboard->set_texture(get_theme_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); |
| 8424 | } |
| 8425 | } break; |
| 8426 | case NOTIFICATION_DRAW: { |
| 8427 | Vector<Vector2> points = { |
| 8428 | Vector2(), |
| 8429 | Vector2(get_size().width, 0), |
| 8430 | get_size(), |
| 8431 | Vector2(0, get_size().height) |
| 8432 | }; |
| 8433 | |
| 8434 | Vector<Vector2> uvs = { |
| 8435 | Vector2(0, 0), |
| 8436 | Vector2(1, 0), |
| 8437 | Vector2(1, 1), |
| 8438 | Vector2(0, 1) |
| 8439 | }; |
| 8440 | |
| 8441 | if (is_valid) { |
| 8442 | Vector<Color> colors = { |
| 8443 | Color(1, 1, 1, 1), |
| 8444 | Color(1, 1, 1, 1), |
| 8445 | Color(1, 1, 1, 1), |
| 8446 | Color(1, 1, 1, 1) |
| 8447 | }; |
| 8448 | draw_primitive(points, colors, uvs); |
| 8449 | } else { |
| 8450 | Vector<Color> colors = { |
| 8451 | Color(0, 0, 0, 1), |
| 8452 | Color(0, 0, 0, 1), |
| 8453 | Color(0, 0, 0, 1), |
| 8454 | Color(0, 0, 0, 1) |
| 8455 | }; |
| 8456 | draw_primitive(points, colors, uvs); |
| 8457 | } |
| 8458 | |
| 8459 | } break; |
| 8460 | } |
| 8461 | } |
| 8462 | |
| 8463 | ////////////////////////////////// |
| 8464 | |
| 8465 | String VisualShaderConversionPlugin::converts_to() const { |
| 8466 | return "Shader"; |
| 8467 | } |
| 8468 | |
| 8469 | bool VisualShaderConversionPlugin::handles(const Ref<Resource> &p_resource) const { |
| 8470 | Ref<VisualShader> vshader = p_resource; |
| 8471 | return vshader.is_valid(); |
| 8472 | } |
| 8473 | |
| 8474 | Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resource) const { |
| 8475 | Ref<VisualShader> vshader = p_resource; |
| 8476 | ERR_FAIL_COND_V(vshader.is_null(), Ref<Resource>()); |
| 8477 | int embed = vshader->has_node_embeds(); |
| 8478 | |
| 8479 | EditorToaster *toast = EditorToaster::get_singleton(); |
| 8480 | if (toast == nullptr) { |
| 8481 | ERR_FAIL_COND_V_MSG(embed == 2, Ref<Resource>(), "Cannot convert VisualShader to GDShader because VisualShader has embedded subresources."); |
| 8482 | if (embed == 1) { |
| 8483 | WARN_PRINT("Visual Shader conversion cannot convert external dependencies. Resource references from Nodes will have to be rebound as ShaderParameters on a Material."); |
| 8484 | } |
| 8485 | } else if (embed == 2) { |
| 8486 | toast->popup_str(TTR("Cannot convert VisualShader to GDShader because VisualShader has embedded subresources."), EditorToaster::SEVERITY_ERROR); |
| 8487 | return Ref<Resource>(); |
| 8488 | } else if (embed == 1) { |
| 8489 | toast->popup_str(TTR("Visual Shader conversion cannot convert external dependencies. Resource references from Nodes will have to be rebound as ShaderParameters on a Material."), EditorToaster::SEVERITY_WARNING); |
| 8490 | } |
| 8491 | |
| 8492 | Ref<Shader> shader; |
| 8493 | shader.instantiate(); |
| 8494 | |
| 8495 | String code = vshader->get_code(); |
| 8496 | shader->set_code(code); |
| 8497 | |
| 8498 | return shader; |
| 8499 | } |