Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/Cg/DualQuaternion_Common.cg @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

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