Game Development Reference
In-Depth Information
SkinIndex : This is a vec4attribute value that holds the indices of the offset
matrices ( boneGlobalMatrices ) affecting the vertex in question.
skinWeight : This is a vec4attribute value that holds the weights of the
corresponding bones in the skinIndices array affecting the vertex.
The vertex shader code for loading the skinned model is as follows:
<script id="shader-vs" type="x-shader/x-vertex">
const int MAX_BONES = 100;
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
uniform mat4 mVMatrix;
uniform mat4 pMatrix;
uniform mat4 nMatrix;
...
uniform bool useSkinning;
uniform mat4 boneGlobalMatrices[ MAX_BONES ];
attribute vec4 skinIndex;
attribute vec4 skinWeight;
mat4 getBoneMatrix( const in float i ) {
mat4 bone = boneGlobalMatrices[ int(i) ];
return bone;
}
void main(void) {
...
if(useSkinning) {
mat4 boneMatX = getBoneMatrix( skinIndex.x );
mat4 boneMatY = getBoneMatrix( skinIndex.y );
vec4 skinVertex = vec4(aVertexPosition, 1.0);
vec4 skinned = boneMatX * skinVertex * skinWeight.x;
skinned += boneMatY * skinVertex * skinWeight.y;
skinned=mVMatrix *skinned;
vertexPos = skinned.xyz;
gl_Position= pMatrix*skinned;
mat4 skinMatrix = skinWeight.x * boneMatX;
skinMatrix += skinWeight.y * boneMatY;
vec4 skinnedNormal = skinMatrix * vec4( aVertexNormal, 0.0 );
transformedNormal = vec3(nMatrix * skinnedNormal);
}else{
gl_Position= pMatrix *vertexPos4;
}
...
}
</script>
 
Search WWH ::




Custom Search