• Advertisement
Sign in to follow this  

GLSL Animation

This topic is 743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've succeed trying to animate mesh in immediate mode and now i'm trying to convert them to GLSL. But I got trouble animating it in GLSL.

It seems like the uniform matrix values are 0 which results the model in default reference pose.

 

This is the vertex shader:

#version 400 core

in vec3 GL_Vertex;
in vec2 GL_TexCoord;
in vec3 GL_Normal;
in int GL_Bone;

out vec2 GL_TexCoord0;

uniform mat4 m_Perspective, m_View, m_Model;
uniform mat2x4 m_QT[100];

vec3 Rotate_Vector(in vec4 q, in vec3 v)
{
    return v + 2.0*cross(cross(v, q.xyz) + q.w*v, q.xyz);
}

void main()
{
    vec4 q = vec4(m_QT[GL_Bone][0][0], m_QT[GL_Bone][0][1], m_QT[GL_Bone][0][2], m_QT[GL_Bone][0][3]);
    vec3 t = vec3(m_QT[GL_Bone][0][0], m_QT[GL_Bone][1][1], m_QT[GL_Bone][1][2]);
    vec3 vVertex = Rotate_Vector(q, GL_Vertex) + t;
    
    mat4 mModelView = m_View * m_Model;
    gl_Position = m_Perspective * mModelView * vec4(vVertex, 1.0);
    
    GL_TexCoord0 = GL_TexCoord;
}

I use quaternion and a vector translation and convert them to matrix 2x4 and send them to shader. Try to debug in GLSL like this:

if (vVertex == GL_Vertex) {
    vVertex = vec3(0.0, 0.0, 0.0);
}

It does not display anything which means the output of rotate_vector + t is 0. I assume the uniform matrix is 0.

 

I have checked the values before send them to shader, they are fine. I think there's something wrong with my code. Here is how I send the matrix to the shader:

Shader_LoadUniformMatrix2x4fv(iShader, "m_QT", pModel->iBone, GL_FALSE, &(pModel->pBone[0].m[0][0]));

I store the matrix in float m[2][4] array and the first row is the quaternion and the second row is the vector, and the column order is x, y, z, w.

Also when I buffer the vbo, I set it to GL_STATIC_DRAW.

 

Thanks before smile.png

Edited by DavidJr

Share this post


Link to post
Share on other sites
Advertisement

Okay I figured out that my bone index in vertex shader was corrupt and I got it fixed by changing it to float type and cast it to integer. The default position now is messed and still the vertex won't move and keeps staying in that strange position.

The black object is the animated object, it keeps in that shape whenever the frame changes.
Error.jpg

The black object should look like this
Correct.jpg

I'm kinda stuck here, please help.
Thank you so much

Edited by DavidJr

Share this post


Link to post
Share on other sites

Hey! I could get it working now! The problem is how I send the uniform is wrong, I change from matrix to 2 vec4 uniform.
Here is the way I send it atm:

float *pQuat, *pTrans;
// allocation and storing the value to pQuat and pTrans
Shader_LoadUniform4fv(CurrentShader, "GL_Q", pModel->iBone, &(pModel->pQuat[0]));
Shader_LoadUniform4fv(CurrentShader, "GL_T", pModel->iBone, &(pModel->pTrans[0]));

But I don't really like it, I like the way how I send before like this (the fQuat and fTrans are in Bone Struct):
float fQuat[4], fTrans[4];
// allocation and storing the value to fQuat and fTrans
Shader_LoadUniform4fv(CurrentShader, "GL_Q", pModel->iBone, &(pModel->pBone[0].fQuat[0]));
Shader_LoadUniform4fv(CurrentShader, "GL_T", pModel->iBone, &(pModel->pBone[0].fTrans[0]));

Any solution with the second one?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement