From e9488dafe427e7b628ae4ebaf06288da35f308c1 Mon Sep 17 00:00:00 2001 From: bonj Date: Fri, 24 Mar 2023 21:35:43 +0100 Subject: [PATCH 01/13] Use non-edit objects to occlude selection The selection engine now uses the depsgraph iterator instead of the list of objects stored in the selection context. Objects that are not in edit mode are drawn into a separate shading group, which is part of the depth only pass. --- .../blender/draw/engines/select/select_engine.c | 15 +++++++++++++++ .../blender/draw/engines/select/select_private.h | 1 + source/blender/draw/intern/draw_manager.c | 12 ++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 7bf0bf91576..99f347ebcc1 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -9,6 +9,8 @@ #include "DNA_screen_types.h" +#include "ED_view3d.h" + #include "UI_resources.h" #include "DRW_engine.h" @@ -142,6 +144,11 @@ static void select_cache_init(void *vedata) DRW_PASS_CREATE(psl->depth_only_pass, state); pd->shgrp_depth_only = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); + if (RETOPOLOGY_ENABLED(draw_ctx->v3d)) { + pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); + DRW_shgroup_uniform_int_copy(pd->shgrp_occlude, "id", 0); + } + DRW_PASS_CREATE(psl->select_id_face_pass, state); if (e_data.context.select_mode & SCE_SELECT_FACE) { pd->shgrp_face_flat = DRW_shgroup_create(sh->select_id_flat, psl->select_id_face_pass); @@ -197,6 +204,14 @@ static void select_cache_populate(void *vedata, Object *ob) SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl; const DRWContextState *draw_ctx = DRW_context_state_get(); + if (!DRW_object_is_in_edit_mode(ob)) { + if (RETOPOLOGY_ENABLED(draw_ctx->v3d) && ob->dt >= OB_SOLID) { + struct GPUBatch *geom_faces = DRW_mesh_batch_cache_get_surface(ob->data); + DRW_shgroup_call_obmat(stl->g_data->shgrp_occlude, geom_faces, ob->object_to_world); + } + return; + } + SELECTID_ObjectData *sel_data = (SELECTID_ObjectData *)DRW_drawdata_get( &ob->id, &draw_engine_select_type); diff --git a/source/blender/draw/engines/select/select_private.h b/source/blender/draw/engines/select/select_private.h index c25ec144658..7f5641275c8 100644 --- a/source/blender/draw/engines/select/select_private.h +++ b/source/blender/draw/engines/select/select_private.h @@ -40,6 +40,7 @@ typedef struct SELECTID_Shaders { typedef struct SELECTID_PrivateData { DRWShadingGroup *shgrp_depth_only; + DRWShadingGroup *shgrp_occlude; DRWShadingGroup *shgrp_face_unif; DRWShadingGroup *shgrp_face_flat; DRWShadingGroup *shgrp_edge; diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index f3a9471dd22..07764c8f37f 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2771,11 +2771,15 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons { drw_engines_cache_init(); - Object **obj = &sel_ctx->objects[0]; - for (uint remaining = sel_ctx->objects_len; remaining--; obj++) { - Object *obj_eval = DEG_get_evaluated_object(depsgraph, *obj); - drw_engines_cache_populate(obj_eval); + DEGObjectIterSettings deg_iter_settings = {0}; + deg_iter_settings.depsgraph = depsgraph; + deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; + DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { + if (ob->type == OB_MESH) { + drw_engines_cache_populate(ob); + } } + DEG_OBJECT_ITER_END; drw_engines_cache_finish(); -- 2.30.2 From 38293cd17c8e45638671322c49742169773e2aac Mon Sep 17 00:00:00 2001 From: bonj Date: Fri, 24 Mar 2023 21:37:14 +0100 Subject: [PATCH 02/13] Use retopology offset for selection occlusion Instead of offsetting edit meshes towards the view, I'm offsetting non-edit meshes away from the view. Otherwise identical to how the retopology overlay works. --- source/blender/draw/engines/select/select_engine.c | 2 ++ .../draw/engines/select/shaders/infos/select_id_info.hh | 2 ++ .../blender/draw/engines/select/shaders/select_id_vert.glsl | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 99f347ebcc1..e29e87b2aaa 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -147,6 +147,8 @@ static void select_cache_init(void *vedata) if (RETOPOLOGY_ENABLED(draw_ctx->v3d)) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); DRW_shgroup_uniform_int_copy(pd->shgrp_occlude, "id", 0); + DRW_shgroup_uniform_float_copy( + pd->shgrp_occlude, "retopologyOffset", -RETOPOLOGY_OFFSET(draw_ctx->v3d)); } DRW_PASS_CREATE(psl->select_id_face_pass, state); diff --git a/source/blender/draw/engines/select/shaders/infos/select_id_info.hh b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh index e3166582197..c8779927024 100644 --- a/source/blender/draw/engines/select/shaders/infos/select_id_info.hh +++ b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh @@ -11,6 +11,7 @@ GPU_SHADER_INTERFACE_INFO(select_id_iface, "").flat(Type::INT, "id"); GPU_SHADER_CREATE_INFO(select_id_flat) .push_constant(Type::FLOAT, "sizeVertex") .push_constant(Type::INT, "offset") + .push_constant(Type::FLOAT, "retopologyOffset") .vertex_in(0, Type::VEC3, "pos") .vertex_in(1, Type::INT, "index") .vertex_out(select_id_iface) @@ -24,6 +25,7 @@ GPU_SHADER_CREATE_INFO(select_id_uniform) .define("UNIFORM_ID") .push_constant(Type::FLOAT, "sizeVertex") .push_constant(Type::INT, "id") + .push_constant(Type::FLOAT, "retopologyOffset") .vertex_in(0, Type::VEC3, "pos") .fragment_out(0, Type::UINT, "fragColor") .vertex_source("select_id_vert.glsl") diff --git a/source/blender/draw/engines/select/shaders/select_id_vert.glsl b/source/blender/draw/engines/select/shaders/select_id_vert.glsl index 7b3b0f9984d..b0885fd526b 100644 --- a/source/blender/draw/engines/select/shaders/select_id_vert.glsl +++ b/source/blender/draw/engines/select/shaders/select_id_vert.glsl @@ -8,8 +8,12 @@ void main() #endif vec3 world_pos = point_object_to_world(pos); - gl_Position = point_world_to_ndc(world_pos); + vec3 view_pos = point_world_to_view(world_pos); + gl_Position = point_view_to_ndc(view_pos); gl_PointSize = sizeVertex; + /* Offset Z position for retopology selection occlusion. */ + gl_Position.z += get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyOffset); + view_clipping_distances(world_pos); } -- 2.30.2 From f8c26304d7bda18c1ab6a4d410991e979b95cf66 Mon Sep 17 00:00:00 2001 From: bonj Date: Mon, 27 Mar 2023 23:42:20 +0200 Subject: [PATCH 03/13] Draw occluders separately from edit meshes First it draws the objects from the selection context object list like it used to, because apparently the order matters. Then it draws non-edit objects from the depsgraph iterator; the order doesn't matter here because it's only for the depth pass. --- source/blender/draw/intern/draw_manager.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 07764c8f37f..44417ef0078 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2771,11 +2771,17 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons { drw_engines_cache_init(); + Object **obj = &sel_ctx->objects[0]; + for (uint remaining = sel_ctx->objects_len; remaining--; obj++) { + Object *obj_eval = DEG_get_evaluated_object(depsgraph, *obj); + drw_engines_cache_populate(obj_eval); + } + DEGObjectIterSettings deg_iter_settings = {0}; deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { - if (ob->type == OB_MESH) { + if ((ob->type == OB_MESH) && !DRW_object_is_in_edit_mode(ob)) { drw_engines_cache_populate(ob); } } -- 2.30.2 From 642463791979ec931f6aa0fafc2fea59bbea539c Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 28 Mar 2023 18:22:17 +0200 Subject: [PATCH 04/13] Add comment explaining object type and mode checks Hopefully this explains well enough what the code is doing. --- source/blender/draw/intern/draw_manager.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 44417ef0078..d558f509d1a 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2781,6 +2781,10 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { + /* The iterator has evaluated meshes for all solid objects. + * It also has non-mesh objects however, which are not supported here. + * + * Only background (non-edit) objects are used for occlusion. */ if ((ob->type == OB_MESH) && !DRW_object_is_in_edit_mode(ob)) { drw_engines_cache_populate(ob); } -- 2.30.2 From 3a85a0d907b0ac7f60c48f31547077c66e2cc2a5 Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 28 Mar 2023 20:30:13 +0200 Subject: [PATCH 05/13] Offset selection mesh towards view Instead of offsetting background objects away. This way it perfectly matches the edit overlay, which matters when clipping is involved. --- source/blender/draw/engines/select/select_engine.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index e29e87b2aaa..0b27bccf868 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -140,36 +140,42 @@ static void select_cache_init(void *vedata) DRWState state = DRW_STATE_DEFAULT; state |= RV3D_CLIPPING_ENABLED(draw_ctx->v3d, draw_ctx->rv3d) ? DRW_STATE_CLIP_PLANES : 0; + bool show_retopology = RETOPOLOGY_ENABLED(draw_ctx->v3d); + float retopology_offset = RETOPOLOGY_OFFSET(draw_ctx->v3d); + { DRW_PASS_CREATE(psl->depth_only_pass, state); pd->shgrp_depth_only = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); - if (RETOPOLOGY_ENABLED(draw_ctx->v3d)) { + if (show_retopology) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); DRW_shgroup_uniform_int_copy(pd->shgrp_occlude, "id", 0); - DRW_shgroup_uniform_float_copy( - pd->shgrp_occlude, "retopologyOffset", -RETOPOLOGY_OFFSET(draw_ctx->v3d)); + DRW_shgroup_uniform_float_copy(pd->shgrp_occlude, "retopologyOffset", 0.0f); } DRW_PASS_CREATE(psl->select_id_face_pass, state); if (e_data.context.select_mode & SCE_SELECT_FACE) { pd->shgrp_face_flat = DRW_shgroup_create(sh->select_id_flat, psl->select_id_face_pass); + DRW_shgroup_uniform_float_copy(pd->shgrp_face_flat, "retopologyOffset", retopology_offset); } else { pd->shgrp_face_unif = DRW_shgroup_create(sh->select_id_uniform, psl->select_id_face_pass); DRW_shgroup_uniform_int_copy(pd->shgrp_face_unif, "id", 0); + DRW_shgroup_uniform_float_copy(pd->shgrp_face_unif, "retopologyOffset", retopology_offset); } if (e_data.context.select_mode & SCE_SELECT_EDGE) { DRW_PASS_CREATE(psl->select_id_edge_pass, state | DRW_STATE_FIRST_VERTEX_CONVENTION); pd->shgrp_edge = DRW_shgroup_create(sh->select_id_flat, psl->select_id_edge_pass); + DRW_shgroup_uniform_float_copy(pd->shgrp_edge, "retopologyOffset", retopology_offset); } if (e_data.context.select_mode & SCE_SELECT_VERTEX) { DRW_PASS_CREATE(psl->select_id_vert_pass, state); pd->shgrp_vert = DRW_shgroup_create(sh->select_id_flat, psl->select_id_vert_pass); DRW_shgroup_uniform_float_copy(pd->shgrp_vert, "sizeVertex", 2 * G_draw.block.size_vertex); + DRW_shgroup_uniform_float_copy(pd->shgrp_vert, "retopologyOffset", retopology_offset); } } -- 2.30.2 From a7a5f045303dfd383a5aca6ea86d716f9212a527 Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 28 Mar 2023 21:03:19 +0200 Subject: [PATCH 06/13] Use retopology offset for selection depth group I forgot this one in the last commit, whoops. --- source/blender/draw/engines/select/select_engine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 0b27bccf868..3acdf56545d 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -146,6 +146,7 @@ static void select_cache_init(void *vedata) { DRW_PASS_CREATE(psl->depth_only_pass, state); pd->shgrp_depth_only = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); + DRW_shgroup_uniform_float_copy(pd->shgrp_depth_only, "retopologyOffset", retopology_offset); if (show_retopology) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); -- 2.30.2 From 00cafbe04e3e9abeae7e4ec312981840af9522fe Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 28 Mar 2023 21:42:53 +0200 Subject: [PATCH 07/13] Check if retopology is enabled for depsgraph iterator This is more efficient than checking it for every object, and perhaps easier to read too, because it indicates what the depsgraph iterator is for. --- .../draw/engines/select/select_engine.c | 2 +- source/blender/draw/intern/draw_manager.c | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 3acdf56545d..28701d039a2 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -214,7 +214,7 @@ static void select_cache_populate(void *vedata, Object *ob) const DRWContextState *draw_ctx = DRW_context_state_get(); if (!DRW_object_is_in_edit_mode(ob)) { - if (RETOPOLOGY_ENABLED(draw_ctx->v3d) && ob->dt >= OB_SOLID) { + if (ob->dt >= OB_SOLID) { struct GPUBatch *geom_faces = DRW_mesh_batch_cache_get_surface(ob->data); DRW_shgroup_call_obmat(stl->g_data->shgrp_occlude, geom_faces, ob->object_to_world); } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index d558f509d1a..59503a3a86c 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2777,19 +2777,21 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons drw_engines_cache_populate(obj_eval); } - DEGObjectIterSettings deg_iter_settings = {0}; - deg_iter_settings.depsgraph = depsgraph; - deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; - DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { - /* The iterator has evaluated meshes for all solid objects. - * It also has non-mesh objects however, which are not supported here. - * - * Only background (non-edit) objects are used for occlusion. */ - if ((ob->type == OB_MESH) && !DRW_object_is_in_edit_mode(ob)) { - drw_engines_cache_populate(ob); + if (RETOPOLOGY_ENABLED(v3d)) { + DEGObjectIterSettings deg_iter_settings = {0}; + deg_iter_settings.depsgraph = depsgraph; + deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; + DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { + /* The iterator has evaluated meshes for all solid objects. + * It also has non-mesh objects however, which are not supported here. + * + * Only background (non-edit) objects are used for occlusion. */ + if ((ob->type == OB_MESH) && !DRW_object_is_in_edit_mode(ob)) { + drw_engines_cache_populate(ob); + } } + DEG_OBJECT_ITER_END; } - DEG_OBJECT_ITER_END; drw_engines_cache_finish(); -- 2.30.2 From 3336c1b45e08d9e78bf0c7c1443d300a830d1b45 Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 28 Mar 2023 22:48:42 +0200 Subject: [PATCH 08/13] Check both retopology and xray for selection occlusion There's no need to use selection occlusion when xray is enabled, since it doesn't work anyway (and is a nice way of disabling selection occlusion without disabling the retopology overlay). Since it's used in multiple places I decided to make a define, though only for v3d, not one that takes overlay because xray lives in shading. --- source/blender/draw/engines/select/select_engine.c | 4 ++-- source/blender/draw/intern/draw_manager.c | 2 +- source/blender/editors/include/ED_view3d.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 28701d039a2..20690b75e29 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -140,7 +140,7 @@ static void select_cache_init(void *vedata) DRWState state = DRW_STATE_DEFAULT; state |= RV3D_CLIPPING_ENABLED(draw_ctx->v3d, draw_ctx->rv3d) ? DRW_STATE_CLIP_PLANES : 0; - bool show_retopology = RETOPOLOGY_ENABLED(draw_ctx->v3d); + bool retopology_occlusion = RETOPOLOGY_OCCLUSION(draw_ctx->v3d); float retopology_offset = RETOPOLOGY_OFFSET(draw_ctx->v3d); { @@ -148,7 +148,7 @@ static void select_cache_init(void *vedata) pd->shgrp_depth_only = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); DRW_shgroup_uniform_float_copy(pd->shgrp_depth_only, "retopologyOffset", retopology_offset); - if (show_retopology) { + if (retopology_occlusion) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); DRW_shgroup_uniform_int_copy(pd->shgrp_occlude, "id", 0); DRW_shgroup_uniform_float_copy(pd->shgrp_occlude, "retopologyOffset", 0.0f); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 59503a3a86c..5b1b2e71cf1 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2777,7 +2777,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons drw_engines_cache_populate(obj_eval); } - if (RETOPOLOGY_ENABLED(v3d)) { + if (RETOPOLOGY_OCCLUSION(v3d)) { DEGObjectIterSettings deg_iter_settings = {0}; deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 3f0ca687903..5cf755f3737 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -1335,6 +1335,7 @@ void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrAr #define RETOPOLOGY_ENABLED(v3d) (OVERLAY_RETOPOLOGY_ENABLED((v3d)->overlay)) #define RETOPOLOGY_OFFSET(v3d) (OVERLAY_RETOPOLOGY_OFFSET((v3d)->overlay)) +#define RETOPOLOGY_OCCLUSION(v3d) (RETOPOLOGY_ENABLED(v3d) && !XRAY_ENABLED(v3d)) /* view3d_draw_legacy.c */ -- 2.30.2 From f5438850712f807b73132c6a840e4bb497a0f340 Mon Sep 17 00:00:00 2001 From: bonj Date: Wed, 29 Mar 2023 16:54:47 +0200 Subject: [PATCH 09/13] Use continue for depsgraph iterator This does the same thing, but may be a bit easier to read in terms of which comment is about which piece of code. --- source/blender/draw/intern/draw_manager.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 5b1b2e71cf1..3a1c4d229f5 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2782,13 +2782,16 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; DEG_OBJECT_ITER_BEGIN (°_iter_settings, ob) { - /* The iterator has evaluated meshes for all solid objects. - * It also has non-mesh objects however, which are not supported here. - * - * Only background (non-edit) objects are used for occlusion. */ - if ((ob->type == OB_MESH) && !DRW_object_is_in_edit_mode(ob)) { - drw_engines_cache_populate(ob); + if (ob->type != OB_MESH) { + /* The iterator has evaluated meshes for all solid objects. + * It also has non-mesh objects however, which are not supported here. */ + continue; } + if (DRW_object_is_in_edit_mode(ob)) { + /* Only background (non-edit) objects are used for occlusion. */ + continue; + } + drw_engines_cache_populate(ob); } DEG_OBJECT_ITER_END; } -- 2.30.2 From 24038c4938c9cf2b3e0d84cb68c0cf0e3b687e25 Mon Sep 17 00:00:00 2001 From: bonj Date: Wed, 29 Mar 2023 16:58:23 +0200 Subject: [PATCH 10/13] Remove unnecessary RETOPOLOGY_OCCLUSION macro It's only used in two places and Germano didn't like it, so I'll just get rid of it. --- source/blender/draw/engines/select/select_engine.c | 2 +- source/blender/draw/intern/draw_manager.c | 2 +- source/blender/editors/include/ED_view3d.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 20690b75e29..cb673cded49 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -140,7 +140,7 @@ static void select_cache_init(void *vedata) DRWState state = DRW_STATE_DEFAULT; state |= RV3D_CLIPPING_ENABLED(draw_ctx->v3d, draw_ctx->rv3d) ? DRW_STATE_CLIP_PLANES : 0; - bool retopology_occlusion = RETOPOLOGY_OCCLUSION(draw_ctx->v3d); + bool retopology_occlusion = RETOPOLOGY_ENABLED(draw_ctx->v3d) && !XRAY_ENABLED(draw_ctx->v3d); float retopology_offset = RETOPOLOGY_OFFSET(draw_ctx->v3d); { diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 3a1c4d229f5..7b6c92b718d 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2777,7 +2777,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons drw_engines_cache_populate(obj_eval); } - if (RETOPOLOGY_OCCLUSION(v3d)) { + if (RETOPOLOGY_ENABLED(v3d) && !XRAY_ENABLED(v3d)) { DEGObjectIterSettings deg_iter_settings = {0}; deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS; diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 5cf755f3737..3f0ca687903 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -1335,7 +1335,6 @@ void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrAr #define RETOPOLOGY_ENABLED(v3d) (OVERLAY_RETOPOLOGY_ENABLED((v3d)->overlay)) #define RETOPOLOGY_OFFSET(v3d) (OVERLAY_RETOPOLOGY_OFFSET((v3d)->overlay)) -#define RETOPOLOGY_OCCLUSION(v3d) (RETOPOLOGY_ENABLED(v3d) && !XRAY_ENABLED(v3d)) /* view3d_draw_legacy.c */ -- 2.30.2 From 273c4c6991cfcff00d8e2a3dbc66b689454daabc Mon Sep 17 00:00:00 2001 From: bonj Date: Wed, 29 Mar 2023 22:45:06 +0200 Subject: [PATCH 11/13] Improve retopology overlay tooltip As Julien mentioned, it was a pretty useless tooltip before. It also mentions selection occlusion now. --- source/blender/makesrna/intern/rna_space.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 5fb55eb6f20..86e867c1e6f 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -4539,7 +4539,10 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) prop = RNA_def_property(srna, "show_retopology", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_RETOPOLOGY); - RNA_def_property_ui_text(prop, "Retopology", "Use retopology display"); + RNA_def_property_ui_text(prop, + "Retopology", + "Hide the solid mesh and offset the overlay towards the view. " + "Selection is occluded by inactive geometry, unless X-Ray is enabled"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL); prop = RNA_def_property(srna, "retopology_offset", PROP_FLOAT, PROP_DISTANCE); -- 2.30.2 From 981294301b1b9a25ce6adb91c60d852aef7b5b89 Mon Sep 17 00:00:00 2001 From: bonj Date: Sat, 8 Apr 2023 21:14:56 +0200 Subject: [PATCH 12/13] Remove unused "id" uniform from shgrp_occlude This is consistent with how unused uniforms are used elsewhere (for example "sizeVertex"). Alternatively I would add the uniform for the depth only group too, and then add a comment for both explaining that it's unused, but I think that this is cleaner. --- source/blender/draw/engines/select/select_engine.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index cb673cded49..cd7be5ea769 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -150,7 +150,6 @@ static void select_cache_init(void *vedata) if (retopology_occlusion) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); - DRW_shgroup_uniform_int_copy(pd->shgrp_occlude, "id", 0); DRW_shgroup_uniform_float_copy(pd->shgrp_occlude, "retopologyOffset", 0.0f); } -- 2.30.2 From 3213371cfefc8ff43606e142675d718caa51789c Mon Sep 17 00:00:00 2001 From: bonj Date: Sat, 8 Apr 2023 21:27:25 +0200 Subject: [PATCH 13/13] Add comments explaining why ID isn't set for depth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClĂ©ment wanted some comments here. --- source/blender/draw/engines/select/select_engine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index cd7be5ea769..6f17a619161 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -146,10 +146,12 @@ static void select_cache_init(void *vedata) { DRW_PASS_CREATE(psl->depth_only_pass, state); pd->shgrp_depth_only = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); + /* Not setting ID because this pass only draws to the depth buffer. */ DRW_shgroup_uniform_float_copy(pd->shgrp_depth_only, "retopologyOffset", retopology_offset); if (retopology_occlusion) { pd->shgrp_occlude = DRW_shgroup_create(sh->select_id_uniform, psl->depth_only_pass); + /* Not setting ID because this pass only draws to the depth buffer. */ DRW_shgroup_uniform_float_copy(pd->shgrp_occlude, "retopologyOffset", 0.0f); } -- 2.30.2