[Bf-blender-cvs] [db0715ee467] temp-angavrilov: Bone Overlay: support bone wireframe opacity settings.

Alexander Gavrilov noreply at git.blender.org
Wed Oct 6 14:57:08 CEST 2021


Commit: db0715ee46778c391500fb02392b270d7aeaded4
Author: Alexander Gavrilov
Date:   Sun Jan 3 23:40:44 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBdb0715ee46778c391500fb02392b270d7aeaded4

Bone Overlay: support bone wireframe opacity settings.

When weight painting the bone overlay is extremely intrusive,
effectively requiring either extensive use of hiding individual
bones, or disabling the whole bone overlay between selections.

This addresses the issue by adding two bone opacity sliders that
are used for the 'wireframe' armature drawing mode. One directly
controls the uniform opacity as the straightforward option.

The other one allows fade based on the depth from the camera,
using exponential decay with the slider specifying the 'half-life'
depth. This is intended as a way to automatically hide bones
in distant parts of the mesh while focused on a specific part.

Differential Revision: https://developer.blender.org/D11804

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_armature.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
A	source/blender/draw/engines/overlay/shaders/armature_alpha_lib.glsl
M	source/blender/draw/engines/overlay/shaders/armature_dof_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/armature_envelope_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/armature_shape_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/armature_sphere_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/armature_stick_frag.glsl
M	source/blender/draw/engines/overlay/shaders/armature_wire_frag.glsl
M	source/blender/makesdna/DNA_view3d_defaults.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 59991eac92a..31039e8f7fe 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6492,17 +6492,18 @@ class VIEW3D_PT_overlay_sculpt(Panel):
         row.prop(overlay, "sculpt_mode_face_sets_opacity", text="Face Sets")
 
 
-class VIEW3D_PT_overlay_pose(Panel):
+class VIEW3D_PT_overlay_bones(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'HEADER'
     bl_parent_id = 'VIEW3D_PT_overlay'
-    bl_label = "Pose Mode"
+    bl_label = "Bones"
 
     @classmethod
     def poll(cls, context):
         mode = context.mode
         return (
             (mode == 'POSE') or
+            (mode == 'EDIT_ARMATURE') or
             (mode == 'PAINT_WEIGHT' and context.pose_object)
         )
 
@@ -6522,10 +6523,18 @@ class VIEW3D_PT_overlay_pose(Panel):
             sub = row.row()
             sub.active = display_all and overlay.show_xray_bone
             sub.prop(overlay, "xray_alpha_bone", text="Fade Geometry")
-        else:
+        elif mode == 'PAINT_WEIGHT':
             row = col.row()
             row.prop(overlay, "show_xray_bone")
 
+        col.prop(overlay, "bone_wire_alpha")
+
+        row = col.row()
+        row.prop(overlay, "bone_wire_use_fade_depth", text="")
+        sub = row.row()
+        sub.active = overlay.bone_wire_use_fade_depth
+        sub.prop(overlay, "bone_wire_fade_depth")
+
 
 class VIEW3D_PT_overlay_texture_paint(Panel):
     bl_space_type = 'VIEW_3D'
@@ -7692,7 +7701,7 @@ classes = (
     VIEW3D_PT_overlay_texture_paint,
     VIEW3D_PT_overlay_vertex_paint,
     VIEW3D_PT_overlay_weight_paint,
-    VIEW3D_PT_overlay_pose,
+    VIEW3D_PT_overlay_bones,
     VIEW3D_PT_overlay_sculpt,
     VIEW3D_PT_snapping,
     VIEW3D_PT_proportional_edit,
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index e2e36accfa5..e05f8cdf295 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -42,6 +42,8 @@
 #include "DNA_listBase.h"
 #include "DNA_material_types.h"
 #include "DNA_modifier_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
 #include "DNA_text_types.h"
 #include "DNA_workspace_types.h"
 
@@ -1629,6 +1631,21 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
                      temp_idname + strlen("FunctionNode"));
       }
     }
