Page 1 of 2

Hardware Skinning (GPU Animation)

Posted: Sat Jan 04, 2014 5:24 am
by Samuel
EDIT:
Thanks to maslobojik who pointed out my mistake Hardware skinning is now working.
Hardware Animation.zip

If I remember right it only supports up to 24 bones and two weights per vertex.
This shader is in HLSL meaning it will only work for DirectX. I can create a CG version later on if someone wants OpenGL support.
If anyone has questions just ask.

Re: I need help with Hardware Skinning

Posted: Sat Jan 04, 2014 7:36 pm
by Samuel
That warning appears whenever you use the sinbad mesh. I'm using Ogre's jaiqua mesh and I believe that is the mesh they used in their hardware skinning demo.
I also tried this on several other meshes and every time it crashed on the parsing of the material script.
I'm thinking that I'm missing something in the shader or maybe there are some bugs with Ogre's GPU animations.
I'll go do some more research and see if I can find anything.

Re: I need help with Hardware Skinning

Posted: Sat Jan 04, 2014 11:31 pm
by Samuel
I looked around and found someone who had issues with getting hardware skinning to work under cg.
So, I gave hlsl a try and it worked without any errors. Unfortunately, I can't see any performance increase compared to the default animations.
From what I've read about hardware skinning. The GPU is supposed to do the calculations for the animations, but from what I can tell
my CPU is still doing all the work. Which is kinda a bummer, but it's still possible I'm doing something wrong or maybe I just don't understand how
hardware skinning is supposed to work. I'll post the hlsl code for others to test shortly.

