1 | #version 120 |
---|
2 | |
---|
3 | //All of these functions are based on dqs.cg from http://isg.cs.tcd.ie/kavanl/dq/ |
---|
4 | /* dqs.cg |
---|
5 | |
---|
6 | Dual quaternion skinning vertex shaders (no shading computations) |
---|
7 | |
---|
8 | Version 1.0.3, November 1st, 2007 |
---|
9 | |
---|
10 | Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights |
---|
11 | Reserved |
---|
12 | |
---|
13 | This software is provided 'as-is', without any express or implied |
---|
14 | warranty. In no event will the author(s) be held liable for any damages |
---|
15 | arising from the use of this software. |
---|
16 | |
---|
17 | Permission is granted to anyone to use this software for any purpose, |
---|
18 | including commercial applications, and to alter it and redistribute it |
---|
19 | freely, subject to the following restrictions: |
---|
20 | |
---|
21 | 1. The origin of this software must not be misrepresented; you must not |
---|
22 | claim that you wrote the original software. If you use this software |
---|
23 | in a product, an acknowledgment in the product documentation would be |
---|
24 | appreciated but is not required. |
---|
25 | 2. Altered source versions must be plainly marked as such, and must not be |
---|
26 | misrepresented as being the original software. |
---|
27 | 3. This notice may not be removed or altered from any source distribution. |
---|
28 | |
---|
29 | Author: Ladislav Kavan, kavanl@cs.tcd.ie |
---|
30 | |
---|
31 | */ |
---|
32 | |
---|
33 | mat2x4 blendTwoWeights(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]) |
---|
34 | { |
---|
35 | mat2x4 blendDQ = blendWgt.x*mat2x4(dualQuaternions[int(blendIdx.x) * 2], dualQuaternions[int(blendIdx.x) * 2 + 1]); |
---|
36 | blendDQ += blendWgt.y*mat2x4(dualQuaternions[int(blendIdx.y) * 2], dualQuaternions[int(blendIdx.y) * 2 + 1]); |
---|
37 | |
---|
38 | return blendDQ; |
---|
39 | } |
---|
40 | |
---|
41 | mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]) |
---|
42 | { |
---|
43 | mat2x4 dq0 = mat2x4(dualQuaternions[int(blendIdx.x) * 2], dualQuaternions[int(blendIdx.x) * 2 + 1]); |
---|
44 | mat2x4 dq1 = mat2x4(dualQuaternions[int(blendIdx.y) * 2], dualQuaternions[int(blendIdx.y) * 2 + 1]); |
---|
45 | |
---|
46 | //Accurate antipodality handling. For speed increase, remove the following line, |
---|
47 | //though, the results will only be valid for rotations less than 180 degrees. |
---|
48 | if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; |
---|
49 | |
---|
50 | mat2x4 blendDQ = blendWgt.x*dq0; |
---|
51 | blendDQ += blendWgt.y*dq1; |
---|
52 | |
---|
53 | return blendDQ; |
---|
54 | } |
---|
55 | |
---|
56 | vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ) |
---|
57 | { |
---|
58 | vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); |
---|
59 | vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); |
---|
60 | blendPosition += trans; |
---|
61 | |
---|
62 | return blendPosition; |
---|
63 | } |
---|
64 | |
---|
65 | vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ) |
---|
66 | { |
---|
67 | return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|