|
| 1 | +#include "stdafx.h" |
| 2 | +#include "Common/Platform.hpp" |
| 3 | +#include "SkinXW_CPP.hpp" |
| 4 | +#ifdef _EDITOR |
| 5 | +#include "SkeletonX.h" |
| 6 | +#include "SkeletonCustom.h" |
| 7 | +#else |
| 8 | +#include "Animation/Bone.hpp" |
| 9 | +#include "Layers/xrRender/SkeletonXVertRender.h" |
| 10 | +#endif |
| 11 | + |
| 12 | +namespace XRay |
| 13 | +{ |
| 14 | +namespace Math |
| 15 | +{ |
| 16 | +void Skin1W_CPP(vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones) |
| 17 | +{ |
| 18 | + // return; |
| 19 | + // Prepare |
| 20 | + int U_Count = vCount / 8; |
| 21 | + vertBoned1W* V = S; |
| 22 | + vertBoned1W* E = V + U_Count * 8; |
| 23 | + |
| 24 | + // Unrolled loop |
| 25 | + for (; S != E;) |
| 26 | + { |
| 27 | + Fmatrix& M0 = Bones[S->matrix].mRenderTransform; |
| 28 | + M0.transform_tiny(D->P, S->P); |
| 29 | + M0.transform_dir(D->N, S->N); |
| 30 | + D->u = S->u; |
| 31 | + D->v = S->v; |
| 32 | + S++; |
| 33 | + D++; |
| 34 | + |
| 35 | + Fmatrix& M1 = Bones[S->matrix].mRenderTransform; |
| 36 | + M1.transform_tiny(D->P, S->P); |
| 37 | + M1.transform_dir(D->N, S->N); |
| 38 | + D->u = S->u; |
| 39 | + D->v = S->v; |
| 40 | + S++; |
| 41 | + D++; |
| 42 | + |
| 43 | + Fmatrix& M2 = Bones[S->matrix].mRenderTransform; |
| 44 | + M2.transform_tiny(D->P, S->P); |
| 45 | + M2.transform_dir(D->N, S->N); |
| 46 | + D->u = S->u; |
| 47 | + D->v = S->v; |
| 48 | + S++; |
| 49 | + D++; |
| 50 | + |
| 51 | + Fmatrix& M3 = Bones[S->matrix].mRenderTransform; |
| 52 | + M3.transform_tiny(D->P, S->P); |
| 53 | + M3.transform_dir(D->N, S->N); |
| 54 | + D->u = S->u; |
| 55 | + D->v = S->v; |
| 56 | + S++; |
| 57 | + D++; |
| 58 | + |
| 59 | + Fmatrix& M4 = Bones[S->matrix].mRenderTransform; |
| 60 | + M4.transform_tiny(D->P, S->P); |
| 61 | + M4.transform_dir(D->N, S->N); |
| 62 | + D->u = S->u; |
| 63 | + D->v = S->v; |
| 64 | + S++; |
| 65 | + D++; |
| 66 | + |
| 67 | + Fmatrix& M5 = Bones[S->matrix].mRenderTransform; |
| 68 | + M5.transform_tiny(D->P, S->P); |
| 69 | + M5.transform_dir(D->N, S->N); |
| 70 | + D->u = S->u; |
| 71 | + D->v = S->v; |
| 72 | + S++; |
| 73 | + D++; |
| 74 | + |
| 75 | + Fmatrix& M6 = Bones[S->matrix].mRenderTransform; |
| 76 | + M6.transform_tiny(D->P, S->P); |
| 77 | + M6.transform_dir(D->N, S->N); |
| 78 | + D->u = S->u; |
| 79 | + D->v = S->v; |
| 80 | + S++; |
| 81 | + D++; |
| 82 | + |
| 83 | + Fmatrix& M7 = Bones[S->matrix].mRenderTransform; |
| 84 | + M7.transform_tiny(D->P, S->P); |
| 85 | + M7.transform_dir(D->N, S->N); |
| 86 | + D->u = S->u; |
| 87 | + D->v = S->v; |
| 88 | + S++; |
| 89 | + D++; |
| 90 | + } |
| 91 | + |
| 92 | + // The end part |
| 93 | + vertBoned1W* E2 = V + vCount; |
| 94 | + for (; S != E2;) |
| 95 | + { |
| 96 | + Fmatrix& M = Bones[S->matrix].mRenderTransform; |
| 97 | + M.transform_tiny(D->P, S->P); |
| 98 | + M.transform_dir(D->N, S->N); |
| 99 | + D->u = S->u; |
| 100 | + D->v = S->v; |
| 101 | + S++; |
| 102 | + D++; |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +void Skin2W_CPP(vertRender* D, vertBoned2W* S, u32 vCount, CBoneInstance* Bones) |
| 107 | +{ |
| 108 | + // Prepare |
| 109 | + int U_Count = vCount; |
| 110 | + vertBoned2W* V = S; |
| 111 | + vertBoned2W* E = V + U_Count; |
| 112 | + Fvector P0, N0, P1, N1; |
| 113 | + |
| 114 | + // NON-Unrolled loop |
| 115 | + for (; S != E;) |
| 116 | + { |
| 117 | + if (S->matrix1 != S->matrix0) |
| 118 | + { |
| 119 | + Fmatrix& M0 = Bones[S->matrix0].mRenderTransform; |
| 120 | + Fmatrix& M1 = Bones[S->matrix1].mRenderTransform; |
| 121 | + M0.transform_tiny(P0, S->P); |
| 122 | + M0.transform_dir(N0, S->N); |
| 123 | + M1.transform_tiny(P1, S->P); |
| 124 | + M1.transform_dir(N1, S->N); |
| 125 | + D->P.lerp(P0, P1, S->w); |
| 126 | + D->N.lerp(N0, N1, S->w); |
| 127 | + D->u = S->u; |
| 128 | + D->v = S->v; |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + Fmatrix& M0 = Bones[S->matrix0].mRenderTransform; |
| 133 | + M0.transform_tiny(D->P, S->P); |
| 134 | + M0.transform_dir(D->N, S->N); |
| 135 | + D->u = S->u; |
| 136 | + D->v = S->v; |
| 137 | + } |
| 138 | + S++; |
| 139 | + D++; |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | + |
| 144 | +void Skin3W_CPP(vertRender* D, vertBoned3W* S, u32 vCount, CBoneInstance* Bones) |
| 145 | +{ |
| 146 | + // Prepare |
| 147 | + int U_Count = vCount; |
| 148 | + vertBoned3W* V = S; |
| 149 | + vertBoned3W* E = V + U_Count; |
| 150 | + Fvector P0, N0, P1, N1, P2, N2; |
| 151 | + |
| 152 | + // NON-Unrolled loop |
| 153 | + for (; S != E;) |
| 154 | + { |
| 155 | + Fmatrix& M0 = Bones[S->m[0]].mRenderTransform; |
| 156 | + Fmatrix& M1 = Bones[S->m[1]].mRenderTransform; |
| 157 | + Fmatrix& M2 = Bones[S->m[2]].mRenderTransform; |
| 158 | + |
| 159 | + M0.transform_tiny(P0, S->P); |
| 160 | + P0.mul(S->w[0]); |
| 161 | + M0.transform_dir(N0, S->N); |
| 162 | + N0.mul(S->w[0]); |
| 163 | + |
| 164 | + M1.transform_tiny(P1, S->P); |
| 165 | + P1.mul(S->w[1]); |
| 166 | + M1.transform_dir(N1, S->N); |
| 167 | + N1.mul(S->w[1]); |
| 168 | + |
| 169 | + M2.transform_tiny(P2, S->P); |
| 170 | + P2.mul(1.0f - S->w[0] - S->w[1]); |
| 171 | + M2.transform_dir(N2, S->N); |
| 172 | + N2.mul(1.0f - S->w[0] - S->w[1]); |
| 173 | + |
| 174 | + P0.add(P1); |
| 175 | + P0.add(P2); |
| 176 | + |
| 177 | + D->P = P0; |
| 178 | + |
| 179 | + N0.add(N1); |
| 180 | + N0.add(N2); |
| 181 | + |
| 182 | + D->N = N0; |
| 183 | + |
| 184 | + D->u = S->u; |
| 185 | + D->v = S->v; |
| 186 | + |
| 187 | + S++; |
| 188 | + D++; |
| 189 | + } |
| 190 | +} |
| 191 | + |
| 192 | + |
| 193 | +void Skin4W_CPP(vertRender* D, vertBoned4W* S, u32 vCount, CBoneInstance* Bones) |
| 194 | +{ |
| 195 | + // Prepare |
| 196 | + int U_Count = vCount; |
| 197 | + vertBoned4W* V = S; |
| 198 | + vertBoned4W* E = V + U_Count; |
| 199 | + Fvector P0, N0, P1, N1, P2, N2, P3, N3; |
| 200 | + |
| 201 | + // NON-Unrolled loop |
| 202 | + for (; S != E;) |
| 203 | + { |
| 204 | + Fmatrix& M0 = Bones[S->m[0]].mRenderTransform; |
| 205 | + Fmatrix& M1 = Bones[S->m[1]].mRenderTransform; |
| 206 | + Fmatrix& M2 = Bones[S->m[2]].mRenderTransform; |
| 207 | + Fmatrix& M3 = Bones[S->m[3]].mRenderTransform; |
| 208 | + |
| 209 | + M0.transform_tiny(P0, S->P); |
| 210 | + P0.mul(S->w[0]); |
| 211 | + M0.transform_dir(N0, S->N); |
| 212 | + N0.mul(S->w[0]); |
| 213 | + |
| 214 | + M1.transform_tiny(P1, S->P); |
| 215 | + P1.mul(S->w[1]); |
| 216 | + M1.transform_dir(N1, S->N); |
| 217 | + N1.mul(S->w[1]); |
| 218 | + |
| 219 | + M2.transform_tiny(P2, S->P); |
| 220 | + P2.mul(S->w[2]); |
| 221 | + M2.transform_dir(N2, S->N); |
| 222 | + N2.mul(S->w[2]); |
| 223 | + |
| 224 | + M3.transform_tiny(P3, S->P); |
| 225 | + P3.mul(1.0f - S->w[0] - S->w[1] - S->w[2]); |
| 226 | + M3.transform_dir(N3, S->N); |
| 227 | + N3.mul(1.0f - S->w[0] - S->w[1] - S->w[2]); |
| 228 | + |
| 229 | + P0.add(P1); |
| 230 | + P0.add(P2); |
| 231 | + P0.add(P3); |
| 232 | + |
| 233 | + D->P = P0; |
| 234 | + |
| 235 | + N0.add(N1); |
| 236 | + N0.add(N2); |
| 237 | + N0.add(N3); |
| 238 | + |
| 239 | + D->N = N0; |
| 240 | + |
| 241 | + D->u = S->u; |
| 242 | + D->v = S->v; |
| 243 | + |
| 244 | + S++; |
| 245 | + D++; |
| 246 | + } |
| 247 | +} |
| 248 | +} // namespace Math |
| 249 | +} // namespace XRay |
0 commit comments