Archived

This topic is now archived and is closed to further replies.

Ilici

Character Animation in Vertex Shader

Recommended Posts

recently i got an ideea: to improve speed by putting the character anim in the vertex shader so i dont have to calculate the interpolated values for every vertex myself. however coz i''m kinda new to vertex shaders with d3d, i was wondering how can i do that? can i tell the shader to interpolate vertex i from frame f with vertex i from frame f + 1? i looked at the sdk an i saw the vertex shader reference, but i didnt see anywhere how to access memory (vertex buffers) with shader code. like how would i write in shader code mov , [<base>+] like in normal assembly

Share this post


Link to post
Share on other sites
Hello,

Sure you can do vertex interpolation in a vertex shader. nVidia has a perfec example of this, using either Hermite or Linear interpolation. They make a vertex buffer for each frame and sends the from and the to buffer to the vertex shader and that''s it. Here you can take a look at it:
http://developer.nvidia.com/view.asp?IO=Keyframe_Interpolation

Regards,
Deficte

Share this post


Link to post
Share on other sites
You can''t make random memory accesses from a vertex shader, you can only operate on the data for a single vertex (along with the constant registers). So, what you need to do is to build a vertex type that contains multiple positions (1 per frame of animation). You can do that either by making a big vertex type that contains all the positions, or by using streams.

Share this post


Link to post
Share on other sites
But to really offload the CPU(Vertex interpolation is pretty cheap anyway to try and get rid of it alone, isn''t it?), you should also perform vertex skining inside of it.

Oops, I''ve just understood that you''re using keyframe interpolation and not model-skinning. As for the vertex shader, it''s going to be something like this(at least in OpenGL)
(v[0],v[1]-are two positions to interpolate between(you can feed them into different buffers,so that you have v[2],v[4] or whatever else e.t.c.

and c[10].x - is an interpol. percentage value(0..1), which you feed into the shader (10, but could again be any other value within the limits) (Sorry, as I''m thinking of it in realtime, no optimisations, but must be quite close anyway)
(res=v1+(v2-v1)*k)

ADD R0, -v[0],v[1];
MUL R1, R0, c[10].x;
ADD R0, v[0], R1;
//Now, transforming into clip space, where c[4]-c[7] - rows of
modelview * proj matrixes
DP4 o[HPOS].x,R0,c[4];
DP4 o[HPOS].y,R0,c[5];
DP4 o[HPOS].z,R0,c[6];
DP4 o[HPOS].w,R0,c[7];

//Don''t forget to output other parameters like tex_coords or color

MOV o[TEX0],v[2];
MOV o[COL0], v[COL0];

Phew, should work. Anyone, fix it if it has a mistake, I just wrote it here, not riped it from my code.

Share this post


Link to post
Share on other sites