Jump to content
  • Advertisement
Sign in to follow this  
SapphireStorm

GLSL Skeletal Animation Shader

This topic is 2571 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

Does this skeletal animation shader make sense?


uniform mat4 u_WorldView;
uniform mat4 u_WorldViewProjection;
uniform mat4 u_BoneTransform[128];

in vec3 in_Position;
in vec3 in_Normal;
in vec2 in_TexCoords;
in int in_BoneID[4];
in vec4 in_Weights;

out vec3 v_ViewSpacePosition;
out vec3 v_VertexToLight;
out vec3 v_Normal;
out vec2 v_TexCoords;

void main(void)
{
// Transform the vertex information based on bones.
vec3 position = (in_Weights[0] * (u_BoneTransform[ in_BoneID[0] ] * vec4(in_Position, 0.0)).xyz) +
(in_Weights[1] * (u_BoneTransform[ in_BoneID[1] ] * vec4(in_Position, 0.0)).xyz) +
(in_Weights[2] * (u_BoneTransform[ in_BoneID[2] ] * vec4(in_Position, 0.0)).xyz) +
(in_Weights[3] * (u_BoneTransform[ in_BoneID[3] ] * vec4(in_Position, 0.0)).xyz);

vec3 normal = (in_Weights[0] * (u_BoneTransform[ in_BoneID[0] ] * vec4(in_Normal, 0.0)).xyz) +
(in_Weights[1] * (u_BoneTransform[ in_BoneID[1] ] * vec4(in_Normal, 0.0)).xyz) +
(in_Weights[2] * (u_BoneTransform[ in_BoneID[2] ] * vec4(in_Normal, 0.0)).xyz) +
(in_Weights[3] * (u_BoneTransform[ in_BoneID[3] ] * vec4(in_Normal, 0.0)).xyz);

// The normal graphic's pipeline transform.
gl_Position = u_WorldViewProjection * vec4( position, 1.0 );

// Only take to view space
v_Normal = ( normalize( u_WorldView * vec4(normal, 0.0) ) ).xyz;

.
.
.


If you need any other information, let me know.

I have never done skeletal animation before and my current attempt does not work. I can load and render my models fine with just a phong shader. However, this vertex shader does not transform anything based on the bones. It just outputs the models in their default pose as if I was only transforming vertices by world, view, and projection matrices.

I'm just trying to narrow down the possibilities of what is wrong in my code at the moment. It is also probable I'm not handling my skeletal and animation data correctly on the CPU side.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I detected one bug. You need to transform positions with w=1 instead of 0, else you would not translate the position. This is not necessary for normals (needed only to be rotated).


// Transform the vertex information based on bones.
vec3 position = (in_Weights[0] * (u_BoneTransform[ in_BoneID[0] ] * vec4(in_Position, 1.0)).xyz) +
(in_Weights[1] * (u_BoneTransform[ in_BoneID[1] ] * vec4(in_Position, 1.0)).xyz) +
(in_Weights[2] * (u_BoneTransform[ in_BoneID[2] ] * vec4(in_Position, 1.0)).xyz) +
(in_Weights[3] * (u_BoneTransform[ in_BoneID[3] ] * vec4(in_Position, 1.0)).xyz);



The rest looks ok.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!