Friday, May 8, 2015

opengl - interpolating frames in a vertex shader


My models are stored as a set of meshes, each with a vertex list and normal list per key-frame, and indices for GL_TRIANGLES which is shared for all frames. Each frame I lerp between two adjacent key-frames to generate the vertices for that frame on the CPU and then draw it.


How can I move this into a GLSL vertex shader? Can a shader interpolate between two sets of vertices, and how can I store those vertices on the GPU?



Answer



This could be easy. You can send another informations then X,Y,Z position with your vertex. If you are not using one of color, normal or texture coord, you can use them for adding there your second vertex list XYZ. It is very common to use texture coords etc. to something different than what its name says. (dont forget to comment it to dont get confused another programmers...)


On vertex shader you can use mix function. It does linear interpolation between two values (or vectors) based on third value between 0-1. mix(vec1,vec2,mixValue).


If you dont have any free space in your vertex desc, use mutlitexturing coords. And if you dont have this either - or you dont want to use this. Make your second vertex list array of floats, send it to the gpu and use gl_InstanceID for addresing in this array. It is vertex id... or index if you want.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...