summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp5
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp5
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp27
-rw-r--r--editor/plugins/audio_stream_editor_plugin.cpp6
-rw-r--r--editor/plugins/audio_stream_editor_plugin.h3
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp51
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp2
-rw-r--r--editor/plugins/curve_editor_plugin.cpp4
-rw-r--r--editor/plugins/editor_preview_plugins.cpp30
-rw-r--r--editor/plugins/editor_preview_plugins.h8
-rw-r--r--editor/plugins/gpu_particles_2d_editor_plugin.cpp2
-rw-r--r--editor/plugins/gpu_particles_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp12
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp803
-rw-r--r--editor/plugins/node_3d_editor_plugin.h68
-rw-r--r--editor/plugins/packed_scene_translation_parser_plugin.cpp2
-rw-r--r--editor/plugins/script_editor_plugin.cpp19
-rw-r--r--editor/plugins/script_text_editor.cpp42
-rw-r--r--editor/plugins/shader_editor_plugin.cpp34
-rw-r--r--editor/plugins/skeleton_3d_editor_plugin.cpp6
-rw-r--r--editor/plugins/sprite_2d_editor_plugin.cpp5
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp7
-rw-r--r--editor/plugins/text_editor.cpp30
-rw-r--r--editor/plugins/texture_3d_editor_plugin.cpp11
-rw-r--r--editor/plugins/texture_3d_editor_plugin.h4
-rw-r--r--editor/plugins/texture_editor_plugin.cpp8
-rw-r--r--editor/plugins/texture_editor_plugin.h2
-rw-r--r--editor/plugins/texture_layered_editor_plugin.cpp12
-rw-r--r--editor/plugins/texture_layered_editor_plugin.h3
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp75
-rw-r--r--editor/plugins/texture_region_editor_plugin.h4
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp19
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp21
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp691
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h21
35 files changed, 1620 insertions, 424 deletions
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index fbfcac3d22..e7e069e8b6 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -255,6 +255,9 @@ void AnimationNodeBlendTreeEditor::_update_graph() {
graph->connect_node(from, 0, to, to_idx);
}
+
+ float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
+ graph->set_minimap_opacity(graph_minimap_opacity);
}
void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) {
@@ -888,6 +891,8 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));
+ float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
+ graph->set_minimap_opacity(graph_minimap_opacity);
VSeparator *vs = memnew(VSeparator);
graph->get_zoom_hbox()->add_child(vs);
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 56d82acd2f..7c623505b5 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -78,7 +78,6 @@ void AnimationPlayerEditor::_notification(int p_what) {
}
frame->set_value(player->get_current_animation_position());
track_editor->set_anim_pos(player->get_current_animation_position());
- EditorNode::get_singleton()->get_inspector()->refresh();
} else if (!player->is_valid()) {
// Reset timeline when the player has been stopped externally
@@ -1072,8 +1071,6 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag)
frame->set_value(Math::snapped(p_pos, _get_editor_step()));
updating = false;
_seek_value_changed(p_pos, !p_drag);
-
- EditorNode::get_singleton()->get_inspector()->refresh();
}
void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
@@ -1400,7 +1397,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
// Render every past/future step with the capture shader.
RS::get_singleton()->canvas_item_set_material(onion.capture.canvas_item, onion.capture.material->get_rid());
- onion.capture.material->set_shader_param("bkg_color", GLOBAL_GET("rendering/environment/default_clear_color"));
+ onion.capture.material->set_shader_param("bkg_color", GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
onion.capture.material->set_shader_param("differences_only", onion.differences_only);
onion.capture.material->set_shader_param("present", onion.differences_only ? RS::get_singleton()->viewport_get_texture(present_rid) : RID());
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index b2d143c416..4d9c5625a3 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -350,7 +350,7 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int
if (sha256 != download_sha256) {
error_text = TTR("Bad download hash, assuming file has been tampered with.") + "\n";
error_text += TTR("Expected:") + " " + sha256 + "\n" + TTR("Got:") + " " + download_sha256;
- status->set_text(TTR("Failed sha256 hash check"));
+ status->set_text(TTR("Failed SHA-256 hash check"));
}
}
} break;
@@ -359,6 +359,8 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int
if (error_text != String()) {
download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text);
download_error->popup_centered();
+ // Let the user retry the download.
+ retry->show();
return;
}
@@ -459,6 +461,9 @@ void EditorAssetLibraryItemDownload::_install() {
}
void EditorAssetLibraryItemDownload::_make_request() {
+ // Hide the Retry button if we've just pressed it.
+ retry->hide();
+
download->cancel_request();
download->set_download_file(EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
@@ -516,6 +521,8 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() {
retry = memnew(Button);
retry->set_text(TTR("Retry"));
retry->connect("pressed", callable_mp(this, &EditorAssetLibraryItemDownload::_make_request));
+ // Only show the Retry button in case of a failure.
+ retry->hide();
hb2->add_child(retry);
hb2->add_child(install);
@@ -900,7 +907,7 @@ void EditorAssetLibrary::_search(int p_page) {
}
if (filter->get_text() != String()) {
- args += "&filter=" + filter->get_text().http_escape();
+ args += "&filter=" + filter->get_text().uri_encode();
}
if (p_page > 0) {
@@ -1364,10 +1371,18 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
search_hb2->add_child(memnew(Label(TTR("Site:") + " ")));
repository = memnew(OptionButton);
- repository->add_item("godotengine.org");
- repository->set_item_metadata(0, "https://godotengine.org/asset-library/api");
- repository->add_item("localhost");
- repository->set_item_metadata(1, "http://127.0.0.1/asset-library/api");
+ {
+ Dictionary default_urls;
+ default_urls["godotengine.org"] = "https://godotengine.org/asset-library/api";
+ default_urls["localhost"] = "http://127.0.0.1/asset-library/api";
+ Dictionary available_urls = _EDITOR_DEF("asset_library/available_urls", default_urls, true);
+ Array keys = available_urls.keys();
+ for (int i = 0; i < available_urls.size(); i++) {
+ String key = keys[i];
+ repository->add_item(key);
+ repository->set_item_metadata(i, available_urls[key]);
+ }
+ }
repository->connect("item_selected", callable_mp(this, &EditorAssetLibrary::_repository_changed));
diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp
index 1765c99572..5963092860 100644
--- a/editor/plugins/audio_stream_editor_plugin.cpp
+++ b/editor/plugins/audio_stream_editor_plugin.cpp
@@ -96,7 +96,7 @@ void AudioStreamEditor::_preview_changed(ObjectID p_which) {
}
}
-void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+void AudioStreamEditor::_audio_changed() {
if (!is_visible()) {
return;
}
@@ -172,7 +172,7 @@ void AudioStreamEditor::_seek_to(real_t p_x) {
void AudioStreamEditor::edit(Ref<AudioStream> p_stream) {
if (!stream.is_null()) {
- stream->remove_change_receptor(this);
+ stream->disconnect("changed", callable_mp(this, &AudioStreamEditor::_audio_changed));
}
stream = p_stream;
@@ -182,7 +182,7 @@ void AudioStreamEditor::edit(Ref<AudioStream> p_stream) {
_duration_label->set_text(text);
if (!stream.is_null()) {
- stream->add_change_receptor(this);
+ stream->connect("changed", callable_mp(this, &AudioStreamEditor::_audio_changed));
update();
} else {
hide();
diff --git a/editor/plugins/audio_stream_editor_plugin.h b/editor/plugins/audio_stream_editor_plugin.h
index f27add7229..aa906a6a05 100644
--- a/editor/plugins/audio_stream_editor_plugin.h
+++ b/editor/plugins/audio_stream_editor_plugin.h
@@ -53,6 +53,8 @@ class AudioStreamEditor : public ColorRect {
float _current;
bool _dragging;
+ void _audio_changed();
+
protected:
void _notification(int p_what);
void _preview_changed(ObjectID p_which);
@@ -63,7 +65,6 @@ protected:
void _draw_indicator();
void _on_input_indicator(Ref<InputEvent> p_event);
void _seek_to(real_t p_x);
- void _changed_callback(Object *p_changed, const char *p_prop) override;
static void _bind_methods();
public:
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index b1ce472043..82ebf48242 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -216,8 +216,8 @@ public:
grid_step_x->set_value(p_grid_step.x);
grid_step_y->set_value(p_grid_step.y);
primary_grid_steps->set_value(p_primary_grid_steps);
- rotation_offset->set_value(p_rotation_offset * (180 / Math_PI));
- rotation_step->set_value(p_rotation_step * (180 / Math_PI));
+ rotation_offset->set_value(Math::rad2deg(p_rotation_offset));
+ rotation_step->set_value(Math::rad2deg(p_rotation_step));
scale_step->set_value(p_scale_step);
}
@@ -225,8 +225,8 @@ public:
p_grid_offset = Point2(grid_offset_x->get_value(), grid_offset_y->get_value());
p_grid_step = Point2(grid_step_x->get_value(), grid_step_y->get_value());
p_primary_grid_steps = int(primary_grid_steps->get_value());
- p_rotation_offset = rotation_offset->get_value() / (180 / Math_PI);
- p_rotation_step = rotation_step->get_value() / (180 / Math_PI);
+ p_rotation_offset = Math::deg2rad(rotation_offset->get_value());
+ p_rotation_step = Math::deg2rad(rotation_step->get_value());
p_scale_step = scale_step->get_value();
}
};
@@ -629,9 +629,9 @@ void CanvasItemEditor::_get_canvas_items_at_pos(const Point2 &p_pos, Vector<_Sel
Node *node = r_items[i].item;
// Make sure the selected node is in the current scene, or editable
- while (node && node != get_tree()->get_edited_scene_root() && node->get_owner() != scene && !scene->is_editable_instance(node->get_owner())) {
- node = node->get_parent();
- };
+ if (node && node != get_tree()->get_edited_scene_root()) {
+ node = scene->get_deepest_editable_node(node);
+ }
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(node);
if (!p_allow_locked) {
@@ -762,7 +762,7 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
Node *scene = editor->get_edited_scene();
- bool editable = p_node == scene || p_node->get_owner() == scene || scene->is_editable_instance(p_node->get_owner());
+ bool editable = p_node == scene || p_node->get_owner() == scene || p_node == scene->get_deepest_editable_node(p_node);
bool lock_children = p_node->has_meta("_edit_group_") && p_node->get_meta("_edit_group_");
bool locked = _is_node_locked(p_node);
@@ -2902,21 +2902,22 @@ void CanvasItemEditor::_draw_guides() {
// Dragged guide
Color text_color = get_theme_color("font_color", "Editor");
- text_color.a = 0.5;
+ Color outline_color = text_color.inverted();
+ const float outline_size = 2;
if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE) {
String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).x)));
- Ref<Font> font = get_theme_font("font", "Label");
- int font_size = get_theme_font_size("font_size", "Label");
+ Ref<Font> font = get_theme_font("bold", "EditorFonts");
+ int font_size = get_theme_font_size("bold_size", "EditorFonts");
Size2 text_size = font->get_string_size(str, font_size);
- viewport->draw_string(font, Point2(dragged_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color);
+ viewport->draw_string(font, Point2(dragged_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color, outline_size, outline_color);
viewport->draw_line(Point2(dragged_guide_pos.x, 0), Point2(dragged_guide_pos.x, viewport->get_size().y), guide_color, Math::round(EDSCALE));
}
if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_H_GUIDE) {
String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).y)));
- Ref<Font> font = get_theme_font("font", "Label");
- int font_size = get_theme_font_size("font_size", "Label");
+ Ref<Font> font = get_theme_font("bold", "EditorFonts");
+ int font_size = get_theme_font_size("bold_size", "EditorFonts");
Size2 text_size = font->get_string_size(str, font_size);
- viewport->draw_string(font, Point2(RULER_WIDTH + 10, dragged_guide_pos.y + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color);
+ viewport->draw_string(font, Point2(RULER_WIDTH + 10, dragged_guide_pos.y + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color, outline_size, outline_color);
viewport->draw_line(Point2(0, dragged_guide_pos.y), Point2(viewport->get_size().x, dragged_guide_pos.y), guide_color, Math::round(EDSCALE));
}
}
@@ -3183,16 +3184,16 @@ void CanvasItemEditor::_draw_ruler_tool() {
float arc_1_start_angle =
end_to_begin.x < 0 ?
- (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 - vertical_angle_rad : Math_PI / 2.0) :
- (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 : Math_PI / 2.0 - vertical_angle_rad);
+ (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 - vertical_angle_rad : Math_PI / 2.0) :
+ (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 : Math_PI / 2.0 - vertical_angle_rad);
float arc_1_end_angle = arc_1_start_angle + vertical_angle_rad;
// Constrain arc to triangle height & max size
float arc_1_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, ABS(end_to_begin.y)), arc_max_radius);
float arc_2_start_angle =
end_to_begin.x < 0 ?
- (end_to_begin.y < 0 ? 0.0 : -horizontal_angle_rad) :
- (end_to_begin.y < 0 ? Math_PI - horizontal_angle_rad : Math_PI);
+ (end_to_begin.y < 0 ? 0.0 : -horizontal_angle_rad) :
+ (end_to_begin.y < 0 ? Math_PI - horizontal_angle_rad : Math_PI);
float arc_2_end_angle = arc_2_start_angle + horizontal_angle_rad;
// Constrain arc to triangle width & max size
float arc_2_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, ABS(end_to_begin.x)), arc_max_radius);
@@ -3901,7 +3902,7 @@ bool CanvasItemEditor::_build_bones_list(Node *p_node) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
Node *scene = editor->get_edited_scene();
- if (!canvas_item || !canvas_item->is_visible() || (canvas_item != scene && canvas_item->get_owner() != scene && !scene->is_editable_instance(canvas_item->get_owner()))) {
+ if (!canvas_item || !canvas_item->is_visible() || (canvas_item != scene && canvas_item->get_owner() != scene && canvas_item != scene->get_deepest_editable_node(canvas_item))) {
return false;
}
@@ -4197,7 +4198,7 @@ void CanvasItemEditor::_notification(int p_what) {
// the icon will be dark, so we need to lighten it before blending it
// with the red color.
const Color key_auto_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25);
- key_auto_insert_button->add_theme_color_override("icon_color_pressed", key_auto_color.lerp(Color(1, 0, 0), 0.55));
+ key_auto_insert_button->add_theme_color_override("icon_pressed_color", key_auto_color.lerp(Color(1, 0, 0), 0.55));
animation_menu->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
zoom_minus->set_icon(get_theme_icon("ZoomLess", "EditorIcons"));
@@ -5673,7 +5674,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
primary_grid_steps = 8; // A power-of-two value works better as a default
grid_step_multiplier = 0;
snap_rotation_offset = 0;
- snap_rotation_step = 15 / (180 / Math_PI);
+ snap_rotation_step = Math::deg2rad(15.0);
snap_scale_step = 0.1f;
smart_snap_active = false;
grid_snap_active = false;
@@ -5817,7 +5818,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
zoom_reset->set_flat(true);
zoom_hb->add_child(zoom_reset);
zoom_reset->add_theme_constant_override("outline_size", 1);
- zoom_reset->add_theme_color_override("font_outline_modulate", Color(0, 0, 0));
+ zoom_reset->add_theme_color_override("font_outline_color", Color(0, 0, 0));
zoom_reset->add_theme_color_override("font_color", Color(1, 1, 1));
zoom_reset->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_zoom_reset));
zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset"), KEY_MASK_CMD | KEY_0));
@@ -6657,7 +6658,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
}
label = memnew(Label);
- label->add_theme_color_override("font_color_shadow", Color(0, 0, 0, 1));
+ label->add_theme_color_override("font_shadow_color", Color(0, 0, 0, 1));
label->add_theme_constant_override("shadow_as_outline", 1 * EDSCALE);
label->hide();
canvas_item_editor->get_controls_container()->add_child(label);
@@ -6665,7 +6666,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
label_desc = memnew(Label);
label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type"));
label_desc->add_theme_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1));
- label_desc->add_theme_color_override("font_color_shadow", Color(0.2f, 0.2f, 0.2f, 1));
+ label_desc->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
label_desc->add_theme_constant_override("shadow_as_outline", 1 * EDSCALE);
label_desc->add_theme_constant_override("line_spacing", 0);
label_desc->hide();
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index a1e7d3d6e0..141ee35cdb 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -207,7 +207,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) {
} break;
}
- node->get_shape()->_change_notify();
+ node->get_shape()->notify_property_list_changed();
}
void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp
index 88e56ccfb9..bff5cb8d2a 100644
--- a/editor/plugins/curve_editor_plugin.cpp
+++ b/editor/plugins/curve_editor_plugin.cpp
@@ -353,8 +353,8 @@ void CurveEditor::open_context_menu(Vector2 pos) {
_context_menu->add_check_item(TTR("Linear"), CONTEXT_LINEAR);
bool is_linear = _selected_tangent == TANGENT_LEFT ?
- _curve_ref->get_point_left_mode(_selected_point) == Curve::TANGENT_LINEAR :
- _curve_ref->get_point_right_mode(_selected_point) == Curve::TANGENT_LINEAR;
+ _curve_ref->get_point_left_mode(_selected_point) == Curve::TANGENT_LINEAR :
+ _curve_ref->get_point_right_mode(_selected_point) == Curve::TANGENT_LINEAR;
_context_menu->set_item_checked(_context_menu->get_item_index(CONTEXT_LINEAR), is_linear);
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index bdf88b82e4..eb3c06fba1 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -301,7 +301,7 @@ EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() {
//////////////////////////////////////////////////////////////////
void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) {
- preview_done = true;
+ preview_done.set();
}
void EditorMaterialPreviewPlugin::_bind_methods() {
@@ -325,10 +325,10 @@ Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Si
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
- preview_done = false;
+ preview_done.clear();
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMaterialPreviewPlugin *>(this), "_preview_done", Variant());
- while (!preview_done) {
+ while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
@@ -382,7 +382,9 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
int lats = 32;
int lons = 32;
- float radius = 1.0;
+ const double lat_step = Math_TAU / lats;
+ const double lon_step = Math_TAU / lons;
+ real_t radius = 1.0;
Vector<Vector3> vertices;
Vector<Vector3> normals;
@@ -391,20 +393,20 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5);
for (int i = 1; i <= lats; i++) {
- double lat0 = Math_PI * (-0.5 + (double)(i - 1) / lats);
+ double lat0 = lat_step * (i - 1) - Math_TAU / 4;
double z0 = Math::sin(lat0);
double zr0 = Math::cos(lat0);
- double lat1 = Math_PI * (-0.5 + (double)i / lats);
+ double lat1 = lat_step * i - Math_TAU / 4;
double z1 = Math::sin(lat1);
double zr1 = Math::cos(lat1);
for (int j = lons; j >= 1; j--) {
- double lng0 = 2 * Math_PI * (double)(j - 1) / lons;
+ double lng0 = lon_step * (j - 1);
double x0 = Math::cos(lng0);
double y0 = Math::sin(lng0);
- double lng1 = 2 * Math_PI * (double)(j) / lons;
+ double lng1 = lon_step * j;
double x1 = Math::cos(lng1);
double y1 = Math::sin(lng1);
@@ -675,7 +677,7 @@ EditorAudioStreamPreviewPlugin::EditorAudioStreamPreviewPlugin() {
///////////////////////////////////////////////////////////////////////////
void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) {
- preview_done = true;
+ preview_done.set();
}
void EditorMeshPreviewPlugin::_bind_methods() {
@@ -712,10 +714,10 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
- preview_done = false;
+ preview_done.clear();
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorMeshPreviewPlugin *>(this), "_preview_done", Variant());
- while (!preview_done) {
+ while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
@@ -790,7 +792,7 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() {
///////////////////////////////////////////////////////////////////////////
void EditorFontPreviewPlugin::_preview_done(const Variant &p_udata) {
- preview_done = true;
+ preview_done.set();
}
void EditorFontPreviewPlugin::_bind_methods() {
@@ -881,11 +883,11 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path,
font->draw_string(canvas_item, pos, sample, HALIGN_LEFT, -1.f, 50, Color(1, 1, 1));
- preview_done = false;
+ preview_done.clear();
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture
RS::get_singleton()->request_frame_drawn_callback(const_cast<EditorFontPreviewPlugin *>(this), "_preview_done", Variant());
- while (!preview_done) {
+ while (!preview_done.is_set()) {
OS::get_singleton()->delay_usec(10);
}
diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h
index 57e2911c89..6e8b9a34cf 100644
--- a/editor/plugins/editor_preview_plugins.h
+++ b/editor/plugins/editor_preview_plugins.h
@@ -33,6 +33,8 @@
#include "editor/editor_resource_preview.h"
+#include "core/templates/safe_refcount.h"
+
void post_process_preview(Ref<Image> p_image);
class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator {
@@ -90,7 +92,7 @@ class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator {
RID light2;
RID light_instance2;
RID camera;
- mutable volatile bool preview_done = false;
+ mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);
@@ -134,7 +136,7 @@ class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator {
RID light2;
RID light_instance2;
RID camera;
- mutable volatile bool preview_done = false;
+ mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);
@@ -156,7 +158,7 @@ class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator {
RID viewport_texture;
RID canvas;
RID canvas_item;
- mutable volatile bool preview_done = false;
+ mutable SafeFlag preview_done;
void _preview_done(const Variant &p_udata);
diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
index 1aaa98d02e..b447304a3f 100644
--- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
@@ -81,7 +81,7 @@ void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) {
cpu_particles->set_name(particles->get_name());
cpu_particles->set_transform(particles->get_transform());
cpu_particles->set_visible(particles->is_visible());
- cpu_particles->set_pause_mode(particles->get_pause_mode());
+ cpu_particles->set_process_mode(particles->get_process_mode());
cpu_particles->set_z_index(particles->get_z_index());
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
index 5b840ddbcf..433a5ae51c 100644
--- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
@@ -263,7 +263,7 @@ void GPUParticles3DEditor::_menu_option(int p_option) {
cpu_particles->set_name(node->get_name());
cpu_particles->set_transform(node->get_transform());
cpu_particles->set_visible(node->is_visible());
- cpu_particles->set_pause_mode(node->get_pause_mode());
+ cpu_particles->set_process_mode(node->get_process_mode());
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
ur->create_action(TTR("Convert to CPUParticles3D"));
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index c0f690bb6a..1ea6630622 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -145,7 +145,7 @@ int ItemListOptionButtonPlugin::get_flags() const {
void ItemListOptionButtonPlugin::add_item() {
ob->add_item(vformat(TTR("Item %d"), ob->get_item_count()));
- _change_notify();
+ notify_property_list_changed();
}
int ItemListOptionButtonPlugin::get_item_count() const {
@@ -154,7 +154,7 @@ int ItemListOptionButtonPlugin::get_item_count() const {
void ItemListOptionButtonPlugin::erase(int p_idx) {
ob->remove_item(p_idx);
- _change_notify();
+ notify_property_list_changed();
}
ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() {
@@ -181,7 +181,7 @@ int ItemListPopupMenuPlugin::get_flags() const {
void ItemListPopupMenuPlugin::add_item() {
pp->add_item(vformat(TTR("Item %d"), pp->get_item_count()));
- _change_notify();
+ notify_property_list_changed();
}
int ItemListPopupMenuPlugin::get_item_count() const {
@@ -190,7 +190,7 @@ int ItemListPopupMenuPlugin::get_item_count() const {
void ItemListPopupMenuPlugin::erase(int p_idx) {
pp->remove_item(p_idx);
- _change_notify();
+ notify_property_list_changed();
}
ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
@@ -213,7 +213,7 @@ int ItemListItemListPlugin::get_flags() const {
void ItemListItemListPlugin::add_item() {
pp->add_item(vformat(TTR("Item %d"), pp->get_item_count()));
- _change_notify();
+ notify_property_list_changed();
}
int ItemListItemListPlugin::get_item_count() const {
@@ -222,7 +222,7 @@ int ItemListItemListPlugin::get_item_count() const {
void ItemListItemListPlugin::erase(int p_idx) {
pp->remove_item(p_idx);
- _change_notify();
+ notify_property_list_changed();
}
ItemListItemListPlugin::ItemListItemListPlugin() {
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 3e8547439f..9643881f96 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -48,6 +48,7 @@
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/physics_body_3d.h"
#include "scene/3d/visual_instance_3d.h"
+#include "scene/gui/center_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
@@ -535,8 +536,8 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b
if (dist < closest_dist) {
item = Object::cast_to<Node>(spat);
- while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) {
- item = item->get_owner();
+ if (item != edited_scene) {
+ item = edited_scene->get_deepest_editable_node(item);
}
closest = item->get_instance_id();
@@ -697,8 +698,8 @@ void Node3DEditorViewport::_select_region() {
}
Node *item = Object::cast_to<Node>(sp);
- while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) {
- item = item->get_owner();
+ if (item != edited_scene) {
+ item = edited_scene->get_deepest_editable_node(item);
}
// Replace the node by the group if grouped
@@ -1027,7 +1028,7 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
for (int i = 0; i < selection_results.size(); i++) {
Node3D *item = selection_results[i].item;
- if (item != scene && item->get_owner() != scene && !scene->is_editable_instance(item->get_owner())) {
+ if (item != scene && item->get_owner() != scene && item != scene->get_deepest_editable_node(item)) {
//invalid result
selection_results.remove(i);
i--;
@@ -2335,7 +2336,43 @@ void Node3DEditorPlugin::edited_scene_changed() {
}
}
+void Node3DEditorViewport::_project_settings_changed() {
+ //update shadow atlas if changed
+ int shadowmap_size = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/size");
+ bool shadowmap_16_bits = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/16_bits");
+ int atlas_q0 = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/quadrant_0_subdiv");
+ int atlas_q1 = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/quadrant_1_subdiv");
+ int atlas_q2 = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/quadrant_2_subdiv");
+ int atlas_q3 = ProjectSettings::get_singleton()->get("rendering/shadows/shadow_atlas/quadrant_3_subdiv");
+
+ viewport->set_shadow_atlas_size(shadowmap_size);
+ viewport->set_shadow_atlas_16_bits(shadowmap_16_bits);
+ viewport->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0));
+ viewport->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1));
+ viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2));
+ viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3));
+
+ bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION));
+
+ if (shrink != (subviewport_container->get_stretch_shrink() > 1)) {
+ subviewport_container->set_stretch_shrink(shrink ? 2 : 1);
+ }
+
+ // Update MSAA, screen-space AA and debanding if changed
+
+ const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/anti_aliasing/quality/msaa");
+ viewport->set_msaa(Viewport::MSAA(msaa_mode));
+ const int ssaa_mode = GLOBAL_GET("rendering/anti_aliasing/quality/screen_space_aa");
+ viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode));
+ const bool use_debanding = GLOBAL_GET("rendering/anti_aliasing/quality/use_debanding");
+ viewport->set_use_debanding(use_debanding);
+}
+
void Node3DEditorViewport::_notification(int p_what) {
+ if (p_what == NOTIFICATION_READY) {
+ EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &Node3DEditorViewport::_project_settings_changed));
+ }
+
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
bool visible = is_visible_in_tree();
@@ -2442,35 +2479,6 @@ void Node3DEditorViewport::_notification(int p_what) {
}
}
- //update shadow atlas if changed
-
- int shadowmap_size = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/size");
- int atlas_q0 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_0_subdiv");
- int atlas_q1 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_1_subdiv");
- int atlas_q2 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_2_subdiv");
- int atlas_q3 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_3_subdiv");
-
- viewport->set_shadow_atlas_size(shadowmap_size);
- viewport->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0));
- viewport->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1));
- viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2));
- viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3));
-
- bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION));
-
- if (shrink != (subviewport_container->get_stretch_shrink() > 1)) {
- subviewport_container->set_stretch_shrink(shrink ? 2 : 1);
- }
-
- // Update MSAA, screen-space AA and debanding if changed
-
- const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/screen_filters/msaa");
- viewport->set_msaa(Viewport::MSAA(msaa_mode));
- const int ssaa_mode = GLOBAL_GET("rendering/quality/screen_filters/screen_space_aa");
- viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode));
- const bool use_debanding = GLOBAL_GET("rendering/quality/screen_filters/use_debanding");
- viewport->set_use_debanding(use_debanding);
-
bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION));
if (show_info != info_label->is_visible()) {
info_label->set_visible(show_info);
@@ -2491,6 +2499,13 @@ void Node3DEditorViewport::_notification(int p_what) {
text += "Z: " + rtos(current_camera->get_translation().z).pad_decimals(1) + "\n";
text += TTR("Pitch") + ": " + itos(Math::round(current_camera->get_rotation_degrees().x)) + "\n";
text += TTR("Yaw") + ": " + itos(Math::round(current_camera->get_rotation_degrees().y)) + "\n\n";
+
+ text += TTR("Size") +
+ vformat(
+ ": %dx%d (%.1fMP)\n",
+ viewport->get_size().x,
+ viewport->get_size().y,
+ viewport->get_size().x * viewport->get_size().y * 0.000'001);
text += TTR("Objects Drawn") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_OBJECTS_IN_FRAME)) + "\n";
text += TTR("Material Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_MATERIAL_CHANGES_IN_FRAME)) + "\n";
text += TTR("Shader Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SHADER_CHANGES_IN_FRAME)) + "\n";
@@ -2822,7 +2837,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_FRONT: {
cursor.x_rot = 0;
- cursor.y_rot = 0;
+ cursor.y_rot = Math_PI;
set_message(TTR("Front View."), 2);
name = TTR("Front");
_set_auto_orthogonal();
@@ -2831,7 +2846,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_REAR: {
cursor.x_rot = 0;
- cursor.y_rot = Math_PI;
+ cursor.y_rot = 0;
set_message(TTR("Rear View."), 2);
name = TTR("Rear");
_set_auto_orthogonal();
@@ -3043,7 +3058,11 @@ void Node3DEditorViewport::_menu_option(int p_option) {
case VIEW_DISPLAY_DEBUG_SDFGI:
case VIEW_DISPLAY_DEBUG_SDFGI_PROBES:
case VIEW_DISPLAY_DEBUG_GI_BUFFER:
- case VIEW_DISPLAY_DEBUG_DISABLE_LOD: {
+ case VIEW_DISPLAY_DEBUG_DISABLE_LOD:
+ case VIEW_DISPLAY_DEBUG_CLUSTER_OMNI_LIGHTS:
+ case VIEW_DISPLAY_DEBUG_CLUSTER_SPOT_LIGHTS:
+ case VIEW_DISPLAY_DEBUG_CLUSTER_DECALS:
+ case VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES: {
static const int display_options[] = {
VIEW_DISPLAY_NORMAL,
VIEW_DISPLAY_WIREFRAME,
@@ -3065,6 +3084,10 @@ void Node3DEditorViewport::_menu_option(int p_option) {
VIEW_DISPLAY_DEBUG_DECAL_ATLAS,
VIEW_DISPLAY_DEBUG_SDFGI,
VIEW_DISPLAY_DEBUG_SDFGI_PROBES,
+ VIEW_DISPLAY_DEBUG_CLUSTER_OMNI_LIGHTS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_SPOT_LIGHTS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_DECALS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES,
VIEW_MAX
};
static const Viewport::DebugDraw debug_draw_modes[] = {
@@ -3088,6 +3111,10 @@ void Node3DEditorViewport::_menu_option(int p_option) {
Viewport::DEBUG_DRAW_DECAL_ATLAS,
Viewport::DEBUG_DRAW_SDFGI,
Viewport::DEBUG_DRAW_SDFGI_PROBES,
+ Viewport::DEBUG_DRAW_CLUSTER_OMNI_LIGHTS,
+ Viewport::DEBUG_DRAW_CLUSTER_SPOT_LIGHTS,
+ Viewport::DEBUG_DRAW_CLUSTER_DECALS,
+ Viewport::DEBUG_DRAW_CLUSTER_REFLECTION_PROBES,
};
int idx = 0;
@@ -3215,6 +3242,8 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) {
void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) {
previewing_cinema = p_activate;
+ rotation_control->set_visible(!p_activate);
+
if (!previewing_cinema) {
if (previewing != nullptr) {
previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene));
@@ -3305,6 +3334,21 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
xform.basis.scale(scale);
+ // if the determinant is zero, we should disable the gizmo from being rendered
+ // this prevents supplying bad values to the renderer and then having to filter it out again
+ if (xform.basis.determinant() == 0) {
+ for (int i = 0; i < 3; i++) {
+ RenderingServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], false);
+ RenderingServer::get_singleton()->instance_set_visible(move_plane_gizmo_instance[i], false);
+ RenderingServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], false);
+ RenderingServer::get_singleton()->instance_set_visible(scale_gizmo_instance[i], false);
+ RenderingServer::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], false);
+ }
+ // Rotation white outline
+ RenderingServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[3], false);
+ return;
+ }
+
for (int i = 0; i < 3; i++) {
RenderingServer::get_singleton()->instance_set_transform(move_gizmo_instance[i], xform);
RenderingServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE));
@@ -3989,6 +4033,12 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito
display_submenu->add_radio_check_item(TTR("GI Buffer"), VIEW_DISPLAY_DEBUG_GI_BUFFER);
display_submenu->add_separator();
display_submenu->add_radio_check_item(TTR("Disable LOD"), VIEW_DISPLAY_DEBUG_DISABLE_LOD);
+ display_submenu->add_separator();
+ display_submenu->add_radio_check_item(TTR("Omni Light Cluster"), VIEW_DISPLAY_DEBUG_CLUSTER_OMNI_LIGHTS);
+ display_submenu->add_radio_check_item(TTR("Spot Light Cluster"), VIEW_DISPLAY_DEBUG_CLUSTER_SPOT_LIGHTS);
+ display_submenu->add_radio_check_item(TTR("Decal Cluster"), VIEW_DISPLAY_DEBUG_CLUSTER_DECALS);
+ display_submenu->add_radio_check_item(TTR("Reflection Probe Cluster"), VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES);
+
display_submenu->set_name("display_advanced");
view_menu->get_popup()->add_submenu_item(TTR("Display Advanced..."), "display_advanced", VIEW_DISPLAY_ADVANCED);
view_menu->get_popup()->add_separator();
@@ -4663,11 +4713,33 @@ Dictionary Node3DEditor::get_state() const {
continue;
}
int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i));
- String name = gizmo_plugins_by_name[i]->get_name();
+ String name = gizmo_plugins_by_name[i]->get_gizmo_name();
gizmos_status[name] = state;
}
d["gizmos_status"] = gizmos_status;
+ {
+ Dictionary pd;
+
+ pd["sun_rotation"] = sun_rotation;
+
+ pd["environ_sky_color"] = environ_sky_color->get_pick_color();
+ pd["environ_ground_color"] = environ_ground_color->get_pick_color();
+ pd["environ_energy"] = environ_energy->get_value();
+ pd["environ_glow_enabled"] = environ_glow_button->is_pressed();
+ pd["environ_tonemap_enabled"] = environ_tonemap_button->is_pressed();
+ pd["environ_ao_enabled"] = environ_ao_button->is_pressed();
+ pd["environ_gi_enabled"] = environ_gi_button->is_pressed();
+ pd["sun_max_distance"] = sun_max_distance->get_value();
+
+ pd["sun_color"] = sun_color->get_pick_color();
+ pd["sun_energy"] = sun_energy->get_value();
+
+ pd["sun_disabled"] = sun_button->is_pressed();
+ pd["environ_disabled"] = environ_button->is_pressed();
+
+ d["preview_sun_env"] = pd;
+ }
return d;
}
@@ -4767,7 +4839,7 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
}
int state = EditorNode3DGizmoPlugin::VISIBLE;
for (int i = 0; i < keys.size(); i++) {
- if (gizmo_plugins_by_name.write[j]->get_name() == String(keys[i])) {
+ if (gizmo_plugins_by_name.write[j]->get_gizmo_name() == String(keys[i])) {
state = gizmos_status[keys[i]];
break;
}
@@ -4777,6 +4849,38 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
}
_update_gizmos_menu();
}
+
+ if (d.has("preview_sun_env")) {
+ sun_environ_updating = true;
+ Dictionary pd = d["preview_sun_env"];
+ sun_rotation = pd["sun_rotation"];
+
+ environ_sky_color->set_pick_color(pd["environ_sky_color"]);
+ environ_ground_color->set_pick_color(pd["environ_ground_color"]);
+ environ_energy->set_value(pd["environ_energy"]);
+ environ_glow_button->set_pressed(pd["environ_glow_enabled"]);
+ environ_tonemap_button->set_pressed(pd["environ_tonemap_enabled"]);
+ environ_ao_button->set_pressed(pd["environ_ao_enabled"]);
+ environ_gi_button->set_pressed(pd["environ_gi_enabled"]);
+ sun_max_distance->set_value(pd["sun_max_distance"]);
+
+ sun_color->set_pick_color(pd["sun_color"]);
+ sun_energy->set_value(pd["sun_energy"]);
+
+ sun_button->set_pressed(pd["sun_disabled"]);
+ environ_button->set_pressed(pd["environ_disabled"]);
+
+ sun_environ_updating = false;
+
+ _preview_settings_changed();
+ _update_preview_environment();
+ } else {
+ _load_default_preview_settings();
+ sun_button->set_pressed(false);
+ environ_button->set_pressed(false);
+ _preview_settings_changed();
+ _update_preview_environment();
+ }
}
void Node3DEditor::edit(Node3D *p_spatial) {
@@ -5222,6 +5326,42 @@ void Node3DEditor::_init_indicators() {
origin_points.push_back(axis * -1048576);
}
+ Ref<Shader> grid_shader = memnew(Shader);
+ grid_shader->set_code(
+ "\n"
+ "shader_type spatial; \n"
+ "render_mode unshaded; \n"
+ "uniform bool orthogonal; \n"
+ "uniform float grid_size; \n"
+ "\n"
+ "void vertex() { \n"
+ " // From FLAG_SRGB_VERTEX_COLOR \n"
+ " if (!OUTPUT_IS_SRGB) { \n"
+ " COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045))); \n"
+ " } \n"
+ "} \n"
+ "\n"
+ "void fragment() { \n"
+ " ALBEDO = COLOR.rgb; \n"
+ " vec3 dir = orthogonal ? -vec3(0, 0, 1) : VIEW; \n"
+ " float angle_fade = abs(dot(dir, NORMAL)); \n"
+ " angle_fade = smoothstep(0.05, 0.2, angle_fade); \n"
+ " \n"
+ " vec3 world_pos = (CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz; \n"
+ " vec3 world_normal = (CAMERA_MATRIX * vec4(NORMAL, 0.0)).xyz; \n"
+ " vec3 camera_world_pos = CAMERA_MATRIX[3].xyz; \n"
+ " vec3 camera_world_pos_on_plane = camera_world_pos * (1.0 - world_normal); \n"
+ " float dist_fade = 1.0 - (distance(world_pos, camera_world_pos_on_plane) / grid_size); \n"
+ " dist_fade = smoothstep(0.02, 0.3, dist_fade); \n"
+ " \n"
+ " ALPHA = COLOR.a * dist_fade * angle_fade; \n"
+ "}");
+
+ for (int i = 0; i < 3; i++) {
+ grid_mat[i].instance();
+ grid_mat[i]->set_shader(grid_shader);
+ }
+
grid_enable[0] = EditorSettings::get_singleton()->get("editors/3d/grid_xy_plane");
grid_enable[1] = EditorSettings::get_singleton()->get("editors/3d/grid_yz_plane");
grid_enable[2] = EditorSettings::get_singleton()->get("editors/3d/grid_xz_plane");
@@ -5314,9 +5454,10 @@ void Node3DEditor::_init_indicators() {
int arrow_sides = 16;
+ const real_t arrow_sides_step = Math_TAU / arrow_sides;
for (int k = 0; k < arrow_sides; k++) {
- Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides);
- Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides);
+ Basis ma(ivec, k * arrow_sides_step);
+ Basis mb(ivec, (k + 1) * arrow_sides_step);
for (int j = 0; j < arrow_points - 1; j++) {
Vector3 points[4] = {
@@ -5391,13 +5532,14 @@ void Node3DEditor::_init_indicators() {
int n = 128; // number of circle segments
int m = 6; // number of thickness segments
+ real_t step = Math_TAU / n;
for (int j = 0; j < n; ++j) {
- Basis basis = Basis(ivec, (Math_PI * 2.0f * j) / n);
+ Basis basis = Basis(ivec, j * step);
Vector3 vertex = basis.xform(ivec2 * GIZMO_CIRCLE_SIZE);
for (int k = 0; k < m; ++k) {
- Vector2 ofs = Vector2(Math::cos((Math_PI * 2.0 * k) / m), Math::sin((Math_PI * 2.0 * k) / m));
+ Vector2 ofs = Vector2(Math::cos((Math_TAU * k) / m), Math::sin((Math_TAU * k) / m));
Vector3 normal = ivec * ofs.x + ivec2 * ofs.y;
surftool->set_normal(basis.xform(normal));
@@ -5424,32 +5566,33 @@ void Node3DEditor::_init_indicators() {
Ref<Shader> rotate_shader = memnew(Shader);
- rotate_shader->set_code("\n"
- "shader_type spatial; \n"
- "render_mode unshaded, depth_test_disabled; \n"
- "uniform vec4 albedo; \n"
- "\n"
- "mat3 orthonormalize(mat3 m) { \n"
- " vec3 x = normalize(m[0]); \n"
- " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n"
- " vec3 z = m[2] - x * dot(x, m[2]); \n"
- " z = normalize(z - y * (dot(y,m[2]))); \n"
- " return mat3(x,y,z); \n"
- "} \n"
- "\n"
- "void vertex() { \n"
- " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n"
- " vec3 n = mv * VERTEX; \n"
- " float orientation = dot(vec3(0,0,-1),n); \n"
- " if (orientation <= 0.005) { \n"
- " VERTEX += NORMAL*0.02; \n"
- " } \n"
- "} \n"
- "\n"
- "void fragment() { \n"
- " ALBEDO = albedo.rgb; \n"
- " ALPHA = albedo.a; \n"
- "}");
+ rotate_shader->set_code(
+ "\n"
+ "shader_type spatial; \n"
+ "render_mode unshaded, depth_test_disabled; \n"
+ "uniform vec4 albedo; \n"
+ "\n"
+ "mat3 orthonormalize(mat3 m) { \n"
+ " vec3 x = normalize(m[0]); \n"
+ " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n"
+ " vec3 z = m[2] - x * dot(x, m[2]); \n"
+ " z = normalize(z - y * (dot(y,m[2]))); \n"
+ " return mat3(x,y,z); \n"
+ "} \n"
+ "\n"
+ "void vertex() { \n"
+ " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n"
+ " vec3 n = mv * VERTEX; \n"
+ " float orientation = dot(vec3(0,0,-1),n); \n"
+ " if (orientation <= 0.005) { \n"
+ " VERTEX += NORMAL*0.02; \n"
+ " } \n"
+ "} \n"
+ "\n"
+ "void fragment() { \n"
+ " ALBEDO = albedo.rgb; \n"
+ " ALPHA = albedo.a; \n"
+ "}");
Ref<ShaderMaterial> rotate_mat = memnew(ShaderMaterial);
rotate_mat->set_render_priority(Material::RENDER_PRIORITY_MAX);
@@ -5469,33 +5612,34 @@ void Node3DEditor::_init_indicators() {
Ref<ShaderMaterial> border_mat = rotate_mat->duplicate();
Ref<Shader> border_shader = memnew(Shader);
- border_shader->set_code("\n"
- "shader_type spatial; \n"
- "render_mode unshaded, depth_test_disabled; \n"
- "uniform vec4 albedo; \n"
- "\n"
- "mat3 orthonormalize(mat3 m) { \n"
- " vec3 x = normalize(m[0]); \n"
- " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n"
- " vec3 z = m[2] - x * dot(x, m[2]); \n"
- " z = normalize(z - y * (dot(y,m[2]))); \n"
- " return mat3(x,y,z); \n"
- "} \n"
- "\n"
- "void vertex() { \n"
- " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n"
- " mv = inverse(mv); \n"
- " VERTEX += NORMAL*0.008; \n"
- " vec3 camera_dir_local = mv * vec3(0,0,1); \n"
- " vec3 camera_up_local = mv * vec3(0,1,0); \n"
- " mat3 rotation_matrix = mat3(cross(camera_dir_local, camera_up_local), camera_up_local, camera_dir_local); \n"
- " VERTEX = rotation_matrix * VERTEX; \n"
- "} \n"
- "\n"
- "void fragment() { \n"
- " ALBEDO = albedo.rgb; \n"
- " ALPHA = albedo.a; \n"
- "}");
+ border_shader->set_code(
+ "\n"
+ "shader_type spatial; \n"
+ "render_mode unshaded, depth_test_disabled; \n"
+ "uniform vec4 albedo; \n"
+ "\n"
+ "mat3 orthonormalize(mat3 m) { \n"
+ " vec3 x = normalize(m[0]); \n"
+ " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n"
+ " vec3 z = m[2] - x * dot(x, m[2]); \n"
+ " z = normalize(z - y * (dot(y,m[2]))); \n"
+ " return mat3(x,y,z); \n"
+ "} \n"
+ "\n"
+ "void vertex() { \n"
+ " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n"
+ " mv = inverse(mv); \n"
+ " VERTEX += NORMAL*0.008; \n"
+ " vec3 camera_dir_local = mv * vec3(0,0,1); \n"
+ " vec3 camera_up_local = mv * vec3(0,1,0); \n"
+ " mat3 rotation_matrix = mat3(cross(camera_dir_local, camera_up_local), camera_up_local, camera_dir_local); \n"
+ " VERTEX = rotation_matrix * VERTEX; \n"
+ "} \n"
+ "\n"
+ "void fragment() { \n"
+ " ALBEDO = albedo.rgb; \n"
+ " ALPHA = albedo.a; \n"
+ "}");
border_mat->set_shader(border_shader);
border_mat->set_shader_param("albedo", Color(0.75, 0.75, 0.75, col.a / 3.0));
@@ -5524,9 +5668,10 @@ void Node3DEditor::_init_indicators() {
int arrow_sides = 4;
+ const real_t arrow_sides_step = Math_TAU / arrow_sides;
for (int k = 0; k < 4; k++) {
- Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides);
- Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides);
+ Basis ma(ivec, k * arrow_sides_step);
+ Basis mb(ivec, (k + 1) * arrow_sides_step);
for (int j = 0; j < arrow_points - 1; j++) {
Vector3 points[4] = {
@@ -5605,7 +5750,7 @@ void Node3DEditor::_update_gizmos_menu() {
if (!gizmo_plugins_by_name[i]->can_be_hidden()) {
continue;
}
- String plugin_name = gizmo_plugins_by_name[i]->get_name();
+ String plugin_name = gizmo_plugins_by_name[i]->get_gizmo_name();
const int plugin_state = gizmo_plugins_by_name[i]->get_state();
gizmos_menu->add_multistate_item(plugin_name, 3, plugin_state, i);
const int idx = gizmos_menu->get_item_index(i);
@@ -5657,8 +5802,11 @@ void Node3DEditor::_init_grid() {
return; // Camera3D is invalid, don't draw the grid.
}
+ bool orthogonal = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL;
+
Vector<Color> grid_colors[3];
Vector<Vector3> grid_points[3];
+ Vector<Vector3> grid_normals[3];
Color primary_grid_color = EditorSettings::get_singleton()->get("editors/3d/primary_grid_color");
Color secondary_grid_color = EditorSettings::get_singleton()->get("editors/3d/secondary_grid_color");
@@ -5694,10 +5842,26 @@ void Node3DEditor::_init_grid() {
int b = (a + 1) % 3;
int c = (a + 2) % 3;
- real_t division_level = Math::log(Math::abs(camera_position[c])) / Math::log((double)primary_grid_steps) + division_level_bias;
- division_level = CLAMP(division_level, division_level_min, division_level_max);
- real_t division_level_floored = Math::floor(division_level);
- real_t division_level_decimals = division_level - division_level_floored;
+ Vector3 normal;
+ normal[c] = 1.0;
+
+ real_t camera_distance = Math::abs(camera_position[c]);
+
+ if (orthogonal) {
+ camera_distance = camera->get_size() / 2.0;
+ Vector3 camera_direction = -camera->get_global_transform().get_basis().get_axis(2);
+ Plane grid_plane = Plane(Vector3(), normal);
+ Vector3 intersection;
+ if (grid_plane.intersects_ray(camera_position, camera_direction, &intersection)) {
+ camera_position = intersection;
+ }
+ }
+
+ real_t division_level = Math::log(Math::abs(camera_distance)) / Math::log((double)primary_grid_steps) + division_level_bias;
+
+ real_t clamped_division_level = CLAMP(division_level, division_level_min, division_level_max);
+ real_t division_level_floored = Math::floor(clamped_division_level);
+ real_t division_level_decimals = clamped_division_level - division_level_floored;
real_t small_step_size = Math::pow(primary_grid_steps, division_level_floored);
real_t large_step_size = small_step_size * primary_grid_steps;
@@ -5709,6 +5873,15 @@ void Node3DEditor::_init_grid() {
real_t bgn_b = center_b - grid_size * small_step_size;
real_t end_b = center_b + grid_size * small_step_size;
+ real_t fade_size = Math::pow(primary_grid_steps, division_level - 1.0);
+ real_t min_fade_size = Math::pow(primary_grid_steps, float(division_level_min));
+ real_t max_fade_size = Math::pow(primary_grid_steps, float(division_level_max));
+ fade_size = CLAMP(fade_size, min_fade_size, max_fade_size);
+
+ real_t grid_fade_size = (grid_size - primary_grid_steps) * fade_size;
+ grid_mat[c]->set_shader_param("grid_size", grid_fade_size);
+ grid_mat[c]->set_shader_param("orthogonal", orthogonal);
+
// In each iteration of this loop, draw one line in each direction (so two lines per loop, in each if statement).
for (int i = -grid_size; i <= grid_size; i++) {
Color line_color;
@@ -5719,11 +5892,6 @@ void Node3DEditor::_init_grid() {
line_color = secondary_grid_color;
line_color.a = line_color.a * (1 - division_level_decimals);
}
- // Makes lines farther from the center fade out.
- // Due to limitations of lines, any that come near the camera have full opacity always.
- // This should eventually be replaced by some kind of "distance fade" system, outside of this function.
- // But the effect is still somewhat convincing...
- line_color.a *= 1 - (1 - division_level_decimals * 0.9) * (Math::abs(i / (float)grid_size));
real_t position_a = center_a + i * small_step_size;
real_t position_b = center_b + i * small_step_size;
@@ -5740,6 +5908,8 @@ void Node3DEditor::_init_grid() {
grid_points[c].push_back(line_end);
grid_colors[c].push_back(line_color);
grid_colors[c].push_back(line_color);
+ grid_normals[c].push_back(normal);
+ grid_normals[c].push_back(normal);
}
if (!(origin_enabled && Math::is_zero_approx(position_b))) {
@@ -5753,6 +5923,8 @@ void Node3DEditor::_init_grid() {
grid_points[c].push_back(line_end);
grid_colors[c].push_back(line_color);
grid_colors[c].push_back(line_color);
+ grid_normals[c].push_back(normal);
+ grid_normals[c].push_back(normal);
}
}
@@ -5762,8 +5934,9 @@ void Node3DEditor::_init_grid() {
d.resize(RS::ARRAY_MAX);
d[RenderingServer::ARRAY_VERTEX] = grid_points[c];
d[RenderingServer::ARRAY_COLOR] = grid_colors[c];
+ d[RenderingServer::ARRAY_NORMAL] = grid_normals[c];
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(grid[c], RenderingServer::PRIMITIVE_LINES, d);
- RenderingServer::get_singleton()->mesh_surface_set_material(grid[c], 0, indicator_mat->get_rid());
+ RenderingServer::get_singleton()->mesh_surface_set_material(grid[c], 0, grid_mat[c]->get_rid());
grid_instance[c] = RenderingServer::get_singleton()->instance_create2(grid[c], get_tree()->get_root()->get_world_3d()->get_scenario());
// Yes, the end of this line is supposed to be a.
@@ -5880,17 +6053,20 @@ void Node3DEditor::snap_selected_nodes_to_floor() {
// Priorities for snapping to floor are CollisionShapes, VisualInstances and then origin
Set<VisualInstance3D *> vi = _get_child_nodes<VisualInstance3D>(sp);
Set<CollisionShape3D *> cs = _get_child_nodes<CollisionShape3D>(sp);
+ bool found_valid_shape = false;
if (cs.size()) {
AABB aabb;
- bool found_valid_shape = false;
- if (cs.front()->get()->get_shape().is_valid()) {
- aabb = sp->get_global_transform().xform(cs.front()->get()->get_shape()->get_debug_mesh()->get_aabb());
+ Set<CollisionShape3D *>::Element *I = cs.front();
+ if (I->get()->get_shape().is_valid()) {
+ CollisionShape3D *collision_shape = cs.front()->get();
+ aabb = collision_shape->get_global_transform().xform(collision_shape->get_shape()->get_debug_mesh()->get_aabb());
found_valid_shape = true;
}
- for (Set<CollisionShape3D *>::Element *I = cs.front(); I; I = I->next()) {
- if (I->get()->get_shape().is_valid()) {
- aabb.merge_with(sp->get_global_transform().xform(I->get()->get_shape()->get_debug_mesh()->get_aabb()));
+ for (I = I->next(); I; I = I->next()) {
+ CollisionShape3D *col_shape = I->get();
+ if (col_shape->get_shape().is_valid()) {
+ aabb.merge_with(col_shape->get_global_transform().xform(col_shape->get_shape()->get_debug_mesh()->get_aabb()));
found_valid_shape = true;
}
}
@@ -5898,10 +6074,9 @@ void Node3DEditor::snap_selected_nodes_to_floor() {
Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
from = aabb.position + size;
position_offset.y = from.y - sp->get_global_transform().origin.y;
- } else {
- from = sp->get_global_transform().origin;
}
- } else if (vi.size()) {
+ }
+ if (!found_valid_shape && vi.size()) {
AABB aabb = vi.front()->get()->get_transformed_aabb();
for (Set<VisualInstance3D *>::Element *I = vi.front(); I; I = I->next()) {
aabb.merge_with(I->get()->get_transformed_aabb());
@@ -5909,7 +6084,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() {
Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
from = aabb.position + size;
position_offset.y = from.y - sp->get_global_transform().origin.y;
- } else {
+ } else if (!found_valid_shape) {
from = sp->get_global_transform().origin;
}
@@ -5992,6 +6167,51 @@ void Node3DEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
}
+void Node3DEditor::_sun_environ_settings_pressed() {
+ Vector2 pos = sun_environ_settings->get_screen_position() + sun_environ_settings->get_size();
+ sun_environ_popup->set_position(pos - Vector2(sun_environ_popup->get_contents_minimum_size().width / 2, 0));
+ sun_environ_popup->popup();
+}
+
+void Node3DEditor::_add_sun_to_scene() {
+ sun_environ_popup->hide();
+
+ Node *base = get_tree()->get_edited_scene_root();
+ if (!base) {
+ EditorNode::get_singleton()->show_warning(TTR("A root node is needed for this operation"));
+ return;
+ }
+ ERR_FAIL_COND(!base);
+ Node *new_sun = preview_sun->duplicate();
+
+ undo_redo->create_action("Add Preview Sun to Scene");
+ undo_redo->add_do_method(base, "add_child", new_sun);
+ undo_redo->add_do_method(new_sun, "set_owner", base);
+ undo_redo->add_undo_method(base, "remove_child", new_sun);
+ undo_redo->add_do_reference(new_sun);
+ undo_redo->commit_action();
+}
+void Node3DEditor::_add_environment_to_scene() {
+ sun_environ_popup->hide();
+
+ Node *base = get_tree()->get_edited_scene_root();
+ if (!base) {
+ EditorNode::get_singleton()->show_warning(TTR("A root node is needed for this operation"));
+ return;
+ }
+ ERR_FAIL_COND(!base);
+
+ WorldEnvironment *new_env = memnew(WorldEnvironment);
+ new_env->set_environment(preview_environment->get_environment()->duplicate(true));
+
+ undo_redo->create_action("Add Preview Environment to Scene");
+ undo_redo->add_do_method(base, "add_child", new_env);
+ undo_redo->add_do_method(new_env, "set_owner", base);
+ undo_redo->add_undo_method(base, "remove_child", new_env);
+ undo_redo->add_do_reference(new_env);
+ undo_redo->commit_action();
+}
+
void Node3DEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_READY) {
tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons"));
@@ -6020,17 +6240,31 @@ void Node3DEditor::_notification(int p_what) {
_refresh_menu_icons();
get_tree()->connect("node_removed", callable_mp(this, &Node3DEditor::_node_removed));
+ get_tree()->connect("node_added", callable_mp(this, &Node3DEditor::_node_added));
EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->connect("node_changed", callable_mp(this, &Node3DEditor::_refresh_menu_icons));
editor_selection->connect("selection_changed", callable_mp(this, &Node3DEditor::_refresh_menu_icons));
editor->connect("stop_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(false));
editor->connect("play_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(true));
+
+ sun_button->set_icon(get_theme_icon("DirectionalLight3D", "EditorIcons"));
+ environ_button->set_icon(get_theme_icon("WorldEnvironment", "EditorIcons"));
+ sun_environ_settings->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
+
+ _update_preview_environment();
+ sun_title->add_theme_font_override("font", get_theme_font("title_font", "Window"));
+ environ_title->add_theme_font_override("font", get_theme_font("title_font", "Window"));
+
+ sun_state->set_custom_minimum_size(sun_vb->get_combined_minimum_size());
+ environ_state->set_custom_minimum_size(environ_vb->get_combined_minimum_size());
} else if (p_what == NOTIFICATION_ENTER_TREE) {
_register_all_gizmos();
_update_gizmos_menu();
_init_indicators();
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
_update_gizmos_menu_theme();
+ sun_title->add_theme_font_override("font", get_theme_font("title_font", "Window"));
+ environ_title->add_theme_font_override("font", get_theme_font("title_font", "Window"));
} else if (p_what == NOTIFICATION_EXIT_TREE) {
_finish_indicators();
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
@@ -6167,7 +6401,37 @@ void Node3DEditor::_toggle_maximize_view(Object *p_viewport) {
}
}
+void Node3DEditor::_node_added(Node *p_node) {
+ if (EditorNode::get_singleton()->get_scene_root()->is_a_parent_of(p_node)) {
+ if (Object::cast_to<WorldEnvironment>(p_node)) {
+ world_env_count++;
+ if (world_env_count == 1) {
+ _update_preview_environment();
+ }
+ } else if (Object::cast_to<DirectionalLight3D>(p_node)) {
+ directional_light_count++;
+ if (directional_light_count == 1) {
+ _update_preview_environment();
+ }
+ }
+ }
+}
+
void Node3DEditor::_node_removed(Node *p_node) {
+ if (EditorNode::get_singleton()->get_scene_root()->is_a_parent_of(p_node)) {
+ if (Object::cast_to<WorldEnvironment>(p_node)) {
+ world_env_count--;
+ if (world_env_count == 0) {
+ _update_preview_environment();
+ }
+ } else if (Object::cast_to<DirectionalLight3D>(p_node)) {
+ directional_light_count--;
+ if (directional_light_count == 0) {
+ _update_preview_environment();
+ }
+ }
+ }
+
if (p_node == selected) {
selected = nullptr;
}
@@ -6194,6 +6458,7 @@ void Node3DEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin)));
add_gizmo_plugin(Ref<BakedLightmapGizmoPlugin>(memnew(BakedLightmapGizmoPlugin)));
add_gizmo_plugin(Ref<LightmapProbeGizmoPlugin>(memnew(LightmapProbeGizmoPlugin)));
+ add_gizmo_plugin(Ref<CollisionObject3DGizmoPlugin>(memnew(CollisionObject3DGizmoPlugin)));
add_gizmo_plugin(Ref<CollisionShape3DGizmoPlugin>(memnew(CollisionShape3DGizmoPlugin)));
add_gizmo_plugin(Ref<CollisionPolygon3DGizmoPlugin>(memnew(CollisionPolygon3DGizmoPlugin)));
add_gizmo_plugin(Ref<NavigationRegion3DGizmoPlugin>(memnew(NavigationRegion3DGizmoPlugin)));
@@ -6237,6 +6502,128 @@ void Node3DEditor::clear() {
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true);
}
+void Node3DEditor::_sun_direction_draw() {
+ sun_direction->draw_rect(Rect2(Vector2(), sun_direction->get_size()), Color(1, 1, 1, 1));
+ sun_direction_material->set_shader_param("sun_direction", -preview_sun->get_transform().basis.get_axis(Vector3::AXIS_Z));
+ float nrg = sun_energy->get_value();
+ sun_direction_material->set_shader_param("sun_color", Vector3(sun_color->get_pick_color().r * nrg, sun_color->get_pick_color().g * nrg, sun_color->get_pick_color().b * nrg));
+}
+
+void Node3DEditor::_preview_settings_changed() {
+ if (sun_environ_updating) {
+ return;
+ }
+
+ { // preview sun
+ Transform t;
+ t.basis = sun_rotation;
+ preview_sun->set_transform(t);
+ sun_direction->update();
+ preview_sun->set_param(Light3D::PARAM_ENERGY, sun_energy->get_value());
+ preview_sun->set_param(Light3D::PARAM_SHADOW_MAX_DISTANCE, sun_max_distance->get_value());
+ preview_sun->set_color(sun_color->get_pick_color());
+ }
+
+ { //preview env
+ sky_material->set_sky_energy(environ_energy->get_value());
+ Color hz_color = environ_sky_color->get_pick_color().lerp(environ_ground_color->get_pick_color(), 0.5).lerp(Color(1, 1, 1), 0.5);
+ sky_material->set_sky_top_color(environ_sky_color->get_pick_color());
+ sky_material->set_sky_horizon_color(hz_color);
+ sky_material->set_ground_bottom_color(environ_ground_color->get_pick_color());
+ sky_material->set_ground_horizon_color(hz_color);
+
+ environment->set_ssao_enabled(environ_ao_button->is_pressed());
+ environment->set_glow_enabled(environ_glow_button->is_pressed());
+ environment->set_sdfgi_enabled(environ_gi_button->is_pressed());
+ environment->set_tonemapper(environ_tonemap_button->is_pressed() ? Environment::TONE_MAPPER_FILMIC : Environment::TONE_MAPPER_LINEAR);
+ }
+}
+void Node3DEditor::_load_default_preview_settings() {
+ sun_environ_updating = true;
+
+ sun_rotation = Basis(Vector3(0, 1, 0), Math_PI * 3.0 / 4) * Basis(Vector3(1, 0, 0), -Math_PI / 4);
+
+ sun_direction->update();
+ environ_sky_color->set_pick_color(Color::hex(0x91b2ceff));
+ environ_ground_color->set_pick_color(Color::hex(0x1f1f21ff));
+ environ_energy->set_value(1.0);
+ environ_glow_button->set_pressed(true);
+ environ_tonemap_button->set_pressed(true);
+ environ_ao_button->set_pressed(false);
+ environ_gi_button->set_pressed(false);
+ sun_max_distance->set_value(250);
+
+ sun_color->set_pick_color(Color(1, 1, 1));
+ sun_energy->set_value(1.0);
+
+ sun_environ_updating = false;
+}
+
+void Node3DEditor::_update_preview_environment() {
+ bool disable_light = directional_light_count > 0 || sun_button->is_pressed();
+
+ sun_button->set_disabled(directional_light_count > 0);
+
+ if (disable_light) {
+ if (preview_sun->get_parent()) {
+ preview_sun->get_parent()->remove_child(preview_sun);
+ sun_state->show();
+ sun_vb->hide();
+ }
+
+ if (directional_light_count > 0) {
+ sun_state->set_text(TTR("Scene contains\nDirectionalLight3D.\nPreview disabled."));
+ } else {
+ sun_state->set_text(TTR("Preview disabled."));
+ }
+
+ } else {
+ if (!preview_sun->get_parent()) {
+ add_child(preview_sun);
+ sun_state->hide();
+ sun_vb->show();
+ }
+ }
+
+ bool disable_env = world_env_count > 0 || environ_button->is_pressed();
+
+ environ_button->set_disabled(world_env_count > 0);
+
+ if (disable_env) {
+ if (preview_environment->get_parent()) {
+ preview_environment->get_parent()->remove_child(preview_environment);
+ environ_state->show();
+ environ_vb->hide();
+ }
+ if (world_env_count > 0) {
+ environ_state->set_text(TTR("Scene contains\nWorldEnvironment.\nPreview disabled."));
+ } else {
+ environ_state->set_text(TTR("Preview disabled."));
+ }
+
+ } else {
+ if (!preview_environment->get_parent()) {
+ add_child(preview_environment);
+ environ_state->hide();
+ environ_vb->show();
+ }
+ }
+}
+
+void Node3DEditor::_sun_direction_input(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
+ float x = -mm->get_relative().y * 0.02 * EDSCALE;
+ float y = mm->get_relative().x * 0.02 * EDSCALE;
+
+ Basis rot = Basis(Vector3(0, 1, 0), y) * Basis(Vector3(1, 0, 0), x);
+
+ sun_rotation = rot * sun_rotation;
+ sun_rotation.orthonormalize();
+ _preview_settings_changed();
+ }
+}
+
Node3DEditor::Node3DEditor(EditorNode *p_editor) {
gizmo.visible = true;
gizmo.scale = 1.0;
@@ -6374,6 +6761,32 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) {
_update_camera_override_button(false);
hbc_menu->add_child(memnew(VSeparator));
+ sun_button = memnew(Button);
+ sun_button->set_tooltip(TTR("Toggle preview sunlight.\nIf a DirectionalLight3D node is added to the scene, preview sunlight is disabled."));
+ sun_button->set_toggle_mode(true);
+ sun_button->set_flat(true);
+ sun_button->connect("pressed", callable_mp(this, &Node3DEditor::_update_preview_environment), varray(), CONNECT_DEFERRED);
+ sun_button->set_disabled(true);
+
+ hbc_menu->add_child(sun_button);
+
+ environ_button = memnew(Button);
+ environ_button->set_tooltip(TTR("Toggle preview environment.\nIf a WorldEnvironment node is added to the scene, preview environment is disabled."));
+ environ_button->set_toggle_mode(true);
+ environ_button->set_flat(true);
+ environ_button->connect("pressed", callable_mp(this, &Node3DEditor::_update_preview_environment), varray(), CONNECT_DEFERRED);
+ environ_button->set_disabled(true);
+
+ hbc_menu->add_child(environ_button);
+
+ sun_environ_settings = memnew(Button);
+ sun_environ_settings->set_tooltip(TTR("Edit Sun and Environment settings."));
+ sun_environ_settings->set_flat(true);
+ sun_environ_settings->connect("pressed", callable_mp(this, &Node3DEditor::_sun_environ_settings_pressed));
+
+ hbc_menu->add_child(sun_environ_settings);
+
+ hbc_menu->add_child(memnew(VSeparator));
// Drag and drop support;
preview_node = memnew(Node3D);
@@ -6603,6 +7016,152 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) {
EDITOR_DEF("editors/3d/navigation/show_viewport_rotation_gizmo", true);
over_gizmo_handle = -1;
+ {
+ //sun popup
+
+ sun_environ_popup = memnew(PopupPanel);
+ add_child(sun_environ_popup);
+
+ HBoxContainer *sun_environ_hb = memnew(HBoxContainer);
+
+ sun_environ_popup->add_child(sun_environ_hb);
+
+ sun_vb = memnew(VBoxContainer);
+ sun_environ_hb->add_child(sun_vb);
+ sun_vb->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
+ sun_vb->hide();
+
+ sun_title = memnew(Label);
+ sun_vb->add_child(sun_title);
+ sun_title->set_text(TTR("Preview Sun"));
+ sun_title->set_align(Label::ALIGN_CENTER);
+
+ CenterContainer *sun_direction_center = memnew(CenterContainer);
+ sun_direction = memnew(Control);
+ sun_direction->set_custom_minimum_size(Size2i(128, 128) * EDSCALE);
+ sun_direction_center->add_child(sun_direction);
+ sun_vb->add_margin_child(TTR("Sun Direction"), sun_direction_center);
+ sun_direction->connect("gui_input", callable_mp(this, &Node3DEditor::_sun_direction_input));
+ sun_direction->connect("draw", callable_mp(this, &Node3DEditor::_sun_direction_draw));
+ sun_direction->set_default_cursor_shape(CURSOR_MOVE);
+
+ String sun_dir_shader_code = "shader_type canvas_item; uniform vec3 sun_direction; uniform vec3 sun_color; void fragment() { vec3 n; n.xy = UV * 2.0 - 1.0; n.z = sqrt(max(0.0, 1.0 - dot(n.xy, n.xy))); COLOR.rgb = dot(n,sun_direction) * sun_color; COLOR.a = 1.0 - smoothstep(0.99,1.0,length(n.xy)); }";
+ sun_direction_shader.instance();
+ sun_direction_shader->set_code(sun_dir_shader_code);
+ sun_direction_material.instance();
+ sun_direction_material->set_shader(sun_direction_shader);
+ sun_direction_material->set_shader_param("sun_direction", Vector3(0, 0, 1));
+ sun_direction_material->set_shader_param("sun_color", Vector3(1, 1, 1));
+ sun_direction->set_material(sun_direction_material);
+
+ sun_color = memnew(ColorPickerButton);
+ sun_color->set_edit_alpha(false);
+ sun_vb->add_margin_child(TTR("Sun Color"), sun_color);
+ sun_color->connect("color_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+
+ sun_energy = memnew(EditorSpinSlider);
+ sun_vb->add_margin_child(TTR("Sun Energy"), sun_energy);
+ sun_energy->connect("value_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+ sun_energy->set_max(64.0);
+
+ sun_max_distance = memnew(EditorSpinSlider);
+ sun_vb->add_margin_child(TTR("Shadow Max Distance"), sun_max_distance);
+ sun_max_distance->connect("value_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+ sun_max_distance->set_min(1);
+ sun_max_distance->set_max(4096);
+
+ sun_add_to_scene = memnew(Button);
+ sun_add_to_scene->set_text(TTR("Add Sun to Scene"));
+ sun_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_sun_to_scene));
+ sun_vb->add_spacer();
+ sun_vb->add_child(sun_add_to_scene);
+
+ sun_state = memnew(Label);
+ sun_environ_hb->add_child(sun_state);
+ sun_state->set_align(Label::ALIGN_CENTER);
+ sun_state->set_valign(Label::VALIGN_CENTER);
+ sun_state->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ VSeparator *sc = memnew(VSeparator);
+ sc->set_custom_minimum_size(Size2(50 * EDSCALE, 0));
+ sc->set_v_size_flags(SIZE_EXPAND_FILL);
+ sun_environ_hb->add_child(sc);
+
+ environ_vb = memnew(VBoxContainer);
+ sun_environ_hb->add_child(environ_vb);
+ environ_vb->set_custom_minimum_size(Size2(200 * EDSCALE, 0));
+ environ_vb->hide();
+
+ environ_title = memnew(Label);
+ environ_vb->add_child(environ_title);
+ environ_title->set_text(TTR("Preview Environment"));
+ environ_title->set_align(Label::ALIGN_CENTER);
+
+ environ_sky_color = memnew(ColorPickerButton);
+ environ_sky_color->set_edit_alpha(false);
+ environ_sky_color->connect("color_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+ environ_vb->add_margin_child(TTR("Sky Color"), environ_sky_color);
+ environ_ground_color = memnew(ColorPickerButton);
+ environ_ground_color->connect("color_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+ environ_ground_color->set_edit_alpha(false);
+ environ_vb->add_margin_child(TTR("Ground Color"), environ_ground_color);
+ environ_energy = memnew(EditorSpinSlider);
+ environ_energy->connect("value_changed", callable_mp(this, &Node3DEditor::_preview_settings_changed).unbind(1));
+ environ_energy->set_max(8.0);
+ environ_vb->add_margin_child(TTR("Sky Energy"), environ_energy);
+ HBoxContainer *fx_vb = memnew(HBoxContainer);
+ fx_vb->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ environ_ao_button = memnew(Button);
+ environ_ao_button->set_text(TTR("AO"));
+ environ_ao_button->set_toggle_mode(true);
+ environ_ao_button->connect("pressed", callable_mp(this, &Node3DEditor::_preview_settings_changed), varray(), CONNECT_DEFERRED);
+ fx_vb->add_child(environ_ao_button);
+ environ_glow_button = memnew(Button);
+ environ_glow_button->set_text(TTR("Glow"));
+ environ_glow_button->set_toggle_mode(true);
+ environ_glow_button->connect("pressed", callable_mp(this, &Node3DEditor::_preview_settings_changed), varray(), CONNECT_DEFERRED);
+ fx_vb->add_child(environ_glow_button);
+ environ_tonemap_button = memnew(Button);
+ environ_tonemap_button->set_text(TTR("Tonemap"));
+ environ_tonemap_button->set_toggle_mode(true);
+ environ_tonemap_button->connect("pressed", callable_mp(this, &Node3DEditor::_preview_settings_changed), varray(), CONNECT_DEFERRED);
+ fx_vb->add_child(environ_tonemap_button);
+ environ_gi_button = memnew(Button);
+ environ_gi_button->set_text(TTR("GI"));
+ environ_gi_button->set_toggle_mode(true);
+ environ_gi_button->connect("pressed", callable_mp(this, &Node3DEditor::_preview_settings_changed), varray(), CONNECT_DEFERRED);
+ fx_vb->add_child(environ_gi_button);
+ environ_vb->add_margin_child(TTR("Post Process"), fx_vb);
+
+ environ_add_to_scene = memnew(Button);
+ environ_add_to_scene->set_text(TTR("Add Environment to Scene"));
+ environ_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_environment_to_scene));
+ environ_vb->add_spacer();
+ environ_vb->add_child(environ_add_to_scene);
+
+ environ_state = memnew(Label);
+ sun_environ_hb->add_child(environ_state);
+ environ_state->set_align(Label::ALIGN_CENTER);
+ environ_state->set_valign(Label::VALIGN_CENTER);
+ environ_state->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ preview_sun = memnew(DirectionalLight3D);
+ preview_sun->set_shadow(true);
+ preview_sun->set_shadow_mode(DirectionalLight3D::SHADOW_PARALLEL_4_SPLITS);
+ preview_environment = memnew(WorldEnvironment);
+ environment.instance();
+ preview_environment->set_environment(environment);
+ Ref<Sky> sky;
+ sky.instance();
+ sky_material.instance();
+ sky->set_material(sky_material);
+ environment->set_sky(sky);
+ environment->set_background(Environment::BG_SKY);
+
+ _load_default_preview_settings();
+ _preview_settings_changed();
+ }
}
Node3DEditor::~Node3DEditor() {
@@ -6693,7 +7252,7 @@ void Node3DEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
struct _GizmoPluginPriorityComparator {
bool operator()(const Ref<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const {
if (p_a->get_priority() == p_b->get_priority()) {
- return p_a->get_name() < p_b->get_name();
+ return p_a->get_gizmo_name() < p_b->get_gizmo_name();
}
return p_a->get_priority() > p_b->get_priority();
}
@@ -6701,7 +7260,7 @@ struct _GizmoPluginPriorityComparator {
struct _GizmoPluginNameComparator {
bool operator()(const Ref<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const {
- return p_a->get_name() < p_b->get_name();
+ return p_a->get_gizmo_name() < p_b->get_gizmo_name();
}
};
@@ -6912,7 +7471,7 @@ void EditorNode3DGizmoPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>()));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "get_name"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "get_gizmo_name"));
BIND_VMETHOD(MethodInfo(Variant::INT, "get_priority"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_be_hidden"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_selectable_when_hidden"));
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index 0cefaa6557..cf4aa33257 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -37,7 +37,10 @@
#include "scene/3d/immediate_geometry_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/visual_instance_3d.h"
+#include "scene/3d/world_environment.h"
#include "scene/gui/panel_container.h"
+#include "scene/resources/environment.h"
+#include "scene/resources/sky_material.h"
class Camera3D;
class Node3DEditor;
@@ -213,6 +216,11 @@ class Node3DEditorViewport : public Control {
VIEW_DISPLAY_DEBUG_SDFGI_PROBES,
VIEW_DISPLAY_DEBUG_GI_BUFFER,
VIEW_DISPLAY_DEBUG_DISABLE_LOD,
+ VIEW_DISPLAY_DEBUG_CLUSTER_OMNI_LIGHTS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_SPOT_LIGHTS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_DECALS,
+ VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES,
+
VIEW_LOCK_ROTATION,
VIEW_CINEMATIC_PREVIEW,
VIEW_AUTO_ORTHOGONAL,
@@ -458,6 +466,8 @@ private:
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+ void _project_settings_changed();
+
protected:
void _notification(int p_what);
static void _bind_methods();
@@ -585,7 +595,6 @@ private:
/////
ToolMode tool_mode;
- bool orthogonal;
RenderingServer::ScenarioDebugMode scenario_debug;
@@ -618,6 +627,7 @@ private:
RID cursor_mesh;
RID cursor_instance;
Ref<StandardMaterial3D> indicator_mat;
+ Ref<ShaderMaterial> grid_mat[3];
Ref<StandardMaterial3D> cursor_material;
// Scene drag and drop support
@@ -725,6 +735,7 @@ private:
static Node3DEditor *singleton;
+ void _node_added(Node *p_node);
void _node_removed(Node *p_node);
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_priority;
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_name;
@@ -737,6 +748,61 @@ private:
void _refresh_menu_icons();
+ // Preview Sun and Environment
+
+ uint32_t world_env_count = 0;
+ uint32_t directional_light_count = 0;
+
+ Button *sun_button;
+ Label *sun_state;
+ Label *sun_title;
+ VBoxContainer *sun_vb;
+ Popup *sun_environ_popup;
+ Control *sun_direction;
+ ColorPickerButton *sun_color;
+ EditorSpinSlider *sun_energy;
+ EditorSpinSlider *sun_max_distance;
+ Button *sun_add_to_scene;
+
+ void _sun_direction_draw();
+ void _sun_direction_input(const Ref<InputEvent> &p_event);
+
+ Basis sun_rotation;
+
+ Ref<Shader> sun_direction_shader;
+ Ref<ShaderMaterial> sun_direction_material;
+
+ Button *environ_button;
+ Label *environ_state;
+ Label *environ_title;
+ VBoxContainer *environ_vb;
+ ColorPickerButton *environ_sky_color;
+ ColorPickerButton *environ_ground_color;
+ EditorSpinSlider *environ_energy;
+ Button *environ_ao_button;
+ Button *environ_glow_button;
+ Button *environ_tonemap_button;
+ Button *environ_gi_button;
+ Button *environ_add_to_scene;
+
+ Button *sun_environ_settings;
+
+ DirectionalLight3D *preview_sun;
+ WorldEnvironment *preview_environment;
+ Ref<Environment> environment;
+ Ref<ProceduralSkyMaterial> sky_material;
+
+ bool sun_environ_updating = false;
+
+ void _load_default_preview_settings();
+ void _update_preview_environment();
+
+ void _preview_settings_changed();
+ void _sun_environ_settings_pressed();
+
+ void _add_sun_to_scene();
+ void _add_environment_to_scene();
+
protected:
void _notification(int p_what);
//void _gui_input(InputEvent p_event);
diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp
index 1f20a87565..0a949c8610 100644
--- a/editor/plugins/packed_scene_translation_parser_plugin.cpp
+++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp
@@ -42,7 +42,7 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path,
// These properties are translated with the tr() function in the C++ code when being set or updated.
Error err;
- RES loaded_res = ResourceLoader::load(p_path, "PackedScene", false, &err);
+ RES loaded_res = ResourceLoader::load(p_path, "PackedScene", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
if (err) {
ERR_PRINT("Failed to load " + p_path);
return err;
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 1af790c48d..a6afd45686 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -894,7 +894,7 @@ void ScriptEditor::_reload_scripts() {
Ref<Script> script = edited_res;
if (script != nullptr) {
- Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
+ Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_CONTINUE(!rel_script.is_valid());
script->set_source_code(rel_script->get_source_code());
script->set_last_modified_time(rel_script->get_last_modified_time());
@@ -1954,7 +1954,20 @@ void ScriptEditor::_update_script_names() {
Vector<String> disambiguated_script_names;
Vector<String> full_script_paths;
for (int j = 0; j < sedata.size(); j++) {
- disambiguated_script_names.append(sedata[j].name.replace("(*)", "").get_file());
+ String name = sedata[j].name.replace("(*)", "");
+ ScriptListName script_display = (ScriptListName)(int)EditorSettings::get_singleton()->get("text_editor/script_list/list_script_names_as");
+ switch (script_display) {
+ case DISPLAY_NAME: {
+ name = name.get_file();
+ } break;
+ case DISPLAY_DIR_AND_NAME: {
+ name = name.get_base_dir().get_file().plus_file(name.get_file());
+ } break;
+ default:
+ break;
+ }
+
+ disambiguated_script_names.append(name);
full_script_paths.append(sedata[j].tooltip);
}
@@ -2198,7 +2211,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
args.push_back(script_path);
}
- Error err = OS::get_singleton()->execute(path, args, false);
+ Error err = OS::get_singleton()->create_process(path, args);
if (err == OK) {
return false;
}
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 1b0e9ec781..b6df66b8af 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -214,7 +214,7 @@ void ScriptTextEditor::_load_theme_settings() {
text_edit->add_theme_color_override("line_number_color", line_number_color);
text_edit->add_theme_color_override("caret_color", caret_color);
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
- text_edit->add_theme_color_override("font_color_selected", text_selected_color);
+ text_edit->add_theme_color_override("font_selected_color", text_selected_color);
text_edit->add_theme_color_override("selection_color", selection_color);
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
text_edit->add_theme_color_override("current_line_color", current_line_color);
@@ -688,7 +688,7 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
uint64_t date = FileAccess::get_modified_time(script->get_path());
if (last_date != date) {
- Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
+ Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_CONTINUE(!rel_script.is_valid());
script->set_source_code(rel_script->get_source_code());
script->set_last_modified_time(rel_script->get_last_modified_time());
@@ -1066,7 +1066,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
return;
}
- tx->indent_left();
+ tx->indent_selected_lines_left();
} break;
case EDIT_INDENT_RIGHT: {
Ref<Script> scr = script;
@@ -1074,7 +1074,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
return;
}
- tx->indent_right();
+ tx->indent_selected_lines_right();
} break;
case EDIT_DELETE_LINE: {
code_editor->delete_lines();
@@ -1632,16 +1632,16 @@ void ScriptTextEditor::_color_changed(const Color &p_color) {
void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) {
context_menu->clear();
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
context_menu->add_separator();
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
context_menu->add_separator();
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
context_menu->add_separator();
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
@@ -1743,14 +1743,14 @@ void ScriptTextEditor::_enable_code_editor() {
search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
edit_hb->add_child(edit_menu);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
@@ -1763,7 +1763,7 @@ void ScriptTextEditor::_enable_code_editor() {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
@@ -1915,12 +1915,6 @@ static ScriptEditorBase *create_editor(const RES &p_resource) {
}
void ScriptTextEditor::register_editor() {
- ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z);
- ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y);
- ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X);
- ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C);
- ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V);
- ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A);
ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP);
ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN);
ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K);
@@ -1936,10 +1930,8 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
#ifdef OSX_ENABLED
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C);
- ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE);
#else
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D);
- ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE);
#endif
ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E);
ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index d6a816f606..c8a46715ad 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -117,7 +117,7 @@ void ShaderTextEditor::_load_theme_settings() {
get_text_editor()->add_theme_color_override("line_number_color", line_number_color);
get_text_editor()->add_theme_color_override("caret_color", caret_color);
get_text_editor()->add_theme_color_override("caret_background_color", caret_background_color);
- get_text_editor()->add_theme_color_override("font_color_selected", text_selected_color);
+ get_text_editor()->add_theme_color_override("font_selected_color", text_selected_color);
get_text_editor()->add_theme_color_override("selection_color", selection_color);
get_text_editor()->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
get_text_editor()->add_theme_color_override("current_line_color", current_line_color);
@@ -282,7 +282,7 @@ void ShaderEditor::_menu_option(int p_option) {
}
CodeEdit *tx = shader_editor->get_text_editor();
- tx->indent_left();
+ tx->indent_selected_lines_left();
} break;
case EDIT_INDENT_RIGHT: {
@@ -291,7 +291,7 @@ void ShaderEditor::_menu_option(int p_option) {
}
CodeEdit *tx = shader_editor->get_text_editor();
- tx->indent_right();
+ tx->indent_selected_lines_right();
} break;
case EDIT_DELETE_LINE: {
@@ -405,7 +405,7 @@ void ShaderEditor::_check_for_external_edit() {
}
void ShaderEditor::_reload_shader_from_disk() {
- Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), true);
+ Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_FAIL_COND(!rel_shader.is_valid());
shader->set_code(rel_shader->get_code());
@@ -533,15 +533,15 @@ void ShaderEditor::_bookmark_item_pressed(int p_idx) {
void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) {
context_menu->clear();
if (p_selection) {
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
}
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
context_menu->add_separator();
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
context_menu->add_separator();
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
@@ -585,14 +585,14 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
edit_menu->set_text(TTR("Edit"));
edit_menu->set_switch_on_hover(true);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
@@ -602,7 +602,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
search_menu = memnew(MenuButton);
diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp
index ea58a4535b..121ccfa417 100644
--- a/editor/plugins/skeleton_3d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_3d_editor_plugin.cpp
@@ -383,8 +383,12 @@ PhysicalBone3D *Skeleton3DEditor::create_physical_bone(int bone_id, int bone_chi
CollisionShape3D *bone_shape = memnew(CollisionShape3D);
bone_shape->set_shape(bone_shape_capsule);
+ Transform capsule_transform;
+ capsule_transform.basis = Basis(Vector3(1, 0, 0), Vector3(0, 0, 1), Vector3(0, -1, 0));
+ bone_shape->set_transform(capsule_transform);
+
Transform body_transform;
- body_transform.set_look_at(Vector3(0, 0, 0), child_rest.origin, Vector3(0, 1, 0));
+ body_transform.set_look_at(Vector3(0, 0, 0), child_rest.origin);
body_transform.origin = body_transform.basis.xform(Vector3(0, 0, -half_height));
Transform joint_transform;
diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp
index 03ddaa2c74..4949d2b9b7 100644
--- a/editor/plugins/sprite_2d_editor_plugin.cpp
+++ b/editor/plugins/sprite_2d_editor_plugin.cpp
@@ -173,6 +173,11 @@ void Sprite2DEditor::_update_mesh_data() {
Ref<Image> image = texture->get_data();
ERR_FAIL_COND(image.is_null());
+
+ if (image->is_compressed()) {
+ image->decompress();
+ }
+
Rect2 rect;
if (node->is_region()) {
rect = node->get_region_rect();
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index 2aa6ad0eaa..0547f99079 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/io/resource_loader.h"
+#include "core/os/keyboard.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/3d/sprite_3d.h"
@@ -952,7 +953,11 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
- _file_load_request(files, at_pos);
+ if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
+ _prepare_sprite_sheet(files[0]);
+ } else {
+ _file_load_request(files, at_pos);
+ }
}
}
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index 3628a2e4d1..b88f1c91e6 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -96,7 +96,7 @@ void TextEditor::_load_theme_settings() {
text_edit->add_theme_color_override("line_number_color", line_number_color);
text_edit->add_theme_color_override("caret_color", caret_color);
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
- text_edit->add_theme_color_override("font_color_selected", text_selected_color);
+ text_edit->add_theme_color_override("font_selected_color", text_selected_color);
text_edit->add_theme_color_override("selection_color", selection_color);
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
text_edit->add_theme_color_override("current_line_color", current_line_color);
@@ -363,10 +363,10 @@ void TextEditor::_edit_option(int p_op) {
code_editor->move_lines_down();
} break;
case EDIT_INDENT_LEFT: {
- tx->indent_left();
+ tx->indent_selected_lines_left();
} break;
case EDIT_INDENT_RIGHT: {
- tx->indent_right();
+ tx->indent_selected_lines_right();
} break;
case EDIT_DELETE_LINE: {
code_editor->delete_lines();
@@ -514,15 +514,15 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) {
context_menu->clear();
if (p_selection) {
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
}
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
context_menu->add_separator();
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
context_menu->add_separator();
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
@@ -584,14 +584,14 @@ TextEditor::TextEditor() {
edit_menu->set_switch_on_hover(true);
edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &TextEditor::_edit_option));
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("un_redo"), EDIT_REDO);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
diff --git a/editor/plugins/texture_3d_editor_plugin.cpp b/editor/plugins/texture_3d_editor_plugin.cpp
index 099257daa1..36297c8a4a 100644
--- a/editor/plugins/texture_3d_editor_plugin.cpp
+++ b/editor/plugins/texture_3d_editor_plugin.cpp
@@ -57,7 +57,7 @@ void Texture3DEditor::_notification(int p_what) {
}
}
-void Texture3DEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+void Texture3DEditor::_texture_changed() {
if (!is_visible()) {
return;
}
@@ -118,7 +118,7 @@ void Texture3DEditor::_texture_rect_update_area() {
void Texture3DEditor::edit(Ref<Texture3D> p_texture) {
if (!texture.is_null()) {
- texture->remove_change_receptor(this);
+ texture->disconnect("changed", callable_mp(this, &Texture3DEditor::_texture_changed));
}
texture = p_texture;
@@ -128,7 +128,7 @@ void Texture3DEditor::edit(Ref<Texture3D> p_texture) {
_make_shaders();
}
- texture->add_change_receptor(this);
+ texture->connect("changed", callable_mp(this, &Texture3DEditor::_texture_changed));
update();
texture_rect->set_material(material);
setting = true;
@@ -173,8 +173,7 @@ Texture3DEditor::Texture3DEditor() {
info->set_h_grow_direction(GROW_DIRECTION_BEGIN);
info->set_v_grow_direction(GROW_DIRECTION_BEGIN);
info->add_theme_color_override("font_color", Color(1, 1, 1, 1));
- info->add_theme_color_override("font_color_shadow", Color(0, 0, 0, 0.5));
- info->add_theme_color_override("font_color_shadow", Color(0, 0, 0, 0.5));
+ info->add_theme_color_override("font_shadow_color", Color(0, 0, 0, 0.5));
info->add_theme_constant_override("shadow_as_outline", 1);
info->add_theme_constant_override("shadow_offset_x", 2);
info->add_theme_constant_override("shadow_offset_y", 2);
@@ -185,7 +184,7 @@ Texture3DEditor::Texture3DEditor() {
Texture3DEditor::~Texture3DEditor() {
if (!texture.is_null()) {
- texture->remove_change_receptor(this);
+ texture->disconnect("changed", callable_mp(this, &Texture3DEditor::_texture_changed));
}
}
diff --git a/editor/plugins/texture_3d_editor_plugin.h b/editor/plugins/texture_3d_editor_plugin.h
index 944abf16d9..9d90d3653f 100644
--- a/editor/plugins/texture_3d_editor_plugin.h
+++ b/editor/plugins/texture_3d_editor_plugin.h
@@ -61,10 +61,12 @@ class Texture3DEditor : public Control {
void _texture_rect_update_area();
void _texture_rect_draw();
+ void _texture_changed();
+
protected:
void _notification(int p_what);
void _gui_input(Ref<InputEvent> p_event);
- void _changed_callback(Object *p_changed, const char *p_prop) override;
+
static void _bind_methods();
public:
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 1d3fd668c6..253f8878d2 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -104,7 +104,7 @@ void TextureEditor::_notification(int p_what) {
}
}
-void TextureEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+void TextureEditor::_texture_changed() {
if (!is_visible()) {
return;
}
@@ -113,13 +113,13 @@ void TextureEditor::_changed_callback(Object *p_changed, const char *p_prop) {
void TextureEditor::edit(Ref<Texture2D> p_texture) {
if (!texture.is_null()) {
- texture->remove_change_receptor(this);
+ texture->disconnect("changed", callable_mp(this, &TextureEditor::_texture_changed));
}
texture = p_texture;
if (!texture.is_null()) {
- texture->add_change_receptor(this);
+ texture->connect("changed", callable_mp(this, &TextureEditor::_texture_changed));
update();
} else {
hide();
@@ -137,7 +137,7 @@ TextureEditor::TextureEditor() {
TextureEditor::~TextureEditor() {
if (!texture.is_null()) {
- texture->remove_change_receptor(this);
+ texture->disconnect("changed", callable_mp(this, &TextureEditor::_texture_changed));
}
}
diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h
index 621d737028..ebe8882194 100644
--- a/editor/plugins/texture_editor_plugin.h
+++ b/editor/plugins/texture_editor_plugin.h
@@ -43,7 +43,7 @@ class TextureEditor : public Control {
protected:
void _notification(int p_what);
void _gui_input(Ref<InputEvent> p_event);
- void _changed_callback(Object *p_changed, const char *p_prop) override;
+ void _texture_changed();
static void _bind_methods();
public:
diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp
index 3b95ed813f..254ad3d56e 100644
--- a/editor/plugins/texture_layered_editor_plugin.cpp
+++ b/editor/plugins/texture_layered_editor_plugin.cpp
@@ -63,7 +63,7 @@ void TextureLayeredEditor::_notification(int p_what) {
}
}
-void TextureLayeredEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+void TextureLayeredEditor::_texture_changed() {
if (!is_visible()) {
return;
}
@@ -173,7 +173,7 @@ void TextureLayeredEditor::_texture_rect_update_area() {
void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) {
if (!texture.is_null()) {
- texture->remove_change_receptor(this);
+ texture->disconnect("changed", callable_mp(this, &TextureLayeredEditor::_texture_changed));
}
texture = p_texture;
@@ -183,7 +183,7 @@ void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) {
_make_shaders();
}
- texture->add_change_receptor(this);
+ texture->connect("changed", callable_mp(this, &TextureLayeredEditor::_texture_changed));
update();
texture_rect->set_material(materials[texture->get_layered_type()]);
setting = true;
@@ -238,8 +238,7 @@ TextureLayeredEditor::TextureLayeredEditor() {
info->set_h_grow_direction(GROW_DIRECTION_BEGIN);
info->set_v_grow_direction(GROW_DIRECTION_BEGIN);
info->add_theme_color_override("font_color", Color(1, 1, 1, 1));
- info->add_theme_color_override("font_color_shadow", Color(0, 0, 0, 0.5));
- info->add_theme_color_override("font_color_shadow", Color(0, 0, 0, 0.5));
+ info->add_theme_color_override("font_shadow_color", Color(0, 0, 0, 0.5));
info->add_theme_constant_override("shadow_as_outline", 1);
info->add_theme_constant_override("shadow_offset_x", 2);
info->add_theme_constant_override("shadow_offset_y", 2);
@@ -249,9 +248,6 @@ TextureLayeredEditor::TextureLayeredEditor() {
}
TextureLayeredEditor::~TextureLayeredEditor() {
- if (!texture.is_null()) {
- texture->remove_change_receptor(this);
- }
}
//
diff --git a/editor/plugins/texture_layered_editor_plugin.h b/editor/plugins/texture_layered_editor_plugin.h
index 4bcc8fa1f1..c4ced62fb9 100644
--- a/editor/plugins/texture_layered_editor_plugin.h
+++ b/editor/plugins/texture_layered_editor_plugin.h
@@ -63,10 +63,11 @@ class TextureLayeredEditor : public Control {
void _texture_rect_update_area();
void _texture_rect_draw();
+ void _texture_changed();
+
protected:
void _notification(int p_what);
void _gui_input(Ref<InputEvent> p_event);
- void _changed_callback(Object *p_changed, const char *p_prop) override;
static void _bind_methods();
public:
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 53e127d4c8..63255e6547 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -42,8 +42,21 @@
void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) {
Vector2 line = (to - from).normalized() * 10;
+
+ // Draw a translucent background line to make the foreground line visible on any background.
+ edit_draw->draw_line(
+ from,
+ to,
+ EditorNode::get_singleton()->get_theme_base()->get_theme_color("mono_color", "Editor").inverted() * Color(1, 1, 1, 0.5),
+ Math::round(2 * EDSCALE));
+
while ((to - from).length_squared() > 200) {
- edit_draw->draw_line(from, from + line, EditorNode::get_singleton()->get_theme_base()->get_theme_color("mono_color", "Editor"), 2);
+ edit_draw->draw_line(
+ from,
+ from + line,
+ EditorNode::get_singleton()->get_theme_base()->get_theme_color("mono_color", "Editor"),
+ Math::round(2 * EDSCALE));
+
from += line * 2;
}
}
@@ -467,20 +480,41 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
Vector2 dragged(mm->get_relative().x / draw_zoom, mm->get_relative().y / draw_zoom);
hscroll->set_value(hscroll->get_value() - dragged.x);
vscroll->set_value(vscroll->get_value() - dragged.y);
-
} else if (drag) {
if (edited_margin >= 0) {
float new_margin = 0;
- if (edited_margin == 0) {
- new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom;
- } else if (edited_margin == 1) {
- new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom;
- } else if (edited_margin == 2) {
- new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom;
- } else if (edited_margin == 3) {
- new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom;
+
+ if (snap_mode != SNAP_GRID) {
+ if (edited_margin == 0) {
+ new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom;
+ } else if (edited_margin == 1) {
+ new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom;
+ } else if (edited_margin == 2) {
+ new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom;
+ } else if (edited_margin == 3) {
+ new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom;
+ } else {
+ ERR_PRINT("Unexpected edited_margin");
+ }
+
+ if (snap_mode == SNAP_PIXEL) {
+ new_margin = Math::round(new_margin);
+ }
} else {
- ERR_PRINT("Unexpected edited_margin");
+ Vector2 pos_snapped = snap_point(mtx.affine_inverse().xform(mm->get_position()));
+ Rect2 rect_rounded = Rect2(rect.position.round(), rect.size.round());
+
+ if (edited_margin == 0) {
+ new_margin = pos_snapped.y - rect_rounded.position.y;
+ } else if (edited_margin == 1) {
+ new_margin = rect_rounded.size.y + rect_rounded.position.y - pos_snapped.y;
+ } else if (edited_margin == 2) {
+ new_margin = pos_snapped.x - rect_rounded.position.x;
+ } else if (edited_margin == 3) {
+ new_margin = rect_rounded.size.x + rect_rounded.position.x - pos_snapped.x;
+ } else {
+ ERR_PRINT("Unexpected edited_margin");
+ }
}
if (new_margin < 0) {
@@ -829,19 +863,19 @@ Sprite2D *TextureRegionEditor::get_sprite() {
void TextureRegionEditor::edit(Object *p_obj) {
if (node_sprite) {
- node_sprite->remove_change_receptor(this);
+ node_sprite->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
if (node_sprite_3d) {
- node_sprite_3d->remove_change_receptor(this);
+ node_sprite_3d->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
if (node_ninepatch) {
- node_ninepatch->remove_change_receptor(this);
+ node_ninepatch->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
if (obj_styleBox.is_valid()) {
- obj_styleBox->remove_change_receptor(this);
+ obj_styleBox->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
if (atlas_tex.is_valid()) {
- atlas_tex->remove_change_receptor(this);
+ atlas_tex->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
if (p_obj) {
node_sprite = Object::cast_to<Sprite2D>(p_obj);
@@ -853,7 +887,7 @@ void TextureRegionEditor::edit(Object *p_obj) {
if (Object::cast_to<AtlasTexture>(p_obj)) {
atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
}
- p_obj->add_change_receptor(this);
+ p_obj->connect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
_edit_region();
} else {
node_sprite = nullptr;
@@ -871,14 +905,11 @@ void TextureRegionEditor::edit(Object *p_obj) {
}
}
-void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+void TextureRegionEditor::_texture_changed() {
if (!is_visible()) {
return;
}
- String prop = p_prop;
- if (prop == "atlas" || prop == "texture" || prop == "region") {
- _edit_region();
- }
+ _edit_region();
}
void TextureRegionEditor::_edit_region() {
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index 56ccefb025..d3db0a08a9 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -117,6 +117,8 @@ class TextureRegionEditor : public VBoxContainer {
void _update_rect();
void _update_autoslice();
+ void _texture_changed();
+
protected:
void _notification(int p_what);
void _node_removed(Object *p_obj);
@@ -124,8 +126,6 @@ protected:
Vector2 snap_point(Vector2 p_target) const;
- virtual void _changed_callback(Object *p_changed, const char *p_prop) override;
-
public:
void _edit_region();
void _region_draw();
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 6a16aa28a9..74b01b3c36 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -40,9 +40,12 @@
void TileMapEditor::_node_removed(Node *p_node) {
if (p_node == node && node) {
- // Fixes #44824, which describes a situation where you can reselect a TileMap node without first de-selecting it when switching scenes.
- node->disconnect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed));
+ Callable callable_tileset_settings_changed = callable_mp(this, &TileMapEditor::_tileset_settings_changed);
+ if (node->is_connected("settings_changed", callable_tileset_settings_changed)) {
+ // Fixes #44824, which describes a situation where you can reselect a TileMap node without first de-selecting it when switching scenes.
+ node->disconnect("settings_changed", callable_tileset_settings_changed);
+ }
node = nullptr;
}
}
@@ -1870,7 +1873,11 @@ void TileMapEditor::edit(Node *p_tile_map) {
}
if (node) {
- node->disconnect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed));
+ Callable callable_tileset_settings_changed = callable_mp(this, &TileMapEditor::_tileset_settings_changed);
+
+ if (node->is_connected("settings_changed", callable_tileset_settings_changed)) {
+ node->disconnect("settings_changed", callable_tileset_settings_changed);
+ }
}
if (p_tile_map) {
node = Object::cast_to<TileMap>(p_tile_map);
@@ -1897,7 +1904,11 @@ void TileMapEditor::edit(Node *p_tile_map) {
}
if (node) {
- node->connect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed));
+ Callable callable_tileset_settings_changed = callable_mp(this, &TileMapEditor::_tileset_settings_changed);
+
+ if (!node->is_connected("settings_changed", callable_tileset_settings_changed)) {
+ node->connect("settings_changed", callable_tileset_settings_changed);
+ }
}
_clear_bucket_cache();
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index deeab2fbc7..c628fe8367 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -39,7 +39,6 @@
void TileSetEditor::edit(const Ref<TileSet> &p_tileset) {
tileset = p_tileset;
- tileset->add_change_receptor(this);
texture_list->clear();
texture_map.clear();
@@ -1859,7 +1858,7 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
_update_toggle_shape_button();
workspace->update();
workspace_container->update();
- helper->_change_notify("");
+ helper->notify_property_list_changed();
}
} else if (p_tool == SELECT_NEXT) {
_select_next_shape();
@@ -2173,7 +2172,7 @@ Array TileSetEditor::_get_tiles_in_current_texture(bool sorted) {
}
}
if (sorted) {
- a.sort_custom(this, "_sort_tiles");
+ a.sort_custom(callable_mp(this, &TileSetEditor::_sort_tiles));
}
return a;
}
@@ -2287,7 +2286,7 @@ void TileSetEditor::_select_next_shape() {
}
workspace->update();
workspace_container->update();
- helper->_change_notify("");
+ helper->notify_property_list_changed();
}
}
@@ -2349,7 +2348,7 @@ void TileSetEditor::_select_previous_shape() {
}
workspace->update();
workspace_container->update();
- helper->_change_notify("");
+ helper->notify_property_list_changed();
}
}
@@ -3012,7 +3011,7 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
undo_redo->add_undo_method(this, "_select_edited_shape_coord");
undo_redo->commit_action();
}
- tileset->_change_notify("");
+ tileset->notify_property_list_changed();
}
void TileSetEditor::select_coord(const Vector2 &coord) {
@@ -3115,7 +3114,7 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
}
workspace->update();
workspace_container->update();
- helper->_change_notify("");
+ helper->notify_property_list_changed();
}
Vector2 TileSetEditor::snap_point(const Vector2 &point) {
@@ -3225,7 +3224,7 @@ void TileSetEditor::update_texture_list() {
workspace_overlay->update();
}
update_texture_list_icon();
- helper->_change_notify("");
+ helper->notify_property_list_changed();
}
void TileSetEditor::update_texture_list_icon() {
@@ -3389,7 +3388,7 @@ int TileSetEditor::get_current_tile() const {
void TileSetEditor::set_current_tile(int p_id) {
if (current_tile != p_id) {
current_tile = p_id;
- helper->_change_notify("");
+ helper->notify_property_list_changed();
select_coord(Vector2(0, 0));
update_workspace_tile_mode();
if (p_id == -1) {
@@ -3414,7 +3413,7 @@ void TilesetEditorContext::set_tileset(const Ref<TileSet> &p_tileset) {
void TilesetEditorContext::set_snap_options_visible(bool p_visible) {
snap_options_visible = p_visible;
- _change_notify("");
+ notify_property_list_changed();
}
bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value) {
@@ -3450,7 +3449,7 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value
tileset->set(String::num(tileset_editor->get_current_tile(), 0) + "/" + name2, p_value, &v);
}
if (v) {
- tileset->_change_notify("");
+ tileset->notify_property_list_changed();
tileset_editor->workspace->update();
tileset_editor->workspace_overlay->update();
}
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 056562a7a7..a63e641c2b 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -44,6 +44,7 @@
#include "scene/gui/panel.h"
#include "scene/main/window.h"
#include "scene/resources/visual_shader_nodes.h"
+#include "scene/resources/visual_shader_sdf_nodes.h"
#include "servers/display_server.h"
#include "servers/rendering/shader_types.h"
@@ -618,7 +619,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
if (vsnode->get_input_port_default_hint(i) != "" && !port_left_used) {
Label *hint_label = memnew(Label);
hint_label->set_text("[" + vsnode->get_input_port_default_hint(i) + "]");
- hint_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color("font_color_readonly", "TextEdit"));
+ hint_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color("font_readonly_color", "TextEdit"));
hint_label->add_theme_style_override("normal", label_style);
hb->add_child(hint_label);
}
@@ -1022,7 +1023,7 @@ void VisualShaderEditor::_update_options_menu() {
Color unsupported_color = get_theme_color("error_color", "Editor");
Color supported_color = get_theme_color("warning_color", "Editor");
- static bool low_driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name") == "GLES2";
+ static bool low_driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "GLES2";
Map<String, TreeItem *> folders;
@@ -1281,6 +1282,9 @@ void VisualShaderEditor::_update_graph() {
graph->connect_node(itos(from), from_idx, itos(to), to_idx);
}
+
+ float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
+ graph->set_minimap_opacity(graph_minimap_opacity);
}
VisualShader::Type VisualShaderEditor::get_current_shader_type() const {
@@ -1733,114 +1737,220 @@ void VisualShaderEditor::_add_curve_node(const String &p_path) {
curve->set_texture(ResourceLoader::load(p_path));
}
-VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
- ERR_FAIL_INDEX_V(p_idx, add_options.size(), nullptr);
+void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, int p_op_idx) {
+ // FLOAT_OP
+ {
+ VisualShaderNodeFloatOp *floatOp = Object::cast_to<VisualShaderNodeFloatOp>(p_node);
- Ref<VisualShaderNode> vsnode;
+ if (floatOp) {
+ floatOp->set_operator((VisualShaderNodeFloatOp::Operator)p_op_idx);
+ return;
+ }
+ }
- bool is_custom = add_options[p_idx].is_custom;
+ // FLOAT_FUNC
+ {
+ VisualShaderNodeFloatFunc *floatFunc = Object::cast_to<VisualShaderNodeFloatFunc>(p_node);
- if (!is_custom && add_options[p_idx].type != String()) {
- VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
- ERR_FAIL_COND_V(!vsn, nullptr);
+ if (floatFunc) {
+ floatFunc->set_function((VisualShaderNodeFloatFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn);
+ // VECTOR_OP
+ {
+ VisualShaderNodeVectorOp *vecOp = Object::cast_to<VisualShaderNodeVectorOp>(p_node);
- if (constant) {
- if ((int)add_options[p_idx].value != -1) {
- constant->set_constant(add_options[p_idx].value);
- }
+ if (vecOp) {
+ vecOp->set_operator((VisualShaderNodeVectorOp::Operator)p_op_idx);
+ return;
}
+ }
- if (p_op_idx != -1) {
- VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsn);
+ // VECTOR_FUNC
+ {
+ VisualShaderNodeVectorFunc *vecFunc = Object::cast_to<VisualShaderNodeVectorFunc>(p_node);
- if (input) {
- input->set_input_name(add_options[p_idx].sub_func_str);
- }
+ if (vecFunc) {
+ vecFunc->set_function((VisualShaderNodeVectorFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(vsn);
+ // COLOR_OP
+ {
+ VisualShaderNodeColorOp *colorOp = Object::cast_to<VisualShaderNodeColorOp>(p_node);
- if (is) {
- is->set_function((VisualShaderNodeIs::Function)p_op_idx);
- }
+ if (colorOp) {
+ colorOp->set_operator((VisualShaderNodeColorOp::Operator)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(vsn);
+ // COLOR_FUNC
+ {
+ VisualShaderNodeColorFunc *colorFunc = Object::cast_to<VisualShaderNodeColorFunc>(p_node);
- if (cmp) {
- cmp->set_function((VisualShaderNodeCompare::Function)p_op_idx);
- }
+ if (colorFunc) {
+ colorFunc->set_function((VisualShaderNodeColorFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeColorOp *colorOp = Object::cast_to<VisualShaderNodeColorOp>(vsn);
+ // INT_OP
+ {
+ VisualShaderNodeIntOp *intOp = Object::cast_to<VisualShaderNodeIntOp>(p_node);
- if (colorOp) {
- colorOp->set_operator((VisualShaderNodeColorOp::Operator)p_op_idx);
- }
+ if (intOp) {
+ intOp->set_operator((VisualShaderNodeIntOp::Operator)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeColorFunc *colorFunc = Object::cast_to<VisualShaderNodeColorFunc>(vsn);
+ // INT_FUNC
+ {
+ VisualShaderNodeIntFunc *intFunc = Object::cast_to<VisualShaderNodeIntFunc>(p_node);
- if (colorFunc) {
- colorFunc->set_function((VisualShaderNodeColorFunc::Function)p_op_idx);
- }
+ if (intFunc) {
+ intFunc->set_function((VisualShaderNodeIntFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeFloatOp *floatOp = Object::cast_to<VisualShaderNodeFloatOp>(vsn);
+ // TRANSFORM_FUNC
+ {
+ VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node);
- if (floatOp) {
- floatOp->set_operator((VisualShaderNodeFloatOp::Operator)p_op_idx);
- }
+ if (matFunc) {
+ matFunc->set_function((VisualShaderNodeTransformFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeIntOp *intOp = Object::cast_to<VisualShaderNodeIntOp>(vsn);
+ // IS
+ {
+ VisualShaderNodeIs *is = Object::cast_to<VisualShaderNodeIs>(p_node);
- if (intOp) {
- intOp->set_operator((VisualShaderNodeIntOp::Operator)p_op_idx);
- }
+ if (is) {
+ is->set_function((VisualShaderNodeIs::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeFloatFunc *floatFunc = Object::cast_to<VisualShaderNodeFloatFunc>(vsn);
+ // COMPARE
+ {
+ VisualShaderNodeCompare *cmp = Object::cast_to<VisualShaderNodeCompare>(p_node);
- if (floatFunc) {
- floatFunc->set_function((VisualShaderNodeFloatFunc::Function)p_op_idx);
- }
+ if (cmp) {
+ cmp->set_function((VisualShaderNodeCompare::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeIntFunc *intFunc = Object::cast_to<VisualShaderNodeIntFunc>(vsn);
+ // DERIVATIVE
+ {
+ VisualShaderNodeScalarDerivativeFunc *sderFunc = Object::cast_to<VisualShaderNodeScalarDerivativeFunc>(p_node);
- if (intFunc) {
- intFunc->set_function((VisualShaderNodeIntFunc::Function)p_op_idx);
- }
+ if (sderFunc) {
+ sderFunc->set_function((VisualShaderNodeScalarDerivativeFunc::Function)p_op_idx);
+ return;
+ }
- VisualShaderNodeVectorOp *vecOp = Object::cast_to<VisualShaderNodeVectorOp>(vsn);
+ VisualShaderNodeVectorDerivativeFunc *vderFunc = Object::cast_to<VisualShaderNodeVectorDerivativeFunc>(p_node);
- if (vecOp) {
- vecOp->set_operator((VisualShaderNodeVectorOp::Operator)p_op_idx);
- }
+ if (vderFunc) {
+ vderFunc->set_function((VisualShaderNodeVectorDerivativeFunc::Function)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeVectorFunc *vecFunc = Object::cast_to<VisualShaderNodeVectorFunc>(vsn);
+ // MIX
+ {
+ VisualShaderNodeMix *mix = Object::cast_to<VisualShaderNodeMix>(p_node);
- if (vecFunc) {
- vecFunc->set_function((VisualShaderNodeVectorFunc::Function)p_op_idx);
- }
+ if (mix) {
+ mix->set_op_type((VisualShaderNodeMix::OpType)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(vsn);
+ // CLAMP
+ {
+ VisualShaderNodeClamp *clampFunc = Object::cast_to<VisualShaderNodeClamp>(p_node);
- if (matFunc) {
- matFunc->set_function((VisualShaderNodeTransformFunc::Function)p_op_idx);
- }
+ if (clampFunc) {
+ clampFunc->set_op_type((VisualShaderNodeClamp::OpType)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeScalarDerivativeFunc *sderFunc = Object::cast_to<VisualShaderNodeScalarDerivativeFunc>(vsn);
+ // SWITCH
+ {
+ VisualShaderNodeSwitch *switchFunc = Object::cast_to<VisualShaderNodeSwitch>(p_node);
- if (sderFunc) {
- sderFunc->set_function((VisualShaderNodeScalarDerivativeFunc::Function)p_op_idx);
- }
+ if (switchFunc) {
+ switchFunc->set_op_type((VisualShaderNodeSwitch::OpType)p_op_idx);
+ return;
+ }
+ }
- VisualShaderNodeVectorDerivativeFunc *vderFunc = Object::cast_to<VisualShaderNodeVectorDerivativeFunc>(vsn);
+ // SMOOTHSTEP
+ {
+ VisualShaderNodeSmoothStep *smoothStepFunc = Object::cast_to<VisualShaderNodeSmoothStep>(p_node);
- if (vderFunc) {
- vderFunc->set_function((VisualShaderNodeVectorDerivativeFunc::Function)p_op_idx);
- }
+ if (smoothStepFunc) {
+ smoothStepFunc->set_op_type((VisualShaderNodeSmoothStep::OpType)p_op_idx);
+ return;
+ }
+ }
+
+ // STEP
+ {
+ VisualShaderNodeStep *stepFunc = Object::cast_to<VisualShaderNodeStep>(p_node);
+
+ if (stepFunc) {
+ stepFunc->set_op_type((VisualShaderNodeStep::OpType)p_op_idx);
+ return;
+ }
+ }
+
+ // MULTIPLY_ADD
+ {
+ VisualShaderNodeMultiplyAdd *fmaFunc = Object::cast_to<VisualShaderNodeMultiplyAdd>(p_node);
+
+ if (fmaFunc) {
+ fmaFunc->set_op_type((VisualShaderNodeMultiplyAdd::OpType)p_op_idx);
+ }
+ }
+}
+
+VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
+ ERR_FAIL_INDEX_V(p_idx, add_options.size(), nullptr);
+
+ Ref<VisualShaderNode> vsnode;
+
+ bool is_custom = add_options[p_idx].is_custom;
- VisualShaderNodeMultiplyAdd *fmaFunc = Object::cast_to<VisualShaderNodeMultiplyAdd>(vsn);
+ if (!is_custom && add_options[p_idx].type != String()) {
+ VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
+ ERR_FAIL_COND_V(!vsn, nullptr);
- if (fmaFunc) {
- fmaFunc->set_op_type((VisualShaderNodeMultiplyAdd::OpType)p_op_idx);
+ VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn);
+
+ if (constant) {
+ if ((int)add_options[p_idx].value != -1) {
+ constant->set_constant(add_options[p_idx].value);
+ }
+ } else {
+ if (p_op_idx != -1) {
+ VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsn);
+
+ if (input) {
+ input->set_input_name(add_options[p_idx].sub_func_str);
+ } else {
+ _setup_node(vsn, p_op_idx);
+ }
}
}
@@ -1879,28 +1989,95 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
undo_redo->add_do_method(expr, "set_size", Size2(250 * EDSCALE, 150 * EDSCALE));
}
+ bool created_expression_port = false;
+
if (to_node != -1 && to_slot != -1) {
- if (vsnode->get_output_port_count() > 0) {
+ VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
+
+ if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) {
+ undo_redo->add_do_method(expr, "add_output_port", 0, input_port_type, "output0");
+ undo_redo->add_undo_method(expr, "remove_output_port", 0);
+
+ String initial_expression_code;
+
+ switch (input_port_type) {
+ case VisualShaderNode::PORT_TYPE_SCALAR:
+ initial_expression_code = "output0 = 1.0;";
+ break;
+ case VisualShaderNode::PORT_TYPE_SCALAR_INT:
+ initial_expression_code = "output0 = 1;";
+ break;
+ case VisualShaderNode::PORT_TYPE_VECTOR:
+ initial_expression_code = "output0 = vec3(1.0, 1.0, 1.0);";
+ break;
+ case VisualShaderNode::PORT_TYPE_BOOLEAN:
+ initial_expression_code = "output0 = true;";
+ break;
+ case VisualShaderNode::PORT_TYPE_TRANSFORM:
+ initial_expression_code = "output0 = mat4(1.0);";
+ break;
+ default:
+ break;
+ }
+
+ undo_redo->add_do_method(expr, "set_expression", initial_expression_code);
+ undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, id_to_use);
+
+ created_expression_port = true;
+ }
+ if (vsnode->get_output_port_count() > 0 || created_expression_port) {
int _from_node = id_to_use;
int _from_slot = 0;
- if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(_from_slot), visual_shader->get_node(type, to_node)->get_input_port_type(to_slot))) {
+ if (created_expression_port) {
undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot);
undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot);
+ } else {
+ // Attempting to connect to the first correct port.
+ for (int i = 0; i < vsnode->get_output_port_count(); i++) {
+ if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type)) {
+ undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
+ undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
+ undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, i, to_node, to_slot);
+ undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, i, to_node, to_slot);
+ break;
+ }
+ }
}
}
} else if (from_node != -1 && from_slot != -1) {
- if (vsnode->get_input_port_count() > 0) {
+ VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot);
+
+ if (expr && expr->is_editable()) {
+ undo_redo->add_do_method(expr, "add_input_port", 0, output_port_type, "input0");
+ undo_redo->add_undo_method(expr, "remove_input_port", 0);
+ undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, id_to_use);
+
+ created_expression_port = true;
+ }
+
+ if (vsnode->get_input_port_count() > 0 || created_expression_port) {
int _to_node = id_to_use;
int _to_slot = 0;
- if (visual_shader->is_port_types_compatible(visual_shader->get_node(type, from_node)->get_output_port_type(from_slot), vsnode->get_input_port_type(_to_slot))) {
+ if (created_expression_port) {
undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, _to_slot);
undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, _to_slot);
+ } else {
+ // Attempting to connect to the first correct port.
+ for (int i = 0; i < vsnode->get_input_port_count(); i++) {
+ if (visual_shader->is_port_types_compatible(output_port_type, vsnode->get_input_port_type(i))) {
+ undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, i);
+ undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, i);
+ undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, from_node, from_slot, _to_node, i);
+ undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, from_node, from_slot, _to_node, i);
+ break;
+ }
+ }
}
}
}
@@ -2087,6 +2264,197 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
}
}
+void VisualShaderEditor::_replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to) {
+ undo_redo->add_do_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_to);
+ undo_redo->add_undo_method(visual_shader.ptr(), "replace_node", p_type_id, p_node_id, p_from);
+}
+
+void VisualShaderEditor::_update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port) {
+ Ref<VisualShaderNode> node = visual_shader->get_node(p_type_id, p_node_id);
+ ERR_FAIL_COND(!node.is_valid());
+ ERR_FAIL_COND(!node->has_method("set_constant"));
+ node->call("set_constant", p_var);
+ if (p_preview_port != -1) {
+ node->set_output_port_for_preview(p_preview_port);
+ }
+}
+
+void VisualShaderEditor::_update_uniform(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port) {
+ Ref<VisualShaderNodeUniform> uniform = visual_shader->get_node(p_type_id, p_node_id);
+ ERR_FAIL_COND(!uniform.is_valid());
+
+ String valid_name = visual_shader->validate_uniform_name(uniform->get_uniform_name(), uniform);
+ uniform->set_uniform_name(valid_name);
+ graph_plugin->set_uniform_name(p_type_id, p_node_id, valid_name);
+
+ if (uniform->has_method("set_default_value_enabled")) {
+ uniform->call("set_default_value_enabled", true);
+ uniform->call("set_default_value", p_var);
+ }
+ if (p_preview_port != -1) {
+ uniform->set_output_port_for_preview(p_preview_port);
+ }
+}
+
+void VisualShaderEditor::_convert_constants_to_uniforms(bool p_vice_versa) {
+ VisualShader::Type type_id = get_current_shader_type();
+
+ if (!p_vice_versa) {
+ undo_redo->create_action(TTR("Convert Constant Node(s) To Uniform(s)"));
+ } else {
+ undo_redo->create_action(TTR("Convert Uniform Node(s) To Constant(s)"));
+ }
+
+ const Set<int> &current_set = p_vice_versa ? selected_uniforms : selected_constants;
+ Set<String> deleted_names;
+
+ for (Set<int>::Element *E = current_set.front(); E; E = E->next()) {
+ int node_id = E->get();
+ Ref<VisualShaderNode> node = visual_shader->get_node(type_id, node_id);
+ bool catched = false;
+ Variant var;
+
+ // float
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeFloatConstant> float_const = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
+ if (float_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeFloatConstant", "VisualShaderNodeFloatUniform");
+ var = float_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeFloatUniform> float_uniform = Object::cast_to<VisualShaderNodeFloatUniform>(node.ptr());
+ if (float_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeFloatUniform", "VisualShaderNodeFloatConstant");
+ var = float_uniform->get_default_value();
+ catched = true;
+ }
+ }
+
+ // int
+ if (!catched) {
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeIntConstant> int_const = Object::cast_to<VisualShaderNodeIntConstant>(node.ptr());
+ if (int_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeIntConstant", "VisualShaderNodeIntUniform");
+ var = int_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeIntUniform> int_uniform = Object::cast_to<VisualShaderNodeIntUniform>(node.ptr());
+ if (int_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeIntUniform", "VisualShaderNodeIntConstant");
+ var = int_uniform->get_default_value();
+ catched = true;
+ }
+ }
+ }
+
+ // boolean
+ if (!catched) {
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeBooleanConstant> boolean_const = Object::cast_to<VisualShaderNodeBooleanConstant>(node.ptr());
+ if (boolean_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeBooleanConstant", "VisualShaderNodeBooleanUniform");
+ var = boolean_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeBooleanUniform> boolean_uniform = Object::cast_to<VisualShaderNodeBooleanUniform>(node.ptr());
+ if (boolean_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeBooleanUniform", "VisualShaderNodeBooleanConstant");
+ var = boolean_uniform->get_default_value();
+ catched = true;
+ }
+ }
+ }
+
+ // vec3
+ if (!catched) {
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeVec3Constant> vec3_const = Object::cast_to<VisualShaderNodeVec3Constant>(node.ptr());
+ if (vec3_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeVec3Constant", "VisualShaderNodeVec3Uniform");
+ var = vec3_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeVec3Uniform> vec3_uniform = Object::cast_to<VisualShaderNodeVec3Uniform>(node.ptr());
+ if (vec3_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeVec3Uniform", "VisualShaderNodeVec3Constant");
+ var = vec3_uniform->get_default_value();
+ catched = true;
+ }
+ }
+ }
+
+ // color
+ if (!catched) {
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeColorConstant> color_const = Object::cast_to<VisualShaderNodeColorConstant>(node.ptr());
+ if (color_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeColorConstant", "VisualShaderNodeColorUniform");
+ var = color_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeColorUniform> color_uniform = Object::cast_to<VisualShaderNodeColorUniform>(node.ptr());
+ if (color_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeColorUniform", "VisualShaderNodeColorConstant");
+ var = color_uniform->get_default_value();
+ catched = true;
+ }
+ }
+ }
+
+ // transform
+ if (!catched) {
+ if (!p_vice_versa) {
+ Ref<VisualShaderNodeTransformConstant> transform_const = Object::cast_to<VisualShaderNodeTransformConstant>(node.ptr());
+ if (transform_const.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeTransformConstant", "VisualShaderNodeTransformUniform");
+ var = transform_const->get_constant();
+ catched = true;
+ }
+ } else {
+ Ref<VisualShaderNodeTransformUniform> transform_uniform = Object::cast_to<VisualShaderNodeTransformUniform>(node.ptr());
+ if (transform_uniform.is_valid()) {
+ _replace_node(type_id, node_id, "VisualShaderNodeTransformUniform", "VisualShaderNodeTransformConstant");
+ var = transform_uniform->get_default_value();
+ catched = true;
+ }
+ }
+ }
+ ERR_CONTINUE(!catched);
+ int preview_port = node->get_output_port_for_preview();
+
+ if (!p_vice_versa) {
+ undo_redo->add_do_method(this, "_update_uniform", type_id, node_id, var, preview_port);
+ undo_redo->add_undo_method(this, "_update_constant", type_id, node_id, var, preview_port);
+ } else {
+ undo_redo->add_do_method(this, "_update_constant", type_id, node_id, var, preview_port);
+ undo_redo->add_undo_method(this, "_update_uniform", type_id, node_id, var, preview_port);
+
+ Ref<VisualShaderNodeUniform> uniform = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
+ ERR_CONTINUE(!uniform.is_valid());
+
+ deleted_names.insert(uniform->get_uniform_name());
+ }
+
+ undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type_id, node_id);
+ undo_redo->add_undo_method(graph_plugin.ptr(), "update_node", type_id, node_id);
+ }
+
+ undo_redo->add_do_method(this, "_update_uniforms", true);
+ undo_redo->add_undo_method(this, "_update_uniforms", true);
+
+ if (deleted_names.size() > 0) {
+ _update_uniform_refs(deleted_names);
+ }
+
+ undo_redo->commit_action();
+}
+
void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
List<int> to_erase;
to_erase.push_back(p_node);
@@ -2134,14 +2502,29 @@ void VisualShaderEditor::_node_selected(Object *p_node) {
void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
+ VisualShader::Type type = get_current_shader_type();
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
+ selected_constants.clear();
+ selected_uniforms.clear();
+
List<int> to_change;
for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
if (gn) {
if (gn->is_selected() && gn->is_close_button_visible()) {
- to_change.push_back(gn->get_name().operator String().to_int());
+ int id = gn->get_name().operator String().to_int();
+ to_change.push_back(id);
+
+ Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
+ VisualShaderNodeConstant *cnode = Object::cast_to<VisualShaderNodeConstant>(node.ptr());
+ if (cnode != nullptr) {
+ selected_constants.insert(id);
+ }
+ VisualShaderNodeUniform *unode = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
+ if (unode != nullptr) {
+ selected_uniforms.insert(id);
+ }
}
}
}
@@ -2152,9 +2535,36 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
popup_menu->set_item_disabled(NodeMenuOptions::PASTE, copy_nodes_buffer.is_empty());
popup_menu->set_item_disabled(NodeMenuOptions::DELETE, to_change.is_empty());
popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, to_change.is_empty());
+
+ int temp = popup_menu->get_item_index(NodeMenuOptions::SEPARATOR2);
+ if (temp != -1) {
+ popup_menu->remove_item(temp);
+ }
+ temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
+ if (temp != -1) {
+ popup_menu->remove_item(temp);
+ }
+ temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_UNIFORMS_TO_CONSTANTS);
+ if (temp != -1) {
+ popup_menu->remove_item(temp);
+ }
+
+ if (selected_constants.size() > 0 || selected_uniforms.size() > 0) {
+ popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
+
+ if (selected_constants.size() > 0) {
+ popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
+ }
+
+ if (selected_uniforms.size() > 0) {
+ popup_menu->add_item(TTR("Convert Uniforms(s) to Constant(s)"), NodeMenuOptions::CONVERT_UNIFORMS_TO_CONSTANTS);
+ }
+ }
+
menu_point = graph->get_local_mouse_position();
Point2 gpos = Input::get_singleton()->get_mouse_position();
popup_menu->set_position(gpos);
+ popup_menu->set_size(Size2(-1, -1));
popup_menu->popup();
}
}
@@ -2695,6 +3105,14 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
case NodeMenuOptions::DUPLICATE:
_duplicate_nodes();
break;
+ case NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS:
+ _convert_constants_to_uniforms(false);
+ break;
+ case NodeMenuOptions::CONVERT_UNIFORMS_TO_CONSTANTS:
+ _convert_constants_to_uniforms(true);
+ break;
+ default:
+ break;
}
}
@@ -2799,15 +3217,35 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
void VisualShaderEditor::_show_preview_text() {
preview_showed = !preview_showed;
- preview_vbox->set_visible(preview_showed);
if (preview_showed) {
+ if (preview_first) {
+ preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
+ preview_window->popup_centered();
+ preview_first = false;
+ } else {
+ preview_window->popup();
+ }
+ _preview_size_changed();
+
if (pending_update_preview) {
_update_preview();
pending_update_preview = false;
}
+ } else {
+ preview_window->hide();
}
}
+void VisualShaderEditor::_preview_close_requested() {
+ preview_showed = false;
+ preview_window->hide();
+ preview_shader->set_pressed(false);
+}
+
+void VisualShaderEditor::_preview_size_changed() {
+ preview_vbox->set_custom_minimum_size(preview_window->get_size());
+}
+
static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) {
RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable);
return RS::global_variable_type_get_shader_datatype(gvt);
@@ -2843,6 +3281,16 @@ void VisualShaderEditor::_update_preview() {
}
}
+void VisualShaderEditor::_visibility_changed() {
+ if (!is_visible()) {
+ if (preview_window->is_visible()) {
+ preview_shader->set_pressed(false);
+ preview_window->hide();
+ preview_showed = false;
+ }
+ }
+}
+
void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
ClassDB::bind_method("_update_options_menu", &VisualShaderEditor::_update_options_menu);
@@ -2856,6 +3304,8 @@ void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
ClassDB::bind_method("_nodes_dragged", &VisualShaderEditor::_nodes_dragged);
ClassDB::bind_method("_float_constant_selected", &VisualShaderEditor::_float_constant_selected);
+ ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant);
+ ClassDB::bind_method("_update_uniform", &VisualShaderEditor::_update_uniform);
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw);
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw);
@@ -2873,7 +3323,6 @@ VisualShaderEditor::VisualShaderEditor() {
saved_node_pos = Point2(0, 0);
ShaderLanguage::get_keyword_list(&keyword_list);
- preview_showed = false;
pending_update_preview = false;
shader_error = false;
@@ -2882,17 +3331,14 @@ VisualShaderEditor::VisualShaderEditor() {
from_node = -1;
from_slot = -1;
- main_box = memnew(HSplitContainer);
- main_box->set_v_size_flags(SIZE_EXPAND_FILL);
- main_box->set_h_size_flags(SIZE_EXPAND_FILL);
- add_child(main_box);
-
graph = memnew(GraphEdit);
graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL);
graph->set_v_size_flags(SIZE_EXPAND_FILL);
graph->set_h_size_flags(SIZE_EXPAND_FILL);
- main_box->add_child(graph);
+ add_child(graph);
graph->set_drag_forwarding(this);
+ float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
+ graph->set_minimap_opacity(graph_minimap_opacity);
graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN);
@@ -2912,6 +3358,7 @@ VisualShaderEditor::VisualShaderEditor() {
graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
+ graph->connect("visibility_changed", callable_mp(this, &VisualShaderEditor::_visibility_changed));
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR);
@@ -2966,29 +3413,35 @@ VisualShaderEditor::VisualShaderEditor() {
preview_shader = memnew(Button);
preview_shader->set_flat(true);
preview_shader->set_toggle_mode(true);
- preview_shader->set_tooltip(TTR("Show resulted shader code."));
+ preview_shader->set_tooltip(TTR("Show generated shader code."));
graph->get_zoom_hbox()->add_child(preview_shader);
preview_shader->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_preview_text));
///////////////////////////////////////
- // PREVIEW PANEL
+ // PREVIEW WINDOW
///////////////////////////////////////
+ preview_window = memnew(Window);
+ preview_window->set_title(TTR("Generated shader code"));
+ preview_window->set_visible(preview_showed);
+ preview_window->connect("close_requested", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
+ preview_window->connect("size_changed", callable_mp(this, &VisualShaderEditor::_preview_size_changed));
+ add_child(preview_window);
+
preview_vbox = memnew(VBoxContainer);
- preview_vbox->set_visible(preview_showed);
- main_box->add_child(preview_vbox);
+ preview_window->add_child(preview_vbox);
+
preview_text = memnew(CodeEdit);
syntax_highlighter.instance();
preview_vbox->add_child(preview_text);
- preview_text->set_h_size_flags(SIZE_EXPAND_FILL);
- preview_text->set_v_size_flags(SIZE_EXPAND_FILL);
- preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
+ preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
preview_text->set_syntax_highlighter(syntax_highlighter);
preview_text->set_draw_line_numbers(true);
preview_text->set_readonly(true);
error_text = memnew(Label);
preview_vbox->add_child(error_text);
+ error_text->set_autowrap(true);
error_text->set_visible(false);
///////////////////////////////////////
@@ -3121,8 +3574,11 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("LessThan", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), VisualShaderNodeCompare::FUNC_LESS_THAN, VisualShaderNode::PORT_TYPE_BOOLEAN));
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));
add_options.push_back(AddOption("NotEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), VisualShaderNodeCompare::FUNC_NOT_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN));
- add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("SwitchS", "Conditional", "Functions", "VisualShaderNodeScalarSwitch", TTR("Returns an associated scalar if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
+ add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), VisualShaderNodeSwitch::OP_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR));
+ 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));
+ 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));
+ 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));
+ 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));
add_options.push_back(AddOption("Compare", "Conditional", "Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
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."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN));
@@ -3345,8 +3801,8 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("ATan2", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeFloatOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_SCALAR));
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));
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));
- add_options.push_back(AddOption("Clamp", "Scalar", "Functions", "VisualShaderNodeScalarClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
- add_options.push_back(AddOption("Clamp", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Constrains a value to lie between two further values."), VisualShaderNodeIntFunc::FUNC_CLAMP, VisualShaderNode::PORT_TYPE_SCALAR_INT));
+ 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));
+ 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));
add_options.push_back(AddOption("Cos", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("CosH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeFloatFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Degrees", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), VisualShaderNodeFloatFunc::FUNC_DEGREES, VisualShaderNode::PORT_TYPE_SCALAR));
@@ -3359,7 +3815,7 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("Log2", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Base-2 logarithm."), VisualShaderNodeFloatFunc::FUNC_LOG2, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Max", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the greater of two values."), VisualShaderNodeFloatOp::OP_MAX, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Min", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Returns the lesser of two values."), VisualShaderNodeFloatOp::OP_MIN, VisualShaderNode::PORT_TYPE_SCALAR));
- add_options.push_back(AddOption("Mix", "Scalar", "Functions", "VisualShaderNodeScalarInterp", TTR("Linear interpolation between two scalars."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
+ add_options.push_back(AddOption("Mix", "Scalar", "Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two scalars."), VisualShaderNodeMix::OP_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("MultiplyAdd", "Scalar", "Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on scalars."), VisualShaderNodeMultiplyAdd::OP_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Negate", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeFloatFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Negate", "Scalar", "Functions", "VisualShaderNodeIntFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeIntFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_SCALAR_INT));
@@ -3375,8 +3831,8 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("Sin", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("SinH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeFloatFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Sqrt", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeFloatFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_SCALAR));
- add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", 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."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
- add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeFloatOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeFloatOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR));
+ 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));
+ 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));
add_options.push_back(AddOption("Tan", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("TanH", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeFloatFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Trunc", "Scalar", "Functions", "VisualShaderNodeFloatFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeFloatFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_SCALAR));
@@ -3397,7 +3853,17 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("FloatUniform", "Scalar", "Variables", "VisualShaderNodeFloatUniform", TTR("Scalar floating-point uniform."), -1, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("IntUniform", "Scalar", "Variables", "VisualShaderNodeIntUniform", TTR("Scalar integer uniform."), -1, VisualShaderNode::PORT_TYPE_SCALAR_INT));
+ // SDF
+ {
+ add_options.push_back(AddOption("ScreenUVToSDF", "SDF", "", "VisualShaderNodeScreenUVToSDF", TTR("Converts screen UV to a SDF."), -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
+ add_options.push_back(AddOption("SDFRaymarch", "SDF", "", "VisualShaderNodeSDFRaymarch", TTR("Casts a ray against the screen SDF and returns the distance travelled."), -1, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
+ add_options.push_back(AddOption("SDFToScreenUV", "SDF", "", "VisualShaderNodeSDFToScreenUV", TTR("Converts a SDF to screen UV."), -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
+ add_options.push_back(AddOption("TextureSDF", "SDF", "", "VisualShaderNodeTextureSDF", TTR("Performs a SDF texture lookup."), -1, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
+ add_options.push_back(AddOption("TextureSDFNormal", "SDF", "", "VisualShaderNodeTextureSDFNormal", TTR("Performs a SDF normal texture lookup."), -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_CANVAS_ITEM));
+ }
+
// TEXTURES
+
cubemap_node_option_idx = add_options.size();
add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), -1, -1));
curve_node_option_idx = add_options.size();
@@ -3450,7 +3916,7 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("ATan2", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("ATanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_VECTOR));
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, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("Clamp", "Vector", "Functions", "VisualShaderNodeVectorClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
+ add_options.push_back(AddOption("Clamp", "Vector", "Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), VisualShaderNodeClamp::OP_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Cos", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("CosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Cross", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Calculates the cross product of two vectors."), VisualShaderNodeVectorOp::OP_CROSS, VisualShaderNode::PORT_TYPE_VECTOR));
@@ -3468,8 +3934,8 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("Log2", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Base-2 logarithm."), VisualShaderNodeVectorFunc::FUNC_LOG2, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Max", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), VisualShaderNodeVectorOp::OP_MAX, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Min", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), VisualShaderNodeVectorOp::OP_MIN, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeVectorInterp", TTR("Linear interpolation between two vectors."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeVectorScalarMix", TTR("Linear interpolation between two vectors using scalar."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
+ add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors."), VisualShaderNodeMix::OP_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR));
+ add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeMix", TTR("Linear interpolation between two vectors using scalar."), VisualShaderNodeMix::OP_TYPE_VECTOR_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("MultiplyAdd", "Vector", "Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on vectors."), VisualShaderNodeMultiplyAdd::OP_TYPE_VECTOR, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Negate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Normalize", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNode::PORT_TYPE_VECTOR));
@@ -3486,10 +3952,10 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("Sin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("SinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Sqrt", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", 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."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", 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."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR));
- add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
+ 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, VisualShaderNode::PORT_TYPE_VECTOR));
+ 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_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR));
+ 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, VisualShaderNode::PORT_TYPE_VECTOR));
+ 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_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Tan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("TanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_VECTOR));
add_options.push_back(AddOption("Trunc", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_VECTOR));
@@ -4007,10 +4473,17 @@ void VisualShaderNodePortPreview::_shader_changed() {
for (int i = EditorNode::get_singleton()->get_editor_history()->get_path_size() - 1; i >= 0; i--) {
Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(i));
+ ShaderMaterial *src_mat;
if (!object) {
continue;
}
- ShaderMaterial *src_mat = Object::cast_to<ShaderMaterial>(object);
+ if (object->has_method("get_material_override")) { // trying getting material from MeshInstance
+ src_mat = Object::cast_to<ShaderMaterial>(object->call("get_material_override"));
+ } else if (object->has_method("get_material")) { // from CanvasItem/Node2D
+ src_mat = Object::cast_to<ShaderMaterial>(object->call("get_material"));
+ } else {
+ src_mat = Object::cast_to<ShaderMaterial>(object);
+ }
if (src_mat && src_mat->get_shader().is_valid()) {
List<PropertyInfo> params;
src_mat->get_shader()->get_param_list(&params);
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 6e8ac92dc2..182bed6ba6 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -134,7 +134,6 @@ class VisualShaderEditor : public VBoxContainer {
int editing_port;
Ref<VisualShader> visual_shader;
- HSplitContainer *main_box;
GraphEdit *graph;
Button *add_node;
Button *preview_shader;
@@ -148,6 +147,7 @@ class VisualShaderEditor : public VBoxContainer {
bool pending_update_preview;
bool shader_error;
+ Window *preview_window;
VBoxContainer *preview_vbox;
CodeEdit *preview_text;
Ref<CodeHighlighter> syntax_highlighter;
@@ -161,7 +161,8 @@ class VisualShaderEditor : public VBoxContainer {
PopupMenu *popup_menu;
MenuButton *tools;
- bool preview_showed;
+ bool preview_first = true;
+ bool preview_showed = false;
bool particles_mode;
enum TypeFlags {
@@ -188,6 +189,9 @@ class VisualShaderEditor : public VBoxContainer {
PASTE,
DELETE,
DUPLICATE,
+ SEPARATOR2, // ignore
+ CONVERT_CONSTANTS_TO_UNIFORMS,
+ CONVERT_UNIFORMS_TO_CONSTANTS,
};
Tree *members;
@@ -272,11 +276,14 @@ class VisualShaderEditor : public VBoxContainer {
void _add_texture3d_node(const String &p_path);
void _add_curve_node(const String &p_path);
+ void _setup_node(VisualShaderNode *p_node, int p_op_idx);
VisualShaderNode *_add_node(int p_idx, int p_op_idx = -1);
void _update_options_menu();
void _set_mode(int p_which);
void _show_preview_text();
+ void _preview_close_requested();
+ void _preview_size_changed();
void _update_preview();
String _get_description(int p_idx);
@@ -316,6 +323,14 @@ class VisualShaderEditor : public VBoxContainer {
int from_node;
int from_slot;
+ Set<int> selected_constants;
+ Set<int> selected_uniforms;
+
+ void _convert_constants_to_uniforms(bool p_vice_versa);
+ void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);
+ void _update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
+ void _update_uniform(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
+
void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
@@ -388,6 +403,8 @@ class VisualShaderEditor : public VBoxContainer {
void _update_uniforms(bool p_update_refs);
void _update_uniform_refs(Set<String> &p_names);
+ void _visibility_changed();
+
protected:
void _notification(int p_what);
static void _bind_methods();