Skinning (samples/gu/skinning)

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

Moderators: cheriff, TyRaNiD

Post Reply
soywiz
Posts: 2
Joined: Tue Feb 26, 2008 1:29 am

Skinning (samples/gu/skinning)

Post by soywiz »

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:
Image

Without morphing (emulator):
Image

With morphing (emulator) (bad implemented):
Image

With morphing (psp):
Image


I'm using opengl shaders to implement GE rendering.

Vertex shader:

Code: Select all

// 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 &#40;int n = 0; n < morphCount; n++&#41; &#123;
		pos += &#40;morphWeight&#91;n&#93; * vertex&#41; * &#40;transpose&#40;BoneMatrix&#91;n&#93;&#41; * morphWeight&#91;n&#93;&#41;;
	&#125;
	
	vertex = pos;
&#125;

void main&#40;&#41; &#123;
	vec4 pos = gl_Vertex;

	gl_TexCoord&#91;0&#93; = gl_TextureMatrix&#91;0&#93; * gl_MultiTexCoord0;
	//lightDir = normalize&#40;vec3&#40;gl_LightSource&#91;0&#93;.position&#41;&#41;;
	gl_FrontColor = gl_Color;

	if &#40;transform2D&#41; &#123;
		gl_Position = ftransform&#40;&#41;;
		return;
	&#125;
	
	if &#40;morphCount&#41; &#123;
		doSkinning&#40;pos&#41;;
	&#125;
	
	gl_Position = gl_ModelViewProjectionMatrix * pos;
&#125;
Fragment shader:

Code: Select all

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

// Texture
uniform sampler2D tex;

void main&#40;&#41; &#123;
	vec4 color;
	
	// If there is clut
	if &#40;clutUse&#41; &#123;
		// tex must have GL_NEAR
		color = texture2D&#40;tex, gl_TexCoord&#91;0&#93;.st&#41;;
		color = texture1D&#40;clut, color.r + clutOffset&#41;;
	&#125; else &#123;
		if &#40;textureUse&#41; &#123;
			color = gl_Color * texture2D&#40;tex, gl_TexCoord&#91;0&#93;.st&#41;;
		&#125; else &#123;
			color = gl_Color;
		&#125;
	&#125;
	
	gl_FragColor = color;
&#125;
I pass weights per vertex and bone matrixes, to vertex shader.
But it's obviusly bad implemented:

Code: Select all

void doSkinning&#40;inout vec4 vertex&#41; &#123;
	vec4 pos = vec4&#40;0, 0, 0, 0&#41;;
	
	for &#40;int n = 0; n < morphCount; n++&#41; &#123;
		pos += &#40;morphWeight&#91;n&#93; * vertex&#41; * &#40;transpose&#40;BoneMatrix&#91;n&#93;&#41; * morphWeight&#91;n&#93;&#41;;
	&#125;
	
	vertex = pos;
&#125;
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.
soywiz
Posts: 2
Joined: Tue Feb 26, 2008 1:29 am

Re: Skinning (samples/gu/skinning)

Post by soywiz »

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.
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

You skinning code should look more like that:

Code: Select all

void doSkinning&#40;inout vec4 vertex, in float boneWeight&#91;&#93;&#41; &#123; 
   vec4 pos = vec4&#40;0, 0, 0, 0&#41;; 
    
   for &#40;int n = 0; n < weightCount; n++&#41; &#123; 
      pos += &#40;BoneMatrix&#91;n&#93; * vertex&#41; * boneWeight&#91;n&#93;;
   &#125; 
    
   vertex = pos; 
&#125;
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).
noxa
Posts: 39
Joined: Sat Aug 05, 2006 9:03 am
Contact:

Post by noxa »

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 :)
Post Reply