diff --git a/mesh.cpp b/mesh.cpp index 1d332dd..3b9f848 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -28,7 +28,7 @@ namespace vb01{ shapeKeyFactors = new float[numShapeKeys]; for(int i = 0; i < numShapeKeys; i++) - shapeKeyFactors[i] = 1; + shapeKeyFactors[i] = 0; } Mesh::~Mesh(){ @@ -102,9 +102,9 @@ namespace vb01{ glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, boneIndices))); glEnableVertexAttribArray(6); for(int i = 0; i < numShapeKeys; i++){ + glVertexAttribPointer(7 + i, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, shapeKeyOffsets) + 3 * i * sizeof(float))); + glEnableVertexAttribArray(7 + i); } - glVertexAttribPointer(7, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, shapeKeyOffsets))); - glEnableVertexAttribArray(7); } void Mesh::update(){ diff --git a/mesh.h b/mesh.h index e2c9ed0..22d87c7 100755 --- a/mesh.h +++ b/mesh.h @@ -19,8 +19,6 @@ namespace vb01{ struct Vertex{ Vector3 pos, norm, tan, biTan; Vector2 uv; - //Vector4 weights; - //float *weights=nullptr; float weights[4]{0, 0, 0, 0}; int boneIndices[4]{-1, -1, -1, -1}; Vector3 shapeKeyOffsets[100]; diff --git a/texture.vert b/texture.vert index b6cb69e..2bfcc49 100755 --- a/texture.vert +++ b/texture.vert @@ -15,7 +15,7 @@ layout (location=3) in vec3 aTan; layout (location=4) in vec3 aBiTan; layout (location=5) in vec4 aWeight; layout (location=6) in ivec4 aBoneIndices; -layout (location=7) in vec3[numShapeKeys] aShapeKeyOffsets; +layout (location=7) in vec3 aShapeKeyOffsets[numShapeKeys]; out vec3 fragPos; out vec3 norm; @@ -85,6 +85,9 @@ void main(){ if(aWeight[i] > 0) anyWeights = true; + for(int i = 0; i < numShapeKeys; i++){ + vertPos.xyz += aShapeKeyOffsets[i] * shapeKeyFactors[i]; + } if(animated && anyWeights){ for(int i = 0; i < numBones; i++){ transform[i] = createTranslationMatrix(bones[i].pos); @@ -111,9 +114,6 @@ void main(){ vertPos.xyz = v0; } - for(int i = 0; i < numShapeKeys; i++){ - vertPos.xyz += aShapeKeyOffsets[i] * shapeKeyFactors[i]; - } gl_Position = proj * view * model * vertPos; fragPos = vec3(model * vertPos);