diff --git a/editor/icons/icon_gizmo_directional_light.svg b/editor/icons/icon_gizmo_directional_light.svg index a0e31c8b199..dc2d6bf82d6 100644 --- a/editor/icons/icon_gizmo_directional_light.svg +++ b/editor/icons/icon_gizmo_directional_light.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/editor/icons/icon_gizmo_light.svg b/editor/icons/icon_gizmo_light.svg index e3d2a148fa3..1e47082a0a0 100644 --- a/editor/icons/icon_gizmo_light.svg +++ b/editor/icons/icon_gizmo_light.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/editor/icons/icon_gizmo_spot_light.svg b/editor/icons/icon_gizmo_spot_light.svg index 7f0b23937f3..23a8364679c 100644 --- a/editor/icons/icon_gizmo_spot_light.svg +++ b/editor/icons/icon_gizmo_spot_light.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 12b67180074..252f067eb17 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -6145,6 +6145,8 @@ void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const icon->set_albedo(color); icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + icon->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + icon->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); icon->set_cull_mode(SpatialMaterial::CULL_DISABLED); icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED); icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 3eb7fd85fcd..356646221ef 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -102,11 +102,11 @@ protected: static void _bind_methods(); public: - void add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard = false); + void add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); void add_mesh(const Ref &p_mesh, bool p_billboard = false, const Ref &p_skin_reference = Ref(), const Ref &p_material = Ref()); void add_collision_segments(const Vector &p_lines); void add_collision_triangles(const Ref &p_tmesh); - void add_unscaled_billboard(const Ref &p_material, float p_scale = 1); + void add_unscaled_billboard(const Ref &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1)); void add_handles(const Vector &p_handles, const Ref &p_material, bool p_billboard = false, bool p_secondary = false); void add_solid_box(Ref &p_material, Vector3 p_size, Vector3 p_position = Vector3()); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 999353df8d5..29b6c12b23c 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -201,7 +201,7 @@ void EditorSpatialGizmo::add_mesh(const Ref &p_mesh, bool p_billboard instances.push_back(ins); } -void EditorSpatialGizmo::add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard) { +void EditorSpatialGizmo::add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard, const Color &p_modulate) { if (p_lines.empty()) { return; } @@ -221,9 +221,9 @@ void EditorSpatialGizmo::add_lines(const Vector &p_lines, const Ref::Write w = color.write(); for (int i = 0; i < p_lines.size(); i++) { if (is_selected()) - w[i] = Color(1, 1, 1, 0.8); + w[i] = Color(1, 1, 1, 0.8) * p_modulate; else - w[i] = Color(1, 1, 1, 0.2); + w[i] = Color(1, 1, 1, 0.2) * p_modulate; } } @@ -253,13 +253,14 @@ void EditorSpatialGizmo::add_lines(const Vector &p_lines, const Ref &p_material, float p_scale) { +void EditorSpatialGizmo::add_unscaled_billboard(const Ref &p_material, float p_scale, const Color &p_modulate) { ERR_FAIL_COND(!spatial_node); Instance ins; Vector vs; Vector uv; + Vector colors; vs.push_back(Vector3(-p_scale, p_scale, 0)); vs.push_back(Vector3(p_scale, p_scale, 0)); @@ -271,11 +272,17 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref &p_material, uv.push_back(Vector2(1, 1)); uv.push_back(Vector2(0, 1)); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + Ref mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = vs; a[Mesh::ARRAY_TEX_UV] = uv; + a[Mesh::ARRAY_COLOR] = colors; mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLE_FAN, a); mesh->surface_set_material(0, p_material); @@ -784,11 +791,10 @@ Vector3 EditorSpatialGizmo::get_handle_pos(int p_idx) const { LightSpatialGizmoPlugin::LightSpatialGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/light", Color(1, 1, 0.7)); - - create_material("lines_primary", gizmo_color); - create_material("lines_secondary", gizmo_color * Color(1, 1, 1, 0.35)); - create_material("lines_billboard", gizmo_color, true); + // Enable vertex colors for the materials below as the gizmo color depends on the light color. + create_material("lines_primary", Color(1, 1, 1), false, false, true); + create_material("lines_secondary", Color(1, 1, 1, 0.35), false, false, true); + create_material("lines_billboard", Color(1, 1, 1), true, false, true); create_icon_material("light_directional_icon", SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons")); create_icon_material("light_omni_icon", SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons")); @@ -934,6 +940,10 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { Light *light = Object::cast_to(p_gizmo->get_spatial_node()); + Color color = light->get_color(); + // Make the gizmo color as bright as possible for better visibility + color.set_hsv(color.get_h(), color.get_s(), 1); + p_gizmo->clear(); if (Object::cast_to(light)) { @@ -970,8 +980,8 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { } } - p_gizmo->add_lines(lines, material); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_lines(lines, material, false, color); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); } if (Object::cast_to(light)) { @@ -1007,9 +1017,9 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { points_billboard.push_back(Vector3(b.x, b.y, 0)); } - p_gizmo->add_lines(points, lines_material, true); - p_gizmo->add_lines(points_billboard, lines_billboard_material, true); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_lines(points, lines_material, true, color); + p_gizmo->add_lines(points_billboard, lines_billboard_material, true, color); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); Vector handles; handles.push_back(Vector3(r, 0, 0)); @@ -1051,8 +1061,8 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { points_primary.push_back(Vector3(0, 0, -r)); points_primary.push_back(Vector3()); - p_gizmo->add_lines(points_primary, material_primary); - p_gizmo->add_lines(points_secondary, material_secondary); + p_gizmo->add_lines(points_primary, material_primary, false, color); + p_gizmo->add_lines(points_secondary, material_secondary, false, color); const float ra = 16 * Math_PI * 2.0 / 64.0; const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w; @@ -1062,7 +1072,7 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { handles.push_back(Vector3(a.x, a.y, -d)); p_gizmo->add_handles(handles, get_material("handles")); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); } } diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index bb6f3aab330..593d0b95b78 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -103,6 +103,8 @@ void Light::set_color(const Color &p_color) { color = p_color; VS::get_singleton()->light_set_color(light, p_color); + // The gizmo color depends on the light color, so update it. + update_gizmo(); } Color Light::get_color() const {