guillaumeblanc / ozz-animation

Open source c++ skeletal animation library and toolset
http://guillaumeblanc.github.io/ozz-animation/
Other
2.44k stars 301 forks source link

Hardware skinning #7

Closed Codewyvern closed 5 years ago

Codewyvern commented 8 years ago

Is hardware skinning a possibility? something like dual quaternion skinning? I guess there would have to be a bone limit though. Would be cool to see this library working on mobile devices with skinning done in the vertex shader.

jazzbre commented 8 years ago

Already did this, works great, sadly I can't share the code/project. To maximise possible bone count I always transpose the 4x4 matrix (on the CPU side) and just use 3 constant vectors instead of 4. Then in vertex shader for x,y,z just do a dot product with the three bone constants.

guillaumeblanc commented 8 years ago

Thanks for your comments.

Hardware skinning I think hardware skinning would break the renderer agnostic aspect of ozz library. Hardware skinning is performed on the gpu, using vertex shaders, which requires a setup and a language (CG, hlsl, glsl...) specific to every API (DX, OpenGL...). So not sure there's really a possibility. I have to think more about it to see how this could fit in different renderers. On the other hand, as @jazzbre has experimented it's quite doable. The good point is that the data input format of ozz SkinningJob is very close to the input format of hardware skinning. Vertices, normals, tangents, weights, indices need to be sent as attributes (via vertex buffer object in OpenGL), in the same format ozz job uses. Skinning matrices (model space * inverse bind pose) are uploaded as uniforms (constants). This can be optimize/packed indeed as the last matrix row isn't meaningful. I'm not really up to date the gpus, but I think hardware skinning brings a bone count limit indeed, one that cpu doesn't have. Skinning matrices are passed as constants which have a limited size. I'd recommend to split the mesh into pieces that are influenced by a fix/small number of joints, and do a draw call per piece. Would a "hardware skinning" sample help ?

Dual Quaternion That's definitely something I want to investigate. There's a conversion stage (from ? to dual quaternion) required at some point of the pipeline, probably after (or while) converting to model space. It should be handled by the library. It would work for software skinning as well as hardware, but at that point I think ozz should still provide software skinning only. I don't know how joint scaling would work though.

Mobile devices I never had a chance to see ozz working on a mobile, except through web/emscripten samples at least. It should compile properly but would most probably lack SIMD acceleration and fall back to the scalar implementation. Is CPU the bottleneck on those platforms, to justify hardware skinning?

Thanks, Guillaume

Codewyvern commented 8 years ago

A sample would be great yes, it would certainly attract a lot more users to this library, there is hardly any other open source skeletal animation libraries out there. One sample for opengl and one for directx would be awesome. From what I know the GPU on mobile devices is usually a lot faster than its CPU, so hardware skinning is ideal. I would attempt to write such a thing myself but all this math heavy stuff is really not my strong point.

kylawl commented 8 years ago

Add any new features you want, but keep the main components lean. Ozz is excellent because doesn't force a tonne of arbitrary features and systems on you.

Codewyvern commented 8 years ago

Well as long as its optional and cleanly separated as an extension to the main library, I don't see a problem.

shakesoda commented 8 years ago

Hardware skinning is fairly easy to implement yourself - I don't think it's the lib's business and it introduces platform (graphics API) dependence. A sample is a good idea, though.

guillaumeblanc commented 7 years ago

A bgfx sample using ozz-animation would be awesome to demonstrate hardware skinning. Anyone interested?

Alan-FGR commented 6 years ago

I don't think it's the lib's business

This! We need a focused high-quality lib for animation (that does just animation and does it well). Samples are fine ofc.

shartte commented 5 years ago

I've been using Ozz for sampling and Google's filament for actual hardware skinning successfully together. The skinning aspect just seems highly rendering engine dependent. One aspect however is object picking, for which CPU side skinning might be needed, but Ozz already has that.

guillaumeblanc commented 5 years ago

I'll close this as it falls outside of library scope. Please don't hesitate to share any work / sample that demonstrates hardware skinning with ozz.

yangfengzzz commented 2 years ago

OZZ GPU-Skinning can refer from https://github.com/ConfettiFX/The-Forge/tree/master/Examples_3/Unit_Tests/src/28_Skinning