Skip to content

Instantly share code, notes, and snippets.

@zeux
Last active February 2, 2018 05:26
Show Gist options
  • Select an option

  • Save zeux/66dca3fea5473f507589c9c53c9a44f3 to your computer and use it in GitHub Desktop.

Select an option

Save zeux/66dca3fea5473f507589c9c53c9a44f3 to your computer and use it in GitHub Desktop.
void transpose(disjoint Matrix4& target, const disjoint Matrix4& source)
{
for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) target.m[i][j] = source.m[j][i];
}
// this is a safe overload
void transpose(Matrix4& target, const Matrix4& source)
{
Matrix4 temp;
for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) temp.m[i][j] = source.m[j][i];
target = temp;
}
void prepare_skinning_data_for_gpu(disjoint Matrix4* cb, const disjoint Matrix4* world_transforms, const disjoint Matrix4* inv_bind_pose, size_t count)
{
for (size_t i = 0; i < count; ++i)
{
mul(cb[i], world_transforms[i], inv_bind_pose[i]);
// TODO: change shader compiler to not need this
transpose(cb[i], cb[i]);
}
}
void prepare_skinning_data_for_gpu_2(disjoint Matrix4* cb, const disjoint Matrix4* world_transforms, const disjoint Matrix4* inv_bind_pose, size_t count)
{
for (size_t i = 0; i < count; ++i)
{
// disjoint Matrix4 result; would be correct and not cause the issue in transpose below
disjoint Matrix4& result = cb[i];
mul(result, world_transforms[i], inv_bind_pose[i]);
// TODO: change shader compiler to not need this
transpose(cb[i], result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment