DRW: support clipping for relationship lines
This commit is contained in:
		@@ -427,11 +427,11 @@ static void drw_shgroup_bone_axes(const float (*bone_mat)[4], const float color[
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Relationship lines */
 | 
			
		||||
static void drw_shgroup_bone_relationship_lines(const float start[3], const float end[3])
 | 
			
		||||
static void drw_shgroup_bone_relationship_lines(const float start[3], const float end[3], const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	if (g_data.lines_relationship == NULL) {
 | 
			
		||||
		g_data.lines_relationship = shgroup_dynlines_dashed_uniform_color(
 | 
			
		||||
		        g_data.passes.relationship_lines, g_theme.wire_color);
 | 
			
		||||
		        g_data.passes.relationship_lines, g_theme.wire_color, sh_cfg);
 | 
			
		||||
	}
 | 
			
		||||
	/* reverse order to have less stipple overlap */
 | 
			
		||||
	float v[3];
 | 
			
		||||
@@ -441,11 +441,11 @@ static void drw_shgroup_bone_relationship_lines(const float start[3], const floa
 | 
			
		||||
	DRW_shgroup_call_dynamic_add(g_data.lines_relationship, v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void drw_shgroup_bone_ik_lines(const float start[3], const float end[3])
 | 
			
		||||
static void drw_shgroup_bone_ik_lines(const float start[3], const float end[3], const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	if (g_data.lines_ik == NULL) {
 | 
			
		||||
		static float fcolor[4] = {0.8f, 0.5f, 0.0f, 1.0f};  /* add theme! */
 | 
			
		||||
		g_data.lines_ik = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
 | 
			
		||||
		g_data.lines_ik = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor, sh_cfg);
 | 
			
		||||
	}
 | 
			
		||||
	/* reverse order to have less stipple overlap */
 | 
			
		||||
	float v[3];
 | 
			
		||||
@@ -455,11 +455,11 @@ static void drw_shgroup_bone_ik_lines(const float start[3], const float end[3])
 | 
			
		||||
	DRW_shgroup_call_dynamic_add(g_data.lines_ik, v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void drw_shgroup_bone_ik_no_target_lines(const float start[3], const float end[3])
 | 
			
		||||
static void drw_shgroup_bone_ik_no_target_lines(const float start[3], const float end[3], const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	if (g_data.lines_ik_no_target == NULL) {
 | 
			
		||||
		static float fcolor[4] = {0.8f, 0.8f, 0.2f, 1.0f};  /* add theme! */
 | 
			
		||||
		g_data.lines_ik_no_target = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
 | 
			
		||||
		g_data.lines_ik_no_target = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor, sh_cfg);
 | 
			
		||||
	}
 | 
			
		||||
	/* reverse order to have less stipple overlap */
 | 
			
		||||
	float v[3];
 | 
			
		||||
@@ -469,11 +469,11 @@ static void drw_shgroup_bone_ik_no_target_lines(const float start[3], const floa
 | 
			
		||||
	DRW_shgroup_call_dynamic_add(g_data.lines_ik_no_target, v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void drw_shgroup_bone_ik_spline_lines(const float start[3], const float end[3])
 | 
			
		||||
static void drw_shgroup_bone_ik_spline_lines(const float start[3], const float end[3], const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	if (g_data.lines_ik_spline == NULL) {
 | 
			
		||||
		static float fcolor[4] = {0.8f, 0.8f, 0.2f, 1.0f};  /* add theme! */
 | 
			
		||||
		g_data.lines_ik_spline = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
 | 
			
		||||
		g_data.lines_ik_spline = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor, sh_cfg);
 | 
			
		||||
	}
 | 
			
		||||
	/* reverse order to have less stipple overlap */
 | 
			
		||||
	float v[3];
 | 
			
		||||
@@ -1585,7 +1585,9 @@ static void draw_bone_dofs(bPoseChannel *pchan)
 | 
			
		||||
/** \name Draw Relationships
 | 
			
		||||
 * \{ */
 | 
			
		||||
 | 
			
		||||
static void pchan_draw_ik_lines(bPoseChannel *pchan, const bool only_temp, const int constflag)
 | 
			
		||||
static void pchan_draw_ik_lines(
 | 
			
		||||
        bPoseChannel *pchan, const bool only_temp, const int constflag,
 | 
			
		||||
        const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	bConstraint *con;
 | 
			
		||||
	bPoseChannel *parchan;
 | 
			
		||||
@@ -1624,10 +1626,10 @@ static void pchan_draw_ik_lines(bPoseChannel *pchan, const bool only_temp, const
 | 
			
		||||
					line_end = parchan->pose_head;
 | 
			
		||||
 | 
			
		||||
					if (constflag & PCHAN_HAS_TARGET) {
 | 
			
		||||
						drw_shgroup_bone_ik_lines(line_start, line_end);
 | 
			
		||||
						drw_shgroup_bone_ik_lines(line_start, line_end, sh_cfg);
 | 
			
		||||
					}
 | 
			
		||||
					else {
 | 
			
		||||
						drw_shgroup_bone_ik_no_target_lines(line_start, line_end);
 | 
			
		||||
						drw_shgroup_bone_ik_no_target_lines(line_start, line_end, sh_cfg);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
@@ -1655,7 +1657,7 @@ static void pchan_draw_ik_lines(bPoseChannel *pchan, const bool only_temp, const
 | 
			
		||||
				/* Only draw line in case our chain is more than one bone long! */
 | 
			
		||||
				if (parchan != pchan) { /* XXX revise the breaking conditions to only stop at the tail? */
 | 
			
		||||
					line_end = parchan->pose_head;
 | 
			
		||||
					drw_shgroup_bone_ik_spline_lines(line_start, line_end);
 | 
			
		||||
					drw_shgroup_bone_ik_spline_lines(line_start, line_end, sh_cfg);
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
@@ -1665,7 +1667,8 @@ static void pchan_draw_ik_lines(bPoseChannel *pchan, const bool only_temp, const
 | 
			
		||||
 | 
			
		||||
static void draw_bone_relations(
 | 
			
		||||
        EditBone *ebone, bPoseChannel *pchan, bArmature *arm,
 | 
			
		||||
        const int boneflag, const short constflag, const bool do_relations)
 | 
			
		||||
        const int boneflag, const short constflag, const bool do_relations,
 | 
			
		||||
        const eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	if (g_data.passes.relationship_lines) {
 | 
			
		||||
		if (ebone && ebone->parent) {
 | 
			
		||||
@@ -1674,7 +1677,7 @@ static void draw_bone_relations(
 | 
			
		||||
				 * since riggers will want to know about the links between bones
 | 
			
		||||
				 */
 | 
			
		||||
				if ((boneflag & BONE_CONNECTED) == 0) {
 | 
			
		||||
					drw_shgroup_bone_relationship_lines(ebone->head, ebone->parent->tail);
 | 
			
		||||
					drw_shgroup_bone_relationship_lines(ebone->head, ebone->parent->tail, sh_cfg);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -1685,7 +1688,7 @@ static void draw_bone_relations(
 | 
			
		||||
				    (pchan->parent->bone && (pchan->parent->bone->flag & BONE_SELECTED)))
 | 
			
		||||
				{
 | 
			
		||||
					if ((boneflag & BONE_CONNECTED) == 0) {
 | 
			
		||||
						drw_shgroup_bone_relationship_lines(pchan->pose_head, pchan->parent->pose_tail);
 | 
			
		||||
						drw_shgroup_bone_relationship_lines(pchan->pose_head, pchan->parent->pose_tail, sh_cfg);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@@ -1694,7 +1697,7 @@ static void draw_bone_relations(
 | 
			
		||||
			if (arm->flag & ARM_POSEMODE) {
 | 
			
		||||
				if (constflag & (PCHAN_HAS_IK | PCHAN_HAS_SPLINEIK)) {
 | 
			
		||||
					if (boneflag & BONE_SELECTED) {
 | 
			
		||||
						pchan_draw_ik_lines(pchan, !do_relations, constflag);
 | 
			
		||||
						pchan_draw_ik_lines(pchan, !do_relations, constflag, sh_cfg);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@@ -1739,7 +1742,7 @@ static void draw_armature_edit(Object *ob)
 | 
			
		||||
					boneflag |= BONE_DRAW_ACTIVE;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				draw_bone_relations(eBone, NULL, arm, boneflag, constflag, show_relations);
 | 
			
		||||
				draw_bone_relations(eBone, NULL, arm, boneflag, constflag, show_relations, draw_ctx->sh_cfg);
 | 
			
		||||
 | 
			
		||||
				if (arm->drawtype == ARM_ENVELOPE) {
 | 
			
		||||
					draw_bone_update_disp_matrix_default(eBone, NULL);
 | 
			
		||||
@@ -1850,7 +1853,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
 | 
			
		||||
					boneflag |= BONE_DRAW_ACTIVE;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				draw_bone_relations(NULL, pchan, arm, boneflag, constflag, show_relations);
 | 
			
		||||
				draw_bone_relations(NULL, pchan, arm, boneflag, constflag, show_relations, draw_ctx->sh_cfg);
 | 
			
		||||
 | 
			
		||||
				if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
 | 
			
		||||
					draw_bone_update_disp_matrix_custom(pchan);
 | 
			
		||||
 
 | 
			
		||||
@@ -321,9 +321,9 @@ DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass, eGPUShaderConfig sh_
 | 
			
		||||
	return grp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, const float color[4])
 | 
			
		||||
DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg)
 | 
			
		||||
{
 | 
			
		||||
	GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
 | 
			
		||||
	GPUShader *sh = GPU_shader_get_builtin_shader_with_config(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, sh_cfg);
 | 
			
		||||
 | 
			
		||||
	static float dash_width = 6.0f;
 | 
			
		||||
	static float dash_factor = 0.5f;
 | 
			
		||||
@@ -333,7 +333,9 @@ DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, const floa
 | 
			
		||||
	DRW_shgroup_uniform_float(grp, "dash_width", &dash_width, 1);
 | 
			
		||||
	DRW_shgroup_uniform_float(grp, "dash_factor", &dash_factor, 1);
 | 
			
		||||
	DRW_shgroup_uniform_int_copy(grp, "colors_len", 0); /* "simple" mode */
 | 
			
		||||
 | 
			
		||||
	if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
 | 
			
		||||
		DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
 | 
			
		||||
	}
 | 
			
		||||
	return grp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -125,7 +125,7 @@ void DRW_globals_free(void);
 | 
			
		||||
void DRW_shgroup_world_clip_planes_from_rv3d(struct DRWShadingGroup *shgrp, const RegionView3D *rv3d);
 | 
			
		||||
 | 
			
		||||
struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
 | 
			
		||||
struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4]);
 | 
			
		||||
struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg);
 | 
			
		||||
struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, const float color[4], const float *size, eGPUShaderConfig sh_cfg);
 | 
			
		||||
struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg);
 | 
			
		||||
struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig sh_cfg);
 | 
			
		||||
 
 | 
			
		||||
@@ -1359,8 +1359,8 @@ static void OBJECT_cache_init(void *vedata)
 | 
			
		||||
		/* -------- STIPPLES ------- */
 | 
			
		||||
 | 
			
		||||
		/* Relationship Lines */
 | 
			
		||||
		sgl->relationship_lines = shgroup_dynlines_dashed_uniform_color(sgl->non_meshes, gb->colorWire);
 | 
			
		||||
		sgl->constraint_lines = shgroup_dynlines_dashed_uniform_color(sgl->non_meshes, gb->colorGridAxisZ);
 | 
			
		||||
		sgl->relationship_lines = shgroup_dynlines_dashed_uniform_color(sgl->non_meshes, gb->colorWire, draw_ctx->sh_cfg);
 | 
			
		||||
		sgl->constraint_lines = shgroup_dynlines_dashed_uniform_color(sgl->non_meshes, gb->colorGridAxisZ, draw_ctx->sh_cfg);
 | 
			
		||||
 | 
			
		||||
		/* Force Field Curve Guide End (here because of stipple) */
 | 
			
		||||
		/* TODO port to shader stipple */
 | 
			
		||||
 
 | 
			
		||||
@@ -1242,7 +1242,8 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(
 | 
			
		||||
			                GPU_SHADER_3D_FLAT_SELECT_ID,
 | 
			
		||||
			                GPU_SHADER_3D_UNIFORM_SELECT_ID) ||
 | 
			
		||||
			           ELEM(shader,
 | 
			
		||||
			                GPU_SHADER_3D_FLAT_COLOR));
 | 
			
		||||
			                GPU_SHADER_3D_FLAT_COLOR,
 | 
			
		||||
			                GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR));
 | 
			
		||||
			const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
 | 
			
		||||
			const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
 | 
			
		||||
			/* In rare cases geometry shaders calculate clipping themselves. */
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,10 @@ void main()
 | 
			
		||||
	gl_Position = v1;
 | 
			
		||||
	color_geom = color_vert[0];
 | 
			
		||||
	distance_along_line = 0.0f;
 | 
			
		||||
 | 
			
		||||
#ifdef USE_WORLD_CLIP_PLANES
 | 
			
		||||
	world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
 | 
			
		||||
#endif
 | 
			
		||||
	EmitVertex();
 | 
			
		||||
 | 
			
		||||
	gl_Position = v2;
 | 
			
		||||
@@ -47,6 +51,10 @@ void main()
 | 
			
		||||
 | 
			
		||||
		distance_along_line = distance(p1, p2);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#ifdef USE_WORLD_CLIP_PLANES
 | 
			
		||||
	world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
 | 
			
		||||
#endif
 | 
			
		||||
	EmitVertex();
 | 
			
		||||
 | 
			
		||||
	EndPrimitive();
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,10 @@
 | 
			
		||||
 | 
			
		||||
uniform mat4 ModelViewProjectionMatrix;
 | 
			
		||||
 | 
			
		||||
#ifdef USE_WORLD_CLIP_PLANES
 | 
			
		||||
uniform mat4 ModelMatrix;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
uniform vec4 color;
 | 
			
		||||
 | 
			
		||||
in vec3 pos;
 | 
			
		||||
@@ -16,6 +20,10 @@ out vec4 color_vert;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
 | 
			
		||||
	vec4 pos_4d = vec4(pos, 1.0);
 | 
			
		||||
	gl_Position = ModelViewProjectionMatrix * pos_4d;
 | 
			
		||||
	color_vert = color;
 | 
			
		||||
#ifdef USE_WORLD_CLIP_PLANES
 | 
			
		||||
	world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user