Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Particles (2D + 3D) visibility rect / gizmo optimization for reduced visual clutter #55052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions editor/plugins/gpu_particles_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ void GPUParticles2DEditorPlugin::_file_selected(const String &p_file) {
emission_mask->popup_centered();
}

void GPUParticles2DEditorPlugin::_selection_changed() {
List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list();

if (selected_particles.is_empty() && selected_nodes.is_empty()) {
return;
}

for (GPUParticles2D *SP : selected_particles) {
SP->set_show_visibility_rect(false);
}
selected_particles.clear();

for (Node *P : selected_nodes) {
GPUParticles2D *selected_particle = Object::cast_to<GPUParticles2D>(P);
if (selected_particle != nullptr) {
selected_particle->set_show_visibility_rect(true);
selected_particles.push_back(selected_particle);
}
}
}

void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) {
switch (p_idx) {
case MENU_GENERATE_VISIBILITY_RECT: {
Expand Down Expand Up @@ -334,6 +355,7 @@ void GPUParticles2DEditorPlugin::_notification(int p_what) {
menu->get_popup()->connect("id_pressed", callable_mp(this, &GPUParticles2DEditorPlugin::_menu_callback));
menu->set_icon(menu->get_theme_icon(SNAME("GPUParticles2D"), SNAME("EditorIcons")));
file->connect("file_selected", callable_mp(this, &GPUParticles2DEditorPlugin::_file_selected));
EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", callable_mp(this, &GPUParticles2DEditorPlugin::_selection_changed));
}
}

Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/gpu_particles_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class GPUParticles2DEditorPlugin : public EditorPlugin {
};

GPUParticles2D *particles;
List<GPUParticles2D *> selected_particles;

EditorFileDialog *file;
EditorNode *editor;
Expand All @@ -79,6 +80,7 @@ class GPUParticles2DEditorPlugin : public EditorPlugin {
void _menu_callback(int p_idx);
void _generate_visibility_rect();
void _generate_emission_mask();
void _selection_changed();

protected:
void _notification(int p_what);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ void CPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
GPUParticles3DGizmoPlugin::GPUParticles3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
create_material("particles_material", gizmo_color);
gizmo_color.a = 0.1;
gizmo_color.a = MAX((gizmo_color.a - 0.2) * 0.02, 0.0);
RPicster marked this conversation as resolved.
Show resolved Hide resolved
create_material("particles_solid_material", gizmo_color);
create_icon_material("particles_icon", Node3DEditor::get_singleton()->get_theme_icon(SNAME("GizmoGPUParticles3D"), SNAME("EditorIcons")));
create_handle_material("handles");
Expand Down
12 changes: 11 additions & 1 deletion scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ void GPUParticles2D::set_trail_section_subdivisions(int p_subdivisions) {
update();
}

#ifdef TOOLS_ENABLED
void GPUParticles2D::set_show_visibility_rect(bool p_show_visibility_rect) {
show_visibility_rect = p_show_visibility_rect;
update();
}
#endif

bool GPUParticles2D::is_trail_enabled() const {
return trail_enabled;
}
Expand Down Expand Up @@ -452,7 +459,7 @@ void GPUParticles2D::_notification(int p_what) {
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);

#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_ancestor_of(this))) {
if (show_visibility_rect) {
draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
}
#endif
Expand Down Expand Up @@ -588,6 +595,9 @@ GPUParticles2D::GPUParticles2D() {
set_speed_scale(1);
set_fixed_fps(30);
set_collision_base_size(collision_base_size);
#ifdef TOOLS_ENABLED
show_visibility_rect = false;
#endif
}

GPUParticles2D::~GPUParticles2D() {
Expand Down
9 changes: 7 additions & 2 deletions scene/2d/gpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class GPUParticles2D : public Node2D {
bool local_coords;
int fixed_fps;
bool fractional_delta;

#ifdef TOOLS_ENABLED
bool show_visibility_rect;
RPicster marked this conversation as resolved.
Show resolved Hide resolved
#endif
Ref<Material> process_material;

DrawOrder draw_order;
Expand All @@ -81,7 +83,6 @@ class GPUParticles2D : public Node2D {
static void _bind_methods();
virtual void _validate_property(PropertyInfo &property) const override;
void _notification(int p_what);

void _update_collision_size();

public:
Expand All @@ -102,6 +103,10 @@ class GPUParticles2D : public Node2D {
void set_trail_sections(int p_sections);
void set_trail_section_subdivisions(int p_subdivisions);

#ifdef TOOLS_ENABLED
void set_show_visibility_rect(bool p_show_visibility_rect);
#endif

bool is_emitting() const;
int get_amount() const;
double get_lifetime() const;
Expand Down