From e4986cf4659bb0fb991f9456b2468d22434536bd Mon Sep 17 00:00:00 2001 From: Laurynas Duburas Date: Fri, 13 Sep 2024 16:44:24 +0300 Subject: [PATCH 1/2] Overlay-Next: origin --- source/blender/draw/CMakeLists.txt | 1 + .../engines/overlay/overlay_next_instance.cc | 6 ++ .../engines/overlay/overlay_next_instance.hh | 2 + .../engines/overlay/overlay_next_origin.hh | 82 +++++++++++++++++++ .../engines/overlay/overlay_next_private.hh | 1 + .../engines/overlay/overlay_next_shader.cc | 11 +++ 6 files changed, 103 insertions(+) create mode 100644 source/blender/draw/engines/overlay/overlay_next_origin.hh diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 56063af04ce..4e179b86ca8 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -307,6 +307,7 @@ set(SRC engines/overlay/overlay_next_lightprobe.hh engines/overlay/overlay_next_mesh.hh engines/overlay/overlay_next_metaball.hh + engines/overlay/overlay_next_origin.hh engines/overlay/overlay_next_outline.hh engines/overlay/overlay_next_paint.hh engines/overlay/overlay_next_particle.hh diff --git a/source/blender/draw/engines/overlay/overlay_next_instance.cc b/source/blender/draw/engines/overlay/overlay_next_instance.cc index cc2e8f498d9..18ad3f23e26 100644 --- a/source/blender/draw/engines/overlay/overlay_next_instance.cc +++ b/source/blender/draw/engines/overlay/overlay_next_instance.cc @@ -115,6 +115,7 @@ void Instance::begin_sync() resources.begin_sync(); background.begin_sync(resources, state); + origins.begin_sync(state); outline.begin_sync(resources, state); auto begin_sync_layer = [&](OverlayLayer &layer) { @@ -274,6 +275,8 @@ void Instance::object_sync(ObjectRef &ob_ref, Manager &manager) layer.particles.object_sync(manager, ob_ref, resources, state); layer.relations.object_sync(ob_ref, resources, state); + origins.object_sync(ob_ref, resources, state); + if (object_is_selected(ob_ref) && !in_edit_paint_mode) { outline.object_sync(manager, ob_ref, state); } @@ -282,6 +285,7 @@ void Instance::object_sync(ObjectRef &ob_ref, Manager &manager) void Instance::end_sync() { + origins.end_sync(resources, state); resources.end_sync(); auto end_sync_layer = [&](OverlayLayer &layer) { @@ -483,6 +487,8 @@ void Instance::draw(Manager &manager) regular.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view); infront.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view); + origins.draw(resources.overlay_color_only_fb, manager, view); + background.draw(resources.overlay_output_fb, manager, view); anti_aliasing.draw(resources.overlay_output_fb, manager, view); diff --git a/source/blender/draw/engines/overlay/overlay_next_instance.hh b/source/blender/draw/engines/overlay/overlay_next_instance.hh index fb1b60b4727..24840fe2ce2 100644 --- a/source/blender/draw/engines/overlay/overlay_next_instance.hh +++ b/source/blender/draw/engines/overlay/overlay_next_instance.hh @@ -28,6 +28,7 @@ #include "overlay_next_lightprobe.hh" #include "overlay_next_mesh.hh" #include "overlay_next_metaball.hh" +#include "overlay_next_origin.hh" #include "overlay_next_outline.hh" #include "overlay_next_paint.hh" #include "overlay_next_particle.hh" @@ -61,6 +62,7 @@ class Instance { /** Overlay types. */ Background background; + Origins origins; Outline outline; struct OverlayLayer { diff --git a/source/blender/draw/engines/overlay/overlay_next_origin.hh b/source/blender/draw/engines/overlay/overlay_next_origin.hh new file mode 100644 index 00000000000..1b916b048fc --- /dev/null +++ b/source/blender/draw/engines/overlay/overlay_next_origin.hh @@ -0,0 +1,82 @@ + +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup overlay + */ + +#pragma once + +#include "overlay_next_private.hh" + +namespace blender::draw::overlay { +class Origins { + private: + StorageVectorBuffer point_buf_; + + PassSimple ps_ = {"Origins"}; + + bool enabled_ = false; + + public: + void begin_sync(const State &state) + { + const bool is_paint_mode = (state.object_mode & + (OB_MODE_ALL_PAINT | OB_MODE_ALL_PAINT_GPENCIL | + OB_MODE_SCULPT_CURVES)) != 0; + enabled_ = !is_paint_mode && (state.overlay.flag & V3D_OVERLAY_HIDE_OBJECT_ORIGINS) == 0; + point_buf_.clear(); + } + + void object_sync(const ObjectRef &ob_ref, Resources &res, State &state) + { + if (!enabled_) { + return; + } + const Object *ob = ob_ref.object; + const bool is_library = ID_REAL_USERS(&ob->id) > 1 || ID_IS_LINKED(ob); + BKE_view_layer_synced_ensure(state.scene, (ViewLayer *)state.view_layer); + const float4 location = float4(ob->object_to_world().location()); + float4 color; + if (ob == BKE_view_layer_active_object_get(state.view_layer)) { + point_buf_.append(VertexData{location, res.theme_settings.color_active}); + } + else if (ob->base_flag & BASE_SELECTED) { + point_buf_.append(VertexData{location, + is_library ? res.theme_settings.color_library_select : + res.theme_settings.color_select}); + } + else if (state.v3d_flag & V3D_DRAW_CENTERS) { + point_buf_.append(VertexData{location, + is_library ? res.theme_settings.color_library : + res.theme_settings.color_deselect}); + } + } + + void end_sync(Resources &res, const State &state) + { + if (!enabled_) { + return; + } + ps_.init(); + ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count); + ps_.shader_set(res.shaders.extra_point.get()); + ps_.bind_ubo("globalsBlock", &res.globals_buf); + point_buf_.push_update(); + ps_.bind_ssbo("data_buf", &point_buf_); + ps_.draw_procedural(GPU_PRIM_POINTS, 1, point_buf_.size()); + } + + void draw(Framebuffer &framebuffer, Manager &manager, View &view) + { + if (!enabled_) { + return; + } + + GPU_framebuffer_bind(framebuffer); + manager.submit(ps_, view); + } +}; +} // namespace blender::draw::overlay diff --git a/source/blender/draw/engines/overlay/overlay_next_private.hh b/source/blender/draw/engines/overlay/overlay_next_private.hh index c575f1a8525..40b170cde27 100644 --- a/source/blender/draw/engines/overlay/overlay_next_private.hh +++ b/source/blender/draw/engines/overlay/overlay_next_private.hh @@ -206,6 +206,7 @@ class ShaderModule { ShaderPtr curve_edit_points; ShaderPtr curve_edit_line; ShaderPtr curve_edit_handles; + ShaderPtr extra_point; ShaderPtr facing; ShaderPtr grid = shader("overlay_grid"); ShaderPtr grid_background; diff --git a/source/blender/draw/engines/overlay/overlay_next_shader.cc b/source/blender/draw/engines/overlay/overlay_next_shader.cc index 2d749eba28d..3731338c1d6 100644 --- a/source/blender/draw/engines/overlay/overlay_next_shader.cc +++ b/source/blender/draw/engines/overlay/overlay_next_shader.cc @@ -142,6 +142,17 @@ ShaderModule::ShaderModule(const SelectionType selection_type, const bool clippi "overlay_edit_curves_handle", [](gpu::shader::ShaderCreateInfo &info) { shader_patch_common(info); }); + extra_point = shader("overlay_extra_point", [](gpu::shader::ShaderCreateInfo &info) { + info.additional_infos_.clear(); + info.vertex_inputs_.pop_last(); + info.push_constants_.pop_last(); + info.additional_info("draw_view", "draw_modelmat_new", "draw_globals") + .typedef_source("overlay_shader_shared.h") + .storage_buf(0, Qualifier::READ, "VertexData", "data_buf[]") + .define("pos", "data_buf[gl_VertexID].pos_.xyz") + .define("ucolor", "data_buf[gl_VertexID].color_"); + }); + grid_background = shader("overlay_grid_background", [](gpu::shader::ShaderCreateInfo &info) { shader_patch_common(info); info.define("tile_pos", "vec3(0.0)"); -- 2.30.2 From bb76986db263796f5fbda76be9f70e0d74acf0e6 Mon Sep 17 00:00:00 2001 From: Laurynas Duburas Date: Fri, 13 Sep 2024 17:45:43 +0300 Subject: [PATCH 2/2] small fixes --- source/blender/draw/engines/overlay/overlay_next_origin.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/draw/engines/overlay/overlay_next_origin.hh b/source/blender/draw/engines/overlay/overlay_next_origin.hh index 1b916b048fc..66a5d45c425 100644 --- a/source/blender/draw/engines/overlay/overlay_next_origin.hh +++ b/source/blender/draw/engines/overlay/overlay_next_origin.hh @@ -26,7 +26,8 @@ class Origins { const bool is_paint_mode = (state.object_mode & (OB_MODE_ALL_PAINT | OB_MODE_ALL_PAINT_GPENCIL | OB_MODE_SCULPT_CURVES)) != 0; - enabled_ = !is_paint_mode && (state.overlay.flag & V3D_OVERLAY_HIDE_OBJECT_ORIGINS) == 0; + enabled_ = state.v3d && !is_paint_mode && + (state.overlay.flag & V3D_OVERLAY_HIDE_OBJECT_ORIGINS) == 0; point_buf_.clear(); } @@ -39,7 +40,7 @@ class Origins { const bool is_library = ID_REAL_USERS(&ob->id) > 1 || ID_IS_LINKED(ob); BKE_view_layer_synced_ensure(state.scene, (ViewLayer *)state.view_layer); const float4 location = float4(ob->object_to_world().location()); - float4 color; + if (ob == BKE_view_layer_active_object_get(state.view_layer)) { point_buf_.append(VertexData{location, res.theme_settings.color_active}); } -- 2.30.2