Author Topic: Hardware skinning needed  (Read 29862 times)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Hardware skinning needed
« on: May 08, 2014, 06:22:10 pm »
Hi Raft,

Is it doable for Bones to have hardware skinning? I checked from orge3d.org and they seem to have it. http://www.ogre3d.org/forums/viewtopic.php?f=4&t=66907#p440560

I have 6 animated models with bones and it seems to takes a lot of CPU usage and slow down Android main UI (I'm doing live wallpaper).

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #1 on: May 08, 2014, 07:28:29 pm »
yes, it is possible but i dont have any plans or time to implement it. sorry

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #2 on: May 09, 2014, 03:03:00 am »
Is it possible if we do it without editing the Bones library? I'll try to implement it if no editing required.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #3 on: May 09, 2014, 08:47:48 am »
no, you need to modify Bones' source. but modification will not be that much. i'm not completely sure about this but I suppose, you should leave calculation of skeleton poses as it is and intervene at applyAnimation method. you should upload poses to GPU and calculate new positions of vertices via shaders.

if you intend to do it, jME2's relevant part may help. it's included in Bones distribution.

also note, with hw skinning, jPCT's polygon level collision detection will not work correctly (unless of course you download vertex positions from GPU). but you can still use sphere or ellipsoid collision detection.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #4 on: May 10, 2014, 07:14:15 am »
Quote
you should leave calculation of skeleton poses as it is and intervene at applyAnimation method
Does it mean animateSkin() method is to be processed by CPU and applyAnimation() by GPU? Can we put the animateSkin() calculation to shader as well? Hoping we could just put all calculations to GPU so CPU would process as less as possible.

Quote
jME2's relevant part may help. it's included in Bones distribution
It seems like jME2 is a really huge library, but it's open-sourced. I guess I can try to find the needle in the ocean ;P
« Last Edit: May 10, 2014, 07:20:31 am by kkl »

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #5 on: May 10, 2014, 11:39:33 am »
Quote
Does it mean animateSkin() method is to be processed by CPU and applyAnimation() by GPU?
yes, that is what I meant
Quote
Can we put the animateSkin() calculation to shader as well? Hoping we could just put all calculations to GPU so CPU would process as less as possible.
that is also possible but it requires much more modification to Bones' code. calculation of skeleton pose is relatively cheaper. the expensive part is applying skeleton pose to mesh. I will suggest starting with porting applyAnimation() to shader. this will have a couple of benefits:

* it wil be easier to implement
* if something does not work, you can be sure the problem is in applyAnimation

Quote
It seems like jME2 is a really huge library, but it's open-sourced. I guess I can try to find the needle in the ocean ;P
yes, jME2 is a huge library but Bones comes with only relevant parts. particularly have a look at com.jmex.model.ogrexml.anim.MeshAnimationController update method

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Hardware skinning needed
« Reply #6 on: May 10, 2014, 03:06:56 pm »
If you manage to do the skinning on the GPU, it would be great if the required shader code is designed as a kind of plugin, so that it's possible to inject it into other shaders by doing some simple insert operation. Because otherwise, it would require everybody who is going to use this to write and manage his/her own shaders and the default shaders would be useless.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #7 on: May 11, 2014, 04:11:52 pm »
Hi Raft,

Yea. I think I can start from applyAnimation(). BTW, I checked by calculating time taken for animateSkin() and applyAnimation() respectively, and found out the time taken for animateSkin() is higher than applyAnimation(). The result is, animateSkin() = ~450000 ns and applyAnimation() = ~45000 ns in average. Since it's taking more process in animateSkin(), just hope we can put both in shader too. But I guess that will deeply involve library editing.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #8 on: May 11, 2014, 04:13:41 pm »
Hi Egon,

Yea. I guess the hardware skinning is somewhat important. I'll try to implement it. If it works, I'll let y'all know.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #9 on: May 11, 2014, 05:25:09 pm »
Yea. I think I can start from applyAnimation(). BTW, I checked by calculating time taken for animateSkin() and applyAnimation() respectively, and found out the time taken for animateSkin() is higher than applyAnimation(). The result is, animateSkin() = ~450000 ns and applyAnimation() = ~45000 ns in average. Since it's taking more process in animateSkin(), just hope we can put both in shader too. But I guess that will deeply involve library editing.
oops, sorry, skin animation is actually applied at applySkeletonPose method, applyAnimation only says jPCT new mesh is ready to upload to GPU.

animateSkin also calls applySkeletonPose so the time you saw is combined time of both

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #10 on: May 11, 2014, 05:43:58 pm »
In this case, does it mean we have to rewrite the whole animateSkin() to shader? Still doable w/o editing the library?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #11 on: May 11, 2014, 06:21:46 pm »
yes, almost the same thing. have a look at the code, you will see it.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #12 on: May 12, 2014, 03:46:23 am »
Ok, I'll have a look at it and keep you guys posted ;)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Hardware skinning needed
« Reply #13 on: May 27, 2014, 04:46:38 pm »
I started reading the code and I just wonder if I can access SkinClipSequence animate() by making it a public method, so I can separate recode the animateSkin and take the applySkeletonPose() to shader and leave the rest to CPU.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Hardware skinning needed
« Reply #14 on: May 27, 2014, 04:48:37 pm »
go ahead, try it