开发者

how to use VBO for morphing?

I want to have a mesh that can be animated. I'm loading mesh from a file, including key frames. I want to put all the frames into VBO and compose two of them on the GPU in a vertex shader. So i want to pass to frames to GPU and some uniform that will allow to create one result frame from these two

Is 开发者_高级运维it possible? If so, how can i do it?


You would just have more vertex attributes. Normally, you might have:

in vec3 position;
in vec3 normal;
in vec4 color;
in vec2 texCoord;

With morph targets, you would need:

in vec3 position0;
in vec3 position1;
in vec3 normal0;
in vec3 normal1;
in vec4 color;
in vec2 texCoord;

The actual model-space position would be a linear interpolation between position0 and position1. Same goes for the normal (I guess). Once you get them, you pass them through the usual transforms. The color and texture coordinates presumably don't change, but if they do, then they too need to have 0 and 1 versions.

The actual rendering is pretty simple. Presumably, you will have all the positions for the morph targets in the same buffer. So it's a matter of binding position0's attribute to the first morph target, and position1's attribute to the second morph target. Same goes for the normals. Then you render as normal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