Matrix Skinning

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Matrix Skinning

Post by ReJ »

I've played a bit with matrix skinning:

sceGuDrawArray()
int vtype: bits from 14-15 seems to be a number of weights per vertex. Must be combined with GU_WEIGHT_xxx.
should be something like:

Code: Select all

#define GU_WEIGHTS_SHIFT&#40;n&#41;	&#40;&#40;n&#41;<<14&#41;
#define GU_WEIGHTS_1		GU_WEIGHTS_SHIFT&#40;0&#41;
#define GU_WEIGHTS_2		GU_WEIGHTS_SHIFT&#40;1&#41;
#define GU_WEIGHTS_3		GU_WEIGHTS_SHIFT&#40;2&#41;
#define GU_WEIGHTS_4		GU_WEIGHTS_SHIFT&#40;3&#41;
Weights order in vertex is before UV. Example:

Code: Select all

struct Vertex &#123;
    float weight;   // GU_WEIGHT_32BITF | GU_WEIGHTS_1
    float u, v;
    float x, y, z;
&#125;;
struct Vertex2 &#123;
    float weight&#91;4&#93;;   // GU_WEIGHT_32BITF | GU_WEIGHTS_4
    float u, v;
    float x, y, z;
&#125;;
Matrixes are set using sceGuBoneMatrix(). Only first 4 matrices out of 8 will be used in ths mode. During skinning the GU will use them in the following manner to calc final vertex:
sum( Vertex.weight * BoneMatrix ) * ModelMatrix.

Still trying to figure out how to use bone indices (matrix palette). Higher bits (16-23) in vertex type (sceGuDrawArray) definetly affect the size of the expected vertex - however not sure if they mean bone indices or something else.
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

Well, I was actually tricked by some site stating that PSP supports only 4 weights per vertex and 8 matrices. Actually there is just 8 weights per vertex - so no need for indices and matrix palette.

It should be more like:

Code: Select all

#define GU_WEIGHTS_SHIFT&#40;n&#41;   &#40;&#40;n&#41;<<14&#41;
#define GU_WEIGHTS_1      GU_WEIGHTS_SHIFT&#40;0&#41;
#define GU_WEIGHTS_2      GU_WEIGHTS_SHIFT&#40;1&#41;
#define GU_WEIGHTS_3      GU_WEIGHTS_SHIFT&#40;2&#41;
#define GU_WEIGHTS_4      GU_WEIGHTS_SHIFT&#40;3&#41;
#define GU_WEIGHTS_5      GU_WEIGHTS_SHIFT&#40;4&#41;
#define GU_WEIGHTS_6      GU_WEIGHTS_SHIFT&#40;5&#41;
#define GU_WEIGHTS_7      GU_WEIGHTS_SHIFT&#40;6&#41;
#define GU_WEIGHTS_8      GU_WEIGHTS_SHIFT&#40;7&#41;
or maybe just:

Code: Select all

#define GU_WEIGHTS&#40;n&#41;   &#40;&#40;&#40;n-1&#41;&7&#41;<<14&#41;
PS: It seems a bit strange that PSP uses weights for all matrices, instead of using matrix palette. It's a huge waste of both space for the vertices (unless weights are 8bit) and GPU power in order to mul/add all 8 matrices (mesh must be carefully divided in order to reduce number of matrixes required per vertex).
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

I haven't heard of any hardware directly supporting a matrix palette the way you imagined PSP did, except possibly the Geforce6800 where you can use fp textures read in the vertex shader as matrix palettes. Yes you have to split your meshes up, but that's true for everything from PC to Xbox to NDS to Gamecube.
Also, using anything bigger than 8-bit weights would be silly. You're not going to be able to tell the difference. 4-bit weights would be fine with me if that were available.
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

ReJ wrote: ...or maybe just:

Code: Select all

