1
\$\begingroup\$

I'm trying to animate multiple(3) entities using one model(IQM format).

It's working but performance is really bad because I'm calling animate function for each entity in my game loop (I think problem is there).

What's the best way to animate multiple entities (with different animation ofc) in OpenGL? I think I can try build one VBO / entity for better performances but I don't think it's the best way to do it.

\$\endgroup\$
1
\$\begingroup\$

You can do skinning using shaders in OpenGL. The IQM format is designed with this in mind. Upload the skinning matrices to a uniform and use the blend index and blend weight vertex arrays in the shader to do the skinning.

That way you only have to update the array of skinning matrices per entity you want to animate.

uniform mat4 SkinMatrix[256];
in vec4 att_BlendIndex;
in vec4 att_BlendWeight;

main() {
    vec4 p = vec4(0);
    p += SkinMatrix[int(att_BlendIndex.x)] * gl_Vertex * att_BlendWeight.x;
    p += SkinMatrix[int(att_BlendIndex.y)] * gl_Vertex * att_BlendWeight.y;
    p += SkinMatrix[int(att_BlendIndex.z)] * gl_Vertex * att_BlendWeight.z;
    p += SkinMatrix[int(att_BlendIndex.w)] * gl_Vertex * att_BlendWeight.w;
    gl_Position = gl_ModelViewProjectionMatrix * p;
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.