2012-05-10 13:06:49 +00:00
|
|
|
uniform mat4 mvp_mat;
|
2012-05-11 06:26:34 +00:00
|
|
|
uniform mat3 norm_mat;
|
2012-05-10 11:39:24 +00:00
|
|
|
uniform mat4 bonemats[80];
|
|
|
|
attribute vec4 vcolor;
|
|
|
|
attribute vec4 vweights;
|
|
|
|
attribute vec4 vbones;
|
|
|
|
attribute vec4 vtangent;
|
|
|
|
attribute vec3 vnormal;
|
2012-05-13 12:44:20 +00:00
|
|
|
attribute vec2 texcoord;
|
2012-05-11 10:17:21 +00:00
|
|
|
attribute vec3 vposition;
|
2012-05-10 11:39:24 +00:00
|
|
|
|
2012-05-11 12:56:34 +00:00
|
|
|
varying vec3 position;
|
2012-05-10 11:39:24 +00:00
|
|
|
varying vec3 bitangent;
|
|
|
|
varying vec3 tangent;
|
|
|
|
varying vec3 normal;
|
|
|
|
varying vec2 st;
|
|
|
|
varying vec4 color;
|
|
|
|
|
2012-05-11 23:19:15 +00:00
|
|
|
vec3
|
|
|
|
qmult (vec4 q, vec3 v)
|
|
|
|
{
|
|
|
|
float qs = q.w;
|
|
|
|
vec3 qv = q.xyz;
|
|
|
|
vec3 t = cross (qv, v);
|
|
|
|
return (qs * qs) * v + 2.0 * qs * t + dot (qv, v) * qv + cross (qv, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3
|
|
|
|
dqtrans (vec4 q0, vec4 qe)
|
|
|
|
{//2.0 * (q0.w * qe.xyz - qe.w * q0.xyz - cross (qe.xyz, q0.xyz));
|
|
|
|
float qs = q0.w, Ts = qe.w;
|
|
|
|
vec3 qv = -q0.xyz, Tv = qe.xyz;
|
|
|
|
|
|
|
|
return 2.0 * (Ts * qv + qs * Tv + cross (Tv, qv));
|
|
|
|
}
|
|
|
|
|
2012-05-10 11:39:24 +00:00
|
|
|
void
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
mat4 m;
|
|
|
|
vec4 q0, qe;
|
|
|
|
vec3 sh, sc, tr, v, n, t;
|
|
|
|
|
|
|
|
m = bonemats[int (vbones.x)] * vweights.x;
|
|
|
|
m += bonemats[int (vbones.y)] * vweights.y;
|
|
|
|
m += bonemats[int (vbones.z)] * vweights.z;
|
|
|
|
m += bonemats[int (vbones.w)] * vweights.w;
|
2012-05-12 10:14:07 +00:00
|
|
|
#if 0
|
2012-05-10 13:06:49 +00:00
|
|
|
q0 = m[0].yzwx; //swizzle for conversion betwen QF and GL
|
|
|
|
qe = m[1].yzwx; //swizzle for conversion betwen QF and GL
|
2012-05-10 11:39:24 +00:00
|
|
|
sh = m[2].xyz;
|
|
|
|
sc = m[3].xyz;
|
|
|
|
|
2012-05-10 13:06:49 +00:00
|
|
|
// extract translation from dual quaternion
|
2012-05-11 23:19:15 +00:00
|
|
|
tr = dqtrans (q0, qe);
|
2012-05-10 11:39:24 +00:00
|
|
|
// apply rotation and translation
|
2012-05-11 23:19:15 +00:00
|
|
|
v = qmult (q0, vposition) + tr;
|
2012-05-10 11:39:24 +00:00
|
|
|
// apply shear
|
|
|
|
v.z += v.y * sh.z + v.x * sh.y;
|
|
|
|
v.y += v.x * sh.x;
|
|
|
|
// apply scale
|
|
|
|
v *= sc;
|
|
|
|
// rotate normal (won't bother with shear or scale: not super accurate,
|
2012-05-11 23:19:15 +00:00
|
|
|
// but probably good enough)
|
|
|
|
n = qmult (q0, vnormal);
|
2012-05-10 11:39:24 +00:00
|
|
|
// rotate tangent (won't bother with shear or scale: not super accurate,
|
2012-05-11 23:19:15 +00:00
|
|
|
// but probably good enough)
|
|
|
|
t = qmult (q0, vtangent.xyz);
|
2012-05-12 10:14:07 +00:00
|
|
|
#else
|
2012-05-14 11:29:36 +00:00
|
|
|
mat3 nm = mat3 (m[0].xyz, m[1].xyz, m[2].xyz);
|
2012-05-12 10:14:07 +00:00
|
|
|
v = (m * vec4 (vposition, 1.0)).xyz;
|
2012-05-14 11:29:36 +00:00
|
|
|
n = nm * vnormal;
|
|
|
|
t = nm * vtangent.xyz;
|
2012-05-12 10:14:07 +00:00
|
|
|
#endif
|
2012-05-15 23:13:59 +00:00
|
|
|
position = v;
|
2012-05-11 06:26:34 +00:00
|
|
|
normal = norm_mat * n;
|
|
|
|
tangent = norm_mat * t;
|
2012-05-10 11:39:24 +00:00
|
|
|
bitangent = cross (normal, tangent) * vtangent.w;
|
|
|
|
color = vcolor;
|
|
|
|
st = texcoord;
|
2012-05-11 12:56:34 +00:00
|
|
|
gl_Position = mvp_mat * vec4 (position, 1.0);
|
2012-05-10 11:39:24 +00:00
|
|
|
}
|