What is the current trend for skinning?
Started by mrheisenberg, Sep 27 2012 10:08 PM
8 replies to this topic
#1 Members - Reputation: 333
Posted 27 September 2012 - 10:08 PM
It has been a while before I did a skinning system and the last time I did one was one the CPU with Directx9.Now I see people talking about vertex shader skinning,compute shader skinning,using textures for bone data..kinda confused here,which is the mosts efficient method?Is interpolation more efficient on the compute shader than in the vertex shader?
Sponsor:
#2 Members - Reputation: 4746
Posted 27 September 2012 - 11:25 PM
I think, that it is pretty common to calculate the bone animation on the CPU and do the skinning in the vertex shader with registers for the bone orientation (quaternion+position or matrix), though saving this data in a texture which will be accessed in the vertex shader could have some advantages.
Ashaman
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
#3 Moderators - Reputation: 14296
Posted 27 September 2012 - 11:44 PM
Yeah the current 'baseline' implementation would be calculate bone anim on CPU, put bones into constant registers as matrices, and do skinning with 4 weights in the vertex shader.
Instead of using 4x4 matrices, the simplest improvement is to just use 4x3 matrices (or 3x4, depending) so that you only need 3 registers per bone -- you can do this because one row/column will always be [0,0,0,1].
You can then get down to just 2 registers per bone by using dual-quaternion skinning, or using some kind of rotation+translation format.
On some cards, you might get better fetch performance by putting the bone data into a texture, or a 'tbuffer' instead of a 'cbuffer'.
Another issue is that in most modern renderers, each model is drawn more than once per frame -- e.g. one from a light's point of view for shadow mapping, and then once for the main camera. With vertex-shader skinning, this means that the model is skinned twice (which doesn't occur with CPU skinning).
You can avoid this issue on DX10 cards by using "stream out" -- where instead of rasterizing your skinned vertices, you instead write the results to a vertex buffer. You can then use this temporary vertex buffer to draw the mesh multiple times (without running skinning again).
On DX11, you also have the option of using a compute shader to do this work.
Instead of using 4x4 matrices, the simplest improvement is to just use 4x3 matrices (or 3x4, depending) so that you only need 3 registers per bone -- you can do this because one row/column will always be [0,0,0,1].
You can then get down to just 2 registers per bone by using dual-quaternion skinning, or using some kind of rotation+translation format.
On some cards, you might get better fetch performance by putting the bone data into a texture, or a 'tbuffer' instead of a 'cbuffer'.
Another issue is that in most modern renderers, each model is drawn more than once per frame -- e.g. one from a light's point of view for shadow mapping, and then once for the main camera. With vertex-shader skinning, this means that the model is skinned twice (which doesn't occur with CPU skinning).
You can avoid this issue on DX10 cards by using "stream out" -- where instead of rasterizing your skinned vertices, you instead write the results to a vertex buffer. You can then use this temporary vertex buffer to draw the mesh multiple times (without running skinning again).
On DX11, you also have the option of using a compute shader to do this work.
#5 Members - Reputation: 333
Posted 28 September 2012 - 02:30 AM
With DX11.1 you can output to a buffer from a vertex shader, which is even better than using a compute shader or stream out since you can just output the skinned verts while rasterizing your first pass.
won't that become overly complicated when you implement advanced animations(animation blending,adjusting character body to match the angle of the terrain he is standing on,ect.),you wold have to send a huge amount of matrices
#6 Members - Reputation: 2031
Posted 28 September 2012 - 06:27 AM
You wouldn't stream out the bones, just the transformed vertices. The point is that you only need to apply the bone transforms (the heavy lifting of skinning) once, and then re-use the resulting mesh in subsequent drawing passes.
Niko Suni
Software developer
Software developer
#8 Members - Reputation: 2031
Posted 30 September 2012 - 08:29 AM
You can stream out from vertex shader by bypassing the geometry shader. This functionality is available in 11.0 hardware.
The device's CreateGeometryShaderWithStreamOutput method also accepts vertex shader bytecode. You do get a geometry shader handle from that (and you need to set it as the active geometry shader), but it is just a straight pipe that sends the vertices from the VS to the SO buffer.
In addition to that, 11.1 hardware allows you to write arbitrarily to r/w shader resources from within all shader stages, which gives you a lot more flexibility.
The device's CreateGeometryShaderWithStreamOutput method also accepts vertex shader bytecode. You do get a geometry shader handle from that (and you need to set it as the active geometry shader), but it is just a straight pipe that sends the vertices from the VS to the SO buffer.
In addition to that, 11.1 hardware allows you to write arbitrarily to r/w shader resources from within all shader stages, which gives you a lot more flexibility.
Edited by Nik02, 30 September 2012 - 08:31 AM.
Niko Suni
Software developer
Software developer
#9 Moderators - Reputation: 5642
Posted 30 September 2012 - 10:16 AM
UAV's from any shader stage is a 11.1 feature, so you'd need a fully-compliant FEATURE_LEVEL_11_1 video card with the necessary driver. I'm not sure if existing DX11 GPU's are fully compliant, but if any are I don't believe there are any publicly-available drivers yet. I could be wrong about that though.
Making a GS with stream out from a vertex shader still creates a "dummy" geometry shader. Either way the really bad part about doing it that way is that you can't rasterize a triangle list while streaming out, because you'd have to stream out the fully-expanded list of vertices which is pretty inefficient. The alternative is to have a dedicated "stream-out" pass where you render with a point list topology and stream out from the GS, since that gives you a non-expanded buffer of vertices that you can index into with your index buffer.
Making a GS with stream out from a vertex shader still creates a "dummy" geometry shader. Either way the really bad part about doing it that way is that you can't rasterize a triangle list while streaming out, because you'd have to stream out the fully-expanded list of vertices which is pretty inefficient. The alternative is to have a dedicated "stream-out" pass where you render with a point list topology and stream out from the GS, since that gives you a non-expanded buffer of vertices that you can index into with your index buffer.






