Re: [osg-users] Animation Instancing/ Skinned Instancing with osg?

24 views
Skip to first unread message

Jan Ciger

unread,
Jan 15, 2010, 12:21:04 PM1/15/10
to M. Moser, osg-...@lists.openscenegraph.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello M.Moser (Markus? Martin?)

On 2010-01-15 17:02, M. Moser wrote:
> Hey Guys, (hey Jan)
>
> we are a team of students from the university of applied science Düsseldorf
> (Germany), studying virtual reality.
>
> In our current project we have the need to display hunderd of animated
> models ... it's an ant-swarm simulation.
> We are using osgCal (cal3D) to import the animated models, and up to this
> its working fine.
>
> But the more animated models we add, the more the framerate drops... this is
> (probably) because the updateTime of more animations needs more time.
> So the question is, if it's somehow possible in OSG / osgCal to instanciate
> animations?
>
> We know that geomety instancing is possible, but for some reason we are not
> able to get it work with animated models..

Aha, I see. Well, the reason is obvious - geometry instancing and
"animation instancing" are two very different things, with geometry
being instanced by the GPU and animation state is completely on the CPU.

Assuming that by "animation instancing" you mean several copies of the
model (ant) sharing the same animation state over the screen to save the
animation computations (mainly the skinning calculations), I have two
news for you:

- - the bad one - osgCal is not designed for this case and will not do
what you want no matter how you massage it.

- - the good one - the solution is not difficult, but you will need to dig
a bit deeper.

Years ago I have done something similar - I had about 2000 animated
models (the Cal3D skeletons) marching on the screen using OSG. This was
without Cal3D though.

First, you will either need to modify osgCal2 (I am not familiar with
osgCal, which was actually forked and relicensed from the original code)
or to make your own OpenGL rendering code for the Cal3D models. It is
not difficult - take the demo application that comes with Cal3D as an
example, or look how osgCal2 does it when not using shaders for skinning.

Basically Cal3D loads the model, calculates the bone positions from the
active animations, blends them and then calculates the corresponding
deformations of the skin. You get the skin as a mesh (vertices organized
into triangles + normals + texture coords) that is ready to be fed into
an OpenGL vertex array or (easier) osg::Geometry instance. This will
display one model.

Now, if you want to instance the animation, just create several
osg::AttitudePositionTransform-s to put the cloned ants in different
places and attach this single osg::Geometry as a child (i.e. all the
transforms with share the *same* geometry sub-node). The difference from
using osgCal node is that osgCal attaches a separate copy of the Cal3D
model behind each copy of the geometry - which is not what you want.

Second consideration - I strongly advise you to define 2-3 levels of
detail for your meshes and use osg::LOD or osg::Switch nodes to manage
the levels of detail. Without that you will likely not be able to scale
the number of ants beyond few thousands unless you use very simple
(ugly) models. Ideally, use the impostors as the last LOD level - when
the camera is far away, the object gets changed to a non-animated (or
only once in a while updated) 2D quad with a texture. OSG has an
impostor node and it works quite well - you can get easily 100 000
impostors on the screen like that. See the osg examples for this.

Third consideration - you can use also geometry instancing to further
save triangles, which wasn't available when I did this originally - look
at the OSG examples at how to do it. With the geometry instancing
extensions, the GPU will do the mesh copying for you, saving fill rate.

Fourth consideration - with Cal3D, you will spend most of the time in
the skinning part (deformation of the skin mesh to conform with the
position of the internal, invisible, bones). Realize that skinning means
at least one extra matrix multiplication per vertex of your mesh to
deform it from the basic (binding) posture. With a large mesh, it
quickly adds up.

If you have a model like the ant that does not really need skinning
(ants have exoskeleton!), you can avoid that calculation by calling the
parts of the Cal3D update function by hand and skipping the skin and
cloth animation parts. Essentially, you will use Cal to only interpolate
the keyframe animations and to blend them.

My guesstimate is that with current hardware and a reasonably complex
scene you should be easily able to have 10-20k ants on the screen at the
same time. I have been able to put 10k on a screen using GeForce4 with
some heavy corner cutting (single animation, heavy impostor use, no
shaders, no instancing) years ago, so today that should be a breeze.

Do not worry about Cal3D being a bottleneck here - it won't, most of the
time you will be spending in rendering those clones and not updating few
quaternions in the skeleton calculations.

> @Jan
> Sorry i'm contacting you directly, but reading other related threads about
> osg's animation you seem to be quite familiar with this topic, and we need a
> solution as soon as possible.
> hope you don't mind..

It is OK - unless you expect me to do your homework for you :) I have
done quite a bit of this work back in the past so I am not completely
current on it, but I still remember the important bits.

Regards,

Jan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLUKP9n11XseNj94gRAoytAJ4pofPY1jjiGtKrFkmm8nSnOE6f5wCdHDFX
4oO/xH6N0uAfKeIwygOUTrw=
=kGS7
-----END PGP SIGNATURE-----
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply all
Reply to author
Forward
0 new messages