Commit: 91d099baa876b53de22c00c32a24fca4f74fdd59 Author: Alexander Gavrilov Date: Sun Jan 3 23:40:44 2021 +0300 Branches: temp-angavrilov https://developer.blender.org/rB91d099baa876b53de22c00c32a24fca4f74fdd59
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 1c2190bb7a0..dc5815d1c9e 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -6493,18 +6493,38 @@ 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" + + @staticmethod + def is_using_wireframe(context): + shading = VIEW3D_PT_shading.get_shading(context) + + if shading.type == 'WIREFRAME' or shading.show_xray: + return True + + mode = context.mode + + if mode in ('POSE', 'PAINT_WEIGHT'): + armature = context.pose_object + elif mode == 'EDIT_ARMATURE': + armature = context.edit_object + else: + return False + + return armature and armature.display_type == 'WIRE' @classmethod def poll(cls, context): mode = context.mode return ( (mode == 'POSE') or - (mode == 'PAINT_WEIGHT' and context.pose_object) + (mode == 'PAINT_WEIGHT' and context.pose_object) or + (mode in ('EDIT_ARMATURE', 'OBJECT') and + VIEW3D_PT_overlay_bones.is_using_wireframe(context)) ) def draw(self, context): @@ -6523,10 +6543,19 @@ 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") + 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' @@ -7693,7 +7722,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 b83e78443e7..def32767428 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" @@ -1837,6 +1839,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 baf83234354..e5733f2821f 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -388,6 +388,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..aa8fcddf14e 100644 --- a/source/blender/draw/engines/overlay/overlay_armature.c +++ b/source/blender/draw/engines/overlay/overlay_armature.c @@ -97,6 +97,8 @@ typedef struct ArmatureDrawContext { bool transparent; bool show_relations; + float *p_fade_depth_bias; + const ThemeWireColor *bcolor; /* pchan color */ } ArmatureDrawContext; @@ -138,6 +140,18 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata) pd->armature.do_pose_fade_geom = pd->armature.do_pose_xray && ((draw_ctx->object_mode & OB_MODE_WEIGHT_PAINT) == 0) && draw_ctx->object_pose != NULL; + + 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; + + pd->armature.do_wire_depth_fade = wire_fade > 0.0f; + + const bool use_wire_alpha = pd->armature.do_wire_depth_fade || (wire_alpha < 1.0f); + + pd->shdata.fade_depth_bias = FLT_MAX; + DRWState state; if (pd->armature.do_pose_fade_geom) { @@ -163,8 +177,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 +201,91 @@ 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}); + DRW_shgroup_uniform_float(grp, "wireFadeDepthBias", &pd->shdata.fade_depth_bias, 1); + 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}); + DRW_shgroup_uniform_float(grp, "wireFadeDepthBias", &pd->shdata.fade_depth_bias, 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()); 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" @@ 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