[Bf-blender-cvs] [5ced5eabaaa] temp-angavrilov: Bone Overlay: support bone wireframe opacity depth fade.

Alexander Gavrilov noreply at git.blender.org
Wed Sep 7 10:11:26 CEST 2022


Commit: 5ced5eabaaacef37cbb023e86732291becd93e64
Author: Alexander Gavrilov
Date:   Sat Dec 11 18:04:34 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB5ced5eabaaacef37cbb023e86732291becd93e64

Bone Overlay: support bone wireframe opacity depth fade.

Add an option that 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.

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

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/shaders/infos/overlay_armature_info.hh
A	source/blender/draw/engines/overlay/shaders/overlay_armature_alpha_lib.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_armature_dof_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_armature_stick_frag.glsl
M	source/blender/draw/engines/overlay/shaders/overlay_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 23c3b0191d4..f748b1425d5 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6761,6 +6761,12 @@ class VIEW3D_PT_overlay_bones(Panel):
         if VIEW3D_PT_overlay_bones.is_using_wireframe(context):
             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'
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 374b4c9d89a..0c0e58c4e07 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -3369,5 +3369,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
       }
       FOREACH_NODETREE_END;
     }
+
+    /* Initialize the bone wireframe opacity depth fade setting. */
+    if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_wire_fade_depth")) {
+      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_fade_depth = 1.0f;
+            }
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index ac7f1c5ff68..c141e81c799 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -545,6 +545,7 @@ set(GLSL_SRC
   engines/basic/shaders/basic_depth_frag.glsl
 
   engines/overlay/shaders/overlay_antialiasing_frag.glsl
+  engines/overlay/shaders/overlay_armature_alpha_lib.glsl
   engines/overlay/shaders/overlay_armature_dof_solid_frag.glsl
   engines/overlay/shaders/overlay_armature_dof_vert.glsl
   engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index defd6e538ce..5371e34d2e2 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -86,6 +86,8 @@ typedef struct ArmatureDrawContext {
   bool transparent;
   bool show_relations;
 
+  float *p_fade_depth_bias;
+
   const ThemeWireColor *bcolor; /* pchan color */
 } ArmatureDrawContext;
 
@@ -126,7 +128,14 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
                                    draw_ctx->object_pose != NULL;
 
   const float wire_alpha = pd->overlay.bone_wire_alpha;
-  const bool use_wire_alpha = (wire_alpha < 1.0f);
+  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;
+
+  pd->armature.do_wire_depth_fade = wire_fade > 0.0f;
+  copy_v2_fl2(pd->shdata.fade_depth_info, wire_fade, FLT_MAX);
+
+  const bool use_wire_alpha = pd->armature.do_wire_depth_fade || (wire_alpha < 1.0f);
 
   DRWState state;
 
@@ -183,6 +192,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
       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", wire_alpha * 0.4f);
+      DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
       cb->transp.point_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_point_get());
 
       sh = OVERLAY_shader_armature_shape(false);
@@ -196,6 +206,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
       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", wire_alpha * 0.6f);
+      DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
       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());
@@ -211,6 +222,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.point_outline = BUF_INSTANCE(
             grp, format, DRW_cache_bone_point_wire_outline_get());
       }
@@ -230,6 +242,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.box_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_box_wire_get());
         cb->transp.octa_outline = BUF_INSTANCE(grp, format, DRW_cache_bone_octahedral_wire_get());
       }
@@ -249,6 +262,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
       }
       else {
         cb->transp.custom_wire = cb->solid.custom_wire;
@@ -268,6 +282,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.dof_lines = BUF_INSTANCE(grp, format, DRW_cache_bone_dof_lines_get());
       }
       else {
@@ -284,6 +299,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         grp = DRW_shgroup_create(sh, armature_transp_ps);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.dof_sphere = BUF_INSTANCE(grp, format, DRW_cache_bone_dof_sphere_get());
       }
       else {
@@ -304,6 +320,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.stick = BUF_INSTANCE(grp, format, DRW_cache_bone_stick_get());
       }
       else {
@@ -324,6 +341,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
       DRW_shgroup_state_disable(grp, DRW_STATE_WRITE_DEPTH);
       DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA | DRW_STATE_CULL_BACK);
       DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha * 0.6f);
+      DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
       cb->transp.envelope_fill = BUF_INSTANCE(grp, format, DRW_cache_bone_envelope_solid_get());
 
       format = formats->instance_bone_envelope_outline;
@@ -340,6 +358,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.envelope_outline = BUF_INSTANCE(
             grp, format, DRW_cache_bone_envelope_outline_get());
       }
@@ -360,6 +379,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         grp = DRW_shgroup_create(sh, armature_transp_ps);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         DRW_shgroup_uniform_bool_copy(grp, "isDistance", true);
         DRW_shgroup_state_enable(grp, DRW_STATE_CULL_FRONT);
         cb->transp.envelope_distance = BUF_INSTANCE(
@@ -383,6 +403,7 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
         DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
         DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
         DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
+        DRW_shgroup_uniform_vec2(grp, "wireFadeDepth", pd->shdata.fade_depth_info, 1);
         cb->transp.wire = BUF_LINE(grp, format);
       }
       else {
@@ -2227,9 +2248,15 @@ static void draw_armature_edit(ArmatureDrawContext *ctx)
    * for now we can draw from the original armature. See: T66773. */
   // bArmature *arm = ob->data;
   bArmature *arm = ob_orig->data;
+  float depth_bias_mat[4][4], pt[3];
 
   edbo_compute_bbone_child(arm);
 
+  if (ctx->p_fade_depth_bias) {
+    DRW_view_viewmat_get(NULL, depth_bias_mat, false);
+    mul_m4_m4m4(depth_bias_mat, depth_bias_mat, ctx->ob->obmat);
+  }
+
   for (eBone = arm->edbo->first, index = ob_orig->runtime.select_id; eBone;
        eBone = eBone->next, index += 0x10000) {
     if (eBone->layer & arm->layer) {
@@ -2250,6 +2277,14 @@ static void draw_armature_edit(Armatu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list