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:
2017-05-18 12:10:10 +02:00
parent 23f256b24b
commit 5dd9e17266
10 changed files with 31 additions and 39 deletions

View File

@@ -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);

View File

@@ -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;