diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-16 10:01:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-16 10:26:16 +0300 |
commit | c55fb58e8a4f1fd34d24deeed3a86b32e819d677 (patch) | |
tree | 1dc15258b9777e08cb3fc7805c00f60662c424d4 /source/blender/draw/intern | |
parent | 6aebb5a4d5f5c0866263b8507dbed460f60ba64f (diff) |
DRW: support clipping for envelope armature draw type
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_armature.c | 11 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 55 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 6 |
3 files changed, 44 insertions, 28 deletions
diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index 417132e6d2f..cab0872bc35 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -207,11 +207,12 @@ static void drw_shgroup_bone_stick( /* Envelope */ static void drw_shgroup_bone_envelope_distance( const float (*bone_mat)[4], - const float *radius_head, const float *radius_tail, const float *distance) + const float *radius_head, const float *radius_tail, const float *distance, + const eGPUShaderConfig sh_cfg) { if (g_data.passes.bone_envelope != NULL) { if (g_data.bone_envelope_distance == NULL) { - g_data.bone_envelope_distance = shgroup_instance_bone_envelope_distance(g_data.passes.bone_envelope); + g_data.bone_envelope_distance = shgroup_instance_bone_envelope_distance(g_data.passes.bone_envelope, sh_cfg); /* passes.bone_envelope should have the DRW_STATE_CULL_FRONT state enabled. */ } float head_sphere[4] = {0.0f, 0.0f, 0.0f, 1.0f}, tail_sphere[4] = {0.0f, 1.0f, 0.0f, 1.0f}; @@ -244,12 +245,12 @@ static void drw_shgroup_bone_envelope( 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); + g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire, sh_cfg); } 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); + g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.passes.bone_solid, g_data.transparent, sh_cfg); /* We can have a lot of overdraw if we don't do this. Also envelope are not subject to * inverted matrix. */ DRW_shgroup_state_enable(g_data.bone_envelope_solid, DRW_STATE_CULL_BACK); @@ -1332,7 +1333,7 @@ static void draw_bone_envelope( (boneflag & BONE_NO_DEFORM) == 0 && ((boneflag & BONE_SELECTED) || (eBone && (boneflag & (BONE_ROOTSEL | BONE_TIPSEL))))) { - drw_shgroup_bone_envelope_distance(BONE_VAR(eBone, pchan, disp_mat), rad_head, rad_tail, distance); + drw_shgroup_bone_envelope_distance(BONE_VAR(eBone, pchan, disp_mat), rad_head, rad_tail, distance, sh_cfg); } if (select_id != -1) { diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 9a7f69c5e58..b5141fa0af1 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -625,13 +625,16 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass) return grp; } -DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass) +DRWShadingGroup *shgroup_instance_bone_envelope_outline(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_envelope_outline == NULL) { - sh_data->bone_envelope_outline = DRW_shader_create( - datatoc_armature_envelope_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_envelope_outline = GPU_shader_create_from_arrays({ + .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_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_envelope_outline, { @@ -646,17 +649,22 @@ DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass) pass, DRW_cache_bone_envelope_outline_get(), g_formats.instance_bone_envelope_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; } -DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass) +DRWShadingGroup *shgroup_instance_bone_envelope_distance(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_envelope_distance == NULL) { - sh_data->bone_envelope_distance = DRW_shader_create( - datatoc_armature_envelope_solid_vert_glsl, NULL, - datatoc_armature_envelope_distance_frag_glsl, NULL); + const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; + sh_data->bone_envelope_distance = GPU_shader_create_from_arrays({ + .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_solid_vert_glsl, NULL}, + .frag = (const char *[]){datatoc_armature_envelope_distance_frag_glsl, NULL}, + .defs = (const char *[]){sh_cfg_data->def, NULL}, + }); } DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, { @@ -669,17 +677,22 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass) sh_data->bone_envelope_distance, pass, DRW_cache_bone_envelope_solid_get(), g_formats.instance_bone_envelope_distance); - + 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_envelope_solid(DRWPass *pass, bool transp) +DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp, 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_envelope == NULL) { - sh_data->bone_envelope = DRW_shader_create( - datatoc_armature_envelope_solid_vert_glsl, NULL, - datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n"); + const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; + sh_data->bone_envelope = GPU_shader_create_from_arrays({ + .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_solid_vert_glsl, NULL}, + .frag = (const char *[]){datatoc_armature_envelope_solid_frag_glsl, NULL}, + .defs = (const char *[]){sh_cfg_data->def, NULL}, + }); } DRW_shgroup_instance_format(g_formats.instance_bone_envelope, { @@ -695,7 +708,9 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp pass, DRW_cache_bone_envelope_solid_get(), g_formats.instance_bone_envelope); DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f); - + if (sh_cfg == GPU_SHADER_CFG_CLIPPED) { + DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d); + } return grp; } @@ -789,7 +804,7 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid( DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp, 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_sphere == NULL) { const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; sh_data->bone_sphere = GPU_shader_create_from_arrays({ @@ -818,7 +833,7 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp, DRWShadingGroup *shgroup_instance_bone_sphere_outline(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_sphere_outline == NULL) { const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; sh_data->bone_sphere_outline = GPU_shader_create_from_arrays({ diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 113369839dd..892c4ea01f9 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -143,9 +143,9 @@ struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, st 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_envelope_distance(struct DRWPass *pass); -struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass); -struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp); +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); 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, eGPUShaderConfig sh_cfg); |