diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-07-30 15:17:53 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-07-30 15:18:55 +0300 |
commit | 6c6ecdd2306b9680ac171b9b80d4a9911fdb8a19 (patch) | |
tree | 188d055fa6db67bda24b4de4b95561d84e95e70c /source/blender/draw/modes | |
parent | 5a05683da1a9fd43cd611fe62f675ddafc8ba3d0 (diff) |
Armature: Fix bone always transparent when enabling MSAA
Diffstat (limited to 'source/blender/draw/modes')
5 files changed, 29 insertions, 20 deletions
diff --git a/source/blender/draw/modes/edit_armature_mode.c b/source/blender/draw/modes/edit_armature_mode.c index 285e703afbf..1e8293b5dbb 100644 --- a/source/blender/draw/modes/edit_armature_mode.c +++ b/source/blender/draw/modes/edit_armature_mode.c @@ -60,7 +60,7 @@ typedef struct EDIT_ARMATURE_Data { /* *********** STATIC *********** */ typedef struct EDIT_ARMATURE_PrivateData { - char pad; /* UNUSED */ + bool transparent_bones; } EDIT_ARMATURE_PrivateData; /* Transient data */ /* *********** FUNCTIONS *********** */ @@ -69,15 +69,18 @@ static void EDIT_ARMATURE_cache_init(void *vedata) { EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl; EDIT_ARMATURE_StorageList *stl = ((EDIT_ARMATURE_Data *)vedata)->stl; + const DRWContextState *draw_ctx = DRW_context_state_get(); if (!stl->g_data) { /* Alloc transient pointers */ - stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__); + 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; { /* Solid bones */ - DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK; + 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 = DRW_pass_create("Bone Solid Pass", state); } @@ -116,10 +119,12 @@ static void EDIT_ARMATURE_cache_init(void *vedata) static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob) { bArmature *arm = ob->data; - EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl; if (ob->type == OB_ARMATURE) { if (arm->edbo) { + EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl; + EDIT_ARMATURE_StorageList *stl = ((EDIT_ARMATURE_Data *)vedata)->stl; + DRWArmaturePasses passes = { .bone_solid = psl->bone_solid, .bone_outline = psl->bone_outline, @@ -128,7 +133,7 @@ static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob) .bone_axes = psl->bone_axes, .relationship_lines = psl->relationship, }; - DRW_shgroup_armature_edit(ob, passes); + DRW_shgroup_armature_edit(ob, passes, stl->g_data->transparent_bones); } } } @@ -136,22 +141,20 @@ 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(); - 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); + if (stl->g_data->transparent_bones) { + /* For performance reason, avoid blending on MS target. */ DRW_draw_pass(psl->bone_solid); } MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl) - if (!transparent_bones) { + if (!stl->g_data->transparent_bones) { DRW_draw_pass(psl->bone_solid); } diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c index 040195b889b..7a4abcac179 100644 --- a/source/blender/draw/modes/pose_mode.c +++ b/source/blender/draw/modes/pose_mode.c @@ -75,6 +75,7 @@ typedef struct POSE_PrivateData { DRWShadingGroup *bone_selection_invert_shgrp; float blend_color[4]; float blend_color_invert[4]; + bool transparent_bones; } POSE_PrivateData; /* Transient data */ static struct { @@ -112,9 +113,10 @@ static void POSE_cache_init(void *vedata) if (!stl->g_data) { /* Alloc transient pointers */ - stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__); + 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; { /* Solid bones */ @@ -195,7 +197,7 @@ static bool POSE_is_driven_by_active_armature(Object *ob) static void POSE_cache_populate(void *vedata, Object *ob) { POSE_PassList *psl = ((POSE_Data *)vedata)->psl; - POSE_StorageList *stl = ((POSE_Data *)vedata)->stl; + POSE_PrivateData *ppd = ((POSE_Data *)vedata)->stl->g_data; const DRWContextState *draw_ctx = DRW_context_state_get(); /* In the future this will allow us to implement face gizmos, @@ -214,7 +216,7 @@ static void POSE_cache_populate(void *vedata, Object *ob) .bone_axes = psl->bone_axes, .relationship_lines = psl->relationship, }; - DRW_shgroup_armature_pose(ob, passes); + DRW_shgroup_armature_pose(ob, passes, ppd->transparent_bones); } } else if (ob->type == OB_MESH && @@ -224,10 +226,10 @@ static void POSE_cache_populate(void *vedata, Object *ob) struct GPUBatch *geom = DRW_cache_object_surface_get(ob); if (geom) { if (POSE_is_driven_by_active_armature(ob)) { - DRW_shgroup_call_object_add(stl->g_data->bone_selection_shgrp, geom, ob); + DRW_shgroup_call_object_add(ppd->bone_selection_shgrp, geom, ob); } else { - DRW_shgroup_call_object_add(stl->g_data->bone_selection_invert_shgrp, geom, ob); + DRW_shgroup_call_object_add(ppd->bone_selection_invert_shgrp, geom, ob); } } } diff --git a/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl index b20656ff326..78b29296601 100644 --- a/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl +++ b/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl @@ -1,4 +1,6 @@ +uniform float alpha = 0.6; + flat in vec3 finalStateColor; flat in vec3 finalBoneColor; in vec3 normalView; @@ -12,5 +14,5 @@ void main() float n = normalize(normalView).z; float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0); fragColor.rgb = mix(finalStateColor, finalBoneColor, fac); - fragColor.a = 0.6; /* Hardcoded transparency factor. */ + fragColor.a = alpha; } diff --git a/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl index 89f4d97f29b..45748bf5644 100644 --- a/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl +++ b/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl @@ -1,9 +1,11 @@ +uniform float alpha = 0.6; + in vec4 finalColor; out vec4 fragColor; void main() { - fragColor = vec4(finalColor.rgb, 0.6); /* Hardcoded transparency factor. */ + fragColor = vec4(finalColor.rgb, alpha); } diff --git a/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl index 3c80f629d79..a0fdd55931f 100644 --- a/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl +++ b/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl @@ -3,6 +3,7 @@ uniform mat4 ViewMatrixInverse; uniform mat4 ProjectionMatrix; +uniform float alpha = 0.4; flat in vec3 finalStateColor; flat in vec3 finalBoneColor; @@ -73,8 +74,7 @@ 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. */ - /* Hardcoded transparency factor. Less than shape to be less distractive. */ - fragColor = vec4(fragColor.rgb + dither, 0.4); + fragColor = vec4(fragColor.rgb + dither, alpha); t /= ray_len; gl_FragDepth = get_depth_from_view_z(ray_dir_view.z * t + ray_ori_view.z); |