DRW: support clipping for bone verts
This commit is contained in:
@@ -232,15 +232,16 @@ static void drw_shgroup_bone_envelope_distance(
|
||||
static void drw_shgroup_bone_envelope(
|
||||
const float (*bone_mat)[4],
|
||||
const float bone_color[4], const float hint_color[4], const float outline_color[4],
|
||||
const float *radius_head, const float *radius_tail)
|
||||
const float *radius_head, const float *radius_tail,
|
||||
const eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
if (g_data.bone_point_wire == NULL) {
|
||||
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
|
||||
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire, sh_cfg);
|
||||
}
|
||||
if (g_data.bone_point_solid == NULL &&
|
||||
g_data.passes.bone_solid != NULL)
|
||||
{
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid, g_data.transparent);
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid, g_data.transparent, sh_cfg);
|
||||
}
|
||||
if (g_data.bone_envelope_wire == NULL) {
|
||||
g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire);
|
||||
@@ -393,15 +394,16 @@ static void drw_shgroup_bone_custom_wire(
|
||||
/* Head and tail sphere */
|
||||
static void drw_shgroup_bone_point(
|
||||
const float (*bone_mat)[4],
|
||||
const float bone_color[4], const float hint_color[4], const float outline_color[4])
|
||||
const float bone_color[4], const float hint_color[4], const float outline_color[4],
|
||||
const eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
if (g_data.bone_point_wire == NULL) {
|
||||
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
|
||||
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire, sh_cfg);
|
||||
}
|
||||
if (g_data.bone_point_solid == NULL &&
|
||||
g_data.passes.bone_solid != NULL)
|
||||
{
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid, g_data.transparent);
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid, g_data.transparent, sh_cfg);
|
||||
}
|
||||
float final_bonemat[4][4];
|
||||
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
|
||||
@@ -1183,7 +1185,7 @@ static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
|
||||
static void draw_points(
|
||||
const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
|
||||
const int boneflag, const short constflag,
|
||||
const int select_id)
|
||||
const eGPUShaderConfig sh_cfg, const int select_id)
|
||||
{
|
||||
float col_solid_root[4], col_solid_tail[4], col_wire_root[4], col_wire_tail[4];
|
||||
float col_hint_root[4], col_hint_tail[4];
|
||||
@@ -1230,10 +1232,10 @@ static void draw_points(
|
||||
if (is_envelope_draw) {
|
||||
drw_shgroup_bone_envelope(
|
||||
eBone->disp_mat, col_solid_root, col_hint_root, col_wire_root,
|
||||
&eBone->rad_head, &envelope_ignore);
|
||||
&eBone->rad_head, &envelope_ignore, sh_cfg);
|
||||
}
|
||||
else {
|
||||
drw_shgroup_bone_point(eBone->disp_mat, col_solid_root, col_hint_root, col_wire_root);
|
||||
drw_shgroup_bone_point(eBone->disp_mat, col_solid_root, col_hint_root, col_wire_root, sh_cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1243,10 +1245,10 @@ static void draw_points(
|
||||
if (is_envelope_draw) {
|
||||
drw_shgroup_bone_envelope(
|
||||
pchan->disp_mat, col_solid_root, col_hint_root, col_wire_root,
|
||||
&bone->rad_head, &envelope_ignore);
|
||||
&bone->rad_head, &envelope_ignore, sh_cfg);
|
||||
}
|
||||
else {
|
||||
drw_shgroup_bone_point(pchan->disp_mat, col_solid_root, col_hint_root, col_wire_root);
|
||||
drw_shgroup_bone_point(pchan->disp_mat, col_solid_root, col_hint_root, col_wire_root, sh_cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1261,10 +1263,10 @@ static void draw_points(
|
||||
const float *rad_tail = eBone ? &eBone->rad_tail : &pchan->bone->rad_tail;
|
||||
drw_shgroup_bone_envelope(
|
||||
BONE_VAR(eBone, pchan, disp_mat), col_solid_tail, col_hint_tail, col_wire_tail,
|
||||
&envelope_ignore, rad_tail);
|
||||
&envelope_ignore, rad_tail, sh_cfg);
|
||||
}
|
||||
else {
|
||||
drw_shgroup_bone_point(BONE_VAR(eBone, pchan, disp_tail_mat), col_solid_tail, col_hint_tail, col_wire_tail);
|
||||
drw_shgroup_bone_point(BONE_VAR(eBone, pchan, disp_tail_mat), col_solid_tail, col_hint_tail, col_wire_tail, sh_cfg);
|
||||
}
|
||||
|
||||
if (select_id != -1) {
|
||||
@@ -1308,7 +1310,7 @@ static void draw_bone_custom_shape(
|
||||
static void draw_bone_envelope(
|
||||
EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
|
||||
const int boneflag, const short constflag,
|
||||
const int select_id)
|
||||
const eGPUShaderConfig sh_cfg, const int select_id)
|
||||
{
|
||||
const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
|
||||
const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
|
||||
@@ -1339,13 +1341,13 @@ static void draw_bone_envelope(
|
||||
|
||||
drw_shgroup_bone_envelope(
|
||||
BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire,
|
||||
rad_head, rad_tail);
|
||||
rad_head, rad_tail, sh_cfg);
|
||||
|
||||
if (select_id != -1) {
|
||||
DRW_select_load_id(-1);
|
||||
}
|
||||
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, sh_cfg, select_id);
|
||||
}
|
||||
|
||||
static void draw_bone_line(
|
||||
@@ -1438,7 +1440,7 @@ static void draw_bone_wire(
|
||||
}
|
||||
|
||||
if (eBone) {
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, sh_cfg, select_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1474,7 +1476,7 @@ static void draw_bone_box(
|
||||
}
|
||||
|
||||
if (eBone) {
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, sh_cfg, select_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1497,7 +1499,7 @@ static void draw_bone_octahedral(
|
||||
DRW_select_load_id(-1);
|
||||
}
|
||||
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
|
||||
draw_points(eBone, pchan, arm, boneflag, constflag, sh_cfg, select_id);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -1741,7 +1743,7 @@ static void draw_armature_edit(Object *ob)
|
||||
|
||||
if (arm->drawtype == ARM_ENVELOPE) {
|
||||
draw_bone_update_disp_matrix_default(eBone, NULL);
|
||||
draw_bone_envelope(eBone, NULL, arm, boneflag, constflag, select_id);
|
||||
draw_bone_envelope(eBone, NULL, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
|
||||
}
|
||||
else if (arm->drawtype == ARM_LINE) {
|
||||
draw_bone_update_disp_matrix_default(eBone, NULL);
|
||||
@@ -1856,7 +1858,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
|
||||
}
|
||||
else if (arm->drawtype == ARM_ENVELOPE) {
|
||||
draw_bone_update_disp_matrix_default(NULL, pchan);
|
||||
draw_bone_envelope(NULL, pchan, arm, boneflag, constflag, select_id);
|
||||
draw_bone_envelope(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
|
||||
}
|
||||
else if (arm->drawtype == ARM_LINE) {
|
||||
draw_bone_update_disp_matrix_default(NULL, pchan);
|
||||
|
||||
@@ -785,13 +785,16 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
if (sh_data->bone_sphere == NULL) {
|
||||
sh_data->bone_sphere = DRW_shader_create(
|
||||
datatoc_armature_sphere_solid_vert_glsl, NULL,
|
||||
datatoc_armature_sphere_solid_frag_glsl, NULL);
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_sphere = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_sphere_solid_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_armature_sphere_solid_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
||||
});
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
||||
@@ -805,17 +808,22 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
|
||||
pass, DRW_cache_bone_point_get(), g_formats.instance_bone);
|
||||
/* More transparent than the shape to be less distractive. */
|
||||
DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.4f : 1.0f);
|
||||
|
||||
if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
if (sh_data->bone_sphere_outline == NULL) {
|
||||
sh_data->bone_sphere_outline = DRW_shader_create(
|
||||
datatoc_armature_sphere_outline_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_sphere_outline = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_sphere_outline_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_bone_outline, {
|
||||
@@ -828,7 +836,9 @@ DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
|
||||
pass, DRW_cache_bone_point_wire_outline_get(),
|
||||
g_formats.instance_bone_outline);
|
||||
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
||||
|
||||
if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,8 @@ struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *p
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct GPUBatch *geom, bool transp, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass, bool transp);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_stick(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom);
|
||||
|
||||
|
||||
@@ -99,4 +99,9 @@ void main()
|
||||
gl_Position.xy += t * edge_dir;
|
||||
|
||||
finalColor = vec4(outlineColorSize.rgb, 1.0);
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
vec4 worldPosition = InstanceModelMatrix * vec4(cam_pos0, 1.0);
|
||||
world_clip_planes_calc_clip_distance(worldPosition.xyz);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -73,10 +73,16 @@ void main()
|
||||
/* Camera oriented position (but still in local space) */
|
||||
vec3 cam_pos = x_axis * pos.x + y_axis * pos.y + z_axis * z_ofs;
|
||||
|
||||
vec4 V = model_view_matrix * vec4(cam_pos, 1.0);
|
||||
vec4 pos_4d = vec4(cam_pos, 1.0);
|
||||
vec4 V = model_view_matrix * pos_4d;
|
||||
gl_Position = ProjectionMatrix * V;
|
||||
viewPosition = V.xyz;
|
||||
|
||||
finalStateColor = stateColor;
|
||||
finalBoneColor = boneColor;
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
vec4 worldPosition = InstanceModelMatrix * pos_4d;
|
||||
world_clip_planes_calc_clip_distance(worldPosition.xyz);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user