🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Basic Question on Animation

Started by
7 comments, last by GfxProgrammer 3 years, 9 months ago

Hi-

I have two meshes, each one represents a 3D graph of vertices. The first mesh represents one snapshot in time, the second is another point in time. I am looking to move every vertex in the first, towards its equivalent in the vertex position in the second mesh. A user clicks something to see the next mesh, and I then want to animate the points forwards and then backwards between the two.

I am unsure whether this is to be done with matrices, or where I should be computing the new positions of each vertex in a frame update. Normally I define my vertices and then call CreateBuffer. But it seems like calling CreateBuffer on every frame, to upload the new animated vertices would be expensive? Or is this how these things are done?

At the moment I am not using index buffers. I am purely writing out each triangle, creating the buffer and then simply rendering the buffer. Given I will need to change the location of each vertex, it seems like I should be doing this in the vertex shader, but I am not sure how to do that.

Thanks for any advice,

sp.

Advertisement

At the first try to make a very simple example of classic skeleton animation with skinning. Make a plane with two bones and export it to the Collada (.dae) file. When you make such example you will understand how matrices work. I made it a few days ago and it is not very complicated. You can study a basic theory by this video: OpenGL Skeletal Animation Tutorial #1

I do not use an index buffer too. I draw using glDrawArrays. I use WebGL and TypeScript. You can run my example in browser by one click here.

Hi-

Thanks for the response. Thanks for the tip here - I will check this tutorial out today.

Appreciated,

sp.

GfxProgrammer said:
I am looking to move every vertex in the first, towards its equivalent in the vertex position in the second mesh.

This is known as vertex animation, I guess officially it's morph target animation.

https://en.wikipedia.org/wiki/Morph_target_animation

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

For a simple animation, you can create a vertex definition with two sets of coordinates. Then in your vertex shader, you interpolate between them based on an animation time, which is passed as a uniform. Simple enough. The mesh data itself never changes; only the animation time does. Pseudo-code:

struct vertex_input {
  float3 pos1, pos2;
};

struct vertex_output {
  float3 pos;
};

uniform float animation_time;

void main(in vertex_input input, out vertex_output output) {
  output.pos = input.pos1 * (1.0 - animation_time) + input.pos2 * animation_time;
}

@a light breeze Thanks for this, this is very helpful. Still getting my head around some of the concepts, so this is helpful to see, thanks.

sp

a light breeze said:
void main(in vertex_input input, out vertex_output output) { output.pos = input.pos1 * (1.0 - animation_time) + input.pos2 * animation_time; }

All is correct but vertices normals (and maybe other attributes) should be interpolated as well. Morph is just an interpolation/blend, it's not related with bones and skeletal animation.

More details: you can use > 2 targets, sequentially or parallel, weight(s) (animation_time) can be negative (sometimes it produces interesrted results). The typical morph problem is a "linear effect" from target to target, ofteb it forces to use more intermediate targets

Thanks Tommato!

sp.

This topic is closed to new replies.

Advertisement