DRW: support clipping for armature bone axes
authorCampbell Barton <ideasman42@gmail.com>
Sat, 16 Mar 2019 07:41:34 +0000 (18:41 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 16 Mar 2019 07:43:36 +0000 (18:43 +1100)
Also minor changes to make empty axis match armature axis.

source/blender/draw/intern/draw_armature.c
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/modes/shaders/armature_axes_vert.glsl
source/blender/draw/modes/shaders/object_empty_axes_vert.glsl

index cab0872..a26313a 100644 (file)
@@ -417,10 +417,12 @@ static void drw_shgroup_bone_point(
 }
 
 /* Axes */
-static void drw_shgroup_bone_axes(const float (*bone_mat)[4], const float color[4])
+static void drw_shgroup_bone_axes(
+        const float (*bone_mat)[4], const float color[4],
+        const eGPUShaderConfig sh_cfg)
 {
        if (g_data.bone_axes == NULL) {
-               g_data.bone_axes = shgroup_instance_bone_axes(g_data.passes.bone_axes);
+               g_data.bone_axes = shgroup_instance_bone_axes(g_data.passes.bone_axes, sh_cfg);
        }
        float final_bonemat[4][4];
        mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
@@ -1172,7 +1174,9 @@ static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan)
        translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
 }
 
-static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
+static void draw_axes(
+        EditBone *eBone, bPoseChannel *pchan,
+        const eGPUShaderConfig sh_cfg)
 {
        float final_col[4];
        const float *col = (g_theme.const_color) ? g_theme.const_color :
@@ -1180,7 +1184,7 @@ static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
        copy_v4_v4(final_col, col);
        /* Mix with axes color. */
        final_col[3] = (g_theme.const_color) ? 1.0 : (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? 0.3 : 0.8;
-       drw_shgroup_bone_axes(BONE_VAR(eBone, pchan, disp_mat), final_col);
+       drw_shgroup_bone_axes(BONE_VAR(eBone, pchan, disp_mat), final_col, sh_cfg);
 }
 
 static void draw_points(
@@ -1783,7 +1787,7 @@ static void draw_armature_edit(Object *ob)
 
                                /*      Draw additional axes */
                                if (arm->flag & ARM_DRAWAXES) {
-                                       draw_axes(eBone, NULL);
+                                       draw_axes(eBone, NULL, draw_ctx->sh_cfg);
                                }
                        }
                }
@@ -1907,7 +1911,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
 
                                /*      Draw additional axes */
                                if (arm->flag & ARM_DRAWAXES) {
-                                       draw_axes(NULL, pchan);
+                                       draw_axes(NULL, pchan, draw_ctx->sh_cfg);
                                }
                        }
                }
index b5141fa..849087d 100644 (file)
@@ -602,13 +602,16 @@ DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom, eGP
        return grp;
 }
 
-DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
+DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass, eGPUShaderConfig sh_cfg)
 {
-       COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
+       COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
        if (sh_data->bone_axes == NULL) {
-               sh_data->bone_axes = DRW_shader_create(
-                       datatoc_armature_axes_vert_glsl, NULL,
-                       datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
+               sh_data->bone_axes = GPU_shader_create_from_arrays({
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_axes_vert_glsl, NULL},
+                       .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
+               });
        }
 
        DRW_shgroup_instance_format(g_formats.instance_color, {
@@ -621,7 +624,9 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
                pass, DRW_cache_bone_arrows_get(),
                g_formats.instance_color);
        DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
-
+       if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
+               DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
+       }
        return grp;
 }
 
index 892c4ea..f6ebfca 100644 (file)
@@ -142,7 +142,7 @@ struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPU
 struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
 struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
 struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
-struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
 struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
 struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
 struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg);
index 137bcff..ac640f0 100644 (file)
@@ -1,7 +1,9 @@
 
 uniform mat4 ViewProjectionMatrix;
 uniform vec3 screenVecs[3];
-
+#ifdef USE_WORLD_CLIP_PLANES
+uniform mat4 ModelMatrix;
+#endif
 /* ---- Instantiated Attrs ---- */
 in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
 in vec2 screenPos;
@@ -23,8 +25,13 @@ void main()
        /* Scale uniformly by axis length */
        spos *= length(chosen_axis);
 
-       gl_Position = ViewProjectionMatrix * vec4(wpos + spos, 1.0);
+       vec4 pos_4d = vec4(wpos + spos, 1.0);
+       gl_Position = ViewProjectionMatrix * pos_4d;
 
        finalColor.rgb = mix(colorAxis, color.rgb, color.a);
        finalColor.a = 1.0;
+
+#ifdef USE_WORLD_CLIP_PLANES
+       world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+#endif
 }
index 4aafcee..8de25de 100644 (file)
@@ -1,6 +1,8 @@
 
 uniform mat4 ViewProjectionMatrix;
+#ifdef USE_WORLD_CLIP_PLANES
 uniform mat4 ModelMatrix;
+#endif
 
 uniform vec3 screenVecs[3];
 
@@ -25,12 +27,12 @@ void main()
        /* Scale uniformly by axis length */
        spos *= length(chosen_axis) * draw_size;
 
-       vec4 pos = vec4(wpos + spos, 1.0);
-       gl_Position = ViewProjectionMatrix * pos;
+       vec4 pos_4d = vec4(wpos + spos, 1.0);
+       gl_Position = ViewProjectionMatrix * pos_4d;
 
        finalColor = vec4(color, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-       world_clip_planes_calc_clip_distance((ModelMatrix * pos).xyz);
+       world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
 #endif
 }