Armature: Force Transparent bone in wireframe display type/mode

This makes the bones transparent when the object or the viewport display
type is Wireframe. This is in order to make things consistent.

In object mode all bones are fully transparent to not create more visual
noise if the scene is complex.

Another small addition is that the Bounding Box draw mode now works as
expected on armatures.
This commit is contained in:
Clément Foucault 2019-02-26 23:44:05 +01:00
parent 4243c29463
commit fe5d26807b
5 changed files with 72 additions and 50 deletions

View File

@ -126,14 +126,17 @@ static void drw_shgroup_bone_octahedral(
g_data.bone_octahedral_outline = shgroup_instance_bone_shape_outline(
g_data.passes.bone_outline, geom, sh_cfg);
}
if (g_data.bone_octahedral_solid == NULL) {
if (g_data.bone_octahedral_solid == NULL &&
g_data.passes.bone_solid != NULL) {
struct GPUBatch *geom = DRW_cache_bone_octahedral_get();
g_data.bone_octahedral_solid = shgroup_instance_bone_shape_solid(
g_data.passes.bone_solid, geom, g_data.transparent, sh_cfg);
}
float final_bonemat[4][4];
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_solid, final_bonemat, bone_color, hint_color);
if (g_data.bone_octahedral_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_solid, final_bonemat, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_outline, final_bonemat, outline_color);
}
@ -150,14 +153,18 @@ static void drw_shgroup_bone_box(
g_data.bone_box_outline = shgroup_instance_bone_shape_outline(
g_data.passes.bone_outline, geom, sh_cfg);
}
if (g_data.bone_box_solid == NULL) {
if (g_data.bone_box_solid == NULL &&
g_data.passes.bone_solid != NULL)
{
struct GPUBatch *geom = DRW_cache_bone_box_get();
g_data.bone_box_solid = shgroup_instance_bone_shape_solid(
g_data.passes.bone_solid, geom, g_data.transparent, sh_cfg);
}
float final_bonemat[4][4];
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
DRW_shgroup_call_dynamic_add(g_data.bone_box_solid, final_bonemat, bone_color, hint_color);
if (g_data.bone_box_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_box_solid, final_bonemat, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_box_outline, final_bonemat, outline_color);
}
@ -229,13 +236,17 @@ static void drw_shgroup_bone_envelope(
if (g_data.bone_point_wire == NULL) {
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
}
if (g_data.bone_point_solid == NULL) {
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);
}
if (g_data.bone_envelope_wire == NULL) {
g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire);
}
if (g_data.bone_envelope_solid == NULL) {
if (g_data.bone_envelope_solid == NULL &&
g_data.passes.bone_solid != NULL)
{
g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.passes.bone_solid, g_data.transparent);
/* We can have a lot of overdraw if we don't do this. Also envelope are not subject to
* inverted matrix. */
@ -256,7 +267,9 @@ static void drw_shgroup_bone_envelope(
tmp[0][0] = tmp[1][1] = tmp[2][2] = tail_sphere[3] / PT_DEFAULT_RAD;
tmp[3][3] = 1.0f;
copy_v3_v3(tmp[3], tail_sphere);
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
if (g_data.bone_point_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
}
@ -267,7 +280,9 @@ static void drw_shgroup_bone_envelope(
tmp[0][0] = tmp[1][1] = tmp[2][2] = head_sphere[3] / PT_DEFAULT_RAD;
tmp[3][3] = 1.0f;
copy_v3_v3(tmp[3], head_sphere);
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
if (g_data.bone_point_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
}
@ -285,8 +300,10 @@ static void drw_shgroup_bone_envelope(
copy_v4_v4(tmp_sphere, head_sphere);
interp_v4_v4v4(head_sphere, tail_sphere, head_sphere, fac_head);
interp_v4_v4v4(tail_sphere, tmp_sphere, tail_sphere, fac_tail);
DRW_shgroup_call_dynamic_add(
g_data.bone_envelope_solid, head_sphere, tail_sphere, bone_color, hint_color, final_bonemat[0]);
if (g_data.bone_envelope_solid != NULL) {
DRW_shgroup_call_dynamic_add(
g_data.bone_envelope_solid, head_sphere, tail_sphere, bone_color, hint_color, final_bonemat[0]);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(
g_data.bone_envelope_wire, head_sphere, tail_sphere, outline_color, final_bonemat[0]);
@ -299,7 +316,9 @@ static void drw_shgroup_bone_envelope(
tmp[0][0] = tmp[1][1] = tmp[2][2] = tmp_sphere[3] / PT_DEFAULT_RAD;
tmp[3][3] = 1.0f;
copy_v3_v3(tmp[3], tmp_sphere);
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
if (g_data.bone_point_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
}
@ -329,7 +348,7 @@ static void drw_shgroup_bone_custom_solid(
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
}
if (surf) {
if (surf && g_data.passes.bone_solid != NULL) {
DRWShadingGroup *shgrp_geom_solid = shgroup_instance_bone_shape_solid(
g_data.passes.bone_solid, surf, g_data.transparent, sh_cfg);
DRW_shgroup_call_dynamic_add(shgrp_geom_solid, final_bonemat, bone_color, hint_color);
@ -378,12 +397,16 @@ static void drw_shgroup_bone_point(
if (g_data.bone_point_wire == NULL) {
g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
}
if (g_data.bone_point_solid == NULL) {
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);
}
float final_bonemat[4][4];
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, final_bonemat, bone_color, hint_color);
if (g_data.bone_point_solid != NULL) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, final_bonemat, bone_color, hint_color);
}
if (outline_color[3] > 0.0f) {
DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, final_bonemat, outline_color);
}
@ -737,7 +760,7 @@ static void update_color(const Object *ob, const float const_color[4])
g_theme.const_color = const_color;
g_theme.const_wire = (
((ob->base_flag & BASE_SELECTED) ||
(arm->drawtype == ARM_WIRE)) ? 1.5f : 0.0f);
(arm->drawtype == ARM_WIRE)) ? 1.5f : ((g_data.transparent) ? 1.0f : 0.0f));
#define NO_ALPHA(c) (((c)[3] = 1.0f), (c))
@ -1901,12 +1924,12 @@ static void drw_shgroup_armature(Object *ob, DRWArmaturePasses passes, bool tran
memset(&g_color, 0x0, sizeof(g_color));
}
void DRW_shgroup_armature_object(Object *ob, ViewLayer *view_layer, DRWArmaturePasses passes)
void DRW_shgroup_armature_object(Object *ob, ViewLayer *view_layer, DRWArmaturePasses passes, bool transp)
{
float *color;
DRW_object_wire_theme_get(ob, view_layer, &color);
passes.bone_envelope = NULL; /* Don't do envelope distance in object mode. */
drw_shgroup_armature(ob, passes, false);
drw_shgroup_armature(ob, passes, transp);
draw_armature_pose(ob, color);
}

View File

@ -175,7 +175,7 @@ typedef struct DRWArmaturePasses {
struct DRWPass *relationship_lines;
} DRWArmaturePasses;
void DRW_shgroup_armature_object(struct Object *ob, struct ViewLayer *view_layer, struct DRWArmaturePasses passes);
void DRW_shgroup_armature_object(struct Object *ob, struct ViewLayer *view_layer, struct DRWArmaturePasses passes, bool transp);
void DRW_shgroup_armature_pose(struct Object *ob, struct DRWArmaturePasses passes, bool transp);
void DRW_shgroup_armature_edit(struct Object *ob, struct DRWArmaturePasses passes, bool transp);

View File

@ -32,6 +32,7 @@
/* *********** LISTS *********** */
typedef struct EDIT_ARMATURE_PassList {
struct DRWPass *bone_solid[2];
struct DRWPass *bone_transp[2];
struct DRWPass *bone_wire[2];
struct DRWPass *bone_outline[2];
struct DRWPass *bone_envelope[2];
@ -69,13 +70,14 @@ static void EDIT_ARMATURE_cache_init(void *vedata)
/* Alloc transient pointers */
stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
}
stl->g_data->transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
stl->g_data->transparent_bones = (draw_ctx->v3d->shading.type == OB_WIRE) ||
(draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
for (int i = 0; i < 2; ++i) {
/* Solid bones */
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
state |= (stl->g_data->transparent_bones) ? DRW_STATE_BLEND : DRW_STATE_WRITE_DEPTH;
psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state);
psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state | DRW_STATE_WRITE_DEPTH);
psl->bone_transp[i] = DRW_pass_create("Bone Transp Pass", state | DRW_STATE_BLEND);
/* Bones Outline */
state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
@ -110,16 +112,17 @@ static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob)
EDIT_ARMATURE_StorageList *stl = ((EDIT_ARMATURE_Data *)vedata)->stl;
int ghost = (ob->dtx & OB_DRAWXRAY) ? 1 : 0;
bool transp = (stl->g_data->transparent_bones || (ob->dt <= OB_WIRE));
DRWArmaturePasses passes = {
.bone_solid = psl->bone_solid[ghost],
.bone_solid = (transp) ? psl->bone_transp[ghost] : psl->bone_solid[ghost],
.bone_outline = psl->bone_outline[ghost],
.bone_wire = psl->bone_wire[ghost],
.bone_envelope = psl->bone_envelope[ghost],
.bone_axes = psl->bone_axes,
.relationship_lines = psl->relationship[ghost],
};
DRW_shgroup_armature_edit(ob, passes, stl->g_data->transparent_bones);
DRW_shgroup_armature_edit(ob, passes, transp);
}
}
}
@ -127,23 +130,17 @@ static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob)
static void EDIT_ARMATURE_draw_scene(void *vedata)
{
EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl;
EDIT_ARMATURE_StorageList *stl = ((EDIT_ARMATURE_Data *)vedata)->stl;
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
DRW_draw_pass(psl->bone_envelope[0]);
if (stl->g_data->transparent_bones) {
/* For performance reason, avoid blending on MS target. */
DRW_draw_pass(psl->bone_solid[0]);
}
/* For performance reason, avoid blending on MS target. */
DRW_draw_pass(psl->bone_transp[0]);
MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl);
if (!stl->g_data->transparent_bones) {
DRW_draw_pass(psl->bone_solid[0]);
}
DRW_draw_pass(psl->bone_solid[0]);
DRW_draw_pass(psl->bone_outline[0]);
DRW_draw_pass(psl->bone_wire[0]);
DRW_draw_pass(psl->relationship[0]);
@ -152,6 +149,7 @@ static void EDIT_ARMATURE_draw_scene(void *vedata)
if (!DRW_pass_is_empty(psl->bone_envelope[1]) ||
!DRW_pass_is_empty(psl->bone_solid[1]) ||
!DRW_pass_is_empty(psl->bone_transp[1]) ||
!DRW_pass_is_empty(psl->bone_outline[1]) ||
!DRW_pass_is_empty(psl->bone_wire[1]) ||
!DRW_pass_is_empty(psl->relationship[1]))
@ -163,6 +161,7 @@ static void EDIT_ARMATURE_draw_scene(void *vedata)
DRW_draw_pass(psl->bone_envelope[1]);
DRW_draw_pass(psl->bone_solid[1]);
DRW_draw_pass(psl->bone_transp[1]);
DRW_draw_pass(psl->bone_outline[1]);
DRW_draw_pass(psl->bone_wire[1]);
DRW_draw_pass(psl->relationship[1]);

