I am just using a compute shader to get the transformed vertex positions of a skinned model and. It seems like there is something going on because the values change when I change the model uniform. I have normalized the bone weights of the vertices then get a copy them from the parts I need and take the information out except the position, bone IDs and weights.
float scale = 1;
//for (float half = 1; half > pow(2, -26); half /= 2) {
modelCompTrans.model =glm::translate(glm::mat4(1), glm::vec3(0, 0, 0)) * glm::scale(glm::mat4(1), glm::vec3(scale, scale, scale));
modelMems.CopyToInputStorageBuffer(0, modverts.data());
modelMems.CopyToInputUniformBuffer(2, &modelCompTrans);
uint32_t axisnum = (uint32_t)ceil((float)modverts.size() / 1000.0);
modelSim.bind(axisnum, 1, 1);
modelSim.compute();
std::vector<glm::vec4> outVerts;
outVerts.resize(modSize);
modelMems.CopyFromOutputBuffer(1, outVerts.data());
If I use a translation where X = 1
modverts[i].position.x - outVerts[i].x / outVerts[i].w
should be equal to 1
This is my compute shader:
#version 450
layout(local_size_x = 1000, local_size_y = 1, local_size_z = 1) in;
struct disVert {
vec4 position;
int boneIds[16];
float weights[16];
};
layout(std430, binding = 0) buffer inputBuffer {
disVert valuesIn[];
};
layout(std430, binding = 1) buffer outputBuffer {
vec4 outPosition[];
};
layout(binding = 2) uniform TRANS{
mat4 model;
int maxNum;
int padd[3];
mat4 bonematrices[160];
}trans;
void main(){
uint index = gl_LocalInvocationID.x + gl_WorkGroupID.x * 1000;
if (index < trans.maxNum){
vec4 totalPosition = vec4(0.0f);
bool cont = true;
int i = 0;
bool nhasBone = true;
while(i < 16 && cont){
if (valuesIn[index].boneIds[i] == -1){
cont = false;
}else{
nhasBone = false;
vec4 localPosition = trans.bonematrices[valuesIn[index].boneIds[i]] * valuesIn[index].position;
totalPosition += localPosition * valuesIn[index].weights[i];
}
i++;
}
if (nhasBone){
outPosition[index] = trans.model * valuesIn[index].position;
}else{
outPosition[index] = trans.model * totalPosition;
}
}
}