#define GU_WEIGHTS&#40;n&#41;   &#40;&#40;&#40;n-1&#41;&7&#41;<<14&#41;
Hey, you've been playing with skinning too? Good. :) I reached the same conclusion, and in addition, I've been playing with vertex morphing (or tweening). It caught my eye after I reviewed the Breakpoint 2005 presentation again, where it was discussed. There are bits available for this too, so in the end, it's

Code: Select all

#define GU_VERTEX_WEIGHTS&#40;n&#41; &#40;&#40;&#40;n-1&#41;&7&#41;<<14&#41;
#define GU_VERTEX_VERTICES&#40;n&#41; &#40;&#40;&#40;n-1&#41;&7&#41;<<18&#41;
And then you specify sceGuMorphWeight(n,f) for every vertex in there (you can have up to 8 vertices it seems). As was noted in the BP-presentation, I wonder if these can be combined, that is, if you can use 8 morph weights to blend between your meshes, and then skin these using 8 matrices. That would make up for the missing VU quite a lot. Although, I wonder how slow it would be. :)

I was planning on doing a skinning/morphing demo this weekend, or have you something already cooking?

I'll add these defines to GU. I'm not quite sure how the vertex format changes with vertex morphing, but it seems a bit weird, because when I pass anything else but just vertices, it gets distorted. It could be that you can blend more than just the vertex position.
GE Dominator
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

ector wrote:I haven't heard of any hardware directly supporting a matrix palette the way you imagined PSP did, except possibly the Geforce6800 where you can use fp textures read in the vertex shader as matrix palettes.
I meant using indices stored per vertex to address matrix in the array. That functionality was introduced with VertexShader1.0 (DirectX). Using address register (a0) to offset vertex constants (not texture, which is of course only VS3.0) - usual way to implement skinning with hardware vertex shaders.

But I was wrong :) no such functionality for PSP.
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

chp wrote:I was planning on doing a skinning/morphing demo this weekend, or have you something already cooking?
I did very simple skinning sample just to demonstrate how it works. Need a bit of source cleaning though (I was doing a day-job coding instead :) ).
chp wrote:It caught my eye after I reviewed the Breakpoint 2005 presentation again, where it was discussed.
Thanks for the mentioning presentation - will look into it. It is pity, that I couldn't go to Breakpoint myself.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

ReJ wrote:
ector wrote:I haven't heard of any hardware directly supporting a matrix palette the way you imagined PSP did, except possibly the Geforce6800 where you can use fp textures read in the vertex shader as matrix palettes.
I meant using indices stored per vertex to address matrix in the array. That functionality was introduced with VertexShader1.0 (DirectX). Using address register (a0) to offset vertex constants (not texture, which is of course only VS3.0) - usual way to implement skinning with hardware vertex shaders.

But I was wrong :) no such functionality for PSP.
Hm, didn't know you could do that so easily with a0 :) Cool.
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Ok, added a very simple morph-demo (gu/morph/), and as we figured, every vertex-set is multiplied by the weight (all entries), so you can do nice transitions between models... too bad you couldn't have multiple textures running aswell.. :)
GE Dominator
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

I did very simple skinning samle as well. Can be downloaded from: http://rej.50megs.com/psp/skinning/

It's not optimal, since all 8 weights are used - and it could be done with only 4 and geometry split into smaller chunks. But, hey, it's only the sample :)
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Added. We're moving at breakneck-speed here. ;)
GE Dominator
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

ReJ wrote:I did very simple skinning samle as well. Can be downloaded from: http://rej.50megs.com/psp/skinning/

It's not optimal, since all 8 weights are used - and it could be done with only 4 and geometry split into smaller chunks. But, hey, it's only the sample :)
hello, it must be a long time since you wrote this code but I thought it would work if i ran it on ma PSP (FW 1.5 + Dark_Alex's Custom FW). Creating an EBOOT.PBP and then place it in x:\PSP\GAME\SKINNING. Running it ends into a blackout screen then switch off my PSP after several seconds (maybe because of a watchdog).

What's wrong with me ?
Post Reply