Archived

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

H0rsen

OpenGL Realtime Skin deformation with OpenGL

Recommended Posts

Hi there! I would like to know if someone has already made a realtime skin deformation renderer in OpenGL, and know the code/theory behind it? I''ve been working on my own renderer for a few weeks now, and I can''t manage to have the correct result. I''ve made my own exporter plug-in for 3DS Max 4, and it works pretty well. I can get all the info I need in my renderer from my exported file (Skin, Bones, Weight etc...). But I think I don''t understand how to compute the correct transformations. I''ve read many papers, but they all stay very general and don''t help me much. For the moment I''m able to render correctly some very simple animations (a cylinder with 2 or 3 bones that controle it). But since I''m trying with a whole body and a dozen of bones, it doesn''t work any more. I should be missing something, but I''ve spent many hours trying to solve the probleme and I still don''t know what. I know there is a support for skin with DX. But how to do it with OpenGL ? Is there some kind of hardware acceleration for that ? I can post some parts of my code and some screen shots of what I get if needed. So if someone could answer my questions or send me an example, I would be very grateful.

Share this post


Link to post
Share on other sites
Not enough information.

The basic idea is to compute a matrix hierarchy, as in simple, non-skinned animation. Each bone gets a local matrix. You would then walk from the root through the hierarchy, push/pop and multiply matrices as you come along, and draw the individual body parts. That would be without skinning.

With skinning, you walk through the whole hierarchy, and do the matrix concatenation. But you don''t render anything, just save the matrices. Once done, you load all those intermediate matrices into constant vertex program registers. Be careful about the reference coordinate frame you use. Different approaches are possible here, but your matrices need some kind of common reference frame.

In the vertex program itself, you transform a vertex by all the matrices he has been assigned to, and weight the results accordingly. Here again, depending on your approach, you might have to compensate for your reference coordinate frame or bone origin.

quote:

I know there is a support for skin with DX. But how to do it with OpenGL ? Is there some kind of hardware acceleration for that ?


There are some dedicated extensions, but the best and most flexible way is to use a vertex shader (ARB_vertex_program).

quote:

I can post some parts of my code and some screen shots of what I get if needed.


That would be a good idea

Share this post


Link to post
Share on other sites
Yeah, thanx a lot for your answer!!

So I was completly wrong :/
I had already heard of vertex program, but never used it.
Now it''s ok, but I still got a few questions. I''ve found some example of skinning programs, but they are all for the NV extension. I tryed to translate it for the ARB, and this is what I get:

For the moment I only use one bone/vertex. If it works, it won''t be difficult to manage the other cases.
glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 4, TM[0] , TM[1] , TM[2] , TM[3] );
glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 5, TM[4] , TM[5] , TM[6] , TM[7] );
glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 6, TM[8] , TM[9] , TM[10], TM[11]);
glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 7, TM[12], TM[13], TM[14], TM[15]);
TM is the bone transformation matrix (in the same order as opengl matrix)

And now my vertex program:

!!ARBvp1.0

PARAM mvp[4]={state.matrix.mvp};
PARAM Matrix2[4] = { program.local[4..7] };
PARAM Pivot = program.local[8];

ATTRIB VertexInitCoord=vertex.position;

OUTPUT VertexFinalCoord=result.position;

TEMP r0, r1, r2;

#Transform the vertex to clip space.
DP4 r0.x, mvp[0], VertexInitCoord;
DP4 r0.y, mvp[1], VertexInitCoord;
DP4 r0.z, mvp[2], VertexInitCoord;
DP4 r0.w, mvp[3], VertexInitCoord;

SUB r2, r0, Pivot;

DP4 r1.x, Matrix2[4], r2;
DP4 r1.y, Matrix2[5], r2;
DP4 r1.z, Matrix2[6], r2;
DP4 r1.w, Matrix2[7], r2;

ADD r0, Pivot, r1;

MOV VertexFinalCoord, r0;

END

Of course it doesn''t work. I get nothing on the screen. When I remove the 4 last DP4 lines the model is back, but w/o animation.
I tryed to pass an identity matrix instead of the bone TM to the local parameter, but the screen stay black too. So I don''t what''s wrong :/

Share this post


Link to post
Share on other sites