EDIT:
I didn't notice that the material script for the hlsl shader had a 'fallback' technique with just the texture in it. Which explains the identical performance with or without the shader.
Once I removed the fallback the Ogre log started reporting an error. The error I'm getting is the vertex program is not supported.
I'll post the new code shortly for others to try. I think it's unlikely (since my hardware isn't that old and hardware skinning has been around for many years),
but it's possible my hardware doesn't support it. So, I'd like to see if everyone gets this error or if some people are able get it to run.

Re: I need help with Hardware Skinning

Posted: Sun Jan 05, 2014 1:09 am
by Samuel
I added the HLSL version in my original post above. I would appreciate it if people could post their Ogre log after giving it a try.
It may be helpful with trying to track down the problems. Thanks!

Re: I need help with Hardware Skinning

Posted: Sun Jan 05, 2014 1:34 am
by luis
Samuel wrote:I added the HLSL version in my original post above. I would appreciate it if people could post their Ogre log after giving it a try.
Here you go

Code: Select all

01:28:39: Creating resource group General
01:28:39: Creating resource group Internal
01:28:39: Creating resource group Autodetect
01:28:39: SceneManagerFactory for type 'DefaultSceneManager' registered.
01:28:39: Registering ResourceManager for type Material
01:28:39: Registering ResourceManager for type Mesh
01:28:39: Registering ResourceManager for type Skeleton
01:28:39: MovableObjectFactory for type 'ParticleSystem' registered.
01:28:39: OverlayElementFactory for type Panel registered.
01:28:39: OverlayElementFactory for type BorderPanel registered.
01:28:39: OverlayElementFactory for type TextArea registered.
01:28:39: Registering ResourceManager for type Font
01:28:39: ArchiveFactory for archive type FileSystem registered.
01:28:39: ArchiveFactory for archive type Zip registered.
01:28:39: ArchiveFactory for archive type EmbeddedZip registered.
01:28:39: DDS codec registering
01:28:39: FreeImage version: 3.10.0
01:28:39: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
01:28:39: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,koa,iff,lbm,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,dds,gif,g3,sgi,j2k,j2c,jp2
01:28:39: PVRTC codec registering
01:28:39: Registering ResourceManager for type HighLevelGpuProgram
01:28:39: Registering ResourceManager for type Compositor
01:28:39: MovableObjectFactory for type 'Entity' registered.
01:28:39: MovableObjectFactory for type 'Light' registered.
01:28:39: MovableObjectFactory for type 'BillboardSet' registered.
01:28:39: MovableObjectFactory for type 'ManualObject' registered.
01:28:39: MovableObjectFactory for type 'BillboardChain' registered.
01:28:39: MovableObjectFactory for type 'RibbonTrail' registered.
01:28:39: *-*-* OGRE Initialising
01:28:39: *-*-* Version 1.8.2 (Byatis)
01:28:39: D3D9 : Direct3D9 Rendering Subsystem created.
01:28:39: D3D9: Driver Detection Starts
01:28:39: D3D9: Driver Detection Ends
01:28:39: Particle Emitter Type 'Point' registered
01:28:39: Particle Emitter Type 'Box' registered
01:28:39: Particle Emitter Type 'Ellipsoid' registered
01:28:39: Particle Emitter Type 'Cylinder' registered
01:28:39: Particle Emitter Type 'Ring' registered
01:28:39: Particle Emitter Type 'HollowEllipsoid' registered
01:28:39: Particle Affector Type 'LinearForce' registered
01:28:39: Particle Affector Type 'ColourFader' registered
01:28:39: Particle Affector Type 'ColourFader2' registered
01:28:39: Particle Affector Type 'ColourImage' registered
01:28:39: Particle Affector Type 'ColourInterpolator' registered
01:28:39: Particle Affector Type 'Scaler' registered
01:28:39: Particle Affector Type 'Rotator' registered
01:28:39: Particle Affector Type 'DirectionRandomiser' registered
01:28:39: Particle Affector Type 'DeflectorPlane' registered
01:28:39: PCZone Factory Type 'ZoneType_Default' registered
01:28:39: CPU Identifier & Features
01:28:39: -------------------------
01:28:39:  *   CPU ID: GenuineIntel: Intel(R) Core(TM) i7 CPU         950  @ 3.07GHz
01:28:39:  *      SSE: yes
01:28:39:  *     SSE2: yes
01:28:39:  *     SSE3: yes
01:28:39:  *      MMX: yes
01:28:39:  *   MMXEXT: yes
01:28:39:  *    3DNOW: no
01:28:39:  * 3DNOWEXT: no
01:28:39:  *     CMOV: yes
01:28:39:  *      TSC: yes
01:28:39:  *      FPU: yes
01:28:39:  *      PRO: yes
01:28:39:  *       HT: no
01:28:39: -------------------------
01:28:39: D3D9 : Subsystem Initialising
01:28:39: Registering ResourceManager for type Texture
01:28:39: Registering ResourceManager for type GpuProgram
01:28:39: ***************************************
01:28:39: *** D3D9 : Subsystem Initialised OK ***
01:28:39: ***************************************
01:28:39: SceneManagerFactory for type 'OctreeSceneManager' registered.
01:28:39: SceneManagerFactory for type 'BspSceneManager' registered.
01:28:39: Registering ResourceManager for type BspLevel
01:28:39: Added resource location './/' of type 'FileSystem' to resource group 'General'
01:28:39: Parsing scripts for resource group Autodetect
01:28:39: Finished parsing scripts for resource group Autodetect
01:28:39: Creating resources for group Autodetect
01:28:39: All done
01:28:39: Parsing scripts for resource group General
01:28:39: Parsing script HWAnimationDX.material
01:28:39: Finished parsing scripts for resource group General
01:28:39: Creating resources for group General
01:28:39: All done
01:28:39: Parsing scripts for resource group Internal
01:28:39: Finished parsing scripts for resource group Internal
01:28:39: Creating resources for group Internal
01:28:39: All done
01:28:39: D3D9RenderSystem::_createRenderWindow "PureBasic Ogre", 1920x1200 windowed  miscParams: FSAA=0 displayFrequency=0 externalWindowHandle=199402 vsync=true 
01:28:39: D3D9 : Created D3D9 Rendering Window 'PureBasic Ogre' : 1920x1200, 32bpp
01:28:39: D3D9: Vertex texture format supported - PF_A8R8G8B8
01:28:39: D3D9: Vertex texture format supported - PF_B8G8R8A8
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT16_RGB
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT16_RGBA
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
01:28:39: D3D9: Vertex texture format supported - PF_R8G8B8A8
01:28:39: D3D9: Vertex texture format supported - PF_DEPTH
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT16_R
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT32_R
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT16_GR
01:28:39: D3D9: Vertex texture format supported - PF_FLOAT32_GR
01:28:39: D3D9: Vertex texture format supported - PF_PVRTC_RGB2
01:28:39: D3D9: Vertex texture format supported - PF_PVRTC_RGBA2
01:28:39: D3D9: Vertex texture format supported - PF_PVRTC_RGB4
01:28:39: D3D9: Vertex texture format supported - PF_PVRTC_RGBA4
01:28:39: D3D9: Vertex texture format supported - PF_R8
01:28:39: D3D9: Vertex texture format supported - PF_RG8
01:28:39: RenderSystem capabilities
01:28:39: -------------------------
01:28:39: RenderSystem Name: Direct3D9 Rendering Subsystem
01:28:39: GPU Vendor: nvidia
01:28:39: Device Name: Monitor-1-NVIDIA GeForce GTX 560 Ti
01:28:39: Driver Version: 9.18.13.3182
01:28:39:  * Fixed function pipeline: yes
01:28:39:  * Hardware generation of mipmaps: yes
01:28:39:  * Texture blending: yes
01:28:39:  * Anisotropic texture filtering: yes
01:28:39:  * Dot product texture operation: yes
01:28:39:  * Cube mapping: yes
01:28:39:  * Hardware stencil buffer: yes
01:28:39:    - Stencil depth: 8
01:28:39:    - Two sided stencil support: yes
01:28:39:    - Wrap stencil values: yes
01:28:39:  * Hardware vertex / index buffers: yes
01:28:39:  * Vertex programs: yes
01:28:39:  * Number of floating-point constants for vertex programs: 256
01:28:39:  * Number of integer constants for vertex programs: 16
01:28:39:  * Number of boolean constants for vertex programs: 16
01:28:39:  * Fragment programs: yes
01:28:39:  * Number of floating-point constants for fragment programs: 224
01:28:39:  * Number of integer constants for fragment programs: 16
01:28:39:  * Number of boolean constants for fragment programs: 16
01:28:39:  * Geometry programs: no
01:28:39:  * Number of floating-point constants for geometry programs: 0
01:28:39:  * Number of integer constants for geometry programs: 0
01:28:39:  * Number of boolean constants for geometry programs: 0
01:28:39:  * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
01:28:39:  * Texture Compression: yes
01:28:39:    - DXT: yes
01:28:39:    - VTC: no
01:28:39:    - PVRTC: no
01:28:39:  * Scissor Rectangle: yes
01:28:39:  * Hardware Occlusion Query: yes
01:28:39:  * User clip planes: yes
01:28:39:  * VET_UBYTE4 vertex element type: yes
01:28:39:  * Infinite far plane projection: yes
01:28:39:  * Hardware render-to-texture: yes
01:28:39:  * Floating point textures: yes
01:28:39:  * Non-power-of-two textures: yes
01:28:39:  * Volume textures: yes
01:28:39:  * Multiple Render Targets: 4
01:28:39:    - With different bit depths: yes
01:28:39:  * Point Sprites: yes
01:28:39:  * Extended point parameters: yes
01:28:39:  * Max Point Size: 8192
01:28:39:  * Vertex texture fetch: yes
01:28:39:  * Number of world matrices: 0
01:28:39:  * Number of texture units: 8
01:28:39:  * Stencil buffer depth: 8
01:28:39:  * Number of vertex blend matrices: 0
01:28:39:    - Max vertex textures: 4
01:28:39:    - Vertex textures shared: no
01:28:39:  * Render to Vertex Buffer : no
01:28:39:  * DirectX per stage constants: yes
01:28:39: DefaultWorkQueue('Root') initialising on thread main.
01:28:39: Particle Renderer Type 'billboard' registered
01:28:39: Mesh: Loading jaiqua.mesh.
01:28:39: Skeleton: Loading jaiqua.skeleton
01:28:39: WARNING: material jaiqua has no supportable Techniques and will be blank. Explanation: 
Pass 0: Vertex program Ogre/HardwareSkinningTwoWeightsHLSL cannot be used - not supported.

Re: I need help with Hardware Skinning

Posted: Sun Jan 05, 2014 3:22 am
by Samuel
Thank you, luis. Looks like you got the same error I've been getting.

Re: I need help with Hardware Skinning

Posted: Sun Jan 05, 2014 3:35 am
by Samuel
Thank you, Alexi. We have three people who have gotten the same support error.
I'm thinking it's not our hardware causing this problem.

I'll start going through each step of the shader again and see if I can find the cause.

If anyone else has ideas or suggestions don't be shy. I'll take whatever I can get.

Re: I need help with Hardware Skinning

Posted: Mon Jan 06, 2014 8:56 pm
by Samuel
After more testing I think this is a bug, but I could still be wrong about that.
I tested Dual Quaternion Skinning, which is another method of putting the animations on the GPU, to no avail.
The cg version of it is giving me the exact same issue as the cg I posted above. It stops right on the parsing of the script.

Hardware skinning is a very big issue (at least to me it is). Without the use of it your losing a huge chunk of CPU time that should be spent elsewhere.
At Ogre they even recommend using hardware skinning over the default whenever possible for the same reason.
So, if anyone plans on making a decent 3D game in Purebasic hardware skinning is a must. Especially if you have several high poly entities being animated at once.

I guess I'll just have to continue working at it. Maybe I'm still missing something. :?

Re: I need help with Hardware Skinning

Posted: Mon Jan 06, 2014 11:23 pm
by Samuel
An update with Purebasic might fix this depending on what is causing it. If it's a bug with Ogre then maybe they solved it with their newest release.

There's one thing that continues to bother me though. If this is a bug in Ogre then I would assume this would be a major issue and there would be a lot of people asking
about it on the Ogre forums. I have yet to see anyone from the Ogre forums report a problem. Which makes me wonder if this is a problem with Ogre at all.

To experiment further I tried reverting to Ogre v1.8.0 (Purebasic currently uses v1.8.2). Ogre 1.8.0 gave me the same problem. I'll try going a bit farther back into the
1.7s and see if I get the same issue.

So, I'd say there's 3 possible causes as to why I can't get it to work.

1. There's a bug in Ogre or Purebasic.
2. I'm incorrectly using or missing something in the shader.
3. It's somehow hardware related.

I don't think it's number 3 since we have several people with fairly good hardware having the same issue.
I also tried raising the shader targets and profiles (which allows better hardware), but I got the same results.

I also don't think it's 2. I'm using Ogre's example and I haven't changed much in the cg examples. The only thing I did was copy the cg from the unified examples.
I set up the HLSL example myself, but the shader code is the same as the cg. I also tried their Dual Quaternion Skinning example and that one I left untouched.

Which leaves us number 1. This is also the worst one of them all. If everyone over at Ogre can run this without issue then why can't I get it to work with Purebasic.
I'm not sure how Purebasic handles shaders, but I'd guess it has little to do with it and just lets Ogre do the work. Once again that's just a guess as I really have no clue
what goes into it.

So, I'll try older versions of Ogre and see if that works. If not then I'll continue with trial and error until I get it to work or I find the bug (assuming there is one).

Re: I need help with Hardware Skinning

Posted: Tue Jan 07, 2014 9:29 am
by Samuel
I gave Purebasic 4.61 a try and I got the same "not supported" results. I believe back then Purebasic was using Ogre 1.6 or a version near it.
I'm going to guess that this isn't a bug in Ogre, but I can't say for sure that this is a problem with Purebasic.

I don't know what's left to try. I don't think Ogre is the cause, but I don't see how Purebasic could be the problem.
Unless it's somehow not allowing the shader to run (which I kinda doubt).

Anyone have any ideas? I'm running out of them.

For the time being I guess I'll go through the shader one more time. I'll take it apart piece by piece until it starts working.

EDIT:
I have no clue what's wrong. It could be as simple as an error on my part or something more complex. Like Purebasic needing to treat the animations differently.
I think I'm going to step back from this at least for a little while. One day something might click and I'll be able to figure out what's wrong, and
if I do ever figure it out. I'll be sure to post the shader for everyone to use.

Hardware skinning will be necessary with certain types of games. I know it would be useful to me and in time I'm sure many others will have a need for it too.
So, if someone comes along and figures this out. I'd appreciate it if you shared your knowledge with us.

Re: I need help with Hardware Skinning

Posted: Thu Jan 09, 2014 9:59 pm
by Samuel
I wasn't going to do much more work on this, but I stumbled across Ogre's sample downloads.
Included was a hardware skinning demo and what do you know it worked perfectly. The shaders it used were the same ones I've been trying to get to work.
Since the shaders are the same and their demo does work on my computer. I'm assuming the problem is in Purebasic.

So, I have a little question for anybody with knowledge of how Ogre works. Does Ogre use different commands for GPU animations?
If Ogre has a separate command to enable them. This would explain why I can't get them to work in Purebasic.
Purebasic's StartEntityAnimation() command might only work for the default animations.
This is kinda a guess on my part, but it seems possible.

Re: I need help with Hardware Skinning

Posted: Tue Apr 01, 2014 7:27 pm
by maslobojik
You must put Parse3DScripts() after OpenWindowedScreen...

Like this:

Code: Select all

If OpenWindow(#Window, 0, 0, DesktopW, DesktopH, "Hardware Skinning")
  If OpenWindowedScreen(WindowID(#Window), 0, 0, DesktopW, DesktopH, 0, 0, 0)
  
    Parse3DScripts()
    CPU$ = CPUName()
    
    CreateSprite(#Info, 350, 120)
    StartDrawing(SpriteOutput(#Info))
      Box(0,0,350,120,RGB(0,0,0))
    StopDrawing()
    ..........

Re: I need help with Hardware Skinning

Posted: Tue Apr 01, 2014 8:10 pm
by Samuel
:oops: I feel very dumb right now. :oops:

Thank you very much for pointing out my mistake. :D
I spent several weeks trying to figure out what was wrong and it turns out it was something so simple.

With hardware skinning now available. Purebasic's 3D became much more powerful.
In my example the FPS was about 30. Now with hardware skinning it jumped right up to 60 FPS.

Thank you again because if you didn't point that out. I would have probably spent another year or two trying to figure out what was wrong.
I'll update my download link with the new code after work.

Re: I need help with Hardware Skinning

Posted: Tue Apr 01, 2014 10:02 pm
by box_80
Thanks from me also for the solution. I did not know about Ogre having hardware skinning so I'm thankful it was posted. Hardware skinning sounds like it would be very useful. Hope I get to put it to the test soon.

Re: I need help with Hardware Skinning

Posted: Wed Apr 02, 2014 12:31 am
by Samuel
Here's a little comparison for speed. I kept adding entities until my FPS started going below 60.
Obviously, it's going to differ for others. Depending on their computer specs and your mesh complexity.

Jaique.mesh with "Sneak" animation
Hardware Skinning On = 160 entities
Hardware Skinning Off = 20 entities

robot.mesh with "Walk" animation
Hardware Skinning On = 250 entities
Hardware Skinning Off = 115 entities

I wanted to test this with the Sinbad mesh, but I need to edit the shader first. Currently this shader only supports 24 bones.