+
+    /* Initialize the bone wireframe opacity setting. */
+    if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_wire_alpha")) {
+      for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+          LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+            if (sl->spacetype == SPACE_VIEW3D) {
+              View3D *v3d = (View3D *)sl;
+              v3d->overlay.bone_wire_alpha = 1.0f;
+              v3d->overlay.bone_wire_fade_depth = 1.0f;
+            }
+          }
+        }
+      }
+    }
   }
 
   if (!MAIN_VERSION_ATLEAST(bmain, 300, 29)) {
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index dd4aa1747e5..d77a8a85348 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -387,6 +387,7 @@ data_to_c_simple(engines/basic/shaders/depth_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/common_overlay_lib.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/antialiasing_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/antialiasing_vert.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/armature_alpha_lib.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_dof_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_dof_solid_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_envelope_outline_vert.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index 4e839747473..6ab3a1f2ef2 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -140,6 +140,12 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
                                    draw_ctx->object_pose != NULL;
   DRWState state;
 
+  const float wire_alpha = pd->overlay.bone_wire_alpha;
+  const float wire_fade = (pd->overlay.flag & V3D_OVERLAY_BONE_FADE_DEPTH) ?
+                              1 / max_ff(1e-3f, pd->overlay.bone_wire_fade_depth) :
+                              0.0f;
+  const bool use_wire_alpha = (wire_alpha < 1.0f || wire_fade > 0.0f);
+
   if (pd->armature.do_pose_fade_geom) {
     state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA;
     DRW_PASS_CREATE(psl->armature_bone_select_ps, state | pd->clipping_state);
@@ -163,8 +169,8 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
     OVERLAY_InstanceFormats *formats = OVERLAY_shader_instance_formats_get();
     OVERLAY_ArmatureCallBuffers *cb = &pd->armature_call_buffers[i];
 
-    cb->custom_shapes_ghash = BLI_ghash_ptr_new(__func__);
-    cb->custom_shapes_transp_ghash = BLI_ghash_ptr_new(__func__);
+    cb->solid.custom_shapes_ghash = BLI_ghash_ptr_new(__func__);
+    cb->transp.custom_shapes_ghash = BLI_ghash_ptr_new(__func__);
 
     DRWPass **p_armature_ps = &psl->armature_ps[i];
     DRWState infront_state = (DRW_state_is_select() && (i == 1)) ? DRW_STATE_IN_FRONT_SELECT : 0;
@@ -187,45 +193,86 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
       sh = OVERLAY_shader_armature_sphere(false);
       grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
-      cb->point_solid = BUF_INSTANCE(grp, format, DRW_cache_bone_point_get());
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){1.0f, 0.0f});
+      cb->solid.point_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_point_get());
 
       grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_state_disable(grp, DRW_STATE_WRITE_DEPTH);
       DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 0.4f);
-      cb->point_transp = BUF_INSTANCE(grp, format, DRW_cache_bone_point_get());
+      DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){wire_alpha * 0.4f, wire_fade});
+      cb->transp.point_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_point_get());
 
       sh = OVERLAY_shader_armature_shape(false);
       grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
-      cb->custom_solid = grp;
-      cb->box_solid = BUF_INSTANCE(grp, format, DRW_cache_bone_box_get());
-      cb->octa_solid = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_get());
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){1.0f, 0.0f});
+      cb->solid.custom_fill = grp;
+      cb->solid.box_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_box_get());
+      cb->solid.octa_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_get());
 
       grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_state_disable(grp, DRW_STATE_WRITE_DEPTH);
       DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 0.6f);
-      cb->custom_transp = grp;
-      cb->box_transp = BUF_INSTANCE(grp, format, DRW_cache_bone_box_get());
-      cb->octa_transp = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_get());
+      DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){wire_alpha * 0.6f, wire_fade});
+      cb->transp.custom_fill = grp;
+      cb->transp.box_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_box_get());
+      cb->transp.octa_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_get());
 
       sh = OVERLAY_shader_armature_sphere(true);
       grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
-      cb->point_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_point_wire_outline_get());
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){1.0f, 0.0f});
+      cb->solid.point_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_point_wire_outline_get());
+
+      if (use_wire_alpha) {
+        grp = DRW_shgroup_create(sh, armature_ps);
+        DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
+        DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+        DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){wire_alpha, wire_fade});
+        cb->transp.point_outline = BUF_INSTANCE(
+            grp, format, DRW_cache_bone_point_wire_outline_get());
+      }
+      else {
+        cb->transp.point_outline = cb->solid.point_outline;
+      }
 
       sh = OVERLAY_shader_armature_shape(true);
-      cb->custom_outline = grp = DRW_shgroup_create(sh, armature_ps);
+      cb->solid.custom_outline = grp = DRW_shgroup_create(sh, armature_ps);
       DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
-      cb->box_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_box_wire_get());
-      cb->octa_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_wire_get());
+      DRW_shgroup_uniform_vec2_copy(grp, "wireAlpha", (float[2]){1.0f, 0.0f});
+      cb->solid.box_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_box_wire_get());
+      cb->solid.octa_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_wire_get());
+
+      if (use_wire_alpha) {
+        cb->transp.custom_outline = grp = DRW_shgroup_create(sh, armature_ps);
+        DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
+        DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list