|
| 1 | +#version 150 |
| 2 | + |
| 3 | +mat2x4 blendTwoWeights(vec4 blendWgt, vec4 blendIdx, mat2x4 dualQuaternions[24]) |
| 4 | +{ |
| 5 | + mat2x4 blendDQ = blendWgt.x*dualQuaternions[int(blendIdx.x)]; |
| 6 | + blendDQ += blendWgt.y*dualQuaternions[int(blendIdx.y)]; |
| 7 | + |
| 8 | + return blendDQ; |
| 9 | +} |
| 10 | + |
| 11 | +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat2x4 dualQuaternions[24]) |
| 12 | +{ |
| 13 | + mat2x4 dq0 = dualQuaternions[int(blendIdx.x)]; |
| 14 | + mat2x4 dq1 = dualQuaternions[int(blendIdx.y)]; |
| 15 | + |
| 16 | + //Accurate antipodality handling. For speed increase, remove the following line, |
| 17 | + //though, the results will only be valid for rotations less than 180 degrees. |
| 18 | + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; |
| 19 | + |
| 20 | + mat2x4 blendDQ = blendWgt.x*dq0; |
| 21 | + blendDQ += blendWgt.y*dq1; |
| 22 | + |
| 23 | + return blendDQ; |
| 24 | +} |
| 25 | + |
| 26 | +mat2x4 blendThreeWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat2x4 dualQuaternions[24]) |
| 27 | +{ |
| 28 | + mat2x4 dq0 = dualQuaternions[int(blendIdx.x)]; |
| 29 | + mat2x4 dq1 = dualQuaternions[int(blendIdx.y)]; |
| 30 | + mat2x4 dq2 = dualQuaternions[int(blendIdx.z)]; |
| 31 | + |
| 32 | + //Accurate antipodality handling. For speed increase, remove the following line, |
| 33 | + //though, the results will only be valid for rotations less than 180 degrees. |
| 34 | + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; |
| 35 | + if (dot(dq0[0], dq2[0]) < 0.0) dq2 *= -1.0; |
| 36 | + |
| 37 | + mat2x4 blendDQ = blendWgt.x*dq0; |
| 38 | + blendDQ += blendWgt.y*dq1; |
| 39 | + blendDQ += blendWgt.z*dq2; |
| 40 | + |
| 41 | + return blendDQ; |
| 42 | +} |
| 43 | + |
| 44 | +mat2x4 blendFourWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat2x4 dualQuaternions[24]) |
| 45 | +{ |
| 46 | + mat2x4 dq0 = dualQuaternions[int(blendIdx.x)]; |
| 47 | + mat2x4 dq1 = dualQuaternions[int(blendIdx.y)]; |
| 48 | + mat2x4 dq2 = dualQuaternions[int(blendIdx.z)]; |
| 49 | + mat2x4 dq3 = dualQuaternions[int(blendIdx.w)]; |
| 50 | + |
| 51 | + //Accurate antipodality handling. For speed increase, remove the following line, |
| 52 | + //though, the results will only be valid for rotations less than 180 degrees. |
| 53 | + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; |
| 54 | + if (dot(dq0[0], dq2[0]) < 0.0) dq2 *= -1.0; |
| 55 | + if (dot(dq0[0], dq3[0]) < 0.0) dq3 *= -1.0; |
| 56 | + |
| 57 | + mat2x4 blendDQ = blendWgt.x*dq0; |
| 58 | + blendDQ += blendWgt.y*dq1; |
| 59 | + blendDQ += blendWgt.z*dq2; |
| 60 | + blendDQ += blendWgt.w*dq3; |
| 61 | + |
| 62 | + return blendDQ; |
| 63 | +} |
| 64 | + |
| 65 | +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ) |
| 66 | +{ |
| 67 | + vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); |
| 68 | + vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); |
| 69 | + blendPosition += trans; |
| 70 | + |
| 71 | + return blendPosition; |
| 72 | +} |
| 73 | + |
| 74 | +vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ) |
| 75 | +{ |
| 76 | + return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); |
| 77 | +} |
| 78 | + |
| 79 | +mat3 adjointTransposeMatrix(mat3 M) |
| 80 | +{ |
| 81 | + mat3 atM; |
| 82 | + atM[0][0] = M[2][2] * M[1][1] - M[1][2] * M[2][1]; |
| 83 | + atM[0][1] = M[1][2] * M[2][0] - M[1][0] * M[2][2]; |
| 84 | + atM[0][2] = M[1][0] * M[2][1] - M[2][0] * M[1][1]; |
| 85 | + |
| 86 | + atM[1][0] = M[0][2] * M[2][1] - M[2][2] * M[0][1]; |
| 87 | + atM[1][1] = M[2][2] * M[0][0] - M[0][2] * M[2][0]; |
| 88 | + atM[1][2] = M[2][0] * M[0][1] - M[0][0] * M[2][1]; |
| 89 | + |
| 90 | + atM[2][0] = M[1][2] * M[0][1] - M[0][2] * M[1][1]; |
| 91 | + atM[2][1] = M[1][0] * M[0][2] - M[1][2] * M[0][0]; |
| 92 | + atM[2][2] = M[0][0] * M[1][1] - M[1][0] * M[0][1]; |
| 93 | + |
| 94 | + return atM; |
| 95 | +} |
0 commit comments