View File

@ -3084,22 +3084,24 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
case OB_ARMATURE:
{
if ((v3d->flag2 & V3D_RENDER_OVERRIDE) ||
(v3d->overlay.flag & V3D_OVERLAY_HIDE_BONES))
(v3d->overlay.flag & V3D_OVERLAY_HIDE_BONES) ||
(ob->dt < OB_WIRE))
{
break;
}
bArmature *arm = ob->data;
if (arm->edbo == NULL) {
if (DRW_state_is_select() || !DRW_pose_mode_armature(ob, draw_ctx->obact)) {
bool is_wire = (v3d->shading.type == OB_WIRE) || (ob->dt <= OB_WIRE);
DRWArmaturePasses passes = {
.bone_solid = sgl->bone_solid,
.bone_solid = (is_wire) ? NULL : sgl->bone_solid,
.bone_outline = sgl->bone_outline,
.bone_wire = sgl->bone_wire,
.bone_envelope = sgl->bone_envelope,
.bone_axes = sgl->bone_axes,
.relationship_lines = NULL, /* Don't draw relationship lines */
};
DRW_shgroup_armature_object(ob, view_layer, passes);
DRW_shgroup_armature_object(ob, view_layer, passes, is_wire);
}
}
break;

View File

@ -42,6 +42,7 @@
typedef struct POSE_PassList {
struct DRWPass *bone_solid[2];
struct DRWPass *bone_transp[2];
struct DRWPass *bone_outline[2];
struct DRWPass *bone_wire[2];
struct DRWPass *bone_envelope[2];
@ -110,12 +111,14 @@ static void POSE_cache_init(void *vedata)
stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
}
POSE_PrivateData *ppd = stl->g_data;
ppd->transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
ppd->transparent_bones = (draw_ctx->v3d->shading.type == OB_WIRE) ||
(draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
for (int i = 0; i < 2; ++i) {
/* Solid bones */
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state);
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state | DRW_STATE_WRITE_DEPTH);
psl->bone_transp[i] = DRW_pass_create("Bone Transp Pass", state | DRW_STATE_BLEND);
/* Bones Outline */
state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
@ -196,16 +199,17 @@ static void POSE_cache_populate(void *vedata, Object *ob)
}
if (DRW_pose_mode_armature(ob, draw_ctx->obact)) {
int ghost = (ob->dtx & OB_DRAWXRAY) ? 1 : 0;
bool transp = (ppd->transparent_bones || (ob->dt <= OB_WIRE));
DRWArmaturePasses passes = {
.bone_solid = psl->bone_solid[ghost],
.bone_solid = (transp) ? psl->bone_transp[ghost] : psl->bone_solid[ghost],
.bone_outline = psl->bone_outline[ghost],
.bone_wire = psl->bone_wire[ghost],
.bone_envelope = psl->bone_envelope[ghost],
.bone_axes = psl->bone_axes,
.relationship_lines = psl->relationship[ghost],
};
DRW_shgroup_armature_pose(ob, passes, ppd->transparent_bones);
DRW_shgroup_armature_pose(ob, passes, transp);
}
}
else if (ob->type == OB_MESH &&
@ -275,19 +279,11 @@ static void POSE_draw_scene(void *vedata)
}
DRW_draw_pass(psl->bone_envelope[0]);
if (transparent_bones) {
DRW_pass_state_add(psl->bone_solid[0], DRW_STATE_BLEND);
DRW_pass_state_remove(psl->bone_solid[0], DRW_STATE_WRITE_DEPTH);
DRW_draw_pass(psl->bone_solid[0]);
}
DRW_draw_pass(psl->bone_transp[0]);
MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl);
if (!transparent_bones) {
DRW_draw_pass(psl->bone_solid[0]);
}
DRW_draw_pass(psl->bone_solid[0]);
DRW_draw_pass(psl->bone_outline[0]);
DRW_draw_pass(psl->bone_wire[0]);
DRW_draw_pass(psl->relationship[0]);
@ -295,6 +291,7 @@ static void POSE_draw_scene(void *vedata)
MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl);
if (!DRW_pass_is_empty(psl->bone_envelope[1]) ||
!DRW_pass_is_empty(psl->bone_transp[1]) ||
!DRW_pass_is_empty(psl->bone_solid[1]) ||
!DRW_pass_is_empty(psl->bone_outline[1]) ||
!DRW_pass_is_empty(psl->bone_wire[1]) ||
@ -312,6 +309,7 @@ static void POSE_draw_scene(void *vedata)
DRW_draw_pass(psl->bone_envelope[1]);
DRW_draw_pass(psl->bone_solid[1]);
DRW_draw_pass(psl->bone_transp[1]);
DRW_draw_pass(psl->bone_outline[1]);
DRW_draw_pass(psl->bone_wire[1]);
DRW_draw_pass(psl->relationship[1]);