2
\$\begingroup\$

I am trying to get shadowmapping right for my animated models. It works perfectly for static meshes but the animated models are just wiggeling a bit

here's the vertex shader for rendering to the depth texture:

#version 400 core


in vec4 inputPosition;
in vec3 inputNormal;
in vec2 inputTexCoord;
in vec4 weights;
in vec4 joint_index;


uniform mat4 bone_matrix[65];
uniform int animate;
uniform mat4 depthMVP;



void main(){
    vec4 pos = inputPosition;

    if(animate != 0) {

        pos = vec4(0);
        vec4 post = inputPosition;

        for(int i=0;i<4;i++) {
            if(weights[i]>0) {

                pos += (bone_matrix[int(joint_index[i])] * post) * weights[i];

            }
        }

    } 

    gl_Position = depthMVP*vec4(pos.xyz, 1);

}

The animation works fine in the second pass but during the first using the vertex shader above the model vertices don't get transformed instead the whole model rotates a little so i get a depth texture with my model in binding pose rotating around the y-axis a little. Weird because i use the exact same bone transformation code as in the second pass shader. So i'm wondering am i missing something crucial in the vertex shader above

\$\endgroup\$
2
  • \$\begingroup\$ Maybe you could provide images about this "wiggeling" action, I bet that will speed up responses. \$\endgroup\$
    – Katu
    May 23, 2015 at 19:49
  • \$\begingroup\$ @Katu Thanks for the suggestion. I'll expand a bit. The animation works fine in the second pass but during the first using the vertex shader above the model vertices don't get transformed instead the whole model rotates a little so i get a depth texture with my model in binding pose rotating around the y-axis a little. Weird because i use the exact same bone transformation code as in the second pass shader. So i'm wondering am i missing something crucial in the vertex shader above. \$\endgroup\$
    – rudy
    May 24, 2015 at 15:04

1 Answer 1

3
\$\begingroup\$

Ok i found the problem. It came down to my misconception of when to call glBindAttribLocation. Changes made with glBindAttribLocation will only take effect after calling glLinkProgram. It hadn't been a problem before but in this particular case it got me.

For those on the same rocky path as me i found that the shadows of my animated models were scaled wrong. I'm using the astroBoy_walk_Max.dae file from the skeletal animation collada tutorial. The model seems to have a scale of 0.01f so i added a multiplication and a uniform to the depth vertex shader which now looks like this:

#version 400

layout (location = 0) in vec4 inputPosition;
layout (location = 1) in vec3 inputNormal;
layout (location = 2) in vec2 inputTexCoord;
layout (location = 3) in vec4 weights;
layout (location = 4) in vec4 joint_index;


uniform float scale;
uniform mat4 depthMVP;
uniform int animate;
uniform mat4 bone_matrix[65];

void main(){
    vec4 pos = inputPosition;

    if(animate == 1) {
        pos = vec4(0, 0, 0, 1);
        vec4 post = inputPosition;

        for(int i=0;i<4;i++) {
            if(weights[i]>0) {
                pos += (bone_matrix[int(joint_index[i])] * scale * post) * weights[i];
            }
        }
    }

    gl_Position = depthMVP*pos;

}

scale = 1.0f / model_scale

\$\endgroup\$
1
  • \$\begingroup\$ If you elaborate on the mistake you made and what difference is made in the solution, the answer will be helpful for other people reading this site. The core purpose of a SX site is not necessarily helping you, but helping others with similiar problems down the line. \$\endgroup\$ May 25, 2015 at 7:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .