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 

Skinning (samples/gu/skinning)

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



Joined: 26 Feb 2008
Posts: 2

PostPosted: Tue Feb 26, 2008 1:44 am    Post subject: Skinning (samples/gu/skinning) Reply with quote

I have been working about a couple of weeks in a psp emulator with an integrated debugger. The aim of the project is be able to debug psp applications and games.
I based the project in the great work of pspplayer and pspsdk.

Currently I'm trying to implement more complicated GE stuff like Skinning. But skinning is broken at this moment:


Without morphing (emulator):


With morphing (emulator) (bad implemented):


With morphing (psp):



I'm using opengl shaders to implement GE rendering.

Vertex shader:
Code:

// Transform2D flag
uniform bool transform2D;
uniform mat4 boneMatrix;
uniform vec2 boneOffset;

// Sprites
uniform vec4 spriteCenter;
attribute int spriteCorner;

// Morphing
uniform mat4 BoneMatrix[8];
uniform int morphCount;
attribute float morphWeight[8];

void doSkinning(inout vec4 vertex) {
   vec4 pos = vec4(0, 0, 0, 0);
   
   for (int n = 0; n < morphCount; n++) {
      pos += (morphWeight[n] * vertex) * (transpose(BoneMatrix[n]) * morphWeight[n]);
   }
   
   vertex = pos;
}

void main() {
   vec4 pos = gl_Vertex;

   gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
   //lightDir = normalize(vec3(gl_LightSource[0].position));
   gl_FrontColor = gl_Color;

   if (transform2D) {
      gl_Position = ftransform();
      return;
   }
   
   if (morphCount) {
      doSkinning(pos);
   }
   
   gl_Position = gl_ModelViewProjectionMatrix * pos;
}


Fragment shader:
Code:

// Color LookUp Table
uniform sampler1D clut;
uniform bool clutUse;
uniform int clutOffset;
uniform bool textureUse;

// Texture
uniform sampler2D tex;

void main() {
   vec4 color;
   
   // If there is clut
   if (clutUse) {
      // tex must have GL_NEAR
      color = texture2D(tex, gl_TexCoord[0].st);
      color = texture1D(clut, color.r + clutOffset);
   } else {
      if (textureUse) {
         color = gl_Color * texture2D(tex, gl_TexCoord[0].st);
      } else {
         color = gl_Color;
      }
   }
   
   gl_FragColor = color;
}


I pass weights per vertex and bone matrixes, to vertex shader.
But it's obviusly bad implemented:

Code:

void doSkinning(inout vec4 vertex) {
   vec4 pos = vec4(0, 0, 0, 0);
   
   for (int n = 0; n < morphCount; n++) {
      pos += (morphWeight[n] * vertex) * (transpose(BoneMatrix[n]) * morphWeight[n]);
   }
   
   vertex = pos;
}


I found this url: http://graphics.ucsd.edu/courses/cse169_w05/3-Skin.htm
but I'm a completly newbie in skinning.

Someone can help me with that?

(Sorry about my bad english)

Thanks in advance,


Last edited by soywiz on Wed Feb 27, 2008 1:00 am; edited 1 time in total
Back to top
View user's profile Send private message
soywiz



Joined: 26 Feb 2008
Posts: 2

PostPosted: Tue Feb 26, 2008 2:46 am    Post subject: Re: Skinning (samples/gu/skinning) Reply with quote

woops, I quoted message instead of editing (and I can't delete it). Well, there is the url of the emu:
http://www.soywiz.com/d/pspemulator/

Source code is a mess, but I'll improve it when I know how to focus some things. It's only a sketch so I don't want to make it public yet.
Back to top
View user's profile Send private message
ReJ



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

PostPosted: Thu Feb 28, 2008 9:14 pm    Post subject: Reply with quote

You skinning code should look more like that:

Code:
void doSkinning(inout vec4 vertex, in float boneWeight[]) {
   vec4 pos = vec4(0, 0, 0, 0);
   
   for (int n = 0; n < weightCount; n++) {
      pos += (BoneMatrix[n] * vertex) * boneWeight[n];
   }
   
   vertex = pos;
}


Btw, it seems that you are using "skinning" and "morphing" terms interchangeably - but they are different things. PSP can do both, bone skinning and geometry morphing, even more they can be combined (as in gu/morphskin sample).
Back to top
View user's profile Send private message Visit poster's website
noxa



Joined: 05 Aug 2006
Posts: 39

PostPosted: Tue Mar 11, 2008 12:08 am    Post subject: Reply with quote

wow someone else working on an emulator - nice!

not sure if that makes me want to work harder on mine, or sit back and watch you finish yours :)
Back to top
View user's profile Send private message Visit poster's website
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