Commit: 87126c214e26133c141a216fe8455b3eb1642124 Author: Alexander Gavrilov Date: Sat Dec 11 18:04:34 2021 +0300 Branches: temp-angavrilov https://developer.blender.org/rB87126c214e26133c141a216fe8455b3eb1642124
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.cc M source/blender/draw/CMakeLists.txt M source/blender/draw/engines/overlay/overlay_armature.cc M source/blender/draw/engines/overlay/overlay_private.hh 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 1ce457480e5..a5addd6990c 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -6811,6 +6811,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.cc b/source/blender/blenloader/intern/versioning_300.cc index 4c45e1433ab..53ce28a057d 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -3912,5 +3912,19 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) */ { /* Keep this block, even when empty. */ + + /* Initialize the bone wireframe opacity depth fade setting. */ + if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_wire_fade_depth")) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + 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 d2835639686..7afd4421341 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -580,6 +580,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.cc b/source/blender/draw/engines/overlay/overlay_armature.cc index 8c9587e7a9a..b0aea51e590 100644 --- a/source/blender/draw/engines/overlay/overlay_armature.cc +++ b/source/blender/draw/engines/overlay/overlay_armature.cc @@ -86,6 +86,8 @@ struct ArmatureDrawContext { bool transparent; bool show_relations; + float *p_fade_depth_bias; + const ThemeWireColor *bcolor; /* pchan color */ }; @@ -126,7 +128,14 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata) draw_ctx->object_pose != nullptr; 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; @@ -186,6 +195,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); @@ -199,6 +209,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()); @@ -214,6 +225,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()); } @@ -233,6 +245,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()); } @@ -252,6 +265,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; @@ -271,6 +285,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 { @@ -287,6 +302,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 { @@ -307,6 +323,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 { @@ -327,6 +344,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; @@ -343,6 +361,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()); } @@ -363,6 +382,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( @@ -386,6 +406,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 { @@ -2234,9 +2255,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 = static_cast<bArmature *>(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->object_to_world); + } + for (eBone = static_cast<EditBone *>(arm->edbo->first), index = ob_orig->runtime.select_id; eBone; eBone = eBone->next, index += 0x10000) { @@ -2258,6 +2285,14 @@ static void draw_armature_edit(Armature @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs