Armature: Add new Transparent Bone overlay option.
authorClément Foucault <foucault.clem@gmail.com>
Mon, 7 May 2018 13:10:11 +0000 (15:10 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Mon, 7 May 2018 15:00:10 +0000 (17:00 +0200)
This is half the replacement of the old wireframe mode. It's not doing any
XRay drawing at the moment.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/draw/intern/draw_armature.c
source/blender/draw/modes/edit_armature_mode.c
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/pose_mode.c
source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl
source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index 767837038202c4a97f602206237a73d522a57135..445b9d867ca1a8e9b1ec325b9a33214fe34bbc65 100644 (file)
@@ -3626,6 +3626,8 @@ class VIEW3D_PT_overlay(Panel):
         subsub.active = scene.unit_settings.system == 'NONE'
         subsub.prop(overlay, "grid_subdivisions", text="Subdivisions")
 
+
+
         if context.mode == 'EDIT_MESH':
             col.separator()
             col.label(text="Edit Mode:")
@@ -3647,6 +3649,21 @@ class VIEW3D_PT_overlay(Panel):
             sub.active = overlay.show_vertex_normals or overlay.show_face_normals or overlay.show_split_normals
             sub.prop(overlay, "normals_length", text="Size")
 
+        elif context.mode == 'POSE':
+            col.separator()
+            col.label(text="Pose Mode:")
+
+            col = layout.column()
+            col.active = display_all
+            col.prop(overlay, "transparent_bones")
+
+        elif context.mode == 'EDIT_ARMATURE':
+            col.separator()
+            col.label(text="Edit Armature:")
+
+            col = layout.column()
+            col.active = display_all
+            col.prop(overlay, "transparent_bones")
 
         elif context.mode in {'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE'}:
             col.separator()
index 9c05f3165df6208fe1919a5ae28515d102d495ca..1a2ff70624bbc6520b051f9e1337334e7fed1b75 100644 (file)
@@ -1028,7 +1028,7 @@ static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
        const float *col = (g_theme.const_color) ? g_theme.const_color :
                           (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? g_theme.text_hi_color : g_theme.text_color;
        copy_v4_v4(final_col, col);
-       final_col[3] = (g_theme.const_color) ? 1.0 : 0.4; /* Mix with axes color. */
+       final_col[3] = (g_theme.const_color) ? 1.0 : (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? 0.3 : 0.8; /* Mix with axes color. */
        drw_shgroup_bone_axes(BONE_VAR(eBone, pchan, disp_mat), final_col);
 }
 
index e744565558b31f7150c2421ceef8c950f31c6598..0288a027b7c8ec659c67e460a600526d121980ac 100644 (file)
@@ -27,6 +27,7 @@
 #include "DRW_render.h"
 
 #include "DNA_armature_types.h"
+#include "DNA_view3d_types.h"
 
 #include "draw_common.h"
 
@@ -76,7 +77,7 @@ static void EDIT_ARMATURE_cache_init(void *vedata)
 
        {
                /* Solid bones */
-               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
                psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
        }
 
@@ -137,13 +138,24 @@ static void EDIT_ARMATURE_draw_scene(void *vedata)
        EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl;
        DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
        DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+       const DRWContextState *draw_ctx = DRW_context_state_get();
+       const bool transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
 
        DRW_draw_pass(psl->bone_envelope);
 
+       if (transparent_bones) {
+               DRW_pass_state_add(psl->bone_solid, DRW_STATE_BLEND);
+               DRW_pass_state_remove(psl->bone_solid, DRW_STATE_WRITE_DEPTH);
+               DRW_draw_pass(psl->bone_solid);
+       }
+
        MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
 
+       if (!transparent_bones) {
+               DRW_draw_pass(psl->bone_solid);
+       }
+
        DRW_draw_pass(psl->bone_outline);
-       DRW_draw_pass(psl->bone_solid);
        DRW_draw_pass(psl->bone_wire);
        DRW_draw_pass(psl->relationship);
 
index 1cfc8e9403d5ae151ebc9d245bb65c40026d4991..312928c57f62a12d85eba690401a9fb55034a221 100644 (file)
@@ -987,7 +987,7 @@ static void OBJECT_cache_init(void *vedata)
 
        {
                /* Solid bones */
-               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
                psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
                psl->bone_outline = DRW_pass_create("Bone Outline Pass", state);
        }
index 18318046869bd3653a31494e01b09436372d1846..a7fc1da959bdc93434cc56197326f3aff5c7cc64 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "DRW_engine.h"
 #include "DRW_render.h"
+#include "DNA_view3d_types.h"
 
 /* If builtin shaders are needed */
 #include "GPU_shader.h"
@@ -85,7 +86,7 @@ static void POSE_cache_init(void *vedata)
 
        {
                /* Solid bones */
-               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
                psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
        }
 
@@ -175,14 +176,25 @@ static void POSE_draw_scene(void *vedata)
        POSE_PassList *psl = ((POSE_Data *)vedata)->psl;
        DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
        DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+       const DRWContextState *draw_ctx = DRW_context_state_get();
+       const bool transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
 
        DRW_draw_pass(psl->bone_envelope);
 
+       if (transparent_bones) {
+               DRW_pass_state_add(psl->bone_solid, DRW_STATE_BLEND);
+               DRW_pass_state_remove(psl->bone_solid, DRW_STATE_WRITE_DEPTH);
+               DRW_draw_pass(psl->bone_solid);
+       }
+
        MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
 
+       if (!transparent_bones) {
+               DRW_draw_pass(psl->bone_solid);
+       }
+
        DRW_draw_pass(psl->bone_outline);
        DRW_draw_pass(psl->bone_wire);
-       DRW_draw_pass(psl->bone_solid);
        DRW_draw_pass(psl->relationship);
 
        MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
index aa455a85cf03ba5e40f572753e89debf005e6604..248281f4e79cdb2c719a0e3bbdaa769aaab9e2fa 100644 (file)
@@ -5,5 +5,5 @@ out vec4 fragColor;
 
 void main()
 {
-       fragColor = finalColor;
+       fragColor = vec4(finalColor.rgb, 0.6); /* Hardcoded transparency factor. */
 }
index a431a048282136665d48ce63f03ddbb688c97e01..3c80f629d791ee2b925784df9c74dc50255bdf0a 100644 (file)
@@ -73,7 +73,8 @@ void main()
        float dither = (0.5 + dot(vec2(ivec2(gl_FragCoord.xy) & ivec2(1)), vec2(1.0, 2.0))) * 0.25;
        dither *= (1.0 / 255.0); /* Assume 8bit per color buffer. */
 
-       fragColor = vec4(fragColor.rgb + dither, 1.0);
+       /* Hardcoded transparency factor. Less than shape to be less distractive. */
+       fragColor = vec4(fragColor.rgb + dither, 0.4);
 
        t /= ray_len;
        gl_FragDepth = get_depth_from_view_z(ray_dir_view.z * t + ray_ori_view.z);
index a206d9e6642f75fc21c5ef6330b7d2f358ed07a7..406f74340333f1832a7309224893e71bbbcba0e1 100644 (file)
@@ -154,7 +154,9 @@ typedef struct View3DOverlay {
 
        /* Paint mode settings */
        int paint_flag;
-       int pad;
+
+       /* Armature edit/pose mode settings */
+       int arm_flag;
 } View3DOverlay;
 
 /* 3D ViewPort Struct */
@@ -353,6 +355,11 @@ enum {
        V3D_OVERLAY_EDIT_WEIGHT       = (1 << 4),
 };
 
+/* View3DOverlay->arm_flag */
+enum {
+       V3D_OVERLAY_ARM_TRANSP_BONES  = (1 << 0),
+};
+
 /* View3DOverlay->paint_flag */
 enum {
        V3D_OVERLAY_PAINT_WIRE        = (1 << 0),
index d209e0f08da04db79c29784d1d7e22b56bf7a69d..8dba90d0a2b7f13b5ad6e80f3701f705518e0761 100644 (file)
@@ -2384,6 +2384,11 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Backwire Opacity", "Opacity when rendering transparent wires");
        RNA_def_property_range(prop, 0.0f, 1.0f);
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "transparent_bones", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "overlay.arm_flag", V3D_OVERLAY_ARM_TRANSP_BONES);
+       RNA_def_property_ui_text(prop, "Transparent Bones", "Display bones as transparent");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 }
 
 static void rna_def_space_view3d(BlenderRNA *brna)