Imagination PowerVR SDK Blog

openGL es 2.0 skinning animaion on vertex shader


#1

hello you can help me ? me need base tutorial or source for skinning animation on vertex shader or help me fix me source





i have same source on openGL 2.0 ((((( me need on openGL es 2.0





code:


Code:

//
// GLSL vertex shader for skeletal animation
//

#define N     100
#define EPS   0.001

uniform vec4 boneQuat [N];
uniform vec4 bonePos [N];

//
// Quaternion multiplication
//

vec4 quatMul ( in vec4 q1, in vec4 q2 )
{
    vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );
    vec4 dt = q1 * q2;
    float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );

    return vec4 ( im, re );
}

//
// vector rotation via quaternion
//

vec4 quatRotate ( in vec3 p, in vec4 q )
{
    vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );
     
    return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
}

vec3 boneTransf ( int index, vec3 pos )
{
    return bonePos [index].xyz + quatRotate ( pos, boneQuat [index] ).xyz;
}

void     main ()
{
    vec4    weights = gl_MultiTexCoord3;        // weights for 4 bones
    vec3    pos     = vec3 ( 0.0 );
    int     index;

    if ( weights.x > EPS )                      // process 1st bone
    {                                           // get 1st bone index
        index = int ( gl_MultiTexCoord4.w );
        pos += weights.x * boneTransf ( index, gl_MultiTexCoord4.xyz );
    }

    if ( weights.y > EPS )                      // process 2nd bone
    {                                           // get 2nd bone index
        index = int ( gl_MultiTexCoord5.w );
        pos += weights.y * boneTransf ( index, gl_MultiTexCoord5.xyz );
    }

    if ( weights.z > EPS )                      // process 3rd bone
    {                                           // get 3rd bone index
        index = int ( gl_MultiTexCoord6.w );
        pos += weights.z * boneTransf ( index, gl_MultiTexCoord6.xyz );
    }

    if ( weights.w > EPS )                      // process 4th bone
    {                                           // get 4th bone index
        index = int ( gl_MultiTexCoord7.w );
        pos += weights.w * boneTransf ( index, gl_MultiTexCoord7.xyz );
    }

    gl_Position     = gl_ModelViewProjectionMatrix * vec4 ( pos, 1.0 );
    gl_TexCoord [0] = gl_MultiTexCoord0;
}



i see demos gremlin ( openGL es 2.0 ) if you use shaders for skinning animation in gremlin pleeeaaas give me source !



fnks for you support !idarkstranger2009-06-23 10:29:16

#2

All you have to do to make this shader GLSL ES compatible is to replace the built-in variables (except gl_Position) with your own uniforms (glMultiTexCoord# and gl_ModelViewProjectionMatrix) and varyings (gl_TexCoord[0]).





However, many OpenGL ES 2.0 implementations are limited to 128 uniform vec4s. You will have to significantly reduce the number of bones to make the shader work on these implementations.


#3

hi fnks for you answer


if you can fix my source plz fix


I only learn also in me to understand easier by a working example


After that I can analyze and use already received knowledge in other prolemmas))))


#4

There is a skinning training course in our SDK that you may want to look at. This works on mobile devices and PC emulation.