DwM: Armature: Cleanup envelope bone code a bit.
Mainly adding 'wire' suffix to wire/distance drawing func and shader. Also, match wire vertex shader behavior with solid one regarding head/tail only drawing (i.e. alwas expect head bone mat, never tail one, and assume that if a radius is negative, then we only draw on the other end of the bone).
This commit is contained in:
parent
23f256b24b
commit
5dd9e17266
Notes:
blender-bot
2023-02-14 10:11:49 +01:00
Referenced by issue #51363, Armature: Bone Draw Type: Envelope
|
@ -159,7 +159,7 @@ static void DRW_shgroup_bone_envelope_distance(
|
|||
if (g_data.bone_envelope_distance == NULL) {
|
||||
struct Batch *geom = DRW_cache_bone_envelope_distance_outline_get();
|
||||
/* Note: bone_wire draw pass is not really working, think we need another one here? */
|
||||
g_data.bone_envelope_distance = shgroup_instance_bone_envelope(g_data.pass_bone_envelope, geom, g_data.ob->obmat);
|
||||
g_data.bone_envelope_distance = shgroup_instance_bone_envelope_wire(g_data.pass_bone_envelope, geom, g_data.ob->obmat);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(g_data.bone_envelope_distance, bone_mat, color, radius_head, radius_tail, distance);
|
||||
|
@ -171,7 +171,7 @@ static void DRW_shgroup_bone_envelope_solid(
|
|||
const float *radius_head, const float *radius_tail)
|
||||
{
|
||||
if (g_data.bone_envelope_solid == NULL) {
|
||||
struct Batch *geom = DRW_cache_bone_envelope_get();
|
||||
struct Batch *geom = DRW_cache_bone_envelope_solid_get();
|
||||
g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.pass_bone_solid, geom, g_data.ob->obmat);
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ static void DRW_shgroup_bone_envelope_wire(
|
|||
{
|
||||
if (g_data.bone_envelope_wire == NULL) {
|
||||
struct Batch *geom = DRW_cache_bone_envelope_wire_outline_get();
|
||||
g_data.bone_envelope_wire = shgroup_instance_bone_envelope(g_data.pass_bone_wire, geom, g_data.ob->obmat);
|
||||
g_data.bone_envelope_wire = shgroup_instance_bone_envelope_wire(g_data.pass_bone_wire, geom, g_data.ob->obmat);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(g_data.bone_envelope_wire, bone_mat, color, radius_head, radius_tail, distance);
|
||||
|
@ -196,7 +196,7 @@ static void DRW_shgroup_bone_envelope_head_wire(
|
|||
{
|
||||
if (g_data.bone_envelope_head_wire == NULL) {
|
||||
struct Batch *geom = DRW_cache_bone_envelope_head_wire_outline_get();
|
||||
g_data.bone_envelope_head_wire = shgroup_instance_bone_envelope(g_data.pass_bone_wire, geom, g_data.ob->obmat);
|
||||
g_data.bone_envelope_head_wire = shgroup_instance_bone_envelope_wire(g_data.pass_bone_wire, geom, g_data.ob->obmat);
|
||||
}
|
||||
|
||||
DRW_shgroup_call_dynamic_add(g_data.bone_envelope_head_wire, bone_mat, color, radius_head, radius_tail, distance);
|
||||
|
@ -974,7 +974,7 @@ static void draw_points(
|
|||
DRW_shgroup_bone_envelope_solid(eBone->disp_mat, col_solid_root,
|
||||
&eBone->rad_head, &envelope_ignore);
|
||||
DRW_shgroup_bone_envelope_head_wire(eBone->disp_mat, col_wire_root,
|
||||
&eBone->rad_head, &eBone->rad_tail, &eBone->dist);
|
||||
&eBone->rad_head, &envelope_ignore, &envelope_ignore);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_bone_point_solid(eBone->disp_mat, col_solid_root);
|
||||
|
@ -989,7 +989,7 @@ static void draw_points(
|
|||
DRW_shgroup_bone_envelope_solid(pchan->disp_mat, col_solid_root,
|
||||
&bone->rad_head, &envelope_ignore);
|
||||
DRW_shgroup_bone_envelope_head_wire(pchan->disp_mat, col_wire_root,
|
||||
&bone->rad_head, &bone->rad_tail, &bone->dist);
|
||||
&bone->rad_head, &envelope_ignore, &envelope_ignore);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_bone_point_solid(pchan->disp_mat, col_solid_root);
|
||||
|
@ -1005,19 +1005,11 @@ static void draw_points(
|
|||
}
|
||||
|
||||
if (is_envelope_draw) {
|
||||
const float *rad_tail, *dist;
|
||||
if (eBone) {
|
||||
rad_tail = &eBone->rad_tail;
|
||||
dist = &eBone->dist;
|
||||
}
|
||||
else {
|
||||
rad_tail = &pchan->bone->rad_tail;
|
||||
dist = &pchan->bone->dist;
|
||||
}
|
||||
const float *rad_tail = eBone ? &eBone->rad_tail : &pchan->bone->rad_tail;
|
||||
DRW_shgroup_bone_envelope_solid(
|
||||
BONE_VAR(eBone, pchan, disp_mat), col_solid_tail, &envelope_ignore, rad_tail);
|
||||
DRW_shgroup_bone_envelope_head_wire(
|
||||
BONE_VAR(eBone, pchan, disp_tail_mat), col_wire_tail, rad_tail, rad_tail, dist);
|
||||
BONE_VAR(eBone, pchan, disp_mat), col_wire_tail, &envelope_ignore, rad_tail, &envelope_ignore);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_bone_point_solid(BONE_VAR(eBone, pchan, disp_tail_mat), col_solid_tail);
|
||||
|
|
|
@ -1560,7 +1560,7 @@ static void benv_add_tri(VertexBuffer *vbo, uint pos_id, uint *v_idx, float *co1
|
|||
}
|
||||
}
|
||||
|
||||
Batch *DRW_cache_bone_envelope_get(void)
|
||||
Batch *DRW_cache_bone_envelope_solid_get(void)
|
||||
{
|
||||
#define CIRCLE_RESOL 32 /* Must be multiple of 4 */
|
||||
if (!SHC.drw_bone_envelope) {
|
||||
|
|
|
@ -82,7 +82,7 @@ struct Batch *DRW_cache_bone_octahedral_wire_outline_get(void);
|
|||
struct Batch *DRW_cache_bone_box_get(void);
|
||||
struct Batch *DRW_cache_bone_box_wire_outline_get(void);
|
||||
struct Batch *DRW_cache_bone_wire_wire_outline_get(void);
|
||||
struct Batch *DRW_cache_bone_envelope_get(void);
|
||||
struct Batch *DRW_cache_bone_envelope_solid_get(void);
|
||||
struct Batch *DRW_cache_bone_envelope_distance_outline_get(void);
|
||||
struct Batch *DRW_cache_bone_envelope_wire_outline_get(void);
|
||||
struct Batch *DRW_cache_bone_envelope_head_wire_outline_get(void);
|
||||
|
|
|
@ -293,9 +293,9 @@ DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct Batch *geom)
|
|||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope(DRWPass *pass, struct Batch *geom, float (*obmat)[4])
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_wire(DRWPass *pass, struct Batch *geom, float (*obmat)[4])
|
||||
{
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE);
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE_WIRE);
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom);
|
||||
DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
|
||||
|
|
|
@ -101,7 +101,7 @@ struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct Batch *geo
|
|||
struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope(struct DRWPass *pass, struct Batch *geom, float (*obmat)[4]);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_wire(struct DRWPass *pass, struct Batch *geom, float (*obmat)[4]);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, struct Batch *geom, float (*obmat)[4]);
|
||||
|
||||
int DRW_object_wire_theme_get(struct Object *ob, struct SceneLayer *sl, float **r_color);
|
||||
|
|
|
@ -171,8 +171,8 @@ data_to_c_simple(shaders/gpu_shader_instance_camera_vert.glsl SRC)
|
|||
data_to_c_simple(shaders/gpu_shader_instance_distance_line_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_geom.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_instance_bone_envelope_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_instance_bone_envelope_solid_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_instance_bone_envelope_wire_vert.glsl SRC)
|
||||
|
||||
data_to_c_simple(shaders/gpu_shader_3D_groundline_geom.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_groundpoint_vert.glsl SRC)
|
||||
|
|
|
@ -168,8 +168,8 @@ typedef enum GPUBuiltinShader {
|
|||
GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE,
|
||||
GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR,
|
||||
|
||||
GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE,
|
||||
GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE_SOLID,
|
||||
GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE_WIRE,
|
||||
|
||||
GPU_NUM_BUILTIN_SHADERS /* (not an actual shader) */
|
||||
} GPUBuiltinShader;
|
||||
|
|
|
@ -92,8 +92,8 @@ extern char datatoc_gpu_shader_instance_camera_vert_glsl[];
|
|||
extern char datatoc_gpu_shader_instance_distance_line_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_instance_edges_variying_color_geom_glsl[];
|
||||
extern char datatoc_gpu_shader_instance_edges_variying_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_instance_bone_envelope_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_instance_bone_envelope_solid_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_instance_bone_envelope_wire_vert_glsl[];
|
||||
|
||||
extern char datatoc_gpu_shader_3D_groundpoint_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_groundline_geom_glsl[];
|
||||
|
@ -789,10 +789,10 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|||
datatoc_gpu_shader_flat_color_frag_glsl,
|
||||
datatoc_gpu_shader_instance_edges_variying_color_geom_glsl},
|
||||
|
||||
[GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE] = { datatoc_gpu_shader_instance_bone_envelope_vert_glsl,
|
||||
datatoc_gpu_shader_flat_color_frag_glsl },
|
||||
[GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE_SOLID] = { datatoc_gpu_shader_instance_bone_envelope_solid_vert_glsl,
|
||||
datatoc_gpu_shader_simple_lighting_frag_glsl },
|
||||
datatoc_gpu_shader_simple_lighting_frag_glsl },
|
||||
[GPU_SHADER_3D_INSTANCE_BONE_ENVELOPE_WIRE] = { datatoc_gpu_shader_instance_bone_envelope_wire_vert_glsl,
|
||||
datatoc_gpu_shader_flat_color_frag_glsl },
|
||||
};
|
||||
|
||||
if (builtin_shaders[shader] == NULL) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
|
||||
/* This shader takes a 2D shape, puts it in 3D Object space such that is stays aligned with view and bone,
|
||||
* and scales head/tail/distance according to per-instance attributes
|
||||
* (and 'role' of current vertex, encoded in zw input, head or tail, and inner or outer for distance outline).
|
||||
* It is used for both the distance outline drawing, and the wire version of envelope bone. */
|
||||
/* This shader essentially operates in Object space, where it aligns given geometry with bone, scales it accordingly
|
||||
* to given radii, and then does usual basic solid operations.
|
||||
* Note that if one of head/tail radius is negative, it assumes it only works on the other end of the bone
|
||||
* (used to draw head/tail spheres). */
|
||||
|
||||
|
||||
uniform mat4 ViewMatrix;
|
||||
|
@ -28,11 +28,6 @@ flat out vec4 finalColor;
|
|||
|
||||
void main()
|
||||
{
|
||||
// gl_Position = ViewProjectionMatrix * ObjectModelMatrix * InstanceModelMatrix * vec4(pos.xyz, 1.0f);
|
||||
// normal = pos.xyz;
|
||||
// finalColor = color;
|
||||
// return;
|
||||
|
||||
/* We get head/tail in object space. */
|
||||
vec4 head = InstanceModelMatrix * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
vec4 tail = InstanceModelMatrix * vec4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
/* This shader takes a 2D shape, puts it in 3D Object space such that is stays aligned with view and bone,
|
||||
* and scales head/tail/distance according to per-instance attributes
|
||||
* (and 'role' of current vertex, encoded in zw input, head or tail, and inner or outer for distance outline).
|
||||
* It is used for both the distance outline drawing, and the wire version of envelope bone. */
|
||||
* It is used for both the distance outline drawing, and the wire version of envelope bone.
|
||||
* Note that if one of head/tail radius is negative, it assumes it only works on the other end of the bone
|
||||
* (used to draw head/tail spheres). */
|
||||
|
||||
|
||||
uniform mat4 ViewMatrix;
|
||||
|
@ -58,8 +60,11 @@ void main()
|
|||
head.xyz *= size;
|
||||
tail.xyz *= size;
|
||||
|
||||
float head_fac = pos.z; // == 0: head; == 1: tail; in-between: along bone.
|
||||
bool do_distance_offset = (pos.w != 0.0f);
|
||||
bool head_only = (radius_tail < 0.0f);
|
||||
bool tail_only = (radius_head < 0.0f);
|
||||
/* == 0: head; == 1: tail; in-between: along bone. */
|
||||
float head_fac = head_only ? 0.0f : (tail_only ? 1.0f : pos.z);
|
||||
bool do_distance_offset = (pos.w != 0.0f) && (distance >= 0.0f);
|
||||
|
||||
vec2 xy_pos = pos.xy;
|
||||
vec4 ob_pos;
|
Loading…
Reference in New Issue