PDA

View Full Version : Skinned mesh?



marksibly
08-08-2006, 03:15 PM
Hi,

I'm trying to get some skinning going in shaderland.

Is this basically the right approach? I was mildly suprised to find you can't have int attributes so the int(...) stuff looks ugly to me.

It's also a tad slow - perhaps there's a better way?

...
attribute vec4 _vertexIndices;
attribute vec3 _vertexWeights;
...
uniform mat4 _vertexMatrices[32];
uniform mat3 _cofactorMatrices[32];
...
void main(){
...
int i0=int(_vertexIndices.x);
int i1=int(_vertexIndices.y);
int i2=int(_vertexIndices.z);
int i3=int(_vertexIndices.w);

float w0=_vertexWeights.x;
float w1=_vertexWeights.y;
float w2=_vertexWeights.z;
float w3=1.0-(w0+w1+w2);

bmx_VertexPosition=(
_vertexMatrices[i0]*bmx_VertexPosition*w0+
_vertexMatrices[i1]*bmx_VertexPosition*w1+
_vertexMatrices[i2]*bmx_VertexPosition*w2+
_vertexMatrices[i3]*bmx_VertexPosition*w3 );

bmx_VertexNormal=normalize(
_cofactorMatrices[i0]*bmx_VertexNormal*w0+
_cofactorMatrices[i1]*bmx_VertexNormal*w1+
_cofactorMatrices[i2]*bmx_VertexNormal*w2+
_cofactorMatrices[i3]*bmx_VertexNormal*w3 );

bmx_VertexTangent.xyz=normalize(
_cofactorMatrices[i0]*bmx_VertexTangent.xyz*w0+
_cofactorMatrices[i1]*bmx_VertexTangent.xyz*w1+
_cofactorMatrices[i2]*bmx_VertexTangent.xyz*w2+
_cofactorMatrices[i3]*bmx_VertexTangent.xyz*w3 );Bye!

Mark

Relic
08-09-2006, 12:53 AM
This will get you into trouble:
uniform mat4 _vertexMatrices[32];
uniform mat3 _cofactorMatrices[32];
It's using up 224 vectors and might not run in HW or compile on some implementations.