Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/shader/visual_shader_editor_plugin.h
9903 views
1
/**************************************************************************/
2
/* visual_shader_editor_plugin.h */
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
#pragma once
32
33
#include "editor/inspector/editor_properties.h"
34
#include "editor/plugins/editor_plugin.h"
35
#include "editor/plugins/editor_resource_conversion_plugin.h"
36
#include "editor/shader/shader_editor.h"
37
#include "scene/gui/graph_edit.h"
38
#include "scene/resources/syntax_highlighter.h"
39
#include "scene/resources/visual_shader.h"
40
41
class CodeEdit;
42
class ColorPicker;
43
class CurveEditor;
44
class GraphElement;
45
class GraphFrame;
46
class HFlowContainer;
47
class MenuButton;
48
class PopupPanel;
49
class RichTextLabel;
50
class Tree;
51
52
class VisualShaderEditor;
53
class MaterialEditor;
54
55
class VisualShaderNodePlugin : public RefCounted {
56
GDCLASS(VisualShaderNodePlugin, RefCounted);
57
58
protected:
59
VisualShaderEditor *vseditor = nullptr;
60
61
protected:
62
static void _bind_methods();
63
64
GDVIRTUAL2RC(Object *, _create_editor, Ref<Resource>, Ref<VisualShaderNode>)
65
66
public:
67
void set_editor(VisualShaderEditor *p_editor);
68
virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node);
69
};
70
71
class VSGraphNode : public GraphNode {
72
GDCLASS(VSGraphNode, GraphNode);
73
74
protected:
75
void _draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color, const Color &p_rim_color);
76
virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override;
77
};
78
79
class VSRerouteNode : public VSGraphNode {
80
GDCLASS(VSRerouteNode, GraphNode);
81
82
const float FADE_ANIMATION_LENGTH_SEC = 0.3;
83
84
float icon_opacity = 0.0;
85
86
protected:
87
void _notification(int p_what);
88
89
virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) override;
90
91
public:
92
VSRerouteNode();
93
void set_icon_opacity(float p_opacity);
94
95
void _on_mouse_entered();
96
void _on_mouse_exited();
97
};
98
99
class VisualShaderGraphPlugin : public RefCounted {
100
GDCLASS(VisualShaderGraphPlugin, RefCounted);
101
102
private:
103
VisualShaderEditor *editor = nullptr;
104
105
struct InputPort {
106
Button *default_input_button = nullptr;
107
};
108
109
struct Port {
110
VisualShaderNode::PortType type = VisualShaderNode::PORT_TYPE_SCALAR;
111
TextureButton *preview_button = nullptr;
112
};
113
114
struct Link {
115
VisualShader::Type type = VisualShader::Type::TYPE_MAX;
116
VisualShaderNode *visual_node = nullptr;
117
GraphElement *graph_element = nullptr;
118
bool preview_visible = false;
119
int preview_pos = 0;
120
HashMap<int, InputPort> input_ports;
121
HashMap<int, Port> output_ports;
122
VBoxContainer *preview_box = nullptr;
123
LineEdit *parameter_name = nullptr;
124
CodeEdit *expression_edit = nullptr;
125
CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr };
126
};
127
128
Ref<VisualShader> visual_shader;
129
HashMap<int, Link> links;
130
List<VisualShader::Connection> connections;
131
132
Color vector_expanded_color[4];
133
134
// Visual shader specific theme for using MSDF fonts (on GraphNodes) which reduce aliasing at higher zoom levels.
135
Ref<Theme> vs_msdf_fonts_theme;
136
137
protected:
138
static void _bind_methods();
139
140
public:
141
void set_editor(VisualShaderEditor *p_editor);
142
void register_shader(VisualShader *p_visual_shader);
143
void set_connections(const List<VisualShader::Connection> &p_connections);
144
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element);
145
void register_output_port(int p_id, int p_port, VisualShaderNode::PortType p_port_type, TextureButton *p_button);
146
void register_parameter_name(int p_id, LineEdit *p_parameter_name);
147
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
148
void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);
149
void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor);
150
void clear_links();
151
void set_shader_type(VisualShader::Type p_type);
152
bool is_preview_visible(int p_id) const;
153
void update_node(VisualShader::Type p_type, int p_id);
154
void update_node_deferred(VisualShader::Type p_type, int p_node_id);
155
void add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames);
156
void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update);
157
void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
158
void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
159
void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid);
160
void update_frames(VisualShader::Type p_type, int p_node);
161
void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);
162
void refresh_node_ports(VisualShader::Type p_type, int p_node);
163
void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value);
164
void update_parameter_refs();
165
void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name);
166
void update_curve(int p_node_id);
167
void update_curve_xyz(int p_node_id);
168
void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);
169
void attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id);
170
void detach_node_from_frame(VisualShader::Type p_type, int p_node_id);
171
void set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable);
172
void set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color);
173
void set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable);
174
void update_reroute_nodes();
175
int get_constant_index(float p_constant) const;
176
Ref<Script> get_node_script(int p_node_id) const;
177
void update_theme();
178
bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const;
179
180
VisualShaderGraphPlugin();
181
};
182
183
class VisualShaderEditedProperty : public RefCounted {
184
GDCLASS(VisualShaderEditedProperty, RefCounted);
185
186
private:
187
Variant edited_property;
188
189
protected:
190
static void _bind_methods();
191
192
public:
193
void set_edited_property(const Variant &p_variant);
194
Variant get_edited_property() const;
195
};
196
197
class VisualShaderEditor : public ShaderEditor {
198
GDCLASS(VisualShaderEditor, ShaderEditor);
199
friend class VisualShaderGraphPlugin;
200
201
Ref<ConfigFile> vs_editor_cache; // Keeps the graph offsets and zoom levels for each VisualShader that has been edited.
202
203
PopupPanel *property_editor_popup = nullptr;
204
EditorProperty *property_editor = nullptr;
205
int editing_node = -1;
206
int editing_port = -1;
207
Ref<VisualShaderEditedProperty> edited_property_holder;
208
209
MaterialEditor *material_editor = nullptr;
210
Ref<VisualShader> visual_shader;
211
Ref<ShaderMaterial> preview_material;
212
Ref<Environment> env;
213
String param_filter_name;
214
EditorProperty *current_prop = nullptr;
215
VBoxContainer *shader_preview_vbox = nullptr;
216
Button *site_search = nullptr;
217
Button *toggle_files_button = nullptr;
218
Control *toggle_files_list = nullptr;
219
GraphEdit *graph = nullptr;
220
Button *add_node = nullptr;
221
MenuButton *varying_button = nullptr;
222
Button *code_preview_button = nullptr;
223
Button *shader_preview_button = nullptr;
224
HFlowContainer *toolbar_hflow = nullptr;
225
226
int last_to_node = -1;
227
int last_to_port = -1;
228
Label *info_label = nullptr;
229
230
OptionButton *edit_type = nullptr;
231
OptionButton *edit_type_standard = nullptr;
232
OptionButton *edit_type_particles = nullptr;
233
OptionButton *edit_type_sky = nullptr;
234
OptionButton *edit_type_fog = nullptr;
235
CheckBox *custom_mode_box = nullptr;
236
bool custom_mode_enabled = false;
237
238
bool pending_update_preview = false;
239
bool shader_error = false;
240
AcceptDialog *code_preview_window = nullptr;
241
VBoxContainer *code_preview_vbox = nullptr;
242
CodeEdit *preview_text = nullptr;
243
Ref<CodeHighlighter> syntax_highlighter = nullptr;
244
PanelContainer *error_panel = nullptr;
245
Label *error_label = nullptr;
246
247
bool pending_custom_scripts_to_delete = false;
248
List<Ref<Script>> custom_scripts_to_delete;
249
250
bool _block_update_options_menu = false;
251
bool _block_rebuild_shader = false;
252
253
Point2 saved_node_pos;
254
bool saved_node_pos_dirty = false;
255
256
ConfirmationDialog *members_dialog = nullptr;
257
VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX;
258
VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX;
259
PopupMenu *popup_menu = nullptr;
260
PopupMenu *connection_popup_menu = nullptr;
261
PopupMenu *constants_submenu = nullptr;
262
MenuButton *tools = nullptr;
263
264
ConfirmationDialog *add_varying_dialog = nullptr;
265
OptionButton *varying_type = nullptr;
266
LineEdit *varying_name = nullptr;
267
OptionButton *varying_mode = nullptr;
268
Label *varying_error_label = nullptr;
269
270
ConfirmationDialog *remove_varying_dialog = nullptr;
271
Tree *varyings = nullptr;
272
273
PopupPanel *frame_title_change_popup = nullptr;
274
LineEdit *frame_title_change_edit = nullptr;
275
276
PopupPanel *frame_tint_color_pick_popup = nullptr;
277
ColorPicker *frame_tint_color_picker = nullptr;
278
279
bool code_preview_first = true;
280
bool code_preview_showed = false;
281
282
bool shader_preview_showed = true;
283
284
LineEdit *param_filter = nullptr;
285
MenuButton *preview_tools = nullptr;
286
String selected_param_id;
287
Tree *parameters = nullptr;
288
HashMap<String, PropertyInfo> parameter_props;
289
VBoxContainer *param_vbox = nullptr;
290
VBoxContainer *param_vbox2 = nullptr;
291
292
enum ShaderModeFlags {
293
MODE_FLAGS_SPATIAL_CANVASITEM = 1,
294
MODE_FLAGS_SKY = 2,
295
MODE_FLAGS_PARTICLES = 4,
296
MODE_FLAGS_FOG = 8,
297
};
298
299
int mode = MODE_FLAGS_SPATIAL_CANVASITEM;
300
VisualShader::Type current_type = VisualShader::Type::TYPE_VERTEX; // The type of the currently edited VisualShader.
301
302
enum TypeFlags {
303
TYPE_FLAGS_VERTEX = 1,
304
TYPE_FLAGS_FRAGMENT = 2,
305
TYPE_FLAGS_LIGHT = 4,
306
};
307
308
enum ParticlesTypeFlags {
309
TYPE_FLAGS_EMIT = 1,
310
TYPE_FLAGS_PROCESS = 2,
311
TYPE_FLAGS_COLLIDE = 4,
312
TYPE_FLAGS_EMIT_CUSTOM = 8,
313
TYPE_FLAGS_PROCESS_CUSTOM = 16,
314
};
315
316
enum SkyTypeFlags {
317
TYPE_FLAGS_SKY = 1,
318
};
319
320
enum FogTypeFlags {
321
TYPE_FLAGS_FOG = 1,
322
};
323
324
enum ToolsMenuOptions {
325
EXPAND_ALL,
326
COLLAPSE_ALL
327
};
328
329
enum PreviewToolsMenuOptions {
330
COPY_PARAMS_FROM_MATERIAL,
331
PASTE_PARAMS_TO_MATERIAL,
332
};
333
334
enum NodeMenuOptions {
335
ADD,
336
SEPARATOR, // ignore
337
CUT,
338
COPY,
339
PASTE,
340
DELETE_, // Conflict with WinAPI.
341
DUPLICATE,
342
CLEAR_COPY_BUFFER,
343
SEPARATOR2, // ignore
344
FLOAT_CONSTANTS,
345
CONVERT_CONSTANTS_TO_PARAMETERS,
346
CONVERT_PARAMETERS_TO_CONSTANTS,
347
UNLINK_FROM_PARENT_FRAME,
348
SEPARATOR3, // ignore
349
SET_FRAME_TITLE,
350
ENABLE_FRAME_COLOR,
351
SET_FRAME_COLOR,
352
ENABLE_FRAME_AUTOSHRINK,
353
};
354
355
enum ConnectionMenuOptions {
356
INSERT_NEW_NODE,
357
INSERT_NEW_REROUTE,
358
DISCONNECT,
359
};
360
361
enum class VaryingMenuOptions {
362
ADD,
363
REMOVE,
364
};
365
366
Tree *members = nullptr;
367
AcceptDialog *alert = nullptr;
368
LineEdit *node_filter = nullptr;
369
RichTextLabel *node_desc = nullptr;
370
Label *highend_label = nullptr;
371
372
void _tools_menu_option(int p_idx);
373
void _show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX);
374
375
void _varying_menu_id_pressed(int p_idx);
376
void _show_add_varying_dialog();
377
void _show_remove_varying_dialog();
378
379
void _preview_tools_menu_option(int p_idx);
380
void _clear_preview_param();
381
void _update_preview_parameter_list();
382
bool _update_preview_parameter_tree();
383
384
void _update_nodes();
385
void _update_graph();
386
387
void _restore_editor_state();
388
389
String _get_cache_id_string() const;
390
String _get_cache_key(const String &p_prop_name) const;
391
392
struct AddOption {
393
String name;
394
String category;
395
String type;
396
String description;
397
Vector<Variant> ops;
398
Ref<Script> script;
399
int mode = 0;
400
int return_type = 0;
401
int func = 0;
402
bool highend = false;
403
bool is_custom = false;
404
bool is_native = false;
405
mutable int temp_idx = 0;
406
407
AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_type = String(), const String &p_description = String(), const Vector<Variant> &p_ops = Vector<Variant>(), int p_return_type = -1, int p_mode = -1, int p_func = -1, bool p_highend = false) {
408
name = p_name;
409
type = p_type;
410
category = p_category;
411
description = p_description;
412
ops = p_ops;
413
return_type = p_return_type;
414
mode = p_mode;
415
func = p_func;
416
highend = p_highend;
417
}
418
};
419
struct _OptionComparator {
420
_FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const {
421
return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0;
422
}
423
};
424
425
Vector<AddOption> add_options;
426
int cubemap_node_option_idx;
427
int texture2d_node_option_idx;
428
int texture2d_array_node_option_idx;
429
int texture3d_node_option_idx;
430
int custom_node_option_idx;
431
int curve_node_option_idx;
432
int curve_xyz_node_option_idx;
433
int mesh_emitter_option_idx;
434
List<String> keyword_list;
435
436
List<VisualShaderNodeParameterRef> uniform_refs;
437
438
void _draw_color_over_button(Object *p_obj, Color p_color);
439
440
void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops);
441
void _add_node(int p_idx, const Vector<Variant> &p_ops, const String &p_resource_path = "", int p_node_idx = -1);
442
void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type);
443
void _remove_varying(const String &p_name);
444
void _update_options_menu();
445
void _set_mode(int p_which);
446
447
void _show_preview_text();
448
void _preview_close_requested();
449
void _preview_size_changed();
450
void _update_preview();
451
void _update_next_previews(int p_node_id);
452
void _get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const;
453
String _get_description(int p_idx);
454
455
void _show_shader_preview();
456
457
void _toggle_files_pressed();
458
459
Vector<int> nodes_link_to_frame_buffer; // Contains the nodes that are requested to be linked to a frame. This is used to perform one Undo/Redo operation for dragging nodes.
460
int frame_node_id_to_link_to = -1;
461
462
struct DragOp {
463
VisualShader::Type type = VisualShader::Type::TYPE_MAX;
464
int node = 0;
465
Vector2 from;
466
Vector2 to;
467
};
468
List<DragOp> drag_buffer;
469
470
Timer *panning_debounce_timer = nullptr;
471
bool shader_fully_loaded = false;
472
473
bool drag_dirty = false;
474
void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
475
void _nodes_dragged();
476
477
void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
478
void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
479
480
void _scroll_offset_changed(const Vector2 &p_scroll);
481
void _node_selected(Object *p_node);
482
483
void _delete_nodes(int p_type, const List<int> &p_nodes);
484
void _delete_node_request(int p_type, int p_node);
485
void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
486
487
void _node_changed(int p_id);
488
489
void _nodes_linked_to_frame_request(const TypedArray<StringName> &p_nodes, const StringName &p_frame);
490
void _frame_rect_changed(const GraphFrame *p_frame, const Rect2 &p_new_rect);
491
492
void _edit_port_default_input(Object *p_button, int p_node, int p_port);
493
void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
494
495
int to_node = -1;
496
int to_slot = -1;
497
int from_node = -1;
498
int from_slot = -1;
499
500
Ref<GraphEdit::Connection> clicked_connection;
501
bool connection_node_insert_requested = false;
502
503
HashSet<int> selected_constants;
504
HashSet<int> selected_parameters;
505
int selected_frame = -1;
506
int selected_float_constant = -1;
507
508
void _convert_constants_to_parameters(bool p_vice_versa);
509
void _detach_nodes_from_frame_request();
510
void _detach_nodes_from_frame(int p_type, const List<int> &p_nodes);
511
void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);
512
void _update_constant(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port);
513
void _update_parameter(VisualShader::Type p_type_id, int p_node_id, const Variant &p_var, int p_preview_port);
514
515
void _unlink_node_from_parent_frame(int p_node_id);
516
517
void _connection_drag_ended();
518
void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
519
void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
520
bool _check_node_drop_on_connection(const Vector2 &p_position, Ref<GraphEdit::Connection> *r_closest_connection, int *r_node_id = nullptr, int *r_to_port = nullptr);
521
void _handle_node_drop_on_connection();
522
523
void _frame_title_popup_show(const Point2 &p_position, int p_node_id);
524
void _frame_title_popup_hide();
525
void _frame_title_popup_focus_out();
526
void _frame_title_text_changed(const String &p_new_text);
527
void _frame_title_text_submitted(const String &p_new_text);
528
529
void _frame_color_enabled_changed(int p_node_id);
530
void _frame_color_popup_show(const Point2 &p_position, int p_node_id);
531
void _frame_color_popup_hide();
532
void _frame_color_confirm();
533
void _frame_color_changed(const Color &p_color);
534
535
void _frame_autoshrink_enabled_changed(int p_node_id);
536
537
void _parameter_line_edit_changed(const String &p_text, int p_node_id);
538
void _parameter_line_edit_focus_out(Object *p_line_edit, int p_node_id);
539
540
void _port_name_focus_out(Object *p_line_edit, int p_node_id, int p_port_id, bool p_output);
541
542
struct CopyItem {
543
int id;
544
Ref<VisualShaderNode> node;
545
Vector2 position;
546
Vector2 size;
547
String group_inputs;
548
String group_outputs;
549
String expression;
550
bool disabled = false;
551
};
552
553
void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections);
554
void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate);
555
556
void _duplicate_nodes();
557
558
static Vector2 selection_center;
559
static List<CopyItem> copy_items_buffer;
560
static List<VisualShader::Connection> copy_connections_buffer;
561
562
void _clear_copy_buffer();
563
void _copy_nodes(bool p_cut);
564
void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2());
565
566
Vector<Ref<VisualShaderNodePlugin>> plugins;
567
Ref<VisualShaderGraphPlugin> graph_plugin;
568
569
void _type_selected(int p_id);
570
void _custom_mode_toggled(bool p_enabled);
571
572
void _input_select_item(Ref<VisualShaderNodeInput> p_input, const String &p_name);
573
void _parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, const String &p_name);
574
void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, const String &p_name);
575
576
void _float_constant_selected(int p_which);
577
578
void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name);
579
void _remove_input_port(int p_node, int p_port);
580
void _change_input_port_type(int p_type, int p_node, int p_port);
581
void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
582
583
void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name);
584
void _remove_output_port(int p_node, int p_port);
585
void _change_output_port_type(int p_type, int p_node, int p_port);
586
void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
587
void _expand_output_port(int p_node, int p_port, bool p_expand);
588
589
void _expression_focus_out(Object *p_code_edit, int p_node);
590
591
void _set_node_size(int p_type, int p_node, const Size2 &p_size);
592
void _node_resized(const Vector2 &p_new_size, int p_type, int p_node);
593
594
void _preview_select_port(int p_node, int p_port);
595
void _graph_gui_input(const Ref<InputEvent> &p_event);
596
597
void _member_filter_changed(const String &p_text);
598
void _sbox_input(const Ref<InputEvent> &p_event);
599
void _member_selected();
600
void _member_create();
601
void _member_cancel();
602
603
void _varying_create();
604
void _varying_validate();
605
void _varying_type_changed(int p_index);
606
void _varying_mode_changed(int p_index);
607
void _varying_name_changed(const String &p_name);
608
void _varying_deleted();
609
void _varying_selected();
610
void _varying_unselected();
611
void _update_varying_tree();
612
613
void _set_custom_node_option(int p_index, int p_node, int p_op);
614
615
Vector2 menu_point;
616
void _node_menu_id_pressed(int p_idx);
617
void _connection_menu_id_pressed(int p_idx);
618
619
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
620
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
621
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
622
623
bool _is_available(int p_mode);
624
void _update_parameters(bool p_update_refs);
625
void _update_parameter_refs(HashSet<String> &p_names);
626
void _update_varyings();
627
628
void _update_options_menu_deferred();
629
void _rebuild_shader_deferred();
630
631
void _visibility_changed();
632
633
void _get_current_mode_limits(int &r_begin_type, int &r_end_type) const;
634
void _update_custom_script(const Ref<Script> &p_script);
635
void _script_created(const Ref<Script> &p_script);
636
void _resource_saved(const Ref<Resource> &p_resource);
637
void _resource_removed(const Ref<Resource> &p_resource);
638
void _resources_removed();
639
640
void _param_property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false);
641
void _update_current_param();
642
void _param_filter_changed(const String &p_text);
643
void _param_selected();
644
void _param_unselected();
645
646
void _help_open();
647
648
protected:
649
void _notification(int p_what);
650
static void _bind_methods();
651
652
public:
653
virtual void edit_shader(const Ref<Shader> &p_shader) override;
654
virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) override;
655
virtual void apply_shaders() override;
656
virtual bool is_unsaved() const override;
657
virtual void save_external_data(const String &p_str = "") override;
658
virtual void validate_script() override;
659
660
void save_editor_layout();
661
662
void set_current_shader_type(VisualShader::Type p_type);
663
VisualShader::Type get_current_shader_type() const;
664
665
void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
666
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
667
668
VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }
669
670
void clear_custom_types();
671
void 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);
672
void set_toggle_list_control(Control *p_control);
673
674
Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node);
675
void update_custom_type(const Ref<Resource> &p_resource);
676
677
virtual Size2 get_minimum_size() const override;
678
void update_toggle_files_button();
679
680
Ref<VisualShader> get_visual_shader() const { return visual_shader; }
681
682
VisualShaderEditor();
683
~VisualShaderEditor();
684
};
685
686
class VisualShaderNodePluginDefault : public VisualShaderNodePlugin {
687
GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin);
688
689
public:
690
virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override;
691
};
692
693
class EditorPropertyVisualShaderMode : public EditorProperty {
694
GDCLASS(EditorPropertyVisualShaderMode, EditorProperty);
695
OptionButton *options = nullptr;
696
697
void _option_selected(int p_which);
698
699
public:
700
void setup(const Vector<String> &p_options);
701
virtual void update_property() override;
702
void set_option_button_clip(bool p_enable);
703
EditorPropertyVisualShaderMode();
704
};
705
706
class EditorInspectorVisualShaderModePlugin : public EditorInspectorPlugin {
707
GDCLASS(EditorInspectorVisualShaderModePlugin, EditorInspectorPlugin);
708
709
public:
710
virtual bool can_handle(Object *p_object) override;
711
virtual bool 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 = false) override;
712
};
713
714
class VisualShaderNodePortPreview : public Control {
715
GDCLASS(VisualShaderNodePortPreview, Control);
716
TextureRect *checkerboard = nullptr;
717
Ref<VisualShader> shader;
718
Ref<ShaderMaterial> preview_mat;
719
VisualShader::Type type = VisualShader::Type::TYPE_MAX;
720
int node = 0;
721
int port = 0;
722
bool is_valid = false;
723
void _shader_changed(); //must regen
724
protected:
725
void _notification(int p_what);
726
727
public:
728
virtual Size2 get_minimum_size() const override;
729
void 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);
730
};
731
732
class VisualShaderConversionPlugin : public EditorResourceConversionPlugin {
733
GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin);
734
735
public:
736
virtual String converts_to() const override;
737
virtual bool handles(const Ref<Resource> &p_resource) const override;
738
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
739
};
740
741