forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Matrix Skinning

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ReJ



Joined: 04 Apr 2004
Posts: 25
Location: Lithuania, Vilnius

PostPosted: Fri Jul 29, 2005 12:53 am    Post subject: Matrix Skinning Reply with quote

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:
#define GU_WEIGHTS_SHIFT(n)   ((n)<<14)
#define GU_WEIGHTS_1      GU_WEIGHTS_SHIFT(0)
#define GU_WEIGHTS_2      GU_WEIGHTS_SHIFT(1)
#define GU_WEIGHTS_3      GU_WEIGHTS_SHIFT(2)
#define GU_WEIGHTS_4      GU_WEIGHTS_SHIFT(3)


Weights order in vertex is before UV. Example:
Code:
struct Vertex {
    float weight;   // GU_WEIGHT_32BITF | GU_WEIGHTS_1
    float u, v;
    float x, y, z;
};
struct Vertex2 {
    float weight[4];   // GU_WEIGHT_32BITF | GU_WEIGHTS_4
    float u, v;
    float x, y, z;
};


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[i] * BoneMatrix[i] ) * 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.
Back to top
View user's profile Send private message Visit poster's website
ReJ



Joined: 04 Apr 2004
Posts: 25
Location: Lithuania, Vilnius

PostPosted: Fri Jul 29, 2005 4:53 pm    Post subject: Reply with quote

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:
#define GU_WEIGHTS_SHIFT(n)   ((n)<<14)
#define GU_WEIGHTS_1      GU_WEIGHTS_SHIFT(0)
#define GU_WEIGHTS_2      GU_WEIGHTS_SHIFT(1)
#define GU_WEIGHTS_3      GU_WEIGHTS_SHIFT(2)
#define GU_WEIGHTS_4      GU_WEIGHTS_SHIFT(3)
#define GU_WEIGHTS_5      GU_WEIGHTS_SHIFT(4)
#define GU_WEIGHTS_6      GU_WEIGHTS_SHIFT(5)
#define GU_WEIGHTS_7      GU_WEIGHTS_SHIFT(6)
#define GU_WEIGHTS_8      GU_WEIGHTS_SHIFT(7)

or maybe just:
Code:
#define GU_WEIGHTS(n)   (((n-1)&7)<<14)


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).
Back to top
View user's profile Send private message Visit poster's website
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Sat Jul 30, 2005 4:01 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sat Jul 30, 2005 5:52 am    Post subject: Reply with quote

ReJ wrote:

...or maybe just:
Code:
#define GU_WEIGHTS(n)   (((n-1)&7)<<14)



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:

#define GU_VERTEX_WEIGHTS(n) (((n-1)&7)<<14)
#define GU_VERTEX_VERTICES(n) (((n-1)&7)<<18)


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
Back to top
View user's profile Send private message
ReJ



Joined: 04 Apr 2004
Posts: 25
Location: Lithuania, Vilnius

PostPosted: Sat Jul 30, 2005 7:06 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
ReJ



Joined: 04 Apr 2004
Posts: 25
Location: Lithuania, Vilnius

PostPosted: Sat Jul 30, 2005 7:15 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Sat Jul 30, 2005 7:22 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Jul 31, 2005 9:27 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ReJ



Joined: 04 Apr 2004
Posts: 25
Location: Lithuania, Vilnius

PostPosted: Sun Jul 31, 2005 10:03 am    Post subject: Reply with quote

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 :)
Back to top
View user's profile Send private message Visit poster's website
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Jul 31, 2005 10:12 am    Post subject: Reply with quote

Added. We're moving at breakneck-speed here. ;)
_________________
GE Dominator
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sun Sep 10, 2006 8:37 pm    Post subject: Reply with quote

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 